-
Notifications
You must be signed in to change notification settings - Fork 194
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
Refactored breakpoints #307
Changes from all commits
04bee8d
04f3691
071b2bc
4a281fe
7a1cf6d
986b6a9
c61a03b
14f6fef
10d555c
584bc53
eb06541
38144f8
18c8a74
7828ffe
a09ad6f
c3ef778
a58d8a4
3941be6
7fabcf0
17fa049
61ac79b
8bcf8c3
f25fb81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import {createBreakpoint} from 'react-use' | ||
|
||
const bp: any = { | ||
_: 0, | ||
xs: 375, | ||
sm: 640, | ||
md: 768, | ||
|
@@ -20,20 +21,16 @@ export const bpMaxSM = `@media (max-width: ${bp.md - 1}px)` | |
export const bpMaxMD = `@media (max-width: ${bp.lg - 1}px)` | ||
export const bpMaxLG = `@media (max-width: ${bp.xl - 1}px)` | ||
|
||
const useBreakpoints = createBreakpoint(bp) | ||
const getBreakpoint = createBreakpoint(bp) | ||
|
||
const useBreakpoint = () => { | ||
const breakpoint = useBreakpoints() | ||
|
||
const xs = breakpoint == 'xs' | ||
const sm = breakpoint == 'sm' || xs | ||
const md = breakpoint == 'md' || sm | ||
const lg = breakpoint == 'lg' || md | ||
const xl = breakpoint == 'xl' || lg | ||
const xl2 = breakpoint == '2xl' || xl | ||
const xl3 = breakpoint == '3xl' || xl2 | ||
|
||
return {xs, sm, md, lg, xl, xl2, xl3} | ||
const breakpoints = () => { | ||
const breakpoint = getBreakpoint() | ||
const keys = Object.keys(bp) | ||
const foundInd = keys.indexOf(breakpoint) | ||
return keys | ||
.map((key, ind) => ({['isMin' + key.toUpperCase()]: ind <= foundInd})) | ||
.filter((_, ind) => ind) | ||
.reduce((acc, cur) => ({...acc, ...cur}), {}) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eventually we get the object like:
"only mobile" breakpoint could be considered as so, if we want to show some component on mobiles only we want to |
||
|
||
export default useBreakpoint | ||
export default breakpoints |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idea here is to filter out first
zero
value, because it's likedefault
class in tailwindcss (flex-row
vssm:flex-row
)