Tokens Name Conventions and CSS #1017
aaronreed708
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Below is sample snippet of JSON code for a "Button" component generated by Theme Builder, which will be pushed to GitHub. The a GitHub PR can trigger GitHub actions that auto generated css from the JSON. The JSON will pushed to Figma Tokens.
The hope is that the JSON passed along to Figma Tokens can be utilized by Anima to update the naming conventions used to the auto generated it's Ai generated React and CSS code.
If the naming taxomony is the same, a user could theroretically use the code which comes out of Anima for any new components styled in Figma and maintain the dynamic logic provided by theme builder.
JSON
CSS
The Desired CSS output from the above JSON, transformed by Style Dictionary, should be:
To achive this the follow rules were followed.
Token path names are converted to lower case css class names. Hence Button becomes .button.
Token variables {} are converted to root variables and loose their prefix. Hence {radius.button-radius} becomes var(--button-radius).
Ignore "type" and "text" properties.
A direct child of a type "clickable" JSON with a the name "Default" renders the listed styles in the parent.
So the JSON styles .Button.Default render in css as:
.button {}
Convert the secondary path name for all JSON with the type "clickable" to "style"
For example a json token with the path Button > Type > Default should be rendered in css as .button.style.default {}.
Tokens values with parentheses, not preceeded by RGB or RGBA, indicate calculations. Hence (0 - {focus-border}) is rendered in css as calc(0 - var(--focus-border)).
For any JSON path with the secondary path of "State" should render the css as pseudo-class and if the child of "State" is named "Default" the corresponding translated class and pseudo-class should be button.style:after.
If he JSON Token is Button > State > Focus then the rendered css would be .button.style:after:focus {}.
Additionally these "State" tokens have the following css added:
position: absolute;
content: "";
JSON styling "x" of "State" tokens is converted to top and bottom varaibles.
Hence "x": "(0 - {focus-border})" is rendered in css as:
top: calc(0 - var(--focus-border)) and bottom: calc(0 - var(--focus-border))
JSON styling "y" of "State" tokens is converted to top and bottom varaibles.
Hence "y": "(0 - {focus-border})" is rendered in css as:
left: calc(0 - var(--focus-border)) and right: calc(0 - var(--focus-border))
JSON styling "number" of "State" tokens is converted to transition so that the css is rendered transition: var(--animation-speed) cubic-bezier(0.68, -0.55, 0.265, 1.55) all
React
The react component in would then be coded as such.
Beta Was this translation helpful? Give feedback.
All reactions