WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions style-dictionary/classic/color-palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import merge from 'lodash/merge.js';

import { ReferenceTokens } from '@cloudscape-design/theming-build';

import { expandReferenceTokens } from '../utils/index.js';
import { StyleDictionary } from '../utils/interfaces.js';
import { referenceTokens as vrReferenceTokens, tokens as parentTokens } from '../visual-refresh/color-palette.js';

Expand Down Expand Up @@ -52,7 +53,7 @@ const tokens: StyleDictionary.ColorPaletteDictionary = {
};

// Reference tokens for classic theme
const referenceTokens: ReferenceTokens = merge({}, vrReferenceTokens, {
const referenceTokens: ReferenceTokens = {
color: {
primary: {
50: tokens.colorBlue50,
Expand Down Expand Up @@ -102,10 +103,12 @@ const referenceTokens: ReferenceTokens = merge({}, vrReferenceTokens, {
1000: tokens.colorBlue1000,
},
},
});
};

const expandedTokens: StyleDictionary.ExpandedColorScopeDictionary = merge({}, parentTokens, tokens);
const expandedReferenceTokens: ReferenceTokens = expandReferenceTokens(merge({}, vrReferenceTokens, referenceTokens));

export { expandedTokens as tokens };
export { referenceTokens };
export { expandedReferenceTokens as referenceTokens };

export const mode: StyleDictionary.ModeIdentifier = 'color';
8 changes: 4 additions & 4 deletions style-dictionary/classic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ const tokenCategories: Array<StyleDictionary.CategoryModule> = [
];

export async function buildClassicOpenSource(builder: ThemeBuilder) {
// Add reference tokens first to generate palette tokens
builder.addReferenceTokens((await import('./color-palette.js')).referenceTokens);

tokenCategories.forEach(({ tokens, mode: modeId }) => {
tokenCategories.forEach(({ tokens, mode: modeId, referenceTokens }) => {
const mode = modes.find(mode => mode.id === modeId);
if (referenceTokens) {
builder.addReferenceTokens(referenceTokens, mode);
}
builder.addTokens(tokens, mode);
});

Expand Down
2 changes: 2 additions & 0 deletions style-dictionary/core/color-palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import { expandColorDictionary } from '../utils/index.js';
import { StyleDictionary } from '../utils/interfaces.js';
import { referenceTokens as vrReferenceTokens } from '../visual-refresh/color-palette.js';

const paletteTokens: StyleDictionary.ColorPaletteDictionary = {
colorGrey50: '#fcfcfd',
Expand Down Expand Up @@ -257,4 +258,5 @@ const expandedTokens: StyleDictionary.ExpandedColorScopeDictionary = expandColor
export const mode: StyleDictionary.ModeIdentifier = 'color';

export { expandedTokens as tokens };
export { vrReferenceTokens as referenceTokens };
export { paletteTokens };
5 changes: 4 additions & 1 deletion style-dictionary/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ const tokenCategories: Array<StyleDictionary.CategoryModule> = [
];

async function buildCoreOpenSource(builder: ThemeBuilder) {
tokenCategories.forEach(({ tokens, mode: modeId }) => {
tokenCategories.forEach(({ tokens, mode: modeId, referenceTokens }) => {
const mode = modes.find(mode => mode.id === modeId);
if (referenceTokens) {
builder.addReferenceTokens(referenceTokens, mode);
}
builder.addTokens(tokens, mode);
});

Expand Down
2 changes: 2 additions & 0 deletions style-dictionary/utils/contexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const createTopNavigationContext = (tokens: TokenCategory<string, GlobalV
id: 'top-navigation',
selector: '.awsui-context-top-navigation',
tokens,
defaultMode: 'dark',
};
};

Expand All @@ -23,6 +24,7 @@ export const createHeaderContext = (tokens: TokenCategory<string, GlobalValue |
id: 'header',
selector: '.awsui-context-content-header',
tokens,
defaultMode: 'dark',
};
};

Expand Down
26 changes: 25 additions & 1 deletion style-dictionary/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { TokenCategory } from '@cloudscape-design/theming-build';
import { ReferenceTokens, TokenCategory } from '@cloudscape-design/theming-build';

import { StyleDictionary } from './interfaces.js';

Expand Down Expand Up @@ -64,6 +64,30 @@ export const expandMotionDictionary = (
}, {} as StyleDictionary.ExpandedMotionScopeDictionary);
};

export const expandReferenceTokens = (referenceTokens: ReferenceTokens) => {
if (!referenceTokens.color) {
return referenceTokens;
}

const expandedColor = Object.entries(referenceTokens.color).reduce(
(acc: any, [colorType, palette]: [string, any]) => {
if (!palette) {
return acc;
}

acc[colorType] = Object.entries(palette).reduce((paletteAcc: any, [step, value]: [string, any]) => {
paletteAcc[step] = expandColorEntry(value);
return paletteAcc;
}, {});

return acc;
},
{}
);

return { ...referenceTokens, color: expandedColor };
};

export const pickState = (tokenCategory: TokenCategory<string, Record<string, string>>, state: string) => {
return Object.fromEntries(
Object.entries(tokenCategory).map(([token, value]) => {
Expand Down
3 changes: 2 additions & 1 deletion style-dictionary/utils/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { GlobalValue, ModeValue, TokenCategory } from '@cloudscape-design/theming-build';
import { GlobalValue, ModeValue, ReferenceTokens, TokenCategory } from '@cloudscape-design/theming-build';

import {
BordersTokenName,
Expand Down Expand Up @@ -63,6 +63,7 @@ export namespace StyleDictionary {
export interface CategoryModule {
mode?: string;
tokens: Record<string, any>;
referenceTokens?: ReferenceTokens;
}

export interface Metadata {
Expand Down
6 changes: 3 additions & 3 deletions style-dictionary/visual-refresh/color-palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import pick from 'lodash/pick.js';
import { ReferenceTokens } from '@cloudscape-design/theming-build';

import { paletteTokens as brand } from '../core/color-palette.js';
import { expandColorDictionary } from '../utils/index.js';
import { expandColorDictionary, expandReferenceTokens } from '../utils/index.js';
import { StyleDictionary } from '../utils/interfaces.js';

/**
Expand Down Expand Up @@ -144,8 +144,8 @@ const referenceTokens: ReferenceTokens = {
};

const expandedTokens: StyleDictionary.ExpandedColorScopeDictionary = expandColorDictionary(tokens);
const expandedReferenceTokens: ReferenceTokens = expandReferenceTokens(referenceTokens);

export const mode: StyleDictionary.ModeIdentifier = 'color';

export { expandedTokens as tokens };
export { referenceTokens };
export { expandedReferenceTokens as referenceTokens };
9 changes: 4 additions & 5 deletions style-dictionary/visual-refresh/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ const tokenCategories: Array<StyleDictionary.CategoryModule> = [
];

export async function buildVisualRefresh(builder: ThemeBuilder) {
// Add reference tokens first to generate palette tokens
builder.addReferenceTokens((await import('./color-palette.js')).referenceTokens);

// Add existing token categories
tokenCategories.forEach(({ tokens, mode: modeId }) => {
tokenCategories.forEach(({ tokens, mode: modeId, referenceTokens }) => {
const mode = modes.find(mode => mode.id === modeId);
if (referenceTokens) {
builder.addReferenceTokens(referenceTokens, mode);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the mode argument is not supported here, so you need to modify this function to make it work

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that is the theming-core PR that's mentioned in the description.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you test this? Did you link the packages locally?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I linked the packages locally and ran them in my dev-pipeline. There is also an internal counterpart to this here: CR-238953785

}
builder.addTokens(tokens, mode);
});

Expand Down
Loading