[theme] Remove hardcoded breakpoints
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 99.1k
- Forks
- 32.5k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 106
Description
There are several places in the codebase where breakpoints are hardcoded.
Since we have the ability to override breakpoints, we should not have hardcoded values in the code
- The issue is present in the latest release.
- I have searched the issues of this repository and believe that this is not a duplicate.
Current Behavior 😯
- PropTypes
PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']),
PropTypes.arrayOf(PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl'])),
- Styles
[theme.breakpoints.only('xs')]: {
...
}
- Functions in withWidth.js
import { breakpointKeys } from '../styles/createBreakpoints';
function isWidthUp(...){
return breakpointKeys.indexOf(...)
}
function isWidthDown(...){
return breakpointKeys.indexOf(...)
}
Expected Behavior 🤔
- PropTypes
PropTypes.string
PropTypes.arrayOf(PropTypes.string),
- Styles
a) Use a media query only if there is such a breakpoint in the theme
[theme.breakpoints.only(theme.breakpoints.keys['xs'] ?? 0)]: {
...
}
b) Add a new property alias to createBreakpoints function to match breakpoints
createBreakpoints({
values: {
tablet: 640,
laptop: 1024,
desktop: 1280,
},
alias: {
xs: 'tablet',
sm: 'tablet',
},
}
})
- Functions in withWidth.js
a) Show the necessity for breakpoints
Removeimport { breakpointKeys } from '../styles/createBreakpoints';
function isWidthUp(breakpoints, breakpoint, width, inclusive = true){ .. }
b) Add breakpoints to options implicitly
import { breakpointKeys } from '../styles/createBreakpoints'
function isWidthUp(breakpoint, width, opts = {}) {
let {breakpoints = breakpointKeys, inclusive = true } = opts;
...
}
Your Environment 🌎
| Tech | Version |
|---|---|
| Material-UI | v4.11.0 |
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading styles/createBreakpoints and withWidth.js, then locate the listed PropTypes and style usages that hardcode xs through xl. Compare the proposed theme override and alias approaches before choosing a consistent direction. Done means breakpoint validation, media-query styles, and withWidth helpers no longer assume fixed breakpoint names.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100