Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a function to get the numeric value of theme.spacing #33497

Closed
2 tasks done
paul23-git opened this issue Jul 13, 2022 · 1 comment
Closed
2 tasks done

Add a function to get the numeric value of theme.spacing #33497

paul23-git opened this issue Jul 13, 2022 · 1 comment
Labels
duplicate This issue or pull request already exists

Comments

@paul23-git
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 💡

I material ui before version 5 the result of theme.spacing(n) was a number. This was useful as one could easily do mathematics on that number.

I understand that adding px would be required by the new emotion engine/syntax, however could there be a separate function that just returns the calculated spacing in pixels? IE theme.pixelSpacing(n: number): number

Examples 🌈

const StyledResponsiveForm = styled(Dialog)(({theme}: {theme: Theme}) => css`
  margin-left: ${theme.spacing(3)};
  maring-right: ${theme.spacing(3)};
  ${theme.breakpoints.up(602+theme.spacing(2))} {
    margin-left: ${theme.spacing(4)};
    maring-right: ${theme.spacing(4)};
  }
`)

Should put a breakpoint (with default spacing settings) at 618 pixels.

Motivation 🔦

While some of this can be offset by letting the css engine use calc it's not everywhere possible on top of that the limitations of calc make some code much harder to read, while inlining the calculation would greatly reduce this.

A good example is for breakpoints in css:

const StyledResponsiveForm = styled(Dialog)(({theme}: {theme: Theme}) => css`
  margin-left: ${theme.spacing(3)};
  maring-right: ${theme.spacing(3)};
  ${theme.breakpoints.up(602+theme.spacing(2))} {
    margin-left: ${theme.spacing(4)};
    maring-right: ${theme.spacing(4)};
  }
`)

This should add a breakpoint at 618 pixels.

@paul23-git paul23-git added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jul 13, 2022
@ZeeshanTamboli
Copy link
Member

Duplicate of #29086

@ZeeshanTamboli ZeeshanTamboli marked this as a duplicate of #29086 Jul 13, 2022
@ZeeshanTamboli ZeeshanTamboli added duplicate This issue or pull request already exists and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants