From 8335e79f2c3a4e8edfb5646eea4d4487d5c84f19 Mon Sep 17 00:00:00 2001 From: Jake Laderman Date: Tue, 4 Jun 2024 18:20:51 -0400 Subject: [PATCH] feat: added honorable Flex replacement (#601) --- src/components/Flex.tsx | 93 +++++++++++++++++++++++++++++++++++++++++ src/index.ts | 1 + 2 files changed, 94 insertions(+) create mode 100644 src/components/Flex.tsx diff --git a/src/components/Flex.tsx b/src/components/Flex.tsx new file mode 100644 index 00000000..2d8850bb --- /dev/null +++ b/src/components/Flex.tsx @@ -0,0 +1,93 @@ +// drop-in replacement for anywhere 'honorable' Flex is used. Moving forward a regular div or a styled component should just be used instead + +import { + type CSSProperties, + type ComponentProps, + type Ref, + forwardRef, + memo, +} from 'react' +import { useTheme } from 'styled-components' + +type FlexBaseProps = { + /** + * Alias for flexDirection + */ + direction?: 'row' | 'column' + /** + * wrap flex property + */ + wrap?: 'wrap' | 'nowrap' | 'wrap-reverse' | boolean + /** + * Alias for flexBasis + */ + basis?: string | number + /** + * Alias for flexGrow + */ + grow?: boolean | number + /** + * Alias for flexShrink + */ + shrink?: boolean | number + /** + * Alias for alignItems + */ + align?: 'flex-start' | 'flex-end' | 'center' | 'baseline' | 'stretch' + /** + * Alias for justifyContent + */ + justify?: + | 'flex-start' + | 'flex-end' + | 'center' + | 'space-between' + | 'space-around' + | 'space-evenly' + + gap?: string +} + +type FlexProps = CSSProperties & ComponentProps<'div'> & FlexBaseProps + +function FlexRef(props: FlexProps, ref: Ref) { + const { + direction, + wrap, + basis, + grow, + shrink, + align, + justify, + gap, + children, + ...otherProps + } = props + const theme = useTheme() + + return ( +
+ {children} +
+ ) +} + +const BaseFlex = forwardRef(FlexRef) + +const Flex = memo(BaseFlex) + +export default Flex diff --git a/src/index.ts b/src/index.ts index ab62b313..da560081 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,6 +25,7 @@ export { default as ContentCard } from './components/ContentCard' export { default as Date } from './components/Date' export { default as Divider } from './components/Divider' export { default as EmptyState } from './components/EmptyState' +export { default as Flex } from './components/Flex' export { default as FormField } from './components/FormField' export { default as Highlight } from './components/Highlight' export type { IconFrameProps } from './components/IconFrame'