question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[DISCUSSION] Modify theming scale values to allow style calculation

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

While developing or overriding components that consume theme values I expect to be able to calculate associated styling values from the theme provided.

i.e. If a style in a component should always have a marginTop value that is 50% the height of the current font lineHeight, I should be able to apply the size via

{
    marginTop: `${$theme.typography.font200.lineHeight / 2}px`
}

This would allow a theme to modify the typography without breaking the spacing provided within a component.

Current Behavior

All spacing, border, and sizing values are represented as strings. This makes ratio calculations impossible.

I suggest we convert these values to numbers (BREAKING change).

Context

I ran into some customization issues between the typography provided by the default and UberMove theme while implementing the ProgressSteps component.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
schnerdcommented, Nov 15, 2018

It’s maybe worth pointing out that such a change would make baseui a strict pixel-based system. As of right now customers could theoretically create a theme that uses rem/em for font sizes or spacing. Not necessarily a blocker, but worth considering.

One alternative to consider, though I’m not 100% sure of the support/performance implications, is using calc(), which works with any units

{
    marginTop: `calc(${$theme.typography.font200.lineHeight} / 2)`
}

I’d be curious to hear design’s take on this as well. When building these are they thinking in terms of “half of line height”, or are they relying on the scale system to ensure consistent spacing?

cc @nguyensomniac

1reaction
sandgrahamcommented, Nov 4, 2020

@tonypee - You can set the sizing scale to be any unit and things should adjust accordingly. This is because we don’t make assumptions about the units you assign to the scale when using them in styling code.

// yes
marginLeft: theme.sizing.scale400

// no
marginLeft: `${theme.sizing.scale400}px`

There are px units used in certain circumstances though- mostly border widths and certain elements that need to be absolutely sized (or at least for our purposes are always an exact size in px). I think in these cases a simple styling override is probably sufficient.

All that said, we are comfortable with px values in our own apps and don’t test the components with relative units.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[DISCUSSION] Modify theming scale values to allow style ...
While developing or overriding components that consume theme values I expect to be able to calculate associated styling values from the theme ......
Read more >
Building a Material Theme on Android: Typography
Material Theming is a way to customize Material Components to align with your brand. A Material theme includes color, typography and shape ...
Read more >
Specificity - CSS: Cascading Style Sheets - MDN Web Docs
The specificity algorithm is basically a three-column value of three categories or weights - ID, CLASS, and TYPE - corresponding to the three ......
Read more >
A Complete Guide to Custom Properties | CSS-Tricks
The var() function is what allows for fallback values in custom properties. Here we're setting a scale() transform function to a custom property ......
Read more >
10 Position scales and axes | ggplot2
Position scales are used to control the locations of visual entities in a plot, and how those locations are mapped to data values....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found