From 6c7f1598b776c3d4a932158b8686394873bdfb9b Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 15 Oct 2020 10:01:00 +1100 Subject: [PATCH] add a flex component using styled --- ts/components/session/Flex.tsx | 114 +++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 ts/components/session/Flex.tsx diff --git a/ts/components/session/Flex.tsx b/ts/components/session/Flex.tsx new file mode 100644 index 000000000..e19665bc3 --- /dev/null +++ b/ts/components/session/Flex.tsx @@ -0,0 +1,114 @@ +import styled, { css } from 'styled-components'; + +export interface FlexProps { + children?: any; + className?: string; + container?: boolean; + /****** Container Props ********/ + flexDirection?: 'row' | 'column'; + justifyContent?: + | 'flex-start' + | 'flex-end' + | 'center' + | 'space-between' + | 'space-around' + | 'initial' + | 'inherit'; + flexWrap?: 'wrap' | 'nowrap' | 'wrap-reverse'; + alignItems?: + | 'stretch' + | 'center' + | 'flex-start' + | 'flex-end' + | 'baseline' + | 'initial' + | 'inherit'; + /****** Child Props ********/ + flexGrow?: number; + flexShrink?: number; + flexBasis?: number; + flex?: string; + /****** Common Layout Props ********/ + padding?: string; + margin?: string; + width?: string; + height?: string; + maxWidth?: string; + maxHeight?: string; +} + +export const Flex = styled.div` + ${props => + (props.container && + css` + display: flex; + `) || + css` + display: block; + `}; + ${props => + props.justifyContent && + css` + justifycontent: ${props.justifyContent || 'flex-start'}; + `}; + ${props => + props.flexDirection && + css` + flexdirection: ${props.flexDirection || 'row'}; + `}; + ${props => + props.flexGrow && + css` + flexgrow: ${props.flexGrow || '0'}; + `}; + ${props => + props.flexBasis && + css` + flexbasis: ${props.flexBasis || 'auto'}; + `}; + ${props => + props.flexShrink && + css` + flexshrink: ${props.flexShrink || '1'}; + `}; + ${props => + props.flexWrap && + css` + flexwrap: ${props.flexWrap || 'nowrap'}; + `}; + ${props => + props.flex && + css` + flex: ${props.flex || '0 1 auto'}; + `}; + ${props => + props.alignItems && + css` + alignitems: ${props.alignItems || 'stretch'}; + `}; + ${props => + props.margin && + css` + margin: ${props.margin || '0'}; + `}; + ${props => + props.padding && + css` + padding: ${props.padding || '0'}; + `}; + ${props => + props.width && + css` + width: ${props.width || 'auto'}; + `}; + ${props => + props.height && + css` + height: ${props.height || 'auto'}; + `}; + ${props => + props.maxWidth && + css` + maxwidth: ${props.maxWidth || 'none'}; + `}; +`;