Skip to content
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

[Feature] Add composite typography tokens #572

Merged
merged 26 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5fc5924
Add typography filter and composite format to build.js. Add configs f…
narin Oct 29, 2024
29ab17c
Fix filter comment
narin Oct 29, 2024
7234c4b
Version bump: tokens-v0.19.1-alpha.0
va-mobile-automation-robot Oct 29, 2024
1e5dddd
Rename typography to fonts. Move composite fonts declaration to index.
narin Oct 29, 2024
2959426
Merge branch 'feature/495-narin-composite-typography-tokens' of githu…
narin Oct 29, 2024
0fdd430
Version bump: tokens-v0.19.1-alpha.1
va-mobile-automation-robot Oct 29, 2024
4589f99
Add comments with values to font declarations
narin Oct 29, 2024
2e73885
Merge branch 'feature/495-narin-composite-typography-tokens' of githu…
narin Oct 29, 2024
6b39505
Version bump: tokens-v0.19.1-alpha.2
va-mobile-automation-robot Oct 29, 2024
b674276
Merge branch 'feature/495-narin-composite-typography-tokens' of githu…
narin Oct 29, 2024
6f81a39
Version bump: tokens-v0.19.1-alpha.3
va-mobile-automation-robot Oct 29, 2024
91f6a5d
Rename fonts to styles. Fix declarations
narin Oct 29, 2024
da47e6b
Version bump: tokens-v0.19.1-alpha.4
va-mobile-automation-robot Oct 29, 2024
844910a
Remove unused var and commented code
narin Oct 29, 2024
40246d2
Merge branch 'feature/495-narin-composite-typography-tokens' of githu…
narin Oct 29, 2024
8a3ccbd
Fix comment. Remove unused var.
narin Oct 30, 2024
310200f
Cleanup
narin Oct 30, 2024
711a8dd
Update comment
narin Oct 30, 2024
ccd0db2
Update packages/tokens/build.js
narin Nov 5, 2024
70bcee4
Rename composite and styles to typography. Remove noSort from typogra…
narin Nov 5, 2024
46c8e33
Sort typography.json alphabetically
narin Nov 5, 2024
95a99fd
Fix files sort
narin Nov 5, 2024
a11eee9
Merge branch 'main' into feature/495-narin-composite-typography-tokens
narin Nov 5, 2024
6d995f0
Merge branch 'feature/495-narin-composite-typography-tokens' of githu…
narin Nov 5, 2024
1dd2703
Merge branch 'main' into feature/495-narin-composite-typography-tokens
narin Nov 5, 2024
60e78a0
Replace composite with typography for font filter
narin Nov 8, 2024
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
42 changes: 40 additions & 2 deletions packages/tokens/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ StyleDictionary.registerFilter({
matcher: (token) => filterFont(token, 'line-height'),
})

/** Filter to tokens of category 'font', type 'composite', and npm true */
StyleDictionary.registerFilter({
name: 'filter/font/composite-npm',
matcher: (token) => filterFont(token, 'composite'),
})

