Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(quill): add Heading and Text typography primitives (#61876)

Adam Leith496a892a2139
diff --git a/packages/quill/apps/storybook/stories/typography.stories.tsx b/packages/quill/apps/storybook/stories/typography.stories.tsx
index b1539670ef21..16cd97638717 100644
--- a/packages/quill/apps/storybook/stories/typography.stories.tsx
+++ b/packages/quill/apps/storybook/stories/typography.stories.tsx
@@ -12,13 +12,30 @@ export const Default: Story = {
render: () => {
return (
<div className="space-y-6">
- <h1 className="text-2xl font-bold">Text-2xl - largest</h1>
- <h2 className="text-xl font-bold">Text-xl - large</h2>
- <h3 className="text-lg font-bold">Text-lg - medium</h3>
- <h4 className="text-base font-bold">Text-base - normal</h4>
- <h5 className="text-sm font-bold">Text-sm - smaller</h5>
- <p className="text-xs">Text-xs - small</p>
- <small className="text-xxs">Text-xxs - super small</small>
+ <div className="space-y-6">
+ <h1 className="text-2xl font-bold">Text-2xl - largest</h1>
+ <h2 className="text-xl font-bold">Text-xl - large</h2>
+ <h3 className="text-lg font-bold">Text-lg - medium</h3>
+ <h4 className="text-base font-bold">Text-base - normal</h4>
+ <h5 className="text-sm font-bold">Text-sm - smaller</h5>
+ <p className="text-xs">Text-xs - small</p>
+ <small className="text-xxs">Text-xxs - super small</small>
+ </div>
+ <p className="text-sm text-muted-foreground">
+ These are the raw type tokens. For components that apply them, see the{' '}
+ <a
+ className="underline"
+ target="_top"
+ href="./?path=/docs/typography-heading--docs"
+ >
+ Heading
+ </a>{' '}
+ and{' '}
+ <a className="underline" target="_top" href="./?path=/docs/typography-text--docs">
+ Text
+ </a>{' '}
+ primitives.
+ </p>
</div>
)
},
diff --git a/packages/quill/packages/primitives/src/heading.stories.tsx b/packages/quill/packages/primitives/src/heading.stories.tsx
new file mode 100644
index 000000000000..b4425e17b1d8
--- /dev/null
+++ b/packages/quill/packages/primitives/src/heading.stories.tsx
@@ -0,0 +1,47 @@
+import type { Meta, StoryObj } from '@storybook/react'
+
+import { Heading } from './heading'
+
+const meta = {
+ title: 'Typography/Heading',
+ component: Heading,
+ tags: ['autodocs'],
+ argTypes: {
+ size: {
+ control: 'select',
+ options: ['2xl', 'xl', 'lg', 'base', 'sm'],
+ },
+ },
+} satisfies Meta<typeof Heading>
+
+export default meta
+type Story = StoryObj<typeof meta>
+
+export const Sizes = {
+ render: () => (
+ <div className="flex flex-col gap-3">
+ <Heading size="2xl">Heading 2xl</Heading>
+ <Heading size="xl">Heading xl</Heading>
+ <Heading size="lg">Heading lg</Heading>
+ <Heading size="base">Heading base</Heading>
+ <Heading size="sm">Heading sm</Heading>
+ </div>
+ ),
+} satisfies Story
+
+export const SemanticLevels = {
+ render: () => (
+ <div className="flex flex-col gap-3">
+ {/* Visual size decoupled from the heading level — pick the tag for document outline */}
+ <Heading size="2xl" render={<h1 />}>
+ Page title (h1)
+ </Heading>
+ <Heading size="lg" render={<h2 />}>
+ Section (h2)
+ </Heading>
+ <Heading size="sm" render={<h3 />}>
+ Subsection (h3)
+ </Heading>
+ </div>
+ ),
+} satisfies Story
diff --git a/packages/quill/packages/primitives/src/heading.tsx b/packages/quill/packages/primitives/src/heading.tsx
new file mode 100644
index 000000000000..cbabf9b2f2d7
--- /dev/null
+++ b/packages/quill/packages/primitives/src/heading.tsx
@@ -0,0 +1,48 @@
+import { mergeProps } from '@base-ui/react/merge-props'
+import { useRender } from '@base-ui/react/use-render'
+import { cva, type VariantProps } from 'class-variance-authority'
+import * as React from 'react'
+
+import { cn } from './lib/utils'
+
+// Visual size is decoupled from the semantic element. Pick `size` for looks
+// and `render` (e.g. <h1 />) for document outline / accessibility.
+const headingVariants = cva('text-foreground font-semibold text-balance', {
+ variants: {
+ size: {
+ '2xl': 'text-2xl tracking-tight',
+ xl: 'text-xl tracking-tight',
+ lg: 'text-lg',
+ base: 'text-base',
+ sm: 'text-sm',
+ },
+ },
+ defaultVariants: {
+ size: 'lg',
+ },
+})
+
+function Heading({
+ className,
+ size = 'lg',
+ render,
+ ...props
+}: useRender.ComponentProps<'h2'> & VariantProps<typeof headingVariants>): React.ReactElement {
+ return useRender({
+ defaultTagName: 'h2',
+ props: mergeProps<'h2'>(
+ {
+ 'data-quill': '',
+ className: cn(headingVariants({ size }), className),
+ } as Omit<React.ComponentProps<'h2'>, 'ref'>,
+ props
+ ),
+ render,
+ state: {
+ slot: 'heading',
+ size,
+ },
+ })
+}
+
+export { Heading, headingVariants }
diff --git a/packages/quill/packages/primitives/src/index.ts b/packages/quill/packages/primitives/src/index.ts
index 197e707f86ee..5f4ecd01fa96 100644
--- a/packages/quill/packages/primitives/src/index.ts
+++ b/packages/quill/packages/primitives/src/index.ts
@@ -124,6 +124,7 @@ export {
FieldContent,
FieldTitle,
} from './field'
+export { Heading, headingVariants } from './heading'
export { Input } from './input'
export {
NumberFieldRoot,
@@ -231,6 +232,7 @@ export { Spinner } from './spinner'
export { Switch } from './switch'
export { Table, TableHeader, TableBody, TableFooter, TableHead, TableRow, TableCell, TableCaption } from './table'
export { Tabs, TabsContent, TabsList, TabsTrigger } from './tabs'
+export { Text, textVariants } from './text'
export { Textarea } from './textarea'
export { Toggle, toggleVariants } from './toggle'
export { ToggleGroup, ToggleGroupItem } from './toggle-group'
diff --git a/packages/quill/packages/primitives/src/text.stories.tsx b/packages/quill/packages/primitives/src/text.stories.tsx
new file mode 100644
index 000000000000..72f01c88d93d
--- /dev/null
+++ b/packages/quill/packages/primitives/src/text.stories.tsx
@@ -0,0 +1,74 @@
+import type { Meta, StoryObj } from '@storybook/react'
+
+import { Text } from './text'
+
+const meta = {
+ title: 'Typography/Text',
+ component: Text,
+ tags: ['autodocs'],
+ argTypes: {
+ size: {
+ control: 'select',
+ options: ['lg', 'base', 'sm', 'xs', 'xxs'],
+ },
+ variant: {
+ control: 'select',
+ options: ['default', 'muted', 'destructive'],
+ },
+ weight: {
+ control: 'select',
+ options: ['normal', 'medium', 'semibold'],
+ },
+ },
+} satisfies Meta<typeof Text>
+
+export default meta
+type Story = StoryObj<typeof meta>
+
+export const Sizes = {
+ render: () => (
+ <div className="flex flex-col gap-2">
+ <Text size="lg">Text lg</Text>
+ <Text size="base">Text base</Text>
+ <Text size="sm">Text sm</Text>
+ <Text size="xs">Text xs</Text>
+ <Text size="xxs">Text xxs</Text>
+ </div>
+ ),
+} satisfies Story
+
+export const Variants = {
+ render: () => (
+ <div className="flex flex-col gap-2">
+ <Text variant="default">Default body text</Text>
+ <Text variant="muted">Muted caption text</Text>
+ <Text variant="destructive">Destructive error text</Text>
+ </div>
+ ),
+} satisfies Story
+
+export const Weights = {
+ render: () => (
+ <div className="flex flex-col gap-2">
+ <Text weight="normal">Normal weight</Text>
+ <Text weight="medium">Medium weight</Text>
+ <Text weight="semibold">Semibold weight</Text>
+ </div>
+ ),
+} satisfies Story
+
+export const Inline = {
+ render: () => (
+ <Text>
+ Body copy with an{' '}
+ <Text render={<span />} weight="semibold">
+ inline emphasis
+ </Text>{' '}
+ and a{' '}
+ <Text render={<span />} variant="muted">
+ muted aside
+ </Text>
+ .
+ </Text>
+ ),
+} satisfies Story
diff --git a/packages/quill/packages/primitives/src/text.tsx b/packages/quill/packages/primitives/src/text.tsx
new file mode 100644
index 000000000000..df752c12084c
--- /dev/null
+++ b/packages/quill/packages/primitives/src/text.tsx
@@ -0,0 +1,63 @@
+import { mergeProps } from '@base-ui/react/merge-props'
+import { useRender } from '@base-ui/react/use-render'
+import { cva, type VariantProps } from 'class-variance-authority'
+import * as React from 'react'
+
+import { cn } from './lib/utils'
+
+// Body / caption / label text. Defaults to a block <p>; pass render=<span /> for inline.
+const textVariants = cva('', {
+ variants: {
+ size: {
+ lg: 'text-lg',
+ base: 'text-base',
+ sm: 'text-sm',
+ xs: 'text-xs',
+ xxs: 'text-xxs',
+ },
+ variant: {
+ default: 'text-foreground',
+ muted: 'text-muted-foreground',
+ destructive: 'text-destructive-foreground',
+ },
+ weight: {
+ normal: 'font-normal',
+ medium: 'font-medium',
+ semibold: 'font-semibold',
+ },
+ },
+ defaultVariants: {
+ size: 'base',
+ variant: 'default',
+ weight: 'normal',
+ },
+})
+
+function Text({
+ className,
+ size = 'base',
+ variant = 'default',
+ weight = 'normal',
+ render,
+ ...props
+}: useRender.ComponentProps<'p'> & VariantProps<typeof textVariants>): React.ReactElement {
+ return useRender({
+ defaultTagName: 'p',
+ props: mergeProps<'p'>(
+ {
+ 'data-quill': '',
+ className: cn(textVariants({ size, variant, weight }), className),
+ } as Omit<React.ComponentProps<'p'>, 'ref'>,
+ props
+ ),
+ render,
+ state: {
+ slot: 'text',
+ size,
+ variant,
+ weight,
+ },
+ })
+}
+
+export { Text, textVariants }