-
Notifications
You must be signed in to change notification settings - Fork 205
docs: create how to work with design tokens #26
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
Changes from all commits
a45cd89
c2b12c7
841ca6b
63c5e31
4e329d7
f81ebef
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,5 @@ | ||
| .PHONY: build | ||
| build: | ||
| rm -rf dist && mkdir dist | ||
| npm run build-tokens | ||
| npm run build-scss |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| =================================== | ||
| 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/ | ||
|
Contributor
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
Contributor
Author
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?
Contributor
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. Thanks for the explanation 💯 |
||
| │ └── <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_dictionary_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", | ||
| }, | ||
| "arrow-side": { // Subitem | ||
| "margin": { // Type | ||
| "$value": "{spacing.annotation.padding}", | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "typography": { | ||
| "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 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) | ||
| - **Modify**: Optional value that helps to apply a specific token modification. | ||
|
|
||
| You can check `Paragon tokens <https://github.com/openedx/paragon/tree/release-23.x/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. You can check its options `here <https://github.com/openedx/paragon?tab=readme-ov-file#paragon-cli>`_. | ||
| For using the help command run: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| npm run paragon:help -- <name of the command you want to see more information> | ||
|
|
||
| #. 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> -t <theme_variant> -t <theme_variant>" | ||
| } | ||
| } | ||
|
|
||
| Replace the destination with the desired path and specify the theme variant to be compiled, then run the command. | ||
| You can explore the command options using Paragon help for ``build-tokens``. | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| npm run build-tokens | ||
|
|
||
| # Create the CSS distribution files modifying the template script in ``package.json``: | ||
|
|
||
| .. code-block:: json | ||
|
|
||
| { | ||
| "scripts": { | ||
| "build-scss": "rm -rf dist && mkdir dist && paragon build-scss --corePath <core_scss_file> --themesPath <themes_css_files> --source", | ||
| } | ||
| } | ||
|
|
||
| Where ``<themes_css_files>`` is the path created when you run the build-tokens command and ``<core_scss_file>`` is the path to the scss core file, | ||
| by default **./paragon/core.scss**. Then run the command: | ||
|
|
||
| .. code-block:: bash | ||
|
|
||
| npm run build | ||
|
|
||
| You can explore the command options using Paragon help for ``build-scss``. Finally, this command should create 3 diffent files (.css, .map, .min.css) for the | ||
| core and each of the available themes; also, the command creates a ``theme-urls.json`` (see below for more details). | ||
|
|
||
| #. Publish the package. | ||
|
|
||
| #. Once it is installed in the application use the Paragon CLI with the ``replace-variables`` command to use your custom tokens. | ||
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.3tag, so maybe having something likecould work