Add layout components

This commit is contained in:
Bill 2022-02-24 13:26:35 -05:00
parent 248ddf53f0
commit 9ed49c902c
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,38 @@
import { CSSProperties, FC, useMemo } from 'react';
import { Base, BaseProps } from './Base';
import { ColorVariantType } from './types';
export interface HorizontalRuleProps extends BaseProps<HTMLDivElement>
{
variant?: ColorVariantType;
height?: number;
}
export const HorizontalRule: FC<HorizontalRuleProps> = props =>
{
const { variant = 'black', height = 1, classNames = [], style = {}, ...rest } = props;
const getClassNames = useMemo(() =>
{
const newClassNames: string[] = [];
if(variant) newClassNames.push('bg-' + variant);
if(classNames.length) newClassNames.push(...classNames);
return newClassNames;
}, [ variant, classNames ]);
const getStyle = useMemo(() =>
{
let newStyle: CSSProperties = { display: 'list-item' };
if(height > 0) newStyle.height = height;
if(Object.keys(style).length) newStyle = { ...newStyle, ...style };
return newStyle;
}, [ height, style ]);
return <Base classNames={ getClassNames } style={ getStyle } { ...rest } />;
}

View File

@ -7,6 +7,7 @@ export * from './Flex';
export * from './FormGroup'; export * from './FormGroup';
export * from './Grid'; export * from './Grid';
export * from './GridContext'; export * from './GridContext';
export * from './HorizontalRule';
export * from './layout'; export * from './layout';
export * from './Text'; export * from './Text';
export * from './types'; export * from './types';