jameslnewell / styled-components-breakpoint

Utility function for using breakpoints with styled-components 💅.
243 stars 17 forks source link

Try and make use of custom breakpoints simpler #5

Closed jameslnewell closed 6 years ago

jameslnewell commented 7 years ago

From:

  ${({theme}) => breakpoint('lg', theme.breakpoints)`
    font-size: 24px;
  `}

To:

  ${breakpoint('lg')`
    font-size: 24px;
    width: ${({width}) => `${width}px`};
  `}

by changing breakpoint to be a fn that returns a fn.

jameslnewell commented 6 years ago

More thoughts:

=====

Use case 1:

import {createStatic} from 'styled-components-breakpoint';

const breakpoint = createStatic({
 xs: 100
});

`
${breakpoint('xs')``};
${breakpoint('xs', 'lg')``};
${breakpoint.lte('xs')``};
${breakpoint.gte('xs')``};
${breakpoint.between('xs')``};
`

// people might want static vars to define their styles
export const xs = breakpoint('xs');
export const md = breakpoint('md');
...

`
${xs`...styles...`}

// implementation looks a bit like this
function createStatic(breakpoints) {
  return name => _gte(breakpoints, name);
}

=====

Use case 2:

import breakpoint from 'styled-components-breakpoint';

`
${breakpoint('xs')``};
${breakpoint('xs', 'lg')``};
${breakpoint.lte('xs')``};
${breakpoint.gte('xs')``};
${breakpoint.between('xs')``};
`

//implementation looks like this
function breakpoint(name) {
  return (props) => _gte(props.theme.breakpoints, name);
}
jameslnewell commented 6 years ago

released in v2