Skip to content

Commit 087f517

Browse files
committed
feat: variantNameOnly
1 parent e1cd72d commit 087f517

5 files changed

Lines changed: 306 additions & 108 deletions

File tree

.changeset/bold-towns-exist.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@hebilicious/cssforge": minor
3+
---
4+
5+
# Introduce variantNameOnly feature for themes.
6+
7+
When working with themes, you can choose to only include the variant name in the CSS variable name by setting
8+
`variantNameOnly: true` in the color definition settings. This is usually used in combination with `condition` to conditionnally apply themes.
9+
10+
- Default: `--theme-${themeName}-${colorName}-${variantName}`
11+
- VariantOnly Name: `--${variantName}`
12+
- Path : `theme.${themeName}.${colorName}.${variantName}`

README.md

Lines changed: 168 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,10 @@ export default defineConfig({
247247
},
248248
variables: {
249249
1: "palette.simple.white",
250-
2: "gradients.white-green.primary",
250+
2: "gradients.white-green.primary", //Reference the color name directly.
251+
},
252+
settings: {
253+
variantNameOnly: true,
251254
},
252255
},
253256
},
@@ -263,12 +266,35 @@ export default defineConfig({
263266
1: "palette.another.yellow",
264267
2: "palette.another.cyan",
265268
},
269+
settings: {
270+
variantNameOnly: true,
271+
},
266272
},
267273
},
268274
settings: {
269275
condition: "@media (prefers-color-scheme: dark)",
270276
},
271277
},
278+
pink: {
279+
value: {
280+
background: {
281+
value: {
282+
primary: "var(--1)",
283+
secondary: "var(--2)",
284+
},
285+
variables: {
286+
1: "palette.simple.red",
287+
2: "palette.simple.violet",
288+
},
289+
settings: {
290+
variantNameOnly: true,
291+
},
292+
},
293+
},
294+
settings: {
295+
condition: ".ThemePink",
296+
},
297+
},
272298
},
273299
},
274300
});
@@ -325,7 +351,10 @@ export default defineConfig({
325351
},
326352
variables: {
327353
1: "palette.simple.white",
328-
2: "gradients.white-green", //Reference the color name directly.
354+
2: "gradients.white-green.primary", //Reference the color name directly.
355+
},
356+
settings: {
357+
variantNameOnly: true,
329358
},
330359
},
331360
},
@@ -341,12 +370,35 @@ export default defineConfig({
341370
1: "palette.another.yellow",
342371
2: "palette.another.cyan",
343372
},
373+
settings: {
374+
variantNameOnly: true,
375+
},
344376
},
345377
},
346378
settings: {
347379
condition: "@media (prefers-color-scheme: dark)",
348380
},
349381
},
382+
pink: {
383+
value: {
384+
background: {
385+
value: {
386+
primary: "var(--1)",
387+
secondary: "var(--2)",
388+
},
389+
variables: {
390+
1: "palette.simple.red",
391+
2: "palette.simple.violet",
392+
},
393+
settings: {
394+
variantNameOnly: true,
395+
},
396+
},
397+
},
398+
settings: {
399+
condition: ".ThemePink",
400+
},
401+
},
350402
},
351403
},
352404
});
@@ -357,40 +409,58 @@ This will generate the following CSS :
357409
```css
358410
/*____ CSSForge ____*/
359411
:root {
360-
/*____ Colors ____*/
361-
/* Palette */
362-
/* simple */
363-
--palette-simple-white: oklch(100% 0 0);
364-
--palette-simple-black: oklch(0% 0 0);
365-
--palette-simple-green: oklch(86.644% 0.29483 142.49535);
366-
--palette-simple-blue: oklch(45.201% 0.31321 264.05202);
367-
--palette-simple-violet: oklch(70% 0.2 270);
368-
--palette-simple-red: oklch(62.796% 0.25768 29.23388);
369-
.Another {
370-
/* another */
371-
--palette-another-yellow: oklch(96.798% 0.21101 109.76924);
372-
--palette-another-cyan: oklch(90.54% 0.15455 194.76896);
373-
}
374-
/* Gradients */
375-
--gradients-white-green-primary: linear-gradient(
376-
to right,
377-
var(--palette-simple-white),
378-
var(--palette-simple-green)
379-
);
380-
/* Themes */
381-
/* Theme: light */
412+
/*____ Colors ____*/
413+
/* Palette */
414+
/* simple */
415+
--palette-simple-white: oklch(100% 0 0);
416+
--palette-simple-black: oklch(0% 0 0);
417+
--palette-simple-green: oklch(86.644% 0.29483 142.49535);
418+
--palette-simple-blue: oklch(45.201% 0.31321 264.05202);
419+
--palette-simple-violet: oklch(70% 0.2 270);
420+
--palette-simple-red: oklch(62.796% 0.25768 29.23388);
421+
/* another */
422+
.Another {
423+
--palette-another-yellow: oklch(96.798% 0.21101 109.76924);
424+
--palette-another-cyan: oklch(90.54% 0.15455 194.76896);
425+
}
426+
/* Gradients */
427+
/* white-green */
428+
--gradients-white-green-primary: linear-gradient(to right, var(--palette-simple-white), var(--palette-simple-green));
429+
/* Themes */
430+
/* Theme: light */
431+
/* background */
432+
--primary: var(--palette-simple-white);
433+
--secondary: var(--gradients-white-green-primary);
434+
/* Theme: dark */
435+
@media (prefers-color-scheme: dark) {
382436
/* background */
383-
@media (prefers-color-scheme: dark) {
384-
/* Theme: dark */
385-
/* background */
386-
--theme-dark-background-primary: var(--palette-another-yellow);
387-
--theme-dark-background-secondary: var(--palette-another-cyan);
388-
}
437+
--primary: var(--palette-another-yellow);
438+
--secondary: var(--palette-another-cyan);
439+
}
440+
/* Theme: pink */
441+
.ThemePink {
442+
/* background */
443+
--primary: var(--palette-simple-red);
444+
--secondary: var(--palette-simple-violet);
445+
}
389446
}
390447
```
391448

