Skip to content

Commit

Permalink
allow @-hack
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasoppermann committed Jul 27, 2023
1 parent 7fde5c2 commit 5946100
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,27 @@ Code example
}
```

#### Token names and @-hack

Token names have to be in camelCase or kebab-case and may only include letters, numbers and `-`. This is enforced by the token validation (`npm run lint:tokens`).
The only acception is the `@`-hack. This is used when you want to have a default value and sub-values, e.g. `bgColor.accent` and `bgColor.accent.muted`.
In this case you can create the follwing structure. The `@` will be removed from the name and act as the default value.

```js
{
bgColor: {
accent: {
"@": {
// default values
},
"muted": {
// values for accent-muted
}
}
}
}
```

## License

[MIT](./LICENSE) © [GitHub](https://github.com/)
Expand Down
2 changes: 1 addition & 1 deletion src/schemas/tokenName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {z} from 'zod'
import {schemaErrorMessage} from '../utilities/schemaErrorMessage'

export const tokenName = z.string().refine(
name => /^[a-z0-9][A-Za-z0-9-]*$/.test(name),
name => /(^[a-z0-9][A-Za-z0-9-]*$|^@$)/.test(name),
name => ({
message: schemaErrorMessage(
`Invalid token name: "${name}"`,
Expand Down
16 changes: 9 additions & 7 deletions src/tokens/functional/color/dark/primitives-dark.json5
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@
},
},
link: {
$value: '{fgColor.accent}',
$type: 'color',
$extensions: {
'org.primer.figma': {
collection: 'mode',
mode: 'dark',
scopes: ['fgColor'],
'@': {
$value: '{fgColor.accent}',
$type: 'color',
$extensions: {
'org.primer.figma': {
collection: 'mode',
mode: 'dark',
scopes: ['fgColor'],
},
},
},
},
Expand Down

0 comments on commit 5946100

Please sign in to comment.