|
| 1 | +import {WstackProps} from '@app/types/widget' |
| 2 | +import {FC} from 'react' |
| 3 | + |
| 4 | +interface StackProps extends WstackProps { |
| 5 | + justifyContent: 'flex-start' | 'center' | 'flex-end' |
| 6 | + alignItems: 'flex-start' | 'center' | 'flex-end' |
| 7 | +} |
| 8 | +export const Stack: FC<StackProps> = ({children, ...props}) => { |
| 9 | + const {justifyContent = 'flex-start', alignItems = 'flex-start', ...wstackProps} = props |
| 10 | + const {flexDirection = 'row'} = wstackProps |
| 11 | + |
| 12 | + const JustifyContentFlexStart: FC<WstackProps> = ({children, ...props}) => { |
| 13 | + const {flexDirection = 'row'} = props |
| 14 | + return ( |
| 15 | + <wstack {...props}> |
| 16 | + <wstack flexDirection={flexDirection}>{children}</wstack> |
| 17 | + <wspacer></wspacer> |
| 18 | + </wstack> |
| 19 | + ) |
| 20 | + } |
| 21 | + const JustifyContentCenter: FC<WstackProps> = ({children, ...props}) => { |
| 22 | + const {flexDirection = 'row'} = props |
| 23 | + return ( |
| 24 | + <wstack {...props}> |
| 25 | + <wspacer></wspacer> |
| 26 | + <wstack flexDirection={flexDirection}>{children}</wstack> |
| 27 | + <wspacer></wspacer> |
| 28 | + </wstack> |
| 29 | + ) |
| 30 | + } |
| 31 | + const JustifyContentFlexEnd: FC<WstackProps> = ({children, ...props}) => { |
| 32 | + const {flexDirection = 'row'} = props |
| 33 | + return ( |
| 34 | + <wstack {...props}> |
| 35 | + <wspacer></wspacer> |
| 36 | + <wstack flexDirection={flexDirection}>{children}</wstack> |
| 37 | + </wstack> |
| 38 | + ) |
| 39 | + } |
| 40 | + const AlignItemsFlexStart: FC<WstackProps> = ({children, ...props}) => { |
| 41 | + const {flexDirection = 'row', ...wstackProps} = props |
| 42 | + return ( |
| 43 | + <wstack {...wstackProps} flexDirection={flexDirection === 'row' ? 'column' : 'row'}> |
| 44 | + <wstack flexDirection={flexDirection}>{children}</wstack> |
| 45 | + <wspacer></wspacer> |
| 46 | + </wstack> |
| 47 | + ) |
| 48 | + } |
| 49 | + const AlignItemsCenter: FC<WstackProps> = ({children, ...props}) => { |
| 50 | + const {flexDirection = 'row', ...wstackProps} = props |
| 51 | + return ( |
| 52 | + <wstack {...wstackProps} flexDirection={flexDirection === 'row' ? 'column' : 'row'}> |
| 53 | + <wspacer></wspacer> |
| 54 | + <wstack flexDirection={flexDirection}>{children}</wstack> |
| 55 | + <wspacer></wspacer> |
| 56 | + </wstack> |
| 57 | + ) |
| 58 | + } |
| 59 | + const AlignItemsFlexEnd: FC<WstackProps> = ({children, ...props}) => { |
| 60 | + const {flexDirection = 'row', ...wstackProps} = props |
| 61 | + return ( |
| 62 | + <wstack {...wstackProps} flexDirection={flexDirection === 'row' ? 'column' : 'row'}> |
| 63 | + <wspacer></wspacer> |
| 64 | + <wstack flexDirection={flexDirection}>{children}</wstack> |
| 65 | + </wstack> |
| 66 | + ) |
| 67 | + } |
| 68 | + const JustifyContentMap: Record<StackProps['justifyContent'], FC<WstackProps>> = { |
| 69 | + 'flex-start': JustifyContentFlexStart, |
| 70 | + center: JustifyContentCenter, |
| 71 | + 'flex-end': JustifyContentFlexEnd, |
| 72 | + } |
| 73 | + const AlignItemsMap: Record<StackProps['alignItems'], FC<WstackProps>> = { |
| 74 | + 'flex-start': AlignItemsFlexStart, |
| 75 | + center: AlignItemsCenter, |
| 76 | + 'flex-end': AlignItemsFlexEnd, |
| 77 | + } |
| 78 | + return h(JustifyContentMap[justifyContent], {...wstackProps}, h(AlignItemsMap[alignItems], {flexDirection}, children)) |
| 79 | +} |
| 80 | + |
| 81 | +export const Row: FC<StackProps> = ({children, ...props}) => { |
| 82 | + props.flexDirection = 'row' |
| 83 | + return <Stack {...props}>{children}</Stack> |
| 84 | +} |
| 85 | + |
| 86 | +export const Col: FC<StackProps> = ({children, ...props}) => { |
| 87 | + props.flexDirection = 'column' |
| 88 | + return <Stack {...props}>{children}</Stack> |
| 89 | +} |
0 commit comments