392449
<!-- /md:generate -->
393450

451+
#### Condition
452+
453+
You can conditionnally apply colors, gradients or themes by setting the `condition` property to a selector or media query. Your variables will be wrapped within the condition.
454+
455+
#### Theme: Variant Name Only
456+
457+
When working with themes, you can choose to only include the variant name in the CSS variable name by setting
458+
`variantNameOnly: true` in the color definition settings. This is usually used in combination with `condition` to conditionnally apply themes.
459+
460+
- Default: `--theme-${themeName}-${colorName}-${variantName}`
461+
- VariantOnly Name: `--${variantName}`
462+
- Path : `theme.${themeName}.${colorName}.${variantName}`
463+
394464
### Spacing
395465

396466
Define custom spacing scale, that can be referenced for other types, such as primitives.
@@ -438,11 +508,11 @@ This will generate the following CSS :
438508
```css
439509
/*____ CSSForge ____*/
440510
:root {
441-
/*____ Spacing ____*/
442-
--spacing-size-1: 0.25rem;
443-
--spacing-size-2: 0.5rem;
444-
--spacing-size-3: 0.75rem;
445-
--spacing-size-4: 1rem;
511+
/*____ Spacing ____*/
512+
--spacing-size-1: 0.25rem;
513+
--spacing-size-2: 0.5rem;
514+
--spacing-size-3: 0.75rem;
515+
--spacing-size-4: 1rem;
446516
}
447517
```
448518

@@ -499,12 +569,12 @@ This will generate the following CSS :
499569
```css
500570
/*____ CSSForge ____*/
501571
:root {
502-
/*____ Spacing ____*/
503-
--spacing_fluid-base-hi-xs: clamp(0rem, 0rem + 0vw, 0rem);
504-
--spacing_fluid-base-hi-s: clamp(0.25rem, -0.1667rem + 2.0833vw, 1.5rem);
505-
--spacing_fluid-base-hi-m: clamp(0.75rem, -0.5rem + 6.25vw, 4.5rem);
506-
--spacing_fluid-base-hi-xs-s: clamp(0rem, -0.5rem + 2.5vw, 1.5rem);
507-
--spacing_fluid-base-hi-s-m: clamp(0.25rem, -1.1667rem + 7.0833vw, 4.5rem);
572+
/*____ Spacing ____*/
573+
--spacing_fluid-base-hi-xs: clamp(0rem, 0rem + 0vw, 0rem);
574+
--spacing_fluid-base-hi-s: clamp(0.25rem, -0.1667rem + 2.0833vw, 1.5rem);
575+
--spacing_fluid-base-hi-m: clamp(0.75rem, -0.5rem + 6.25vw, 4.5rem);
576+
--spacing_fluid-base-hi-xs-s: clamp(0rem, -0.5rem + 2.5vw, 1.5rem);
577+
--spacing_fluid-base-hi-s-m: clamp(0.25rem, -1.1667rem + 7.0833vw, 4.5rem);
508578
}
509579
```
510580

