A set of text components for displaying content at different levels.
This is a standard paragraph with default styling. Typography is the art and technique of arranging type to make written language legible, readable, and appealing when displayed.
import { type Styles, css, cx } from '@styled-system/css'
import { type HeadingVariantMap, heading as headingStyles } from '@styled-system/recipes'
import type React from 'react'
import { type ReactNode, forwardRef } from 'react'
type HeadingProps = React.ComponentPropsWithRef<'h1'> & {
level?: 1 | 2 | 3 | 4 | 5 | 6
variant?: 'normal' | 'accent'
color?: 'default' | 'secondary' | 'disabled'
children: ReactNode
css?: Styles
}
const Heading = forwardRef<HTMLHeadingElement, HeadingProps>(
({ level = 1, variant = 'normal', color, children, css: cssProp, ...props }, ref) => {
const headingStylesRaw = headingStyles({
level: level as unknown as HeadingVariantMap['level'],
variant,
color,
})
console.log(headingStylesRaw)
const headingClassName = cx(headingStylesRaw, css(cssProp || {}))
const Tag: keyof React.JSX.IntrinsicElements = `h${level}`
return (
<Tag ref={ref} className={headingClassName} {...props}>
{children}
</Tag>
)
},
)
Heading.displayName = 'Heading'
export default Headingimport { styled } from '@styled-system/jsx'
import { paragraph } from '@styled-system/recipes'
const Paragraph = styled('p', paragraph)
export default Paragraphimport Heading from './heading'
import Paragraph from './paragraph'
export { Heading, Paragraph }import { Heading, Paragraph } from '@/components/ui/typography'<Heading level={1}>Main Heading</Heading>
<Paragraph>This is a paragraph of text.</Paragraph>Base size paragraph. Typography is the art and technique of arranging type to make written language legible, readable, and appealing when displayed.
Large size paragraph. Typography is the art and technique of arranging type to make written language legible, readable, and appealing when displayed.
Compact size paragraph. Typography is the art and technique of arranging type to make written language legible, readable, and appealing when displayed.
Subscript size paragraph. Typography is the art and technique of arranging type to make written language legible, readable, and appealing when displayed.
Default color paragraph text.
Secondary color paragraph text.
Success color paragraph text.
Warning color paragraph text.
Error color paragraph text.
Disabled color paragraph text.
Italic text style.
Bold text style.
Underlined text style.
Left-aligned paragraph. Typography is the art and technique of arranging type to make written language legible, readable, and appealing when displayed.
Center-aligned paragraph. Typography is the art and technique of arranging type to make written language legible, readable, and appealing when displayed.
Right-aligned paragraph. Typography is the art and technique of arranging type to make written language legible, readable, and appealing when displayed.
Justify-aligned paragraph. Typography is the art and technique of arranging type to make written language legible, readable, and appealing when displayed. This text is justified, which means it is aligned to both the left and right margins.