Skip to content

Commit

Permalink
refactor: expose Tailwind preset from package
Browse files Browse the repository at this point in the history
  • Loading branch information
kripod committed Dec 10, 2023
1 parent ab5e97c commit 9e74f8b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 38 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"*.css"
],
"type": "module",
"exports": "./dist/mod.js",
"exports": {
".": "./dist/mod.js",
"./tailwind-preset": "./dist/tailwind-preset.js"
},
"files": [
"dist/",
"src/",
Expand Down
1 change: 1 addition & 0 deletions rollup.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const outDir = "dist";
module.exports = defineConfig({
input: {
mod: `${rootDir}/mod.ts`,
"tailwind-preset": `${rootDir}/tailwind-preset.ts`,
},
output: [
{
Expand Down
42 changes: 42 additions & 0 deletions src/tailwind-preset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import colors from "@evilmartians/harmony/tailwind";
import type { Config } from "tailwindcss";
import defaultTheme from "tailwindcss/defaultTheme";
import plugin from "tailwindcss/plugin";

import { darkTheme, lightTheme } from "./themes";

export default {
future: {
hoverOnlyWhenSupported: true,
respectDefaultRingColorOpacity: true,
disableColorOpacityUtilitiesByDefault: true,
relativeContentPathsByDefault: true,
},
theme: {
colors,
extend: {
borderColor: ({ theme }) => ({
DEFAULT: theme("colors.ui.neutral-2") as string,
}),
colors: {
ui: Object.fromEntries(
Object.entries(lightTheme).map(([key, value]) => [
key.slice("--color-".length),
`oklch(var(${key}, ${value}) / <alpha-value>)`,
]),
),
},
transitionTimingFunction: {
DEFAULT: defaultTheme.transitionTimingFunction.out,
},
},
},
plugins: [
plugin(({ addComponents }) => {
addComponents({
".theme-light": lightTheme,
".theme-dark": darkTheme,
});
}),
],
} satisfies Partial<Config>;
File renamed without changes.
39 changes: 2 additions & 37 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,8 @@
import colors from "@evilmartians/harmony/tailwind";
import type { Config } from "tailwindcss";
import defaultTheme from "tailwindcss/defaultTheme";
import plugin from "tailwindcss/plugin";

import { darkTheme, lightTheme } from "./themes";
import tailwindPreset from "./src/tailwind-preset";

export default {
content: ["./src/**/*.{js,jsx,ts,tsx}"],
future: {
hoverOnlyWhenSupported: true,
respectDefaultRingColorOpacity: true,
disableColorOpacityUtilitiesByDefault: true,
relativeContentPathsByDefault: true,
},
theme: {
colors,
extend: {
borderColor: ({ theme }) => ({
DEFAULT: theme("colors.ui.neutral-2") as string,
}),
colors: {
ui: Object.fromEntries(
Object.entries(lightTheme).map(([key, value]) => [
key.slice("--color-".length),
`oklch(var(${key}, ${value}) / <alpha-value>)`,
]),
),
},
transitionTimingFunction: {
DEFAULT: defaultTheme.transitionTimingFunction.out,
},
},
},
plugins: [
plugin(({ addComponents }) => {
addComponents({
".theme-light": lightTheme,
".theme-dark": darkTheme,
});
}),
],
presets: [tailwindPreset],
} satisfies Config;

0 comments on commit 9e74f8b

Please sign in to comment.