@digdir/designsystemet 0.0.0-next-20250227103607 → 0.0.0-next-20250228195802
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -3
- package/dist/bin/designsystemet.js +10 -10
- package/dist/bin/options.d.ts +9 -4
- package/dist/bin/options.d.ts.map +1 -1
- package/dist/bin/options.js +6 -4
- package/dist/src/migrations/beta-to-v1.js +1 -1
- package/dist/src/tokens/build/configs.js +1 -1
- package/dist/src/tokens/design-tokens/default/primitives/globals.json +1 -1
- package/dist/src/tokens/design-tokens/default/primitives/modes/typography/size/large.json +1 -1
- package/dist/src/tokens/design-tokens/default/primitives/modes/typography/size/medium.json +1 -1
- package/dist/src/tokens/design-tokens/default/primitives/modes/typography/size/small.json +1 -1
- package/dist/src/tokens/design-tokens/default/semantic/style.json +3 -3
- package/dist/src/tokens/design-tokens/template/$themes.json +2 -2
- package/dist/src/tokens/design-tokens/template/semantic/color-base-file.json +8 -0
- package/dist/src/tokens/template.d.ts.map +1 -1
- package/dist/src/tokens/template.js +1 -0
- package/dist/src/tokens/write.d.ts.map +1 -1
- package/dist/src/tokens/write.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,7 +10,98 @@ Read the Designsystemet [README](https://github.com/digdir/designsystemet) to ge
|
|
|
10
10
|
## Usage
|
|
11
11
|
|
|
12
12
|
### Create tokens
|
|
13
|
-
We recommend using the [Designsystemet theme-builder](https://theme.designsystemet.no/) for generating options and commandline snippet.
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
Use `npx @digdir/designsystemet tokens create <options>` to create design tokens for use with Designsystemet.
|
|
15
|
+
|
|
16
|
+
This allows you to define themes including custom colors, font-family, and border-radius.
|
|
17
|
+
We recommend using the [Designsystemet theme builder](https://theme.designsystemet.no/) for generating a valid command with correct options.
|
|
18
|
+
|
|
19
|
+
#### Update tokens
|
|
20
|
+
|
|
21
|
+
Whenever a new version of the CLI is released, or you have done changes, we recommend to update design tokens with the `--clean` option to potentially remove any changes deprecated files or unneeded files.
|
|
22
|
+
|
|
23
|
+
To update design tokens, re-run `npx @digdir/designsystemet tokens create <options> --clean`.
|
|
24
|
+
If a [config file](#using-a-config-file) you can also re-run with `"clean": true`.
|
|
25
|
+
|
|
26
|
+
> ⚠️ **WARNING** ⚠️
|
|
27
|
+
> The design tokens created by this tool are considered an implementation detail, and is subject
|
|
28
|
+
> to change at any time without being considered a breaking change. We **only** support customisations
|
|
29
|
+
> done through the CLI options. Direct editing of the design tokens are **not** supported.
|
|
30
|
+
>
|
|
31
|
+
> Since tokens may be added or removed at any time, it is necessary to routinely re-run this
|
|
32
|
+
> command when upgrading the libraries. This will remove any direct edits to the design tokens.
|
|
33
|
+
|
|
34
|
+
### Build CSS from tokens
|
|
35
|
+
|
|
36
|
+
Use `npx @digdir/designsystemet tokens build <options>` to build CSS from design tokens generated in the previous step.
|
|
37
|
+
|
|
38
|
+
> ⚠️ **WARNING** ⚠️
|
|
39
|
+
> The CSS files from created by this tool are considered build artifacts. They should **not** be
|
|
40
|
+
> edited directly. While the CSS will not change unexpectedly, new variables may be added at any
|
|
41
|
+
> time. Therefore, it is necessary to routinely re-run this command when upgrading the libraries.
|
|
42
|
+
> This will remove any direct edits to the CSS.
|
|
43
|
+
|
|
44
|
+
#### Update built CSS
|
|
45
|
+
|
|
46
|
+
Whenever a new version of the CLI is released, or you have done changes, we recommend to build a new set of CSS from design tokens with the `--clean` option to potentially remove any changes deprecated files or unneeded files.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### Using a config file
|
|
50
|
+
|
|
51
|
+
> ⚠️ **WARNING** ⚠️
|
|
52
|
+
> This feature is experimental. The config schema may change at any time.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
The `tokens create` command supports a config file. It will auto-detect a `designsystemet.config.json` file in the current directory. You can also use the `--config <path>` option to supply a different config name and location.
|
|
56
|
+
|
|
57
|
+
The main advantage of using a config file is for automation in scenarios with multiple themes.
|
|
58
|
+
|
|
59
|
+
To get started, use this template for a `designsystemet.config.json` file:
|
|
60
|
+
|
|
61
|
+
```jsonc
|
|
62
|
+
{
|
|
63
|
+
"$schema": "node_modules/@digdir/designsystemet/dist/config.schema.json",
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
In editors which support JSON Schema, the `$schema` will then give you editor hints for the structure of the file.
|
|
68
|
+
|
|
69
|
+
#### Minimal config example
|
|
70
|
+
As a minimal example, the following CLI snippet from the theme builder
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
npx @digdir/designsystemet tokens create \
|
|
74
|
+
--main-colors "primary:#0062BA" "accent:#1E98F5" \
|
|
75
|
+
--neutral-color "#1E2B3C" \
|
|
76
|
+
--support-colors "extra1:#F45F63" "extra2:#E5AA20" \
|
|
77
|
+
--border-radius 4 \
|
|
78
|
+
--theme "theme"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
...is equivalent to this `designsystemet.config.json` file
|
|
82
|
+
```jsonc
|
|
83
|
+
{
|
|
84
|
+
"$schema": "./node_modules/@digdir/designsystemet/dist/config.schema.json",
|
|
85
|
+
"outDir": "../path/to/design-tokens",
|
|
86
|
+
"themes": {
|
|
87
|
+
"theme": {
|
|
88
|
+
"colors": {
|
|
89
|
+
"main": { "primary": "#0062BA", "accent": "#1E98F5" },
|
|
90
|
+
"neutral": "#1E2B3C",
|
|
91
|
+
"support": { "extra1": "#F45F63", "extra2": "#E5AA20" }
|
|
92
|
+
},
|
|
93
|
+
"borderRadius": 4
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
To generate new design tokens and CSS files, you would then run.
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
npx @digdir/designsystemet tokens create
|
|
102
|
+
npx @digdir/designsystemet tokens build
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### Complex config example
|
|
106
|
+
|
|
107
|
+
Have a look at the `*.config.json` files under the `packages/cli` in the Github repo for more complex examples.
|
|
@@ -12,7 +12,7 @@ import { cliOptions, createTokens } from "../src/tokens/create.js";
|
|
|
12
12
|
import { cleanDir } from "../src/tokens/utils.js";
|
|
13
13
|
import { writeTokens } from "../src/tokens/write.js";
|
|
14
14
|
import { combinedConfigSchema, configFileSchema, mapPathToOptionName } from "./config.js";
|
|
15
|
-
import {
|
|
15
|
+
import { getCliOption, getDefaultCliOption, getSuppliedCliOption } from "./options.js";
|
|
16
16
|
program.name("designsystemet").description("CLI for working with Designsystemet").showHelpAfterError();
|
|
17
17
|
function makeTokenCommands() {
|
|
18
18
|
const tokenCmd = createCommand("tokens");
|
|
@@ -39,7 +39,7 @@ function makeTokenCommands() {
|
|
|
39
39
|
`-o, --${cliOptions.outDir} <string>`,
|
|
40
40
|
`Output directory for created ${chalk.blue("design-tokens")}`,
|
|
41
41
|
DEFAULT_TOKENS_CREATE_DIR
|
|
42
|
-
).option(`--${cliOptions.clean} [boolean]`, "Clean output directory before creating tokens", parseBoolean, false).option("--dry [boolean]", `Dry run for created ${chalk.blue("design-tokens")}`, parseBoolean, false).option(`-f, --${cliOptions.theme.typography.fontFamily} <string>`, `Font family`, DEFAULT_FONT).option(
|
|
42
|
+
).option(`--${cliOptions.clean} [boolean]`, "Clean output directory before creating tokens", parseBoolean, false).option("--dry [boolean]", `Dry run for created ${chalk.blue("design-tokens")}`, parseBoolean, false).option(`-f, --${cliOptions.theme.typography.fontFamily} <string>`, `Font family (experimental)`, DEFAULT_FONT).option(
|
|
43
43
|
`-b, --${cliOptions.theme.borderRadius} <number>`,
|
|
44
44
|
`Unitless base border-radius in px`,
|
|
45
45
|
(radiusAsString) => Number(radiusAsString),
|
|
@@ -86,17 +86,17 @@ function makeTokenCommands() {
|
|
|
86
86
|
borderRadius: optionGetter(cmd, "borderRadius")
|
|
87
87
|
});
|
|
88
88
|
const unvalidatedConfig = noUndefined({
|
|
89
|
-
outDir: propsFromJson?.outDir ??
|
|
90
|
-
clean: propsFromJson?.clean ??
|
|
91
|
-
themes: propsFromJson?.themes ? (
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
R.
|
|
95
|
-
) : (
|
|
89
|
+
outDir: propsFromJson?.outDir ?? getCliOption(cmd, "outDir"),
|
|
90
|
+
clean: propsFromJson?.clean ?? getCliOption(cmd, "clean"),
|
|
91
|
+
themes: propsFromJson?.themes ? R.map((jsonThemeValues) => {
|
|
92
|
+
const defaultThemeValues = getThemeOptions(getDefaultCliOption);
|
|
93
|
+
const cliThemeValues = getThemeOptions(getSuppliedCliOption);
|
|
94
|
+
return R.mergeDeepRight(defaultThemeValues, R.mergeDeepRight(jsonThemeValues, cliThemeValues));
|
|
95
|
+
}, propsFromJson.themes) : (
|
|
96
96
|
// If there are no themes specified in the JSON config, we use both explicit
|
|
97
97
|
// and default theme options from the CLI.
|
|
98
98
|
{
|
|
99
|
-
[opts.theme]: getThemeOptions(
|
|
99
|
+
[opts.theme]: getThemeOptions(getCliOption)
|
|
100
100
|
}
|
|
101
101
|
)
|
|
102
102
|
});
|
package/dist/bin/options.d.ts
CHANGED
|
@@ -6,11 +6,16 @@ export type OptionGetter = ReturnType<typeof getOptionIfMatchingSource>;
|
|
|
6
6
|
* The difference between this and using the option directly is that we return undefined
|
|
7
7
|
* instead of the default value if the option was not explicitly set.
|
|
8
8
|
*/
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const getSuppliedCliOption: <Args extends unknown[], Opts extends OptionValues, K extends keyof Opts>(command: Command<Args, Opts>, option: K) => Opts[K] | undefined;
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
11
|
+
* Get the default value specified for a CLI command option.
|
|
12
|
+
* Mostly useful for getting values which may later be overridden.
|
|
13
13
|
*/
|
|
14
|
-
export declare const
|
|
14
|
+
export declare const getDefaultCliOption: <Args extends unknown[], Opts extends OptionValues, K extends keyof Opts>(command: Command<Args, Opts>, option: K) => Opts[K] | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Try to get the explicitly supplied CLI option, and fall back to the default value
|
|
17
|
+
* for the option as defined in the {@link Command}
|
|
18
|
+
*/
|
|
19
|
+
export declare const getCliOption: <Args extends unknown[], Opts extends OptionValues, K extends keyof Opts>(command: Command<Args, Opts>, option: K) => Opts[K] | undefined;
|
|
15
20
|
export {};
|
|
16
21
|
//# sourceMappingURL=options.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../bin/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE5F,QAAA,MAAM,yBAAyB,eAChB,iBAAiB,EAAE,MAC/B,IAAI,SAAS,OAAO,EAAE,EAAE,IAAI,SAAS,YAAY,EAAE,CAAC,SAAS,MAAM,IAAI,WAC7D,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,UACpB,CAAC,wBAMV,CAAC;AAEJ,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAExE;;;;GAIG;AACH,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../bin/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE5F,QAAA,MAAM,yBAAyB,eAChB,iBAAiB,EAAE,MAC/B,IAAI,SAAS,OAAO,EAAE,EAAE,IAAI,SAAS,YAAY,EAAE,CAAC,SAAS,MAAM,IAAI,WAC7D,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,UACpB,CAAC,wBAMV,CAAC;AAEJ,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAExE;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAjB9B,IAAI,SAAS,OAAO,EAAE,EAAE,IAAI,SAAS,YAAY,EAAE,CAAC,SAAS,MAAM,IAAI,WAC7D,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,UACpB,CAAC,wBAeuD,CAAC;AAErE;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAvB7B,IAAI,SAAS,OAAO,EAAE,EAAE,IAAI,SAAS,YAAY,EAAE,CAAC,SAAS,MAAM,IAAI,WAC7D,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,UACpB,CAAC,wBAqB0D,CAAC;AAExE;;;GAGG;AACH,eAAO,MAAM,YAAY,GA7BtB,IAAI,SAAS,OAAO,EAAE,EAAE,IAAI,SAAS,YAAY,EAAE,CAAC,SAAS,MAAM,IAAI,WAC7D,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,UACpB,CAAC,wBA2B0D,CAAC"}
|
package/dist/bin/options.js
CHANGED
|
@@ -4,9 +4,11 @@ const getOptionIfMatchingSource = (...sources) => (command, option) => {
|
|
|
4
4
|
return command.getOptionValue(option);
|
|
5
5
|
}
|
|
6
6
|
};
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const getSuppliedCliOption = getOptionIfMatchingSource("cli");
|
|
8
|
+
const getDefaultCliOption = getOptionIfMatchingSource("default");
|
|
9
|
+
const getCliOption = getOptionIfMatchingSource("cli", "default");
|
|
9
10
|
export {
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
getCliOption,
|
|
12
|
+
getDefaultCliOption,
|
|
13
|
+
getSuppliedCliOption
|
|
12
14
|
};
|
|
@@ -276,7 +276,7 @@ var beta_to_v1_default = (glob) => runCssCodemod({
|
|
|
276
276
|
"--fds-sizing-22": "--ds-size-22",
|
|
277
277
|
"--fds-sizing-26": "--ds-size-26",
|
|
278
278
|
"--fds-sizing-30": "--ds-size-30",
|
|
279
|
-
"--fds-opacity-disabled": "--ds-disabled
|
|
279
|
+
"--fds-opacity-disabled": "--ds-opacity-disabled",
|
|
280
280
|
"--fds-colors-blue-100": "--ds-global-blue-1",
|
|
281
281
|
"--fds-colors-blue-200": "--ds-global-blue-2",
|
|
282
282
|
"--fds-colors-blue-700": "--ds-global-blue-7",
|
|
@@ -57,7 +57,7 @@ const colorSchemeVariables = ({ "color-scheme": colorScheme = "light", theme },
|
|
|
57
57
|
{
|
|
58
58
|
destination: `color-scheme/${colorScheme}.css`,
|
|
59
59
|
format: formats.colorScheme.name,
|
|
60
|
-
filter: (token) => !token.isSource && typeEquals("color", token)
|
|
60
|
+
filter: (token) => !token.isSource && typeEquals("color", token) && !R.startsWith(["global"], token.path)
|
|
61
61
|
}
|
|
62
62
|
],
|
|
63
63
|
options: {
|
|
@@ -1347,7 +1347,6 @@
|
|
|
1347
1347
|
"color.warning.base-contrast-default": "3d38f3079fb9fd155567ec24c7fde25f68c40f42",
|
|
1348
1348
|
"color.focus.inner": "1ec8f76f658042889b1eb4b08f3ce9bca1b7e603",
|
|
1349
1349
|
"color.focus.outer": "09e04f0bfff8fdc309db58a0131b5d07dae6b4f8",
|
|
1350
|
-
"disabled.opacity": "d94940d06b80e1cb6184ae12c5793a1ef95420ba",
|
|
1351
1350
|
"border-width.default": "ac5b6181d17de3d25249c91674dce4fef8711216",
|
|
1352
1351
|
"border-width.highlight": "dd40bb1cb729138762c0bfa29d26adb58b726354",
|
|
1353
1352
|
"border-radius.sm": "7b2af5d22e01253d20184bf5c3f872a18d41a315",
|
|
@@ -1375,7 +1374,8 @@
|
|
|
1375
1374
|
"size.18": "803716e7a1ab4f0ed08180713a5ddc53f5a80a13",
|
|
1376
1375
|
"size.22": "f0e62cce260051ffae97ed9709e77fb22e2dac2e",
|
|
1377
1376
|
"size.26": "a42e9a42d13ce2453de8005b58147b9a9b9b5dde",
|
|
1378
|
-
"size.30": "600d545445deae2077866ba3953a64000a123606"
|
|
1377
|
+
"size.30": "600d545445deae2077866ba3953a64000a123606",
|
|
1378
|
+
"opacity.disabled": "d94940d06b80e1cb6184ae12c5793a1ef95420ba"
|
|
1379
1379
|
},
|
|
1380
1380
|
"group": "Semantic"
|
|
1381
1381
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../../src/tokens/template.ts"],"names":[],"mappings":"AA2BA,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../../src/tokens/template.ts"],"names":[],"mappings":"AA2BA,eAAO,MAAM,eAAe,qBAyG3B,CAAC"}
|
|
@@ -28,6 +28,7 @@ const updateTemplates = async () => {
|
|
|
28
28
|
JSON.stringify(categoryColorTemplate, null, 2).replaceAll("color.accent", "color.<color>")
|
|
29
29
|
);
|
|
30
30
|
const colorBaseFile = {
|
|
31
|
+
...originalColorJson,
|
|
31
32
|
color: R.omit(["accent", "neutral", "brand1", "brand2", "brand3"], originalColorJson.color)
|
|
32
33
|
};
|
|
33
34
|
await fs.writeFile(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/tokens/write.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAoB,KAAK,EAAE,MAAM,EAA8B,MAAM,YAAY,CAAC;AAS9F,eAAO,MAAM,SAAS,SAAU,OAAO,WAAkC,CAAC;AAyB1E,KAAK,kBAAkB,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,wCAAwC;IACxC,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,WAAW,YAAmB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/tokens/write.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAoB,KAAK,EAAE,MAAM,EAA8B,MAAM,YAAY,CAAC;AAS9F,eAAO,MAAM,SAAS,SAAU,OAAO,WAAkC,CAAC;AAyB1E,KAAK,kBAAkB,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,wCAAwC;IACxC,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,WAAW,YAAmB,kBAAkB,kBA6K5D,CAAC"}
|
package/dist/src/tokens/write.js
CHANGED