@@ -567,26 +637,26 @@ This will generate the following CSS :
567637
```css
568638
/*____ CSSForge ____*/
569639
:root {
570-
/*____ Spacing ____*/
571-
--spacing_fluid-base-smooth-3xs: clamp(0.0625rem, -0.0417rem + 0.5208vw, 0.375rem);
572-
--spacing_fluid-base-smooth-2xs: clamp(0.125rem, -0.0833rem + 1.0417vw, 0.75rem);
573-
--spacing_fluid-base-smooth-xs: clamp(0.1875rem, -0.125rem + 1.5625vw, 1.125rem);
574-
--spacing_fluid-base-smooth-s: clamp(0.25rem, -0.1667rem + 2.0833vw, 1.5rem);
575-
--spacing_fluid-base-smooth-m: clamp(0.375rem, -0.25rem + 3.125vw, 2.25rem);
576-
--spacing_fluid-base-smooth-l: clamp(0.5rem, -0.3333rem + 4.1667vw, 3rem);
577-
--spacing_fluid-base-smooth-xl: clamp(0.75rem, -0.5rem + 6.25vw, 4.5rem);
578-
--spacing_fluid-base-smooth-2xl: clamp(1rem, -0.6667rem + 8.3333vw, 6rem);
579-
--spacing_fluid-base-smooth-3xl: clamp(1.5rem, -1rem + 12.5vw, 9rem);
580-
--spacing_fluid-base-smooth-3xs-2xs: clamp(0.0625rem, -0.1667rem + 1.1458vw, 0.75rem);
581-
--spacing_fluid-base-smooth-2xs-xs: clamp(0.125rem, -0.2083rem + 1.6667vw, 1.125rem);
582-
--spacing_fluid-base-smooth-xs-s: clamp(0.1875rem, -0.25rem + 2.1875vw, 1.5rem);
583-
--spacing_fluid-base-smooth-s-m: clamp(0.25rem, -0.4167rem + 3.3333vw, 2.25rem);
584-
--spacing_fluid-base-smooth-m-l: clamp(0.375rem, -0.5rem + 4.375vw, 3rem);
585-
--spacing_fluid-base-smooth-l-xl: clamp(0.5rem, -0.8333rem + 6.6667vw, 4.5rem);
586-
--spacing_fluid-base-smooth-xl-2xl: clamp(0.75rem, -1rem + 8.75vw, 6rem);
587-
--spacing_fluid-base-smooth-2xl-3xl: clamp(1rem, -1.6667rem + 13.3333vw, 9rem);
588-
--spacing-gap-1: 0.25rem;
589-
--spacing-gap-2: 0.5rem;
640+
/*____ Spacing ____*/
641+
--spacing_fluid-base-smooth-3xs: clamp(0.0625rem, -0.0417rem + 0.5208vw, 0.375rem);
642+
--spacing_fluid-base-smooth-2xs: clamp(0.125rem, -0.0833rem + 1.0417vw, 0.75rem);
643+
--spacing_fluid-base-smooth-xs: clamp(0.1875rem, -0.125rem + 1.5625vw, 1.125rem);
644+
--spacing_fluid-base-smooth-s: clamp(0.25rem, -0.1667rem + 2.0833vw, 1.5rem);
645+
--spacing_fluid-base-smooth-m: clamp(0.375rem, -0.25rem + 3.125vw, 2.25rem);
646+
--spacing_fluid-base-smooth-l: clamp(0.5rem, -0.3333rem + 4.1667vw, 3rem);
647+
--spacing_fluid-base-smooth-xl: clamp(0.75rem, -0.5rem + 6.25vw, 4.5rem);
648+
--spacing_fluid-base-smooth-2xl: clamp(1rem, -0.6667rem + 8.3333vw, 6rem);
649+
--spacing_fluid-base-smooth-3xl: clamp(1.5rem, -1rem + 12.5vw, 9rem);
650+
--spacing_fluid-base-smooth-3xs-2xs: clamp(0.0625rem, -0.1667rem + 1.1458vw, 0.75rem);
651+
--spacing_fluid-base-smooth-2xs-xs: clamp(0.125rem, -0.2083rem + 1.6667vw, 1.125rem);
652+
--spacing_fluid-base-smooth-xs-s: clamp(0.1875rem, -0.25rem + 2.1875vw, 1.5rem);
653+
--spacing_fluid-base-smooth-s-m: clamp(0.25rem, -0.4167rem + 3.3333vw, 2.25rem);
654+
--spacing_fluid-base-smooth-m-l: clamp(0.375rem, -0.5rem + 4.375vw, 3rem);
655+
--spacing_fluid-base-smooth-l-xl: clamp(0.5rem, -0.8333rem + 6.6667vw, 4.5rem);
656+
--spacing_fluid-base-smooth-xl-2xl: clamp(0.75rem, -1rem + 8.75vw, 6rem);
657+
--spacing_fluid-base-smooth-2xl-3xl: clamp(1rem, -1.6667rem + 13.3333vw, 9rem);
658+
--spacing-gap-1: 0.25rem;
659+
--spacing-gap-2: 0.5rem;
590660
}
591661
```
592662

