Skip to content

Commit 9740077

Browse files
authored
Merge branch 'main' into fix/upgrade-u-combobox-and-u-datalist
2 parents 99c2ff4 + e8d1ecd commit 9740077

15 files changed

Lines changed: 126 additions & 79 deletions

File tree

.changeset/warm-streets-clap.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

apps/www/app/_components/mdx-components/mdx-components.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export const MDXComponents = ({
168168
);
169169
};
170170

171-
const Story = ({ story, ...rest }: LiveComponentProps) => {
171+
const Story = ({ story, language = 'html', ...rest }: LiveComponentProps) => {
172172
const { stories } = useLoaderData();
173173
if (!stories) return null;
174174

@@ -179,6 +179,7 @@ const Story = ({ story, ...rest }: LiveComponentProps) => {
179179
return (
180180
<LiveComponent
181181
story={`${foundStory.code}\n\nrender(<${foundStory.name} />)`}
182+
language={language}
182183
{...rest}
183184
/>
184185
);

apps/www/app/content/components/dropdown/en/code.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Story story="Preview" language="html"/>
1+
<Story story="Preview" />
22

33
## Usage
44

@@ -57,15 +57,15 @@ When using `@digdir/designsystemet-react` we extend `@types/react-dom` to accept
5757

5858
You must then add `popovertarget={id}` to `Dropdown`, and `id` to `Dropdown`.
5959

60-
<Story story="WithoutTrigger" />
60+
<Story story="WithoutTrigger" language="react"/>
6161

6262
### Controlled
6363

6464
If you submit `open`, then you use `Dropdown` controlled. You can use `onClose` to get notified when `Dropdown` wants to close.
6565

6666
Note that we do not use `onClick` on the trigger, the dropdown handles this internally and sends to `onOpen` and `onClose`.
6767

68-
<Story story="ControlledEn" />
68+
<Story story="ControlledEn" language="react"/>
6969

7070
### Props
7171

apps/www/app/content/components/dropdown/no/code.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Story story="Preview" language="html" />
1+
<Story story="Preview" />
22

33
## Bruk
44

apps/www/app/content/components/dropdown/no/overview.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
search_terms: nedtrekksmeny, rullegardinmeny, valgmeny, valmeny, veljar, popup, select, menu, listbox, popup, dropdownmenu, options
33
---
44

5-
<Story story="Preview" language="html" />
5+
<Story story="Preview" />
66

77
**Bruk dropdown når**
88
- du vil tilby flere alternativer uten at de tar mye plass i grensesnittet

apps/www/app/content/components/table/no/code.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Merk at vi legger på `type="button"` for å unngå at knappen oppfører seg som
8282
### Klikkbar rad
8383
Du kan legge på `data-clickdelegatefor` på en `<tr>` for å delegere klikk-hendelser til et element i raden, for eksempel en `<a>`-tag.
8484

85-
<Story story="HTMLClickableRows" language="html" />
85+
<Story story="HTMLClickableRows" />
8686

8787

8888
## CSS variabler og data-attributter

packages/cli/bin/designsystemet.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import { convertToHex } from '../src/colors/index.js';
77
import type { CssColor } from '../src/colors/types.js';
88
import migrations from '../src/migrations/index.js';
99
import { buildTokens } from '../src/tokens/build.js';
10-
import { createTokenFiles } from '../src/tokens/create/files.js';
11-
import { cliOptions, createTokens } from '../src/tokens/create.js';
10+
import { createSystemTokenFiles, tokenSetsToFiles } from '../src/tokens/create/files.js';
11+
import { cliOptions, createTokens, tokenSetDimensions } from '../src/tokens/create.js';
1212
import { generateConfigFromTokens } from '../src/tokens/generate-config.js';
1313
import type { OutputFile, Theme } from '../src/tokens/types.js';
14+
import { colorNamesByCategory } from '../src/tokens/utils.js';
1415
import { dsfs } from '../src/utils/filesystem.js';
1516
import { parseCreateConfig, readConfigFile } from './config.js';
1617

@@ -124,21 +125,29 @@ function makeTokenCommands() {
124125

125126
const outDir = dsfs.outDir;
126127

127-
if (config.clean) {
128-
await dsfs.cleanDir(outDir);
128+
const files: OutputFile[] = [];
129+
130+
for (const [name, themeConfig] of Object.entries(config.themes)) {
131+
const { tokenSets } = await createTokens({ name, ...themeConfig } as Theme);
132+
files.push(...tokenSetsToFiles(tokenSets));
129133
}
130134

131-
let files: OutputFile[] = [];
132-
if (config.themes) {
133-
for (const [name, themeWithoutName] of Object.entries(config.themes)) {
134-
// Casting as missing properties should be validated by `getDefaultOrExplicitOption` to default values
135-
const theme = { name, ...themeWithoutName } as Theme;
135+
// Pick colors from first theme since we have a constraint they should be the same across themes.
136+
const colors = config.themes?.[themeNames[0]]?.colors ?? { main: {}, support: {} };
136137

137-
const { tokenSets } = await createTokens(theme);
138-
files = files.concat(await createTokenFiles({ outDir, theme, tokenSets, themeNames }));
139-
}
138+
files.push(
139+
...(await createSystemTokenFiles({
140+
tokenSetDimensions,
141+
themeNames,
142+
colors: colorNamesByCategory(colors),
143+
})),
144+
);
145+
146+
if (config.clean) {
147+
await dsfs.cleanDir(outDir);
140148
}
141149

150+
await dsfs.mkdir(outDir);
142151
await dsfs.writeFiles(files, outDir);
143152

144153
console.log(`\n✅ Finished creating tokens in ${pc.green(outDir)} for themes: ${pc.blue(themeNames.join(', '))}`);

packages/cli/src/scripts/update-preview-tokens.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import pc from 'picocolors';
22
import type { TransformedToken } from 'style-dictionary/types';
33
import config from './../../../../designsystemet.config.json' with { type: 'json' };
44
import { generate$Themes } from '../tokens/create/generators/$themes.js';
5-
import { createTokens } from '../tokens/create.js';
5+
import { createTokens, tokenSetDimensions } from '../tokens/create.js';
66
import { buildOptions, processPlatform } from '../tokens/process/platform.js';
77
import { processThemeObject } from '../tokens/process/utils/getMultidimensionalThemes.js';
8-
import type { SizeModes, Theme } from '../tokens/types.js';
8+
import type { Theme } from '../tokens/types.js';
9+
import { colorNamesByCategory } from '../tokens/utils.js';
910
import { dsfs } from '../utils/filesystem.js';
1011

1112
const OUTDIR = '../../internal/components/src/tokens/design-tokens';
@@ -26,9 +27,10 @@ type PreviewToken = { variable: string; value: string };
2627
export const formatTheme = async (themeConfig: Theme) => {
2728
const { tokenSets } = await createTokens(themeConfig);
2829

29-
const sizeModes: SizeModes[] = ['small', 'medium', 'large'];
30+
const themeNames = [themeConfig.name];
31+
const colors = colorNamesByCategory(themeConfig.colors);
32+
const $themes = await generate$Themes(tokenSetDimensions, themeNames, colors);
3033

31-
const $themes = await generate$Themes(['dark', 'light'], [themeConfig.name], themeConfig.colors, sizeModes);
3234
const processed$themes = $themes.map(processThemeObject);
3335

3436
// We run this to populate the `buildOptions.buildTokenFormats` with transformed tokens

packages/cli/src/tokens/create.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { ColorScheme } from '../colors/types.js';
21
import { generateColorScheme } from './create/generators/primitives/color-scheme.js';
32
import { generateGlobals } from './create/generators/primitives/globals.js';
43
import { generateSize, generateSizeGlobal } from './create/generators/primitives/size.js';
@@ -7,7 +6,12 @@ import { generateSemanticColors } from './create/generators/semantic/color.js';
76
import { generateColorModes } from './create/generators/semantic/color-modes.js';
87
import { generateSemanticStyle } from './create/generators/semantic/style.js';
98
import { generateTheme } from './create/generators/themes/theme.js';
10-
import type { SizeModes, Theme, TokenSet, TokenSets } from './types.js';
9+
import type { Theme, TokenSet, TokenSetDimensions, TokenSets } from './types.js';
10+
11+
export const tokenSetDimensions: TokenSetDimensions = {
12+
colorSchemes: ['dark', 'light'],
13+
sizeModes: ['small', 'medium', 'large'],
14+
};
1115

1216
export const cliOptions = {
1317
outDir: 'out-dir',
@@ -28,8 +32,7 @@ export const cliOptions = {
2832

2933
export const createTokens = async (theme: Theme) => {
3034
const { colors, typography, name, borderRadius, overrides } = theme;
31-
const colorSchemes: ColorScheme[] = ['light', 'dark'];
32-
const sizeModes: SizeModes[] = ['small', 'medium', 'large'];
35+
const { colorSchemes, sizeModes } = tokenSetDimensions;
3336

3437
const tokenSets: TokenSets = new Map([
3538
['primitives/globals', generateGlobals()],
Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,46 @@
1-
import { dsfs } from '../../utils/filesystem.js';
2-
import type { OutputFile, SizeModes, Theme, TokenSets } from '../types.js';
1+
import type { ColorNamesByCategory, OutputFile, TokenSetDimensions, TokenSets } from '../types.js';
32
import { generate$Designsystemet } from './generators/$designsystemet.js';
43
import { generate$Metadata } from './generators/$metadata.js';
54
import { generate$Themes } from './generators/$themes.js';
65

76
export const stringify = (data: unknown) => JSON.stringify(data, null, 2);
87

98
type CreateTokenFilesOptions = {
10-
outDir: string;
11-
theme: Theme;
12-
tokenSets: TokenSets;
9+
tokenSetDimensions: TokenSetDimensions;
10+
colors: ColorNamesByCategory;
1311
themeNames: string[];
1412
};
1513

16-
export const createTokenFiles = async (options: CreateTokenFilesOptions) => {
17-
const {
18-
outDir,
19-
tokenSets,
20-
theme: { colors },
21-
themeNames,
22-
} = options;
14+
/**
15+
* Creates system token files (`$themes.json`, `$metadata.json`, `$designsystemet.jsonc`) based on the provided token set dimensions and theme names.
16+
*
17+
* `$themes.json` and `$metadata.json` are essential for Token Studio and Style Dictionary to correctly interpret and manage the design tokens.
18+
*/
19+
export const createSystemTokenFiles = async (options: CreateTokenFilesOptions) => {
20+
const { colors, themeNames, tokenSetDimensions } = options;
2321

22+
const files: OutputFile[] = [];
2423
const $themesPath = '$themes.json';
2524
const $metadataPath = '$metadata.json';
2625
const $designsystemetPath = '$designsystemet.jsonc';
27-
// let themeObjects: ThemeObject[] = [];
28-
const sizeModes: SizeModes[] = ['small', 'medium', 'large'];
29-
30-
await dsfs.mkdir(outDir);
3126

32-
// Create metadata and themes json for Token Studio and build script
33-
const $themes = await generate$Themes(['dark', 'light'], themeNames, colors, sizeModes);
34-
const $metadata = generate$Metadata(['dark', 'light'], themeNames, colors, sizeModes);
27+
const $themes = await generate$Themes(tokenSetDimensions, themeNames, colors);
28+
const $metadata = generate$Metadata(tokenSetDimensions, themeNames, colors);
3529
const $designsystemet = generate$Designsystemet();
3630

37-
const files: OutputFile[] = [];
38-
3931
files.push({ destination: $themesPath, output: stringify($themes) });
4032
files.push({ destination: $metadataPath, output: stringify($metadata) });
4133
files.push({ destination: $designsystemetPath, output: stringify($designsystemet) });
4234

35+
return files;
36+
};
37+
38+
export const tokenSetsToFiles = (tokenSets: TokenSets): OutputFile[] => {
39+
const files: OutputFile[] = [];
40+
4341
for (const [set, tokens] of tokenSets) {
4442
const filePath = `${set}.json`;
4543
files.push({ destination: filePath, output: stringify(tokens) });
4644
}
47-
4845
return files;
4946
};

0 commit comments

Comments
 (0)