[CSS-in-JS] Sizes with units#4578
Conversation
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_4578/ |
|
This looks good to me in the theme, but when I look out the output, this nesty
|
We could roll our own calculation function to use instead. That way the output is always a px string. |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_4578/ |
|
Exploring options for a custom math function and found https://polished.js.org/docs/#math
Math on mixed units and user provided values is either risky or not possible. CSS |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_4578/ |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_4578/ |
|
Latest commit results in output like: "base": 16,
"sizes": {
"euiSize": "16px",
"euiSizeXS": "4px",
"euiSizeS": "8px",
"euiSizeM": "12px",
"euiSizeL": "24px",
"euiSizeXL": "32px",
"euiSizeXXL": "40px",
"euiButtonMinWidth": "112px",
"euiScrollBar": "16px",
"euiScrollBarCorner": "calc(8px * 0.75)"
},Note that |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_4578/ |
| euiSizeXXL: computed(['sizes.euiSize'], ([euiSize]) => euiSize * 2.5), | ||
| euiSize: computed(['base'], ([base]) => `${base}px`), | ||
| euiSizeXS: computed(['base'], ([base]) => `${base * 0.25}px`), | ||
| euiSizeS: computed(['base'], ([base]) => `${base * 0.5}px`), |
There was a problem hiding this comment.
Has there been more thought on how we might be able to simplify this without needing to write base 3 times?
There was a problem hiding this comment.
Haven't put any thought to it until just now. I think at best you're looking at writing base twice, and I'm not sure it scales well beyond top-level keys like base. I can think about it a bit.
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_4578/ |
|
Preview documentation changes for this PR: https://eui.elastic.co/pr_4578/ |
|
Will merge this soon so that work based on this branch can move forward |

Summary
Converts unitless number values to strings with units. Allows for use in string- and object-based Emotion styling.
Thinking that we can use the
calcapproach for now and determine if we want to move to a custom math function as we build more of the theme.### Checklist