Skip to content

Commit

Permalink
feat: simplify tailwind config by introducing tailwind config wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
sapkra committed Apr 9, 2024
1 parent 8c36e68 commit 8359e43
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"bradlc.vscode-tailwindcss"
]
}
5 changes: 5 additions & 0 deletions src/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tailwindCSS.experimental.classRegex": [
["tv\\((([^()]*|\\([^()]*\\))*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"]
]
}
30 changes: 28 additions & 2 deletions src/tailwind.plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { NextUIPluginConfig, nextui } from "@nextui-org/react";
import defaultsDeep from "lodash.defaultsdeep";
import { Config } from "tailwindcss";
import plugin from "tailwindcss/plugin"
import { withTV } from 'tailwind-variants/transformer';

export const fragmentui = () => plugin(function({ addBase, config }) {
addBase({
Expand All @@ -8,11 +12,33 @@ export const fragmentui = () => plugin(function({ addBase, config }) {
},
'h2': {
fontSize: config('theme.fontSize.2xl'),
fontWeight: config('theme.fontWeight.bold'),
fontWeight: config('theme.fontWeight.semibold'),
},
'h3': {
fontSize: config('theme.fontSize.xl'),
fontWeight: config('theme.fontWeight.bold'),
fontWeight: config('theme.fontWeight.semibold'),
},
});
});

interface TailwindFragmentOptions {
nextUIPluginConfig?: NextUIPluginConfig;
}

export const withTailwindFragment = (config: Config, options?: TailwindFragmentOptions): Config => withTV({
darkMode: 'class',
...config,
plugins: [
...(config.plugins ?? []),
fragmentui(),
nextui(defaultsDeep(options?.nextUIPluginConfig ?? {}, {
themes: {
dark: {
colors: {
background: '#131316',
}
},
},
})),
],
});
20 changes: 3 additions & 17 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
import type { Config } from 'tailwindcss';
import { nextui } from '@nextui-org/react';
import { fragmentui } from './src/tailwind.plugin';
import { withTailwindFragment } from './src/tailwind.plugin';

const config: Config = {
const config: Config = withTailwindFragment({
content: [
'./src/**/*.{js,jsx,ts,tsx}',
'./node_modules/@nextui-org/theme/dist/**/*.{js,ts,jsx,tsx}',
],
theme: {
extend: {},
},
darkMode: 'class',
plugins: [
fragmentui(),
nextui({
themes: {
dark: {
colors: {
background: '#131316',
}
},
},
}),
],
};
});

export default config;

0 comments on commit 8359e43

Please sign in to comment.