/** * Flex Layout Components * * Simple flexbox layout components to replace WordPress experimental Flex components */ import * as React from 'react'; interface FlexProps { children: React.ReactNode; direction?: 'row' | 'column'; align?: 'start' | 'center' | 'end' | 'stretch' | 'space-between'; justify?: 'start' | 'center' | 'end' | 'space-between' | 'space-around' | 'space-evenly'; gap?: number | string; wrap?: boolean; className?: string; style?: React.CSSProperties; } interface FlexItemProps { children: React.ReactNode; grow?: number; shrink?: number; basis?: string | number; className?: string; style?: React.CSSProperties; } const alignmentMap: Record = { start: 'flex-start', center: 'center', end: 'flex-end', stretch: 'stretch', 'space-between': 'space-between', }; const justifyMap: Record = { start: 'flex-start', center: 'center', end: 'flex-end', 'space-between': 'space-between', 'space-around': 'space-around', 'space-evenly': 'space-evenly', }; export const Flex: React.FC = ({ children, direction = 'row', align = 'stretch', justify = 'start', gap = 0, wrap = false, className = '', style = {}, }) => { const flexStyle: React.CSSProperties = { display: 'flex', flexDirection: direction, alignItems: alignmentMap[align] || align, justifyContent: justifyMap[justify] || justify, gap: typeof gap === 'number' ? `${gap * 4}px` : gap, flexWrap: wrap ? 'wrap' : 'nowrap', ...style, }; return (
{children}
); }; export const FlexItem: React.FC = ({ children, grow = 0, shrink = 1, basis = 'auto', className = '', style = {}, }) => { const itemStyle: React.CSSProperties = { flexGrow: grow, flexShrink: shrink, flexBasis: basis, ...style, }; return (
{children}
); }; export const FlexBlock: React.FC = ({ children, className = '', style = {}, ...props }) => { return ( {children} ); }; export default Flex;