mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-27 08:00:51 +01:00
Add layout components
This commit is contained in:
parent
248ddf53f0
commit
9ed49c902c
38
src/common/HorizontalRule.tsx
Normal file
38
src/common/HorizontalRule.tsx
Normal 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 } />;
|
||||
}
|
@ -7,6 +7,7 @@ export * from './Flex';
|
||||
export * from './FormGroup';
|
||||
export * from './Grid';
|
||||
export * from './GridContext';
|
||||
export * from './HorizontalRule';
|
||||
export * from './layout';
|
||||
export * from './Text';
|
||||
export * from './types';
|
||||
|
Loading…
Reference in New Issue
Block a user