Skip to content

Commit 3e146fe

Browse files
committed
feat(docs): add dark mode configuration support
- Introduced `dark` option in `.flowbite-react/config.json` to enable dark mode styles. - Implemented functionality to strip dark mode classes from generated styles.
1 parent f2d0b29 commit 3e146fe

File tree

15 files changed

+181
-5
lines changed

15 files changed

+181
-5
lines changed

apps/storybook/.flowbite-react/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"$schema": "../../../node_modules/flowbite-react/schema.json",
33
"components": [],
4+
"dark": true,
45
"path": "src/components",
56
"prefix": "",
67
"rsc": true,

apps/web/.flowbite-react/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"$schema": "../../../node_modules/flowbite-react/schema.json",
33
"components": [],
4+
"dark": true,
45
"path": "components",
56
"prefix": "",
67
"rsc": true,

apps/web/content/docs/customize/config.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ The configuration file follows this JSON Schema:
6464
- Use `"*"` to explicitly include all components (equivalent to listing every component)
6565
- When not using `"*"`, use valid component names (e.g., `Button`, `Card`, `Modal`). See the [schema](https://unpkg.com/flowbite-react/schema.json) for the full list of valid components.
6666

67+
#### `dark`
68+
69+
- Type: `boolean`
70+
- Default: `true`
71+
- Description: Whether to generate dark mode styles.
72+
6773
#### `path`
6874

6975
- Type: `string`

apps/web/content/docs/getting-started/cli.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ The CLI creates a `.flowbite-react/config.json` file with several configuration
229229
{
230230
"$schema": "https://unpkg.com/flowbite-react/schema.json",
231231
"components": [],
232+
"dark": true,
232233
"path": "src/components",
233234
"prefix": "",
234235
"rsc": true,
@@ -240,6 +241,10 @@ The CLI creates a `.flowbite-react/config.json` file with several configuration
240241

241242
List of component names to generate styles for. An empty array enables automatic detection.
242243

244+
#### `dark`
245+
246+
Whether to generate dark mode styles. Default is `true`.
247+
243248
#### `path`
244249

245250
Path where components will be created, relative to the project root. Default is `"src/components"`.

packages/ui/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@
116116
},
117117
"uniqueItems": true
118118
},
119+
"dark": {
120+
"description": "Whether to generate dark mode styles. \nSee https://flowbite-react.com/docs/customize/config#dark for more details.",
121+
"type": "boolean",
122+
"default": true
123+
},
119124
"path": {
120125
"description": "Path where components will be created, relative to the project root. \nSee https://flowbite-react.com/docs/customize/config#path for more details.",
121126
"type": "string",

packages/ui/scripts/generate-metadata.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ async function generateSchema(components: string[]): Promise<void> {
219219
},
220220
uniqueItems: true,
221221
},
222+
dark: {
223+
description:
224+
"Whether to generate dark mode styles. \nSee https://flowbite-react.com/docs/customize/config#dark for more details.",
225+
type: "boolean",
226+
default: true,
227+
},
222228
path: {
223229
description:
224230
"Path where components will be created, relative to the project root. \nSee https://flowbite-react.com/docs/customize/config#path for more details.",

packages/ui/src/cli/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,9 @@ export async function dev() {
270270

271271
const config = await getConfig();
272272
const newClassList = buildClassList({
273-
prefix: config.prefix,
274273
components: config.components.length ? config.components : newImportedComponents,
274+
dark: config.dark,
275+
prefix: config.prefix,
275276
});
276277

277278
if (!isEqual(classList, newClassList)) {
@@ -504,6 +505,7 @@ export async function setupConfig() {
504505
const defaultConfig: Config = {
505506
$schema: "https://unpkg.com/flowbite-react/schema.json",
506507
components: [],
508+
dark: true,
507509
prefix: "",
508510
path: "src/components",
509511
tsx: true,

packages/ui/src/cli/utils/build-class-list.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { applyPrefix } from "../../helpers/apply-prefix";
22
import { applyPrefixV3 } from "../../helpers/apply-prefix-v3";
33
import { convertUtilitiesToV4 } from "../../helpers/convert-utilities-to-v4";
44
import { getTailwindVersion } from "../../helpers/get-tailwind-version";
5+
import { stripDark } from "../../helpers/strip-dark";
56
import { CLASS_LIST_MAP, COMPONENT_TO_CLASS_LIST_MAP } from "../../metadata/class-list";
67
import { DEPENDENCY_LIST_MAP } from "../../metadata/dependency-list";
78

@@ -10,10 +11,19 @@ import { DEPENDENCY_LIST_MAP } from "../../metadata/dependency-list";
1011
*
1112
* @param {Object} options - The options for building the class list.
1213
* @param {string[]} options.components - The components to include in the class list.
14+
* @param {boolean} options.dark - Whether to include dark mode classes.
1315
* @param {string} options.prefix - The prefix to apply to the class names.
1416
* @returns {string[]} The sorted list of CSS classes.
1517
*/
16-
export function buildClassList({ components, prefix }: { components: string[]; prefix: string }): string[] {
18+
export function buildClassList({
19+
components,
20+
dark,
21+
prefix,
22+
}: {
23+
components: string[];
24+
dark: boolean;
25+
prefix: string;
26+
}): string[] {
1727
const version = getTailwindVersion();
1828

1929
let classList: string[] = [];
@@ -59,6 +69,9 @@ export function buildClassList({ components, prefix }: { components: string[]; p
5969
];
6070
}
6171

72+
if (dark === false) {
73+
classList = classList.map(stripDark);
74+
}
6275
if (version === 4) {
6376
classList = classList.map(convertUtilitiesToV4);
6477
}

packages/ui/src/cli/utils/get-config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { configFilePath } from "../consts";
44
export interface Config {
55
$schema: string;
66
components: string[];
7+
dark: boolean;
78
path: string;
89
prefix: string;
910
rsc: boolean;
@@ -22,6 +23,7 @@ export async function getConfig(): Promise<Config> {
2223
const config: Config = {
2324
$schema: "",
2425
components: [],
26+
dark: true,
2527
path: "src/components",
2628
prefix: "",
2729
rsc: true,
@@ -38,6 +40,9 @@ export async function getConfig(): Promise<Config> {
3840
if (parsed.components !== undefined && Array.isArray(parsed.components)) {
3941
config.components = parsed.components.map((component) => component.trim()).filter(Boolean);
4042
}
43+
if (parsed.dark !== undefined && typeof parsed.dark === "boolean") {
44+
config.dark = parsed.dark;
45+
}
4146
if (parsed.path !== undefined && typeof parsed.path === "string") {
4247
config.path = parsed.path;
4348
}

packages/ui/src/helpers/get-tailwind-version.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import colors from "tailwindcss/colors.js";
22

33
/**
44
* Gets the major version number of the installed Tailwind CSS
5+
*
56
* @returns The major version number (3 or 4) or undefined if not found
67
*/
78
export function getTailwindVersion(): 3 | 4 | undefined {

0 commit comments

Comments
 (0)