-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add js platform formats to calcite-design-tokens (#8044)
**Related Issue:** #7986 ## Summary Adds two new platforms and four formats to design-token exports. ### JS platform The "js" platform creates a javascript object of the design-tokens and a typescript types declaration file representing that object. This format is necessary for documentation. #### Examples ```js export default { core: { breakpoint: { width: { xxs: { value: "320px", type: "sizing", description: "Small handheld devices and mini-windows", filePath: "src/core.json", isSource: true, original: { value: "320px", type: "sizing", description: "Small handheld devices and mini-windows", }, name: "xxs", attributes: {}, path: ["core", "breakpoint", "width", "xxs"], }, xs: { ``` ```typescript declare const root: RootObject export default root interface RootObject { core: Core; semantic: Semantic; } interface Core { font: Font20; border: Border7; opacity: Opacity2; color: Color; sizing: Sizing; spacing: Sizing; breakpoint: Breakpoint; 'z-index': Zindex; } ``` ### ES6 platform The "es6" platform provides the design tokens as tree-shakable javascript named exports. #### Examples ```js export const CoreSpacing27 = "256px"; export const CoreSpacing28 = "288px"; export const CoreSpacingNone = "0px"; export const CoreBreakpointWidthXxs = "320px"; export const CoreBreakpointWidthXs = "476px"; export const CoreBreakpointWidthSm = "768px"; export const CoreBreakpointWidthMd = "1152px"; export const CoreBreakpointWidthLg = "1440px"; ``` ```typescript export const CoreSpacing27 : string; export const CoreSpacing28 : string; export const CoreSpacingNone : string; export const CoreBreakpointWidthXxs : string; export const CoreBreakpointWidthXs : string; export const CoreBreakpointWidthSm : string; export const CoreBreakpointWidthMd : string; export const CoreBreakpointWidthLg : string; ```
- Loading branch information
1 parent
6a31ea7
commit 0e1fefb
Showing
5 changed files
with
233 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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
22 changes: 22 additions & 0 deletions
22
packages/calcite-design-tokens/support/token-transformer/format/javascript.ts
This file contains 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,22 @@ | ||
import StyleDictionary, { Dictionary, File } from "style-dictionary"; | ||
import { default as JsonToTS } from "json-to-ts"; | ||
|
||
type FormatOptions = { dictionary: Dictionary; file: File }; | ||
|
||
export function formatJs({ dictionary, file }: FormatOptions): string { | ||
return ( | ||
StyleDictionary.formatHelpers.fileHeader({ file }) + | ||
"export default" + | ||
JSON.stringify(dictionary.tokens, null, 2) + | ||
";\n" | ||
); | ||
} | ||
|
||
export function formatTs({ dictionary, file }: FormatOptions): string { | ||
return ( | ||
StyleDictionary.formatHelpers.fileHeader({ file }) + | ||
"declare const root: RootObject\n" + | ||
"export default root\n" + | ||
JsonToTS(dictionary.properties).join("\n") | ||
); | ||
} |
This file contains 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