mirror of
https://github.com/zhigang1992/react.git
synced 2026-04-25 21:05:36 +08:00
feat(grid): hide item when unit size is 0
This commit is contained in:
@@ -32,19 +32,23 @@ type ItemLayoutValue = {
|
||||
grow: number
|
||||
width: string
|
||||
basis: string
|
||||
display: string
|
||||
}
|
||||
const getItemLayout = (val: BreakpointsValue): ItemLayoutValue => {
|
||||
const display = val === 0 ? 'none' : 'flex'
|
||||
if (typeof val === 'number') {
|
||||
const width = (100 / 24) * val
|
||||
const ratio = width > 100 ? '100%' : width < 0 ? '0' : `${width}%`
|
||||
return {
|
||||
grow: 0,
|
||||
display,
|
||||
width: ratio,
|
||||
basis: ratio,
|
||||
}
|
||||
}
|
||||
return {
|
||||
grow: 1,
|
||||
display,
|
||||
width: '100%',
|
||||
basis: '0',
|
||||
}
|
||||
@@ -77,11 +81,11 @@ const GridBasicItem: React.FC<React.PropsWithChildren<GridBasicItemProps>> = ({
|
||||
xl,
|
||||
}
|
||||
const classString = Object.keys(aligns).reduce((pre, name) => {
|
||||
if (Boolean(aligns[name]) && aligns[name] !== 0) return `${pre} ${name}`
|
||||
if (aligns[name] !== undefined && aligns[name] !== false) return `${pre} ${name}`
|
||||
return pre
|
||||
}, '')
|
||||
return classString.trim()
|
||||
}, [justify, direction, alignItems, alignContent])
|
||||
}, [justify, direction, alignItems, alignContent, xs, sm, md, lg, xl])
|
||||
|
||||
const layout = useMemo<
|
||||
{
|
||||
@@ -125,6 +129,7 @@ const GridBasicItem: React.FC<React.PropsWithChildren<GridBasicItemProps>> = ({
|
||||
flex-grow: ${layout.xs.grow};
|
||||
max-width: ${layout.xs.width};
|
||||
flex-basis: ${layout.xs.basis};
|
||||
display: ${layout.xs.display};
|
||||
}
|
||||
|
||||
@media only screen and (max-width: ${theme.breakpoints.xs.max}) {
|
||||
@@ -132,6 +137,7 @@ const GridBasicItem: React.FC<React.PropsWithChildren<GridBasicItemProps>> = ({
|
||||
flex-grow: ${layout.xs.grow};
|
||||
max-width: ${layout.xs.width};
|
||||
flex-basis: ${layout.xs.basis};
|
||||
display: ${layout.xs.display};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,6 +146,7 @@ const GridBasicItem: React.FC<React.PropsWithChildren<GridBasicItemProps>> = ({
|
||||
flex-grow: ${layout.sm.grow};
|
||||
max-width: ${layout.sm.width};
|
||||
flex-basis: ${layout.sm.basis};
|
||||
display: ${layout.sm.display};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,6 +155,7 @@ const GridBasicItem: React.FC<React.PropsWithChildren<GridBasicItemProps>> = ({
|
||||
flex-grow: ${layout.md.grow};
|
||||
max-width: ${layout.md.width};
|
||||
flex-basis: ${layout.md.basis};
|
||||
display: ${layout.md.display};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,6 +164,7 @@ const GridBasicItem: React.FC<React.PropsWithChildren<GridBasicItemProps>> = ({
|
||||
flex-grow: ${layout.lg.grow};
|
||||
max-width: ${layout.lg.width};
|
||||
flex-basis: ${layout.lg.basis};
|
||||
display: ${layout.lg.display};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,6 +173,7 @@ const GridBasicItem: React.FC<React.PropsWithChildren<GridBasicItemProps>> = ({
|
||||
flex-grow: ${layout.xl.grow};
|
||||
max-width: ${layout.xl.width};
|
||||
flex-basis: ${layout.xl.basis};
|
||||
display: ${layout.xl.display};
|
||||
}
|
||||
}
|
||||
`}</style>
|
||||
|
||||
Reference in New Issue
Block a user