/** Remove tokens that do not have 'font' in the category and have figma attribute */
StyleDictionary.registerFilter({
name: 'filter/font-figma',
Expand Down Expand Up @@ -170,7 +176,7 @@ StyleDictionary.registerFormat({
StyleDictionary.registerFormat({
name: 'javascript/es6/fontIndex',
formatter: function () {
const files = ['family', 'letterSpacing', 'lineHeight', 'size']
const files = ['family', 'letterSpacing', 'lineHeight', 'size', 'styles']
let imports = '',
exports = ''

Expand All @@ -186,7 +192,7 @@ StyleDictionary.registerFormat({
StyleDictionary.registerFormat({
name: 'typescript/es6-declarations/fontIndex',
formatter: function () {
const files = ['family', 'letterSpacing', 'lineHeight', 'size']
const files = ['family', 'letterSpacing', 'lineHeight', 'size', 'styles']
let imports = '',
exports = ''

Expand Down Expand Up @@ -249,6 +255,38 @@ StyleDictionary.registerFormat({
},
})

/** Formats declarations exports for composite tokens */
StyleDictionary.registerFormat({
name: 'typescript/es6-declarations/composite',
formatter: function ({ dictionary, options }) {
let tokens = dictionary.allTokens,
declaration = `export declare const ${options.exportName}: {\n`

if (!options.noSort) {
tokens = sortTokensByName(tokens)
}

for (const token of tokens) {
let docs = `/** `
let valueKeys = '{\n'

// Generate docs line and object of value types
Object.keys(token.value).forEach((key, index) => {
docs += `${index !== 0 ? '| ' : ''}${key}: ${token.value[key]} `
valueKeys += ` ${key}: ${typeof token.value[key]}\n`
})

docs += `*/\n`
declaration += ` ${docs}`
narin marked this conversation as resolved.
Show resolved Hide resolved
declaration += ` ${token.name}: ${valueKeys}`
declaration += ` }\n`
}

declaration += '}'
return declaration
},
})

/** Creates named type declaration for Themes. Allows for TypeScript autocomplete */
StyleDictionary.registerFormat({
name: 'typescript/es6-declarations/theme',
narin marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
17 changes: 17 additions & 0 deletions packages/tokens/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ module.exports = {
destination: 'js/themes.js',
format: 'javascript/es6/vads-colors-themes',
},
{
destination: 'js/font/styles.js',
narin marked this conversation as resolved.
Show resolved Hide resolved
format: 'javascript/es6/simple-key-value',
filter: 'filter/font/composite-npm',
options: {
exportName: 'styles',
narin marked this conversation as resolved.
Show resolved Hide resolved
},
},
// TS defs
{
destination: 'types/colors.d.ts',
Expand Down Expand Up @@ -130,6 +138,15 @@ module.exports = {
noSort: true,
},
},
{
destination: 'types/font/styles.d.ts',
format: 'typescript/es6-declarations/composite',
filter: 'filter/font/composite-npm',
options: {
exportName: 'styles',
noSort: true,
narin marked this conversation as resolved.
Show resolved Hide resolved
},
},
{
destination: 'types/spacing.d.ts',
format: 'typescript/es6-declarations/simple-key-value',
Expand Down
2 changes: 1 addition & 1 deletion packages/tokens/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@department-of-veterans-affairs/mobile-tokens",
"version": "0.19.0",
"version": "0.19.1-alpha.4",
"description": "VA Design System Mobile Token Library",
"main": "dist/js/index.js",
"types": "dist/index.d.ts",
Expand Down
152 changes: 152 additions & 0 deletions packages/tokens/src/tokens/font/composite.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
{
narin marked this conversation as resolved.
Show resolved Hide resolved
"vads-font-display": {
narin marked this conversation as resolved.
Show resolved Hide resolved
"name": "vads-font-display",
"value": {
"fontFamily": "{vads-font-family-serif-regular}",
"fontSize": "{vads-font-size-display}",
"lineHeight": "{vads-font-line-height-heading-5xl}",
"marginBottom": "{vads-font-paragraph-spacing-heading-5xl}",
narin marked this conversation as resolved.
Show resolved Hide resolved
"letterSpacing": "{vads-font-letter-spacing-heading}"
},
"attributes": {
"category": "font",
"type": "composite",
"npm": true
}
},
"vads-font-heading-large": {
"name": "vads-font-heading-large",
"value": {
"fontFamily": "{vads-font-family-serif-regular}",
"fontSize": "{vads-font-size-heading-level-1}",
"lineHeight": "{vads-font-line-height-heading-2xl}",
"marginBottom": "{vads-font-paragraph-spacing-heading-2xl}",
"letterSpacing": "{vads-font-letter-spacing-heading}"
},
"attributes": {
"category": "font",
"type": "composite",
"npm": true
}
},
"vads-font-heading-medium": {
"name": "vads-font-heading-medium",
"value": {
"fontFamily": "{vads-font-family-serif-regular}",
"fontSize": "{vads-font-size-heading-level-2}",
"lineHeight": "{vads-font-line-height-heading-xl}",
"marginBottom": "{vads-font-paragraph-spacing-heading-xl}",
"letterSpacing": "{vads-font-letter-spacing-heading}"
},
"attributes": {
"category": "font",
"type": "composite",
"npm": true
}
},
"vads-font-heading-small": {
"name": "vads-font-heading-small",
"value": {
"fontFamily": "{vads-font-family-sans-serif-bold}",
"fontSize": "{vads-font-size-heading-level-3}",
"lineHeight": "{vads-font-line-height-heading-lg}",
"marginBottom": "{vads-font-paragraph-spacing-heading-lg}",
"letterSpacing": "{vads-font-letter-spacing-heading}"
},
"attributes": {
"category": "font",
"type": "composite",
"npm": true
}
},
"vads-font-heading-xsmall": {
"name": "vads-font-heading-xsmall",
"value": {
"fontFamily": "{vads-font-family-sans-serif-bold}",
"fontSize": "{vads-font-size-heading-level-4}",
"lineHeight": "{vads-font-line-height-heading-md}",
"marginBottom": "{vads-font-paragraph-spacing-heading-md}",
"letterSpacing": "{vads-font-letter-spacing-heading}"
},
"attributes": {
"category": "font",
"type": "composite",
"npm": true
}
},
"vads-font-body-large": {
"name": "vads-font-body-large",
"value": {
"fontFamily": "{vads-font-family-sans-serif-regular}",
"fontSize": "{vads-font-size-body-large}",
"lineHeight": "{vads-font-line-height-default-lg}",
"marginBottom": "{vads-font-paragraph-spacing-default-lg}",
"letterSpacing": "{vads-font-letter-spacing-default}"
},
"attributes": {
"category": "font",
"type": "composite",
"npm": true
}
},
"vads-font-body-medium": {
"name": "vads-font-body-medium",
"value": {
"fontFamily": "{vads-font-family-sans-serif-regular}",
"fontSize": "{vads-font-size-body-medium}",
"lineHeight": "{vads-font-line-height-default-md}",
"marginBottom": "{vads-font-paragraph-spacing-default-md}",
"letterSpacing": "{vads-font-letter-spacing-default}"
},
"attributes": {
"category": "font",
"type": "composite",
"npm": true
}
},
"vads-font-body-small": {
"name": "vads-font-body-small",
"value": {
"fontFamily": "{vads-font-family-sans-serif-regular}",
"fontSize": "{vads-font-size-body-small}",
"lineHeight": "{vads-font-line-height-default-sm}",
"marginBottom": "{vads-font-paragraph-spacing-default-sm}",
"letterSpacing": "{vads-font-letter-spacing-default}"
},
"attributes": {
"category": "font",
"type": "composite",
"npm": true
}
},
"vads-font-body-xsmall": {
"name": "vads-font-body-xsmall",
"value": {
"fontFamily": "{vads-font-family-sans-serif-regular}",
"fontSize": "{vads-font-size-body-xsmall}",
"lineHeight": "{vads-font-line-height-default-xs}",
"marginBottom": "{vads-font-paragraph-spacing-default-xs}",
"letterSpacing": "{vads-font-letter-spacing-default}"
},
"attributes": {
"category": "font",
"type": "composite",
"npm": true
}
},
"vads-font-navigation": {
"name": "vads-font-navigation",
"value": {
"fontFamily": "{vads-font-family-sans-serif-regular}",
"fontSize": "{vads-font-size-navigation}",
"lineHeight": "{vads-font-line-height-default-2xs}",
"marginBottom": "{vads-font-paragraph-spacing-default-2xs}",
"letterSpacing": "{vads-font-letter-spacing-default}"
},
"attributes": {
"category": "font",
"type": "composite",
"npm": true
}
}
}
Loading