Files
web/packages/design-system/lib/components/Typography/Typography.tsx
Rasmus Langvad c65091b36a Merged in feat/SW-3644-storybook-v10 (pull request #3240)
feat(SW-3644): Storybook v10

* Auto update to Storybook v10

* Add scandic theme and logo

* Update yarn.lock

* Update formatting of package.json

* Update vitest config and playwright plugin

* Remove vitest 4 update

* Re-added comment

* Update the Typography component to explicitly return React.ReactNode

* Add an explicit type assertion to the export

* Add an explicit type assertion to the export for Checkbox

* Explicit return type assertion

* Add an explicit type assertion to the export

* Update @types/react and fix ts warnings

* Updated typings


Approved-by: Linus Flood
Approved-by: Matilda Landström
2025-11-28 08:05:40 +00:00

25 lines
512 B
TypeScript

import { cloneElement, isValidElement } from 'react'
import { variants } from './variants'
import type { TypographyProps } from './types'
export function Typography({
variant,
className,
children,
}: TypographyProps): React.ReactNode {
if (!isValidElement(children)) return null
const classNames = variants({
variant,
})
return cloneElement(children, {
...children.props,
className: [className, children.props.className, classNames]
.filter(Boolean)
.join(' '),
})
}