From 449ace0490c45b8db22e92cc89a64f94c5072b49 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Tue, 4 Oct 2022 17:59:33 -0400 Subject: [PATCH] fix(striker-ui): expose additional props in HeaderText --- striker-ui/components/Text/HeaderText.tsx | 35 +++++++++++++++++++---- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/striker-ui/components/Text/HeaderText.tsx b/striker-ui/components/Text/HeaderText.tsx index cb08cc2a..0b85b5df 100644 --- a/striker-ui/components/Text/HeaderText.tsx +++ b/striker-ui/components/Text/HeaderText.tsx @@ -1,13 +1,38 @@ -import Typography from '@mui/material/Typography'; -import { styled } from '@mui/material/styles'; +import { styled, Typography, TypographyProps } from '@mui/material'; +import { FC, useMemo } from 'react'; + import { TEXT } from '../../lib/consts/DEFAULT_THEME'; const WhiteTypography = styled(Typography)({ color: TEXT, }); -const HeaderText = ({ text }: { text: string }): JSX.Element => ( - {text} -); +type HeaderTextOptionalPropsWithoutDefault = { + text?: string; +}; + +type HeaderTextOptionalProps = HeaderTextOptionalPropsWithoutDefault; + +type HeaderTextProps = TypographyProps & HeaderTextOptionalProps; + +const HEADER_TEXT_DEFAULT_PROPS: HeaderTextOptionalPropsWithoutDefault = { + text: undefined, +}; + +const HeaderText: FC = ({ + children, + text, + ...restHeaderTextProps +}) => { + const content = useMemo(() => children ?? text, [children, text]); + + return ( + + {content} + + ); +}; + +HeaderText.defaultProps = HEADER_TEXT_DEFAULT_PROPS; export default HeaderText;