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;
`
export type GridSize = number
export const gridSize = 12
export interface ColumnProps {
xs?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12
sm?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12
md?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12
lg?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12
xs?: GridSize
sm?: GridSize
md?: GridSize
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>`
padding: 1rem;
width: ${props => props.xs! * 100 / 12}%;
width: ${props => getPercentage(props.xs!)};
${props => keys(props.theme.screen.min)
.filter(key => !!props[key])
.map(key => `@media(min-width: ${props.theme.screen.min[key]}) {
width: ${props[key]! * 100 / 12}%;
}`)
.map(key => {
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')
}
`
Column.defaultProps = {
xs: 12,
xs: gridSize,
}

View File

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