@@ -658,17 +728,17 @@ This will generate the following CSS :
658728
```css
659729
/*____ CSSForge ____*/
660730
:root {
661-
/*____ Typography ____*/
662-
--typography_fluid-arial-4xl: clamp(2.6703rem, 2.5608rem + 0.5474vw, 3.0518rem);
663-
--typography_fluid-arial-3xl: clamp(2.1362rem, 2.0486rem + 0.4379vw, 2.4414rem);
664-
--typography_fluid-arial-2xl: clamp(1.709rem, 1.6389rem + 0.3503vw, 1.9531rem);
665-
--typography_fluid-arial-xl: clamp(1.3672rem, 1.3111rem + 0.2803vw, 1.5625rem);
666-
--typography_fluid-arial-l: clamp(1.0938rem, 1.0489rem + 0.2242vw, 1.25rem);
667-
--typography_fluid-arial-m: clamp(0.875rem, 0.8391rem + 0.1794vw, 1rem);
668-
--typography_fluid-arial-s: clamp(0.7rem, 0.6713rem + 0.1435vw, 0.8rem);
669-
--typography_fluid-arial-xs: clamp(0.56rem, 0.537rem + 0.1148vw, 0.64rem);
670-
--typography_fluid-arial-2xs: clamp(0.448rem, 0.4296rem + 0.0918vw, 0.512rem);
671-
--typography-weight-arial-regular: 600;
731+
/*____ Typography ____*/
732+
--typography_fluid-arial-4xl: clamp(2.6703rem, 2.5608rem + 0.5474vw, 3.0518rem);
733+
--typography_fluid-arial-3xl: clamp(2.1362rem, 2.0486rem + 0.4379vw, 2.4414rem);
734+
--typography_fluid-arial-2xl: clamp(1.709rem, 1.6389rem + 0.3503vw, 1.9531rem);
735+
--typography_fluid-arial-xl: clamp(1.3672rem, 1.3111rem + 0.2803vw, 1.5625rem);
736+
--typography_fluid-arial-l: clamp(1.0938rem, 1.0489rem + 0.2242vw, 1.25rem);
737+
--typography_fluid-arial-m: clamp(0.875rem, 0.8391rem + 0.1794vw, 1rem);
738+
--typography_fluid-arial-s: clamp(0.7rem, 0.6713rem + 0.1435vw, 0.8rem);
739+
--typography_fluid-arial-xs: clamp(0.56rem, 0.537rem + 0.1148vw, 0.64rem);
740+
--typography_fluid-arial-2xs: clamp(0.448rem, 0.4296rem + 0.0918vw, 0.512rem);
741+
--typography-weight-arial-regular: 600;
672742
}
673743
```
674744

