-
Notifications
You must be signed in to change notification settings - Fork 123
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
docs: create how to work with design tokens #26
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.DS_Store | ||
.vscode | ||
node_modules |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
=================================== | ||
Paragon Design Tokens Compatibility | ||
=================================== | ||
|
||
|
||
From version 23 `Paragon <https://github.com/openedx/paragon/>`_ supports CSS variables and | ||
`design tokens <https://tr.designtokens.org/format/#abstract>`_. | ||
|
||
How to structure the brand design tokens files | ||
============================================== | ||
|
||
The file structure in the brand package should be the same as the version of Paragon used as a reference to allow the merge/override during the build time. | ||
To see the tokens directory structure for the version of Paragon you are targeting, navigate to ``https://github.com/openedx/paragon/tree/TARGET_PARAGON_VERSION/tokens``. | ||
For example, if you were working with Paragon v23.0.0 you would navigate to https://github.com/openedx/paragon/tree/v23.0.0/tokens. | ||
|
||
.. code-block:: | ||
|
||
paragon/ | ||
└── tokens/ | ||
└── src/ | ||
├── core/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [question]: Is it worth specifying here more precisely which directories may be needed? For example, now in the alpha version of Paragon we have semantic tokens that we divide into core, alias and global tokens? More information on semantic design tokens There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think due to the the how-to is explaining how to work with the paragon design tokens version I think a mention and a link to that explanation about semantic tokens is a valuable addition. I don't want to duplicate the information if it is already in Paragon. As well, I think the user should decide the folders that they want to include I mean if I want to change a token in the component folder worth it add the global and aliases as well? |
||
│ └── <name_of_the_folder>/ | ||
│ └── <name_of_the_file>.json | ||
└── themes/ | ||
├── light/ | ||
│ └── <name_of_the_folder>/ | ||
│ └── <name_of_the_file>.json | ||
├── dark/ | ||
│ └── <name_of_the_folder>/ | ||
│ └── <name_of_the_file>.json | ||
└── my-theme/ | ||
└── <name_of_the_folder>/ | ||
└── <name_of_the_file>.json | ||
|
||
|
||
Once you have identified the token to override, you can replace ``<name_of_the_folder>`` and ``<name_of_the_file>`` with the right names. | ||
Currently, Paragon is organized under **semantic tokens**, for a better understanding visit: | ||
`Design tokens implementation in Paragon <https://github.com/openedx/paragon/blob/master/docs/decisions/0019-scaling-styles-with-design-tokens.rst#design-tokens-implementation-in-paragon>` | ||
|
||
Tokens format | ||
============= | ||
|
||
In terms of tokens, Paragon follows the specifications of the `Design Tokens Community Group <https://tr.designtokens.org/format/#abstract>`_, and | ||
takes `style dictionary token structure <https://styledictionary.com/info/tokens/#category--type--item>`_ as inspiration: | ||
|
||
|
||
.. image:: ./style_diccionary_tokens.webp | ||
|
||
|
||
With a subtle variation the structure to define most of the Paragon tokens is ``category > item > subitem > type > state``, for example: | ||
|
||
.. code-block:: json | ||
|
||
{ | ||
"spacing": { // Category | ||
"$type": "dimension", | ||
"annotation": { // Item | ||
"padding": { // Type | ||
"$value": ".5rem", | ||
"$source": "$annotation-padding" | ||
}, | ||
"arrow-side": { // Subitem | ||
"margin": { // Type | ||
"$value": "{spacing.annotation.padding}", | ||
"$source": "$annotation-arrow-side-margin" | ||
} | ||
} | ||
} | ||
}, | ||
"typography": { | ||
"annotation": { | ||
"font-size": { | ||
"source": "$annotation-font-size", | ||
"$value": "{typography.font.size.sm}", | ||
"$type": "dimension" | ||
}, | ||
} | ||
}, | ||
} | ||
|
||
Each token has specific attributes: | ||
|
||
- **Value**: It is the value that will be assigned to the variable, which could be a value or a reference, such as l arrow-side in the above example. | ||
- **Type**: Indicates the property to be processed (color, dimension, etc..). This value could be defined for the token itself or a group of tokens (e.g. spacing) | ||
- **Source**: This value is additional and indicates the equivalent in saas notation. | ||
- **Modify**: Optional value that helps to apply a specific token modification. | ||
|
||
Use the ``source`` attribute to map the tokens in Paragon and create the theme files. Also, it will help you to replace the values in scss files if you have custom variables (see below). | ||
|
||
You can check `Paragon tokens <https://github.com/openedx/paragon/tree/alpha/tokens>`_ to know the folder and token structure, and how to work with modifiers. | ||
|
||
|
||
Build the tokens and generate the CSS variables | ||
=============================================== | ||
|
||
To build the tokens you can use Paragon CLI. | ||
|
||
#. Install Paragon as a dev dependency | ||
|
||
.. code-block:: bash | ||
|
||
npm ci | ||
|
||
#. Once the tokens have been created. Go to the ``package.json``, there is a script template: | ||
|
||
.. code-block:: json | ||
|
||
{ | ||
"scripts": { | ||
"build-tokens": "paragon build-tokens --source ./tokens/ --build-dir <destination_path>" | ||
} | ||
} | ||
|
||
Replace the destination with the desired path and run the command, it is recommended to use ``./dist/``. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a specific reason to have this as a template instead of just hardcoding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. highlight and in any case be use in the package.json file as the destination for the script template |
||
You can check the CLI options `here <https://openedx.atlassian.net/wiki/spaces/BPL/pages/3770744958/Migrating+MFEs+to+Paragon+design+tokens+and+CSS+variables#Paragon-CLI-Documentation>`_ | ||
|
||
.. code-block:: bash | ||
|
||
npm run build-tokens | ||
|
||
#. Publish the package. | ||
|
||
#. Once it is installed in the application use the Paragon CLI with the ``replace-variables`` command to use your custom tokens. | ||
|
||
|
||
The ``theme-urls.json`` file | ||
============================= | ||
|
||
It is recommended to create the `theme-urls.json` if you are working with runtime theming and want to use ``ParagonWebpackPlugin`` to preload the token URLs during the application build time. | ||
|
||
The file must be in the ``dist`` folder and should have: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not the biggest fan of having people directly create/edit files in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think could live in the paragon/tokens folder, referencing all the desired variants. May be in this way, we will need to be clear about the relative path (understanding that the design tokens destination path is not necessary the dist folder, it is the ideal but is not limited to it) |
||
|
||
.. code-block:: json | ||
|
||
{ | ||
"themeUrls": { | ||
"defaults": { | ||
"light": "light" | ||
}, | ||
"variants": { | ||
"light": { | ||
"paths": { | ||
"default": "./light.css", | ||
"minified": "./light.min.css" | ||
} | ||
} | ||
"my-theme": { | ||
"paths": { | ||
"default": "./my-theme.css", | ||
"minified": "./my-theme.min.css" | ||
} | ||
} | ||
}, | ||
"core": { | ||
"paths": { | ||
"default": "./core.css", | ||
"minified": "./core.min.css" | ||
} | ||
} | ||
} | ||
} | ||
|
||
The paths must be relative to the ``theme-urls.json`` file and contain all the variants that you want to preload. |
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.
It might be nice to link to and/or provide a URL format for the paragon tokens directory from here
https://github.com/openedx/paragon/tree/v23.0.0-alpha.3/tokens currently works to show the directory for the
v23.0.0-alpha.3
tag, so maybe having something likecould work