Comments (2)
Hey, @vitordino. Thank you for the insights.
Yes, indeed, this utility shouldn't be anything critical to implement. Especially, because there is an already published useResponsiveQuery
React hook that accepts the "from/to" API, but instead of returning a media query string it returns a media query match (the hook is designed for conditional rendering):
atomic-layout/packages/atomic-layout/src/hooks/useResponsiveQuery.ts
Lines 101 to 109 in ba295c7
The
getBreakpoints()
function converts "from/to" API into a list of media query Objects. Then that list is mapped withcreateMediaQuery
, that converts a single media query Object into a string.
If this logic above is put into a separate function, then it could be reused in useResponsiveQuery
, and exported standalone for the inline media query composition, as mentioned in the issue's description.
How would you call a hook that behaves like this? I'm thinking of naming it query
:
import { query } from 'atomic-layout'
const MyComponent = styled.div`
@media (${query({ from: 'sm', to: 'lg' }}) {
font-size: 2rem;
}
`
from atomic-layout.
i’ve did something similar on my etymos library, more specific a above
util.. shouldn’t be so hard to adapt to this from
/to
behaviour — i had one of it, but as i usually only use above, i removed the between
util at some point prior the release of the lib..
i did kept the useMediaQuery
hook tho (supporting above
and below
options), and it was a render prop component before
it might help
from atomic-layout.
Related Issues (20)
- SSR: "useLayoutEffect does nothing on the server" HOT 2
- Support the "order" CSS property
- Responsive props suffixes ignore casing (templateLg = templatelg) HOT 3
- I can't attach a ref to Composition, because Composition does not use React.forwardRef HOT 1
- Rename "useResponsiveComponent" since it's not a hook HOT 2
- Warning: React does not recognize the `A` prop on a DOM element HOT 1
- Add "Area" component HOT 1
- Exported components must have "displayName"
- Rerendering of parent component causes Only to unmount and mount its children HOT 4
- Replace "MediaQuery" component with "useMediaQuery" hook
- Input in a grid item loses focus due to extra parent rerendering HOT 3
- makeResponsive causes memory heap on hot reload
- Creating a 3 column layout. HOT 3
- useResponsiveValue might require to fire an effect for a dependency change HOT 4
- the except prop on the Only component get ignored with a custom breakpoint ref HOT 1
- useResponsiveValue won't use custom breakpoint names HOT 2
- Warning: React does not recognize the `sortingOrder` prop on a DOM element - `DataGrid`
- useResponsiveProps always returns empty object initialy client-side
- Are you considering supporting Vue or native JavaScript usage . HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from atomic-layout.