53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
import { ReactNode, forwardRef } from 'react';
|
|
import { Box, BoxProps, ResponsiveValue } from './Box';
|
|
|
|
export interface HeadingProps extends BoxProps<any> {
|
|
children: ReactNode;
|
|
level?: 1 | 2 | 3 | 4 | 5 | 6;
|
|
weight?: 'normal' | 'medium' | 'semibold' | 'bold';
|
|
align?: 'left' | 'center' | 'right';
|
|
fontSize?: string | ResponsiveValue<string>;
|
|
}
|
|
|
|
export const Heading = forwardRef<HTMLHeadingElement, HeadingProps>(({
|
|
children,
|
|
level = 1,
|
|
weight = 'bold',
|
|
align = 'left',
|
|
fontSize,
|
|
...props
|
|
}, ref) => {
|
|
const Tag = `h${level}` as const;
|
|
|
|
const weightClasses = {
|
|
normal: 'font-normal',
|
|
medium: 'font-medium',
|
|
semibold: 'font-semibold',
|
|
bold: 'font-bold'
|
|
};
|
|
|
|
const sizeClasses = {
|
|
1: 'text-4xl md:text-5xl',
|
|
2: 'text-3xl md:text-4xl',
|
|
3: 'text-2xl md:text-3xl',
|
|
4: 'text-xl md:text-2xl',
|
|
5: 'text-lg md:text-xl',
|
|
6: 'text-base md:text-lg'
|
|
};
|
|
|
|
const classes = [
|
|
'text-[var(--ui-color-text-high)]',
|
|
weightClasses[weight],
|
|
fontSize ? '' : sizeClasses[level],
|
|
align === 'center' ? 'text-center' : (align === 'right' ? 'text-right' : 'text-left'),
|
|
].join(' ');
|
|
|
|
return (
|
|
<Box as={Tag} ref={ref} className={classes} fontSize={typeof fontSize === 'string' ? fontSize : undefined} {...props}>
|
|
{children}
|
|
</Box>
|
|
);
|
|
});
|
|
|
|
Heading.displayName = 'Heading';
|