@@ -746,12 +816,12 @@ This will generate the following CSS :
746816
```css
747817
/*____ CSSForge ____*/
748818
:root {
749-
/*____ Typography ____*/
750-
--typography_fluid-comicsans-text-e: clamp(1.3672rem, 1.3111rem + 0.2803vw, 1.5625rem);
751-
--typography_fluid-comicsans-text-d: clamp(1.0938rem, 1.0489rem + 0.2242vw, 1.25rem);
752-
--typography_fluid-comicsans-text-c: clamp(0.875rem, 0.8391rem + 0.1794vw, 1rem);
753-
--typography_fluid-comicsans-text-b: clamp(0.7rem, 0.6713rem + 0.1435vw, 0.8rem);
754-
--typography_fluid-comicsans-text-a: clamp(0.56rem, 0.537rem + 0.1148vw, 0.64rem);
819+
/*____ Typography ____*/
820+
--typography_fluid-comicsans-text-e: clamp(1.3672rem, 1.3111rem + 0.2803vw, 1.5625rem);
821+
--typography_fluid-comicsans-text-d: clamp(1.0938rem, 1.0489rem + 0.2242vw, 1.25rem);
822+
--typography_fluid-comicsans-text-c: clamp(0.875rem, 0.8391rem + 0.1794vw, 1rem);
823+
--typography_fluid-comicsans-text-b: clamp(0.7rem, 0.6713rem + 0.1435vw, 0.8rem);
824+
--typography_fluid-comicsans-text-a: clamp(0.56rem, 0.537rem + 0.1148vw, 0.64rem);
755825
}
756826
```
757827

@@ -870,26 +940,26 @@ This will generate the following CSS :
870940
```css
871941
/*____ CSSForge ____*/
872942
:root {
873-
/*____ Spacing ____*/
874-
--spacing-size-2: 0.5rem;
875-
--spacing-size-3: 0.75rem;
876-
/*____ Typography ____*/
877-
--typography_fluid-arial-4xl: clamp(2.6703rem, 2.5608rem + 0.5474vw, 3.0518rem);
878-
--typography_fluid-arial-3xl: clamp(2.1362rem, 2.0486rem + 0.4379vw, 2.4414rem);
879-
--typography_fluid-arial-2xl: clamp(1.709rem, 1.6389rem + 0.3503vw, 1.9531rem);
880-
--typography_fluid-arial-xl: clamp(1.3672rem, 1.3111rem + 0.2803vw, 1.5625rem);
881-
--typography_fluid-arial-l: clamp(1.0938rem, 1.0489rem + 0.2242vw, 1.25rem);
882-
--typography_fluid-arial-m: clamp(0.875rem, 0.8391rem + 0.1794vw, 1rem);
883-
--typography_fluid-arial-s: clamp(0.7rem, 0.6713rem + 0.1435vw, 0.8rem);
884-
--typography_fluid-arial-xs: clamp(0.56rem, 0.537rem + 0.1148vw, 0.64rem);
885-
--typography_fluid-arial-2xs: clamp(0.448rem, 0.4296rem + 0.0918vw, 0.512rem);
886-
/*____ Primitives ____*/
887-
/* button */
888-
--button-small-width: 7.5rem;
889-
--button-small-height: 2.5rem;
890-
--button-small-fontSize: var(--typography_fluid-arial-m);
891-
--button-small-radius: 0.5rem;
892-
--button-small-padding: var(--spacing-size-2) var(--spacing-size-3);
943+
/*____ Spacing ____*/
944+
--spacing-size-2: 0.5rem;
945+
--spacing-size-3: 0.75rem;
946+
/*____ Typography ____*/
947+
--typography_fluid-arial-4xl: clamp(2.6703rem, 2.5608rem + 0.5474vw, 3.0518rem);
948+
--typography_fluid-arial-3xl: clamp(2.1362rem, 2.0486rem + 0.4379vw, 2.4414rem);
949+
--typography_fluid-arial-2xl: clamp(1.709rem, 1.6389rem + 0.3503vw, 1.9531rem);
950+
--typography_fluid-arial-xl: clamp(1.3672rem, 1.3111rem + 0.2803vw, 1.5625rem);
951+
--typography_fluid-arial-l: clamp(1.0938rem, 1.0489rem + 0.2242vw, 1.25rem);
952+
--typography_fluid-arial-m: clamp(0.875rem, 0.8391rem + 0.1794vw, 1rem);
953+
--typography_fluid-arial-s: clamp(0.7rem, 0.6713rem + 0.1435vw, 0.8rem);
954+
--typography_fluid-arial-xs: clamp(0.56rem, 0.537rem + 0.1148vw, 0.64rem);
955+
--typography_fluid-arial-2xs: clamp(0.448rem, 0.4296rem + 0.0918vw, 0.512rem);
956+
/*____ Primitives ____*/
957+
/* button */
958+
--button-small-width: 7.5rem;
959+
--button-small-height: 2.5rem;
960+
--button-small-fontSize: var(--typography_fluid-arial-m);
961+
--button-small-radius: 0.5rem;
962+
--button-small-padding: var(--spacing-size-2) var(--spacing-size-3);
893963
}
894964
```
895965

0 commit comments

Comments
 (0)