GithubHelp home page GithubHelp logo

Comments (2)

kettanaito avatar kettanaito commented on May 23, 2024 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):

const breakpointsList = useMemo(() => {
const breakpoints = getBreakpoints(exactBreakpoint, from, to, except)
if (!breakpoints) {
return []
}
return [].concat(breakpoints).map(createMediaQuery)
}, [exactBreakpoint, from, to, except])

The getBreakpoints() function converts "from/to" API into a list of media query Objects. Then that list is mapped with createMediaQuery, 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.

vitordino avatar vitordino commented on May 23, 2024 1

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.