-
Notifications
You must be signed in to change notification settings - Fork 89
fix(tokens): restore --calcite-color-focus
#11960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0465acf
add semantic focus color in light/dark themes
matgalla 8a8e8d4
fix: restore --calcite-color-focus
jcfranco 1943055
update test snapshots
jcfranco 852efcf
add `.default` to focus token path and add `scope` attribute
matgalla eb5e1c4
merge dev
jcfranco a2edc5b
Merge branch 'dev' into matgalla/add-focus-color-token
jcfranco da2a8a4
chore(tokens): enable strict and drop ypescript-strict-plugin
jcfranco 5d92797
update build to generate component/host-specific stylesheet
jcfranco abff752
fix focus util regression
jcfranco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
packages/calcite-design-tokens/src/build/format/component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import prettierSync from "@prettier/sync"; | ||
| import type { FormatFn, TransformedToken } from "style-dictionary/types"; | ||
| import { fileHeader } from "style-dictionary/utils"; | ||
| import StyleDictionary from "style-dictionary"; | ||
| import { Config, PlatformConfig } from "../../types/extensions.js"; | ||
| import { RegisterFn, Stylesheet } from "../../types/interfaces.js"; | ||
| import { fromTokens } from "../utils/dictionary.js"; | ||
| import { light } from "../dictionaries/index.js"; | ||
| import { Platform } from "../utils/enums.js"; | ||
| import { createVarList } from "./utils/index.js"; | ||
|
|
||
| export const FormatComponent = "calcite/format/component"; | ||
|
|
||
| export const registerFormatComponent: RegisterFn = () => { | ||
| StyleDictionary.registerFormat({ | ||
| name: FormatComponent, | ||
| format: formatComponentFile, | ||
| }); | ||
| }; | ||
|
|
||
| export const formatComponentFile: FormatFn = async (args) => { | ||
| const { file, options, platform } = args; | ||
| const platformConfig = platform as PlatformConfig; | ||
|
|
||
| if (platformConfig.options.platform !== Platform.css) { | ||
| throw new Error("Only css platform is supported."); | ||
| } | ||
|
|
||
| const header = await fileHeader({ file }); | ||
| const stylesheetFormat: Stylesheet = platformConfig.options.platform; | ||
|
|
||
| const lightDictionary = await light.getPlatformTokens(options.platform, { cache: true }); | ||
| const filteredTokens: TransformedToken[] = []; | ||
| const componentTokens = lightDictionary.allTokens.filter((token) => { | ||
| const isComponent = token.attributes?.scope === "component"; | ||
| if (!isComponent) { | ||
| filteredTokens.push(token); | ||
| } | ||
| return isComponent; | ||
| }); | ||
|
|
||
| const componentTokenDictionary = fromTokens(componentTokens, filteredTokens); | ||
| const componentVarDeclarations = createVarList(stylesheetFormat, componentTokenDictionary, { | ||
| ...args, | ||
| options: { | ||
| ...args.options, | ||
| // assumes all component tokens need to use a reference (custom CSS prop) as the value | ||
| outputReferences: true, | ||
| }, | ||
| }) | ||
| .split(";") | ||
| .filter(Boolean) | ||
| .map((varDeclaration) => varDeclaration.split(":").map((part) => part.trim())); | ||
|
|
||
| const prefix = (options as Config).platforms[platformConfig.options.platform].prefix!; | ||
| const componentScopedVars = componentVarDeclarations.map(([name, value]) => { | ||
| // we define internal variables to allow overrides at a global or component level | ||
| const internalVarName = name.replace(prefix, `${prefix}-internal`); | ||
|
|
||
| return `${internalVarName}: var(${name}, var(${getLegacyVarName(name, prefix)}, ${value.trim()}))`; | ||
| }); | ||
|
|
||
| const content = `:host {${componentScopedVars.join(";\n")}}`; | ||
|
|
||
| return prettierSync.format(`${header}${content}`, { | ||
| parser: stylesheetFormat, | ||
| }); | ||
| }; | ||
|
|
||
| /** | ||
| * This is based on the focus color variable, but we could use additional token attributes to get the proper legacy var name | ||
| * | ||
| * @param name - The name of the token. | ||
| * @param prefix - The prefix used in the token name. | ||
| */ | ||
| function getLegacyVarName(name: string, prefix: string): string { | ||
| const legacyPrefix = `${prefix}-ui`; | ||
| const suffix = name | ||
| .slice(name.indexOf(prefix) + prefix.length) | ||
| .split("-") | ||
| .filter(Boolean) | ||
| .reverse() | ||
| .join("-"); | ||
| return `--${legacyPrefix}-${suffix}`; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 13 additions & 2 deletions
15
packages/calcite-design-tokens/src/build/utils/dictionary.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,21 @@ | ||
| import type { Dictionary } from "style-dictionary/types"; | ||
| import { convertTokenData } from "style-dictionary/utils"; | ||
|
|
||
| export function fromTokens(tokens: Parameters<typeof convertTokenData>[0]): Dictionary { | ||
| return { | ||
| export function fromTokens( | ||
| tokens: Parameters<typeof convertTokenData>[0], | ||
| unfilteredTokens?: Parameters<typeof convertTokenData>[0], | ||
| ): Dictionary { | ||
| const dictionary: Dictionary = { | ||
| tokens: convertTokenData(tokens, { output: "object" }), | ||
| allTokens: convertTokenData(tokens, { output: "array" }), | ||
| tokenMap: convertTokenData(tokens, { output: "map" }), | ||
| }; | ||
|
|
||
| if (unfilteredTokens) { | ||
| dictionary.unfilteredTokens = convertTokenData(unfilteredTokens, { output: "object" }); | ||
| dictionary.unfilteredAllTokens = convertTokenData(tokens, { output: "array" }); | ||
| dictionary.unfilteredTokenMap = convertTokenData(tokens, { output: "map" }); | ||
| } | ||
|
|
||
| return dictionary; | ||
| } |
5 changes: 5 additions & 0 deletions
5
packages/calcite-design-tokens/src/build/utils/output-references.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import type { OutputReferences } from "style-dictionary/types"; | ||
|
|
||
| export const primitiveValueOutputReferences: Exclude<OutputReferences, boolean> = (token) => { | ||
| return !!(token.type === "color" && token.path.includes("focus")); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use a var for
2px? Maybe the border width var? var(--calcite-spacing-base)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I'll do that in a follow-up since I'll also have to update the preset utils.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR submitted! #12348