@@ -33,43 +33,57 @@ const config = _extend({
3333await config .buildAllPlatforms ();
3434```
3535
36- ### Color Tokens with Light/Dark Mode
36+ ### Creating Light/Dark CSS colour variables
37+
38+ Generate separate CSS files for light and dark themes using the color scheme pattern:
3739
3840``` typescript
3941import {
4042 _extend ,
41- createLightDarkTransform ,
42- includeTokenFilter
43+ includeTokenFilter ,
44+ mergeLightDarkFoundation
4345} from ' @equinor/eds-tokens-build' ;
44- import { readJsonFiles } from ' @equinor/eds-tokens-sync' ;
45- import { StyleDictionary } from ' style-dictionary-utils' ;
46-
47- // Read dark mode tokens
48- const darkTokens = readJsonFiles ([' tokens/dark-theme.json' ]);
4946
50- // Create and register light/dark transform
51- const lightDarkTransform = createLightDarkTransform ({
52- name: ' lightDarkMatrix' ,
53- darkTokensObject: darkTokens [' dark-theme.json' ]
47+ // Build light color scheme CSS variables
48+ const lightColorScheme = _extend ({
49+ source: [' tokens/light-color-scheme.json' ],
50+ include: [' tokens/light-colors.json' ], // Core light colors
51+ filter : (token ) => includeTokenFilter (token , [' Color scheme' ]),
52+ buildPath: ' build/css/' ,
53+ fileName: ' light-color-scheme' ,
54+ selector: ' [data-color-scheme="light"]' ,
55+ prefix: ' eds-color' ,
56+ outputReferences: false ,
5457});
5558
56- StyleDictionary .registerTransform (lightDarkTransform );
57-
58- // Build color tokens with light/dark support
59- const colorConfig = _extend ({
60- source: [' tokens/light-theme.json' ],
61- include: [' tokens/core.json' ],
59+ // Build dark color scheme CSS variables
60+ const darkColorScheme = _extend ({
61+ source: [' tokens/dark-color-scheme.json' ],
62+ include: [' tokens/dark-colors.json' ], // Core dark colors
63+ filter : (token ) => includeTokenFilter (token , [' Color scheme' ]),
6264 buildPath: ' build/css/' ,
63- fileName: ' colors' ,
64- selector: ' :root' ,
65- filter : (token ) => includeTokenFilter (token , [' Color' ]),
66- transforms: [' name/kebab' , ' color/css' , ' lightDarkMatrix' ],
67- outputReferences: true
65+ fileName: ' dark-color-scheme' ,
66+ selector: ' [data-color-scheme="dark"]' ,
67+ prefix: ' eds-color' ,
68+ outputReferences: false ,
6869});
6970
70- await colorConfig .buildAllPlatforms ();
71+ await lightColorScheme .buildAllPlatforms ();
72+ await darkColorScheme .buildAllPlatforms ();
73+
74+ // Merge into a single file using light-dark() CSS function
75+ mergeLightDarkFoundation ({
76+ prefix: ' eds-color' ,
77+ });
7178```
7279
80+ This approach:
81+ - Uses ` source ` for the color scheme tokens (semantic colors like primary, secondary)
82+ - Uses ` include ` for the base color definitions (hex values, etc.)
83+ - Filters specifically for ` ['Color scheme'] ` tokens to avoid outputting all colors
84+ - Generates separate files for each theme with appropriate selectors
85+ - Merges them into a modern CSS file using the ` light-dark() ` function
86+
7387### Typography Tokens
7488
7589``` typescript
0 commit comments