claus / storyblok-rich-text-react-renderer

A React renderer for Storyblok rich text content
MIT License
87 stars 16 forks source link

More specific typings for Heading level attribute #18

Closed pdrbrnd closed 2 years ago

pdrbrnd commented 2 years ago

Hi!

In reality, headings can't be any any number other than 1 to 6. This small PR makes it possible to use level directly in strongly typed props:

const variant = {
  [1]: 'title',
  [2]: 'big',
  [3]: 'body',
  [4]: 'regular',
  [5]: 'small',
  [6]: 'caps',
} as const

<Text as={`h${level}`} variant={variant[level]}>
claus commented 2 years ago

Thank you!