-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add xgrids (bootstrap like grids)
- Loading branch information
Showing
9 changed files
with
198 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { createStyleGenerator, reduceBreakpoints, compose } from '../style' | ||
import { obj } from '../util' | ||
import { getPercent } from './basics' | ||
|
||
export const row = createStyleGenerator( | ||
() => ({ | ||
boxSizing: 'border-box', | ||
flexGrow: 1, | ||
flexWrap: 'wrap', | ||
display: 'flex', | ||
}), | ||
['row'], | ||
) | ||
|
||
function getColStyle(props, size) { | ||
if (size === true) { | ||
return { | ||
flexBasis: 0, | ||
flexGrow: 1, | ||
maxWidth: '100%', | ||
} | ||
} | ||
|
||
if (size === 'auto') { | ||
return { | ||
flex: `0 0 auto`, | ||
maxWidth: 'none', | ||
width: 'auto', | ||
} | ||
} | ||
|
||
const sizeWidth = getPercent(size)(props) | ||
|
||
return { | ||
flex: `0 0 ${sizeWidth}`, | ||
maxWidth: sizeWidth, | ||
} | ||
} | ||
|
||
export const col = createStyleGenerator( | ||
props => { | ||
const value = props.col | ||
const common = { | ||
boxSizing: 'border-box', | ||
flexBasis: 0, | ||
flexGrow: 1, | ||
maxWidth: '100%', | ||
} | ||
|
||
if (obj(value)) { | ||
const breakpointsStyle = reduceBreakpoints( | ||
props, | ||
value, | ||
breakpointValue => getColStyle(props, breakpointValue), | ||
) | ||
|
||
return { | ||
...common, | ||
...breakpointsStyle, | ||
} | ||
} | ||
|
||
return { | ||
...common, | ||
...getColStyle(props, value), | ||
} | ||
}, | ||
['col'], | ||
) | ||
|
||
export const xgrids = compose( | ||
row, | ||
col, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { xgrids } from './xgrids' | ||
|
||
describe('#xgrids', () => { | ||
it('supports row', () => { | ||
expect(xgrids({ row: true })).toEqual({ | ||
boxSizing: 'border-box', | ||
flexGrow: 1, | ||
flexWrap: 'wrap', | ||
display: 'flex', | ||
}) | ||
}) | ||
|
||
it('supports col', () => { | ||
expect(xgrids({ col: 0.2 })).toEqual({ | ||
boxSizing: 'border-box', | ||
flexBasis: 0, | ||
flexGrow: 1, | ||
maxWidth: '20%', | ||
flex: '0 0 20%', | ||
}) | ||
|
||
expect(xgrids({ col: 4 / 12 })).toEqual({ | ||
boxSizing: 'border-box', | ||
flexBasis: 0, | ||
flexGrow: 1, | ||
maxWidth: '33.3333%', | ||
flex: '0 0 33.3333%', | ||
}) | ||
|
||
expect(xgrids({ col: true })).toEqual({ | ||
boxSizing: 'border-box', | ||
flexBasis: 0, | ||
flexGrow: 1, | ||
maxWidth: '100%', | ||
}) | ||
|
||
expect(xgrids({ col: 'auto' })).toEqual({ | ||
boxSizing: 'border-box', | ||
flexBasis: 0, | ||
flexGrow: 1, | ||
maxWidth: 'none', | ||
flex: '0 0 auto', | ||
width: 'auto', | ||
}) | ||
|
||
expect(xgrids({ col: { xs: 0.2, md: 20 } })).toEqual({ | ||
boxSizing: 'border-box', | ||
flexBasis: 0, | ||
flexGrow: 1, | ||
maxWidth: '20%', | ||
flex: '0 0 20%', | ||
'@media (min-width: 768px)': { flex: '0 0 20px', maxWidth: '20px' }, | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters