Recommendation on using sizing units #525
-
Hi, I am trying to figure out what's the best way to use sizing units within this plugin. ExampleHere's a typography specification that I want to achieve in css: .h1 {
...
font-size: 6rem;
line-height: 1.167;
letter-spacing: -0.01562em;
} I have set up my tokens like this, with units exactly as specified above:
Now I set up my Typography When I hit
Since this did not work, I changed the lineHeight in my typography token to do some math: When I hit update, the Figma style changes to line height of The only way I could make this work was to specify all units as numbers, thus assuming pixels. Is this assumption correct? A couple of related questions:
Overall, what's is the recommended way to work with units? Thanks in advance for your help. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Digging into the examples, the following transform assumes that the incoming size will be a number and appends I am starting to think that the best approach may be to specify all sizes as unit-less numbers in Figma representing pixels, and then converting them to rem, em etc. in platform specific transformers. Am I thinking in the right direction? StyleDictionary.registerTransform({
name: 'sizes/px',
type: 'value',
matcher: function (prop) {
// You can be more specific here if you only want 'em' units for font sizes
return [
'fontSize',
'spacing',
'borderRadius',
'borderWidth',
'sizing',
].includes(prop.attributes.category);
},
transformer: function (prop) {
// You can also modify the value here if you want to convert pixels to ems
return parseFloat(prop.original.value) + 'px';
},
}); |
Beta Was this translation helpful? Give feedback.
-
Another thing I learned when reading Style Dictionary docs was the concept of "Category / Type / Item" (CTI). I was completely unaware of this and it was interesting to note that their transformers assume this taxonomy. Also the component-cti example was very helpful in understanding how this taxonomy can be overridden. @six7, it would be good to add these references to the plugin docs - it will help people get a broader context of the ecosystem. |
Beta Was this translation helpful? Give feedback.
Digging into the examples, the following transform assumes that the incoming size will be a number and appends
px
to it. In my case, it was coming in as6rem
which got converted into6px
- obviously not correct.I am starting to think that the best approach may be to specify all sizes as unit-less numbers in Figma representing pixels, and then converting them to rem, em etc. in platform specific transformers. Am I thinking in the right direction?