Skip to content

Commit 120188f

Browse files
committed
refactor(theme): refactor enums to use them similarly in root.tsx, make-it-yours and setup-tailwind-generator
1 parent 8fe23ef commit 120188f

File tree

14 files changed

+567
-391
lines changed

14 files changed

+567
-391
lines changed

apps/website/src/_state/make-it-yours.ts

Lines changed: 0 additions & 48 deletions
This file was deleted.

apps/website/src/components/make-it-yours/make-it-yours.tsx

Lines changed: 302 additions & 270 deletions
Large diffs are not rendered by default.

apps/website/src/root.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ import { RouterHead } from './components/router-head/router-head';
1111
import globalStyles from './global.css?inline';
1212

1313
import { ThemeProvider } from 'qwik-themes';
14-
import {
15-
baseOptions,
16-
borderRadiusOptions,
17-
modeOptions,
18-
primaryOptions,
19-
styleOptions,
20-
fontOptions,
21-
} from './_state/make-it-yours';
2214

2315
import '@fontsource-variable/inter';
2416
import '@fontsource/ibm-plex-mono';
2517
import '@fontsource/source-serif-pro';
2618
import '@fontsource/londrina-shadow';
2719
import '@fontsource/rubik-doodle-shadow';
20+
import {
21+
ThemeBaseColor,
22+
ThemeBorderRadius,
23+
ThemeFont,
24+
ThemeMode,
25+
ThemePrimaryColor,
26+
ThemeStyle,
27+
} from '@qwik-ui/utils';
2828

2929
export default component$(() => {
3030
/**
@@ -57,12 +57,12 @@ export default component$(() => {
5757
attribute="class"
5858
enableSystem={false}
5959
themes={[
60-
...modeOptions,
61-
...fontOptions,
62-
...styleOptions,
63-
...baseOptions,
64-
...primaryOptions,
65-
...borderRadiusOptions,
60+
...Object.values(ThemeFont),
61+
...Object.values(ThemeMode),
62+
...Object.values(ThemeStyle),
63+
...Object.values(ThemeBaseColor),
64+
...Object.values(ThemePrimaryColor),
65+
...Object.values(ThemeBorderRadius),
6666
]}
6767
>
6868
<RouterOutlet />

packages/cli/src/generators/setup-tailwind/setup-tailwind-generator.spec.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
2-
import { ThemeStyle } from '@qwik-ui/utils';
2+
import { ThemeBorderRadius, ThemePrimaryColor, ThemeStyle } from '@qwik-ui/utils';
33
import { SetupTailwindGeneratorSchema } from './schema';
44
import { setupTailwindGenerator } from './setup-tailwind-generator';
55

@@ -416,7 +416,7 @@ html {
416416

417417
test(`
418418
GIVEN no options are passed
419-
THEN it should generate "simple" style with primary color "cyan-600", base color "slate" and border-radios 0`, async () => {
419+
THEN it should generate "simple" style with primary color "cyan-600", base color "slate" and border-radius 0`, async () => {
420420
const { tree, options } = setupWithProperFiles();
421421

422422
options.rootCssPath = 'src/global.css';
@@ -443,8 +443,8 @@ html {
443443
--input: 214.3 31.8% 91.4%;
444444
--primary: 191.6 91.4% 36.5%;
445445
--primary-foreground: 0 0% 100%;
446-
--secondary: 222.2 47.4% 11.2%;
447-
--secondary-foreground: 0 0% 100%;
446+
--secondary: 214.3 31.8% 91.4%;
447+
--secondary-foreground: 0 0% 0%;
448448
--accent: 210 40% 96.1%;
449449
--accent-foreground: 222.2 47.4% 11.2%;
450450
--alert: 0 84.2% 60.2%;
@@ -478,7 +478,7 @@ html {
478478
--input: 217.2 32.6% 17.5%;
479479
--primary: 191.6 91.4% 36.5%;
480480
--primary-foreground: 0 0% 100%;
481-
--secondary: 210 40% 96.1%;
481+
--secondary: 214.3 31.8% 91.4%;
482482
--secondary-foreground: 0 0% 0%;
483483
--accent: 217.2 32.6% 17.5%;
484484
--accent-foreground: 210 40% 98%;
@@ -513,13 +513,13 @@ html {
513513
`);
514514
});
515515
test(`
516-
GIVEN style is "brutalist" and primary color is "red-600" and border-radios is 1
516+
GIVEN style is "brutalist" and primary color is "red-600" and border-radius is 1
517517
THEN it should generate the correct theme`, async () => {
518518
const { tree, options } = setupWithProperFiles();
519519

520520
options.rootCssPath = 'src/global.css';
521-
options.borderRadius = 'border-radius-1';
522-
options.primaryColor = 'red-600';
521+
options.borderRadius = ThemeBorderRadius['BORDER-RADIUS-1'];
522+
options.primaryColor = ThemePrimaryColor.RED600;
523523
options.style = ThemeStyle.BRUTALIST;
524524

525525
await setupTailwindGenerator(tree, options);
@@ -544,8 +544,8 @@ html {
544544
--input: 0 0% 0%;
545545
--primary: 0 72.2% 50.6%;
546546
--primary-foreground: 0 0% 100%;
547-
--secondary: 222.2 47.4% 11.2%;
548-
--secondary-foreground: 0 0% 100%;
547+
--secondary: 214.3 31.8% 91.4%;
548+
--secondary-foreground: 0 0% 0%;
549549
--accent: 210 40% 96.1%;
550550
--accent-foreground: 222.2 47.4% 11.2%;
551551
--alert: 0 84.2% 60.2%;
@@ -576,7 +576,7 @@ html {
576576
--input: 0 0% 0%;
577577
--primary: 0 72.2% 50.6%;
578578
--primary-foreground: 0 0% 100%;
579-
--secondary: 210 40% 96.1%;
579+
--secondary: 214.3 31.8% 91.4%;
580580
--secondary-foreground: 0 0% 0%;
581581
--accent: 217.2 32.6% 17.5%;
582582
--accent-foreground: 210 40% 98%;

packages/cli/src/generators/setup-tailwind/setup-tailwind-generator.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Tree, formatFiles, joinPathFragments, workspaceRoot } from '@nx/devkit';
22
import {
3-
Color,
43
ThemeStyle,
54
extractBetweenComments,
65
extractThemeCSS,
76
type ThemeConfig,
7+
ThemePrimaryColor,
8+
ThemeBorderRadius,
9+
ThemeBaseColor,
810
} from '@qwik-ui/utils';
911
import { readFileSync } from 'fs';
1012
import { join } from 'path';
@@ -22,10 +24,9 @@ export async function setupTailwindGenerator(
2224
options.projectRoot = options.projectRoot ?? '';
2325

2426
options.style = options.style ?? ThemeStyle.SIMPLE;
25-
options.primaryColor = options.primaryColor ?? Color.CYAN + '-600';
26-
options.primaryColor = 'primary-' + options.primaryColor;
27+
options.primaryColor = options.primaryColor ?? ThemePrimaryColor.CYAN600;
2728

28-
options.borderRadius = options.borderRadius ?? 'border-radius-0';
29+
options.borderRadius = options.borderRadius ?? ThemeBorderRadius['BORDER-RADIUS-0'];
2930

3031
updateTailwindConfig(tree, options.projectRoot, kitRoot);
3132

@@ -180,7 +181,7 @@ function updateRootCss(
180181
kitRoot: string,
181182
themeConfig: ThemeConfig,
182183
) {
183-
themeConfig.baseColor = 'base-' + Color.SLATE;
184+
themeConfig.baseColor = ThemeBaseColor.SLATE;
184185

185186
const rootCssContent = tree.read(globalCssPath, 'utf-8');
186187

packages/utils/src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
export * from './cn';
2-
export * from './theme/base-color.enum';
3-
export * from './theme/border-radius.type';
4-
export * from './theme/color.enum';
52
export * from './theme/extract-between-comments';
63
export * from './theme/extract-theme-css';
7-
export * from './theme/font.enum';
8-
export * from './theme/mode.enum';
94
export * from './theme/theme-config.type';
5+
export * from './theme/theme-base-color.enum';
6+
export * from './theme/theme-border-radius.enum';
7+
export * from './theme/theme-primary-color.enum';
8+
export * from './theme/theme-font.enum';
9+
export * from './theme/theme-mode-enum';
1010
export * from './theme/theme-style.enum';

packages/utils/src/theme/border-radius.type.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/utils/src/theme/color.enum.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

packages/utils/src/theme/base-color.enum.ts renamed to packages/utils/src/theme/theme-base-color.enum.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export enum BaseColor {
1+
export enum ThemeBaseColor {
22
SLATE = 'base-slate',
33
GRAY = 'base-gray',
44
ZINC = 'base-zinc',
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export enum ThemeBorderRadius {
2+
'BORDER-RADIUS-0' = 'border-radius-0',
3+
'BORDER-RADIUS-DOT-25' = 'border-radius-dot-25',
4+
'BORDER-RADIUS-DOT-50' = 'border-radius-dot-50',
5+
'BORDER-RADIUS-DOT-75' = 'border-radius-dot-75',
6+
'BORDER-RADIUS-1' = 'border-radius-1',
7+
}

0 commit comments

Comments
 (0)