Skip to content

Instantly share code, notes, and snippets.

@nickydonna
Created December 20, 2017 19:49
Show Gist options
  • Save nickydonna/08b0bd8dee222028dded114e6cce43fe to your computer and use it in GitHub Desktop.
Save nickydonna/08b0bd8dee222028dded114e6cce43fe to your computer and use it in GitHub Desktop.
// @flow
import React from 'react';
import styled from 'styled-components';
import { Segment } from 'semantic-ui-react';
import { parsePadding } from '../utils/styledHelpers';
import type { Component as ComponentType } from 'styled-components';
type FlexItemProps = {
flex?: string|number,
padding?: string|number,
verticalPadding?: string|number,
horizontalPadding?: string|number,
fullHeight?: boolean,
}
type FlexContainerProps = {
alignItems?: 'flex-start' | 'flex-end' | 'center' | 'baseline' | 'stretch',
justifyContent?: 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around',
wrap?: 'nowrap' | 'wrap' | 'wrap-reverse',
direction?: 'row' | 'row-reverse' | 'column' | 'column-reverse',
padding?: string|number,
verticalPadding?: string|number,
horizontalPadding?: string|number,
fullHeight?: boolean,
};
const flexItem = (Component: ComponentType) => styled(
Component
)`
flex: ${({ flex }: FlexItemProps) => flex || 0 };
padding: ${parsePadding};
height: ${({ fullHeight = false }: FlexContainerProps) => fullHeight ? '100%' : 'auto' };
`;
const flexContainer = (Component: ComponentType) => styled(
Component
)`
display: flex;
align-items: ${({ alignItems = 'stretch' }: FlexContainerProps) => alignItems };
flex-wrap: ${({ wrap = 'nowrap' }: FlexContainerProps) => wrap };
justify-content: ${({ justifyContent = 'flex-start' }: FlexContainerProps) => justifyContent };
flex-direction: ${({ direction = 'row' }: FlexContainerProps) => direction };
padding: ${parsePadding};
height: ${({ fullHeight = false }: FlexContainerProps) => fullHeight ? '100%' : 'auto' };
`
const FlexItem = flexItem((p) => <div {...p} />);
const FlexContainer = flexContainer((p) => <div {...p} />);
const FlexContainerSegment = flexContainer(Segment);
export {
FlexContainer,
flexContainer,
flexItem,
FlexItem,
FlexContainerSegment
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment