-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
49 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,35 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
// import MediaQuery from 'react-responsive' | ||
import MediaQuery from 'react-responsive' | ||
|
||
import safeRest from '../../utils/safeRest' | ||
|
||
// import styles from './Responsive.modules.scss' | ||
const breakpoints = { | ||
sm: 576, | ||
md: 768, | ||
lg: 992, | ||
xl: 1200, | ||
} | ||
|
||
// const breakpoints = { | ||
// small: 576, | ||
// medium: 768, | ||
// large: 992, | ||
// xl: 1200, | ||
// } | ||
const getQuery = breakpoint => { | ||
if (!breakpoint) { | ||
return undefined | ||
} | ||
|
||
// const Small = props => <MediaQuery {...props} minWidth={breakpoints.small} /> | ||
// const Medium = props => <MediaQuery {...props} minWidth={breakpoints.medium} /> | ||
// const Large = props => <MediaQuery {...props} minWidth={breakpoints.large} /> | ||
// const XL = props => <MediaQuery {...props} minWidth={breakpoints.xl} /> | ||
return `(min-width: ${breakpoints[breakpoint]}px)` | ||
} | ||
|
||
const Responsive = ({ children, ...rest }) => <div {...safeRest(rest)}>{children}</div> | ||
const Responsive = ({ minWidth, children }) => ( | ||
<MediaQuery query={getQuery(minWidth)}>{children}</MediaQuery> | ||
) | ||
|
||
Responsive.propTypes = { | ||
query: PropTypes.string, | ||
minWidth: PropTypes.oneOf(['sm', 'md', 'lg', 'xl']), | ||
// maxWidth: PropTypes.oneOf(['sm', 'md', 'lg', 'xl']), | ||
children: PropTypes.node.isRequired, | ||
} | ||
|
||
Responsive.defaultProps = { | ||
query: undefined, | ||
minWidth: undefined, | ||
// maxWidth: undefined, | ||
} | ||
|
||
export default Responsive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
src/components/Responsive/__tests__/__snapshots__/Responsive.spec.jsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Responsive renders 1`] = ` | ||
<div> | ||
This is children | ||
</div> | ||
<MediaQuery | ||
query="(min-width: 576px)" | ||
values={Object {}} | ||
> | ||
Some content | ||
</MediaQuery> | ||
`; |