Skip to content

Instantly share code, notes, and snippets.

@adamseckel
Created October 1, 2017 14:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamseckel/e15b083a574dfba5eb9fa088a88f1be1 to your computer and use it in GitHub Desktop.
Save adamseckel/e15b083a574dfba5eb9fa088a88f1be1 to your computer and use it in GitHub Desktop.
Basic Flexbox Component with Emotion
import styled from 'emotion/react';
import {css} from 'emotion';
const justifyMap = {
start: 'flex-start',
end: 'flex-end',
'space-between': 'space-between',
'space-around': 'space-around'
};
const alignMap = {
start: 'flex-start',
end: 'flex-end',
'space-between': 'space-between',
'space-around': 'space-around',
stretch: 'stretch'
};
export const box = css`
display: flex;
flex-direction: ${props => props.column ? 'column' : 'row'};
justify-content: ${props => justifyMap[props.justify] || 'center'};
align-items: ${props => alignMap[props.align] || 'center'};
flex-wrap: ${props => props.wrap ? 'wrap' : ' no-wrap'};
flex-grow: ${props => props.grow ? 1 : 0};
`;
const Box = styled.div`
composes: ${box};
`;
export const Row = styled(Box)`
flex-direction: row;
`;
export const Column = styled(Box)`
flex-direction: column;
`;
export default Box;
@adamseckel
Copy link
Author

e.g.

<Row wrap/>

<Row align="start"/>

<Column grow/>

@manobalas
Copy link

can you please give me in tsx format ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment