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

Update to Style Dictionary v4 #203

Merged
merged 16 commits into from
Sep 20, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ jobs:

strategy:
matrix:
node-version: [14.x]
node-version: [20.x]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
Expand Down
20 changes: 0 additions & 20 deletions Changelog.md

This file was deleted.

22 changes: 4 additions & 18 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
MIT License
ISC License

Copyright (c) 2018 REI Engineering
Copyright 2024 REI Engineering

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
78 changes: 35 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ All other formats should consult the changelog for a migration path.
2. `npm install`
3. `npm run build` (output tokens)

Tokens are generated using [Style Dictionary](https://amzn.github.io/style-dictionary/#/).
Tokens are generated using [Style Dictionary v4](https://styledictionary.com/).

### Project structure
The project is made of these files and folders:
Expand Down Expand Up @@ -56,8 +56,8 @@ We follow the basic structure of style-dictionary with the exception being that
The following properties can be added to tokens to support different options

```
value # *required* The token value (most token values should be referenced from options)
category # *required* The tokens category (used to transform values for their specific platform)
$value # *required* The token value (most token values should be referenced from options)
$type # *required* The tokens type (used to transform values for their specific platform)
docs # Object to define meta data for docs
category # The category tokens are grouped in on the examples page
type # The sub category tokens are grouped in on the examples page
Expand All @@ -80,12 +80,12 @@ Options are skipped and do not get exported for consumers. However they can be [
options: { // <-- anything beneath this will be ignored in output
color: {
'easily-excited': {
value: '#3278ae',
category: 'color',
'$value': '#3278ae',
'$type': 'color',
},
'heart-of-darkness': {
value: '#292929',
category: 'color',
'$value': '#292929',
'$type': 'color',
},
// ...
},
Expand All @@ -105,12 +105,12 @@ Token names are defined by the hierarchy of the object:
body: {
default: {
size: {
value: '23px',
category: 'font-size',
'$value': '23px',
'$type': 'fontSize',
},
height: {
value: '25px',
category: 'size',
'$value': '25px',
'$type': 'size',
},
},
},
Expand All @@ -124,19 +124,19 @@ Token output of above:

`text-body-default-height: 25px;`

#### Categories
#### Types

> Categories need to be attached to **both** options and tokens (due to limitations of style-dictionary resolve order. [This may change in the future](https://github.com/amzn/style-dictionary/issues/208))
> Types need to be attached to **both** options and tokens (due to limitations of style-dictionary resolve order. [This may change in the future](https://github.com/amzn/style-dictionary/issues/208))

Categories define how style-dictionary should transform values between platforms.
Types define how style-dictionary should transform values between platforms.

For example, a category of "size" will transform to 'rem' for SCSS/LESS but 'dp' for Android. A category of "font-size" will still transform values to 'rem' for SCSS/LESS but 'sp' for Android.
For example, a type of "dimension" will transform to 'rem' for SCSS/LESS but 'dp' for Android. A type of "fontSize" will still transform values to 'rem' for SCSS/LESS but 'sp' for Android.

Categories are one of the following:

- `size`: Anything that would have a value in px. With the exception of font-size
- `font-size`: Anything that defines a text size
- `letter-spacing`: exists too?
- `dimension`: Anything that would have a value in px. With the exception of fontSize
- `fontSize`: Anything that defines a text size
- `letterSpacing`: Anything that defined a letter spacing
- `color`: Anything that defines a color
- `time`: Anything the defines a timing
- Values without a category will not be transformed: Anything that is a string like `'normal'` or `'italic'`
Expand All @@ -151,8 +151,8 @@ See [attribute referencing](https://amzn.github.io/style-dictionary/#/properties
text: {
primary: {
'on-dark': {
value: '{options.color.heart-of-darkness}',
category: 'color',
'$value': '{options.color.heart-of-darkness}',
'$type': 'color',
docs: {
category: 'colors',
type: 'text',
Expand Down Expand Up @@ -185,19 +185,19 @@ docs: {

Deprecated tokens should be moved to a seprate file (or into the existing file) which corresponds to the release cycle in which they will be deprecated.

For example, if tokens will be considered deprecated in the "Winter 2019" release they would be moved into a file called `deprecated-2019-winter.json5` in whichever directory they currently reside. Structure for naming the file is : `deprecated-<year>-<release>`
For example, if tokens will be considered deprecated in the "Winter 2019" release they would be moved into a file called `deprecated-2024-summer.json5` in whichever directory they currently reside. Structure for naming the file is : `deprecated-<year>-<release>`
Copy link
Member

Choose a reason for hiding this comment

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

"Q4 2024"
deprecated-2024-Q2.json


Additionally, the contents will be wrapped inside an object with a key that corresponds to the release as well (so we can auto generate some deprecation warnings with the correct release). The key matches the naming of the file. See below for an example.

```js
{
'deprecated-2019-winter`: { // <-------- `deprecated-<year>-<release>`
color: {
text: {
primary: {
'on-dark': {
value: '{options.color.heart-of-darkness}',
category: 'color',
'deprecated-2024-q4': { // <-------- `deprecated-<year>-<release>`
color: {
text: {
primary: {
'on-dark': {
'$value': '{options.color.heart-of-darkness}',
'$type': 'color',
docs: {
category: 'colors',
type: 'text',
Expand All @@ -218,12 +218,12 @@ When tokens are deprecated they can also be provided a new token name or new mix

```js
{
'deprecated-2019-winter': {
'deprecated-2024-q4': {
text: {
header: {
'1': {
family: {
value: '{options.font.family.serif.value}',
'$value': '{options.font.family.serif.$value}',
mixin: 'textHeader1',
property: 'font-family',
newMixin: 'new-mixin-name', //<--- a new mixin name to use instead of the deprecated one
Expand Down Expand Up @@ -253,39 +253,31 @@ All actions, configs, formats, etc are imported in this file and it [extends](ht

Found in `style-dictionary/actions`

See API for [creating an action](https://amzn.github.io/style-dictionary/#/api?id=registeraction)

See [actions docs](https://amzn.github.io/style-dictionary/#/actions)
See API for [creating an action](https://styledictionary.com/reference/hooks/actions/)

#### Configs

Found in `style-dictionary/configs`

See [config docs](https://amzn.github.io/style-dictionary/#/config).
See [config docs](https://styledictionary.com/reference/config/#configuration-file-formats).

Configs follow standard config options. They are organized separately by platform and are required into the `_index.js` file where they all have a filter for options applied.

#### Formats

Found in `style-dictionary/formats`

See API for [creating a format](https://amzn.github.io/style-dictionary/#/api?id=registerformat)

See [format docs](https://amzn.github.io/style-dictionary/#/formats).
See API for [creating a format](https://styledictionary.com/reference/hooks/formats/)

#### Transform Groups

Found in `style-dictionary/transformGroups`

See API for [creating a transform group](https://amzn.github.io/style-dictionary/#/api?id=registertransformgroup)

See [transform group docs](https://amzn.github.io/style-dictionary/#/transform_groups).
See API for [creating a transform group](https://styledictionary.com/reference/hooks/transform-groups/)

#### Transforms

Found in `style-dictionary/transforms`

See API for [creating a transform](https://amzn.github.io/style-dictionary/#/api?id=registertransform)
See API for [creating a transform](https://styledictionary.com/reference/hooks/transforms/)

See [transform docs](https://amzn.github.io/style-dictionary/#/transforms).

Expand Down
3 changes: 1 addition & 2 deletions dist/docsite/android/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,4 @@
<color name="cdr_knockout_color_border_table_row">#ff4e4d49</color>
<color name="cdr_knockout_color_icon_inverse_default">#ffdcd6cb</color>
<color name="cdr_knockout_color_icon_background_note">#ffc4b03b</color>

</resources>
</resources>
3 changes: 1 addition & 2 deletions dist/docsite/android/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,4 @@
<dimen name="cdr_text_default_caption1_line_spacing">16.00dp</dimen>
<dimen name="cdr_text_default_caption2_line_spacing">16.00dp</dimen>
<dimen name="cdr_text_default_button_line_spacing">24.00dp</dimen>

</resources>
</resources>
3 changes: 1 addition & 2 deletions dist/docsite/android/font_dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@
<dimen name="cdr_text_default_caption1_size">12.00sp</dimen>
<dimen name="cdr_text_default_caption2_size">11.00sp</dimen>
<dimen name="cdr_text_default_button_size">15.00sp</dimen>

</resources>
</resources>
Loading