@doubleedesign/styled-media-queries
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

styled-media-queries

Shorthand for media queries within styled-components.

Find on NPM


Usage Examples

import { breakpointUp } from '@doubleedesign/styled-media-queries';

Standalone, passing a number:

export const SampleElement = styled.div`
    width: 30%;
    flex-basis: 30%;
    
    ${breakpointUp(768, css`
        width: 15%;
        flex-basis: 15%;
    `)};
`;

Components within a ThemeProvider:

export const SampleElement = styled.div`
    width: 30%;
    flex-basis: 30%;
    
    ${props => breakpointUp(props.theme.breakpoints.md, css`
        width: 15%;
        flex-basis: 15%;
    `)};
`;
export const SampleElement = styled.div`
    width: 30%;
    flex-basis: 30%;
    
    ${({ theme }) => breakpointUp(theme.breakpoints.md, css`
        width: 15%;
        flex-basis: 15%;
    `)};
`;
export const SampleElement = styled.div`
    width: 30%;
    flex-basis: 30%;
    
    ${({ theme }) => {
        return breakpointUp(theme.breakpoints.md, css`
            width: 15%;
            flex-basis: 15%;
        `);
    }};
`;

Note: css is optional for basic CSS - you can just pass a template literal on its own; but including css is helpful for enabling syntax highlighting. That said, if you have functions inside, you do need to use css:

export const SampleElement = styled.div`
    background: ${({ theme }): string => theme.colors.light};
    
    ${props => breakpointUp(props.theme.breakpoints.md, css`
        background: ${props.theme.colors.dark};
    `)};
`;

For a full list of available functions and more details, please see this doc.

Package Sidebar

Install

npm i @doubleedesign/styled-media-queries

Weekly Downloads

1

Version

0.2.0

License

MIT

Unpacked Size

28.5 kB

Total Files

9

Last publish

Collaborators

  • doubleedesign