2022-01-24 21:16:50 +05:00
|
|
|
import React, { HTMLAttributes, memo } from 'react'
|
2021-11-18 15:06:23 +05:00
|
|
|
|
2022-01-24 21:16:50 +05:00
|
|
|
export type ComponentProps = HTMLAttributes<HTMLDivElement>
|
2021-11-18 15:06:23 +05:00
|
|
|
|
2022-01-24 21:16:50 +05:00
|
|
|
export type GridItemProps = ComponentProps & {
|
2021-11-18 15:06:23 +05:00
|
|
|
row: number
|
|
|
|
col: number
|
|
|
|
rowSpan?: number
|
|
|
|
colSpan?: number
|
|
|
|
}
|
|
|
|
|
2022-01-24 21:16:50 +05:00
|
|
|
export const gridDefaultStyle = {
|
2021-11-18 15:06:23 +05:00
|
|
|
display: 'grid',
|
|
|
|
margin: '8px',
|
|
|
|
justifyItems: 'stretch',
|
|
|
|
alignItems: 'stretch',
|
|
|
|
}
|
|
|
|
|
2022-01-24 21:16:50 +05:00
|
|
|
export const Grid = memo<ComponentProps>(({ children, style, ...other }) => (
|
2021-11-18 15:06:23 +05:00
|
|
|
<div style={{...gridDefaultStyle, ...style}} {...other}>
|
|
|
|
{children}
|
|
|
|
</div>
|
2022-01-24 21:16:50 +05:00
|
|
|
))
|
2021-11-18 15:06:23 +05:00
|
|
|
|
2022-01-24 21:16:50 +05:00
|
|
|
export const GridItem = memo<GridItemProps>(({ children, row, col, rowSpan, colSpan, style, ...other }) => {
|
2021-11-18 15:06:23 +05:00
|
|
|
const localRow = +row
|
|
|
|
const localCol = +col
|
|
|
|
const localColSpan = colSpan ? colSpan - 1 : 0
|
|
|
|
const localRowSpan = rowSpan ? rowSpan - 1 : 0
|
|
|
|
const gridItemStyle = {
|
|
|
|
gridColumnStart: localCol,
|
|
|
|
gridColumnEnd: localCol + localColSpan,
|
|
|
|
gridRowStart: localRow,
|
|
|
|
gridRowEnd: localRow + localRowSpan,
|
|
|
|
padding: '4px',
|
|
|
|
...style,
|
|
|
|
}
|
|
|
|
|
2022-01-24 21:16:50 +05:00
|
|
|
return (
|
|
|
|
<div style={gridItemStyle} {...other}>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
})
|
2021-11-18 15:06:23 +05:00
|
|
|
|
2022-01-24 21:16:50 +05:00
|
|
|
export const Flex = memo<ComponentProps>(({ children, style, ...other }) => (
|
2021-11-18 15:06:23 +05:00
|
|
|
<div style={{ display: 'flex', ...style }} {...other}>
|
|
|
|
{children}
|
|
|
|
</div>
|
2022-01-24 21:16:50 +05:00
|
|
|
))
|