Skip to content

Instantly share code, notes, and snippets.

@OleksandrDanylchenko
Last active February 12, 2022 09:43
Show Gist options
  • Save OleksandrDanylchenko/5e4a181225675bcb41e74ab82b0045b4 to your computer and use it in GitHub Desktop.
Save OleksandrDanylchenko/5e4a181225675bcb41e74ab82b0045b4 to your computer and use it in GitHub Desktop.
Emotion CSS Flexbox Mixin
export const flexbox = (options: {
display?: string;
direction?: string;
placeContent?: string;
placeItems?: string;
wrap?: string;
shrink?: string;
grow?: string;
alignContent?: string;
justifyContent?: string;
alignItems?: string;
justifyItems?: string;
gap?: string;
}) => css`
display: ${options.display || 'flex'};
flex-direction: ${options.direction || 'row'};
${options.placeContent
? css`
place-content: ${options.placeContent};
`
: css`
align-content: ${options.alignContent};
justify-content: ${options.justifyContent};
`}
${options.placeItems
? css`
place-items: ${options.placeContent};
`
: css`
align-items: ${options.alignItems};
justify-items: ${options.justifyItems};
`}
flex-wrap: ${options.wrap || 'nowrap'};
flex-shrink: ${options.shrink};
flex-grow: ${options.grow};
gap: ${options.gap};
`;
import { Property } from 'csstype';
export const flexbox = (options: {
display?: Property.Display;
direction?: Property.FlexDirection;
placeContent?: Property.PlaceContent;
placeItems?: Property.PlaceItems;
wrap?: Property.FlexWrap;
shrink?: Property.FlexShrink;
grow?: Property.FlexGrow;
alignContent?: Property.AlignContent;
justifyContent?: Property.JustifyContent;
alignItems?: Property.AlignItems;
justifyItems?: Property.JustifyItems;
gap?: Property.Gap;
}) => css`
display: ${options.display || 'flex'};
flex-direction: ${options.direction || 'row'};
${options.placeContent
? css`
place-content: ${options.placeContent};
`
: css`
align-content: ${options.alignContent};
justify-content: ${options.justifyContent};
`}
${options.placeItems
? css`
place-items: ${options.placeContent};
`
: css`
align-items: ${options.alignItems};
justify-items: ${options.justifyItems};
`}
flex-wrap: ${options.wrap || 'nowrap'};
flex-shrink: ${options.shrink};
flex-grow: ${options.grow};
gap: ${options.gap};
`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment