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.

Allow theme.spacing() to return a number

See original GitHub issue

Motivation 🔦

I love the spacing utility function because it makes keeping spacing consistent throughout an application very easy, but in some cases, I want to tweak the value returned by it a little. This is currently quite difficult because the function always returns a string with "px" appended to it. Currently, if I want to, for example, add 2 to the return value of the spacing function, I would have to do something like this:

`${Number(theme.spacing(3).slice(0, -2)) + 2}px`

I did check to see if the spacing value provided to createTheme() was exposed anywhere in the Theme object, but it didn’t look like it was.

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

Summary 💡

There should be some way (possibly a fifth argument?) to make the spacing function return a number. If this isn’t possible, then the spacing multiplier value provided to createTheme() should be exposed somewhere in the Theme object so that developers can use it to do the multiplication themselves.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:23
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

14reactions
chaosmiragecommented, Jan 11, 2022

Workaround: calc(${theme.spacing(2)} - 1px)

8reactions
mnajdovacommented, Oct 20, 2021

As per your code this is all it takes to implement it: Number(theme.spacing(3).slice(0, -2)) It should be fairly easy to add this inf your custom theme, or even as a util:

const getSpacing = (theme, value) => Number(theme.spacing(value).slice(0, -2))

I am not sure if it is worth adding it to the theme. I would wait to see if it will get some traction 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spacing math with theme.spacing() in MUI v5 - reactjs
In v5 however, theme.spacing() returns a string instead of a number. So the above statement would set paddingTop to 568px , which is...
Read more >
Spacing - Material UI
Use the theme.spacing() helper to create consistent spacing between the elements of your UI. MUI uses a recommended 8px scaling factor by default....
Read more >
Quick-Start Guide to NMS Development
Spacing Guidelines. Within the context of the NMS, it's important to have consistency within the design so that all pages feel unified.
Read more >
How to Customise Material UI's Default Styling
Spacing: Spacing is used to give consistent distance between elements UI. Spacing can be applied to our UI by using "theme. spacing()".
Read more >
How to Add a Line Break in WordPress (New Line Spacing)
Let's take a look at the easy method first. Adding Line Spacing Using a Plugin. If you want to make style changes to...
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