Add offset keys to Column

This commit is contained in:
Jerko Steiner 2019-11-03 14:55:45 -04:00
parent 76b20551c7
commit 1b5209ca08
2 changed files with 29 additions and 10 deletions

View File

@ -23,26 +23,45 @@ export const Columns = styled.div`
align-items: center; align-items: center;
` `
export type GridSize = number
export const gridSize = 12
export interface ColumnProps { export interface ColumnProps {
xs?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 xs?: GridSize
sm?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 sm?: GridSize
md?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 md?: GridSize
lg?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 lg?: GridSize
offsetxs?: GridSize
offsetsm?: GridSize
offsetmd?: GridSize
offsetlg?: GridSize
} }
function getPercentage(size: number) {
return (size * 100 / gridSize) + '%'
}
export type OffsetKey = 'offsetxs' | 'offsetsm' | 'offsetmd' | 'offsetlg'
export const Column = styled.div<ColumnProps>` export const Column = styled.div<ColumnProps>`
padding: 1rem; padding: 1rem;
width: ${props => props.xs! * 100 / 12}%; width: ${props => getPercentage(props.xs!)};
${props => keys(props.theme.screen.min) ${props => keys(props.theme.screen.min)
.filter(key => !!props[key]) .filter(key => !!props[key])
.map(key => `@media(min-width: ${props.theme.screen.min[key]}) { .map(key => {
width: ${props[key]! * 100 / 12}%; const offsetKey = 'offset' + key as OffsetKey
}`) const offset = props[offsetKey] || 0
return `@media(min-width: ${props.theme.screen.min[key]}) {
width: ${getPercentage(props[key]!)};
margin-left: ${getPercentage(offset)};
}`
})
.join('\n') .join('\n')
} }
` `
Column.defaultProps = { Column.defaultProps = {
xs: 12, xs: gridSize,
} }

View File

@ -59,7 +59,7 @@ export class TeamList extends React.PureComponent<TeamListProps> {
return ( return (
<Panel> <Panel>
<PanelHeading> <PanelHeading>
<span className='is-flex is-vcentered'> <span>
<span>Teams</span> <span>Teams</span>
<Link <Link
className='ml-auto' className='ml-auto'