Title
Card and panel title component: a responsive h3 for the title of a card, panel, list group or dialog section, between Subheading and body text in size. One size, no size prop. Pair with Text for the supporting line.
import { mergeProps } from "@base-ui/react/merge-props"
import { useRender } from "@base-ui/react/use-render"
import { cn } from "cn"
// No width of its own: the card, panel or column that holds it is the
// measure. text-pretty keeps a wrapped title from ending on one word.
/**
* The title of a card, panel or list group, rendered as an `<h3>` in the body
* font: 18px with a 28px line, 20px from the `sm` breakpoint, medium weight.
* One size, no props beyond the element's own; pass `render` to use another
* heading level. Inside a stock `Card`, use `CardTitle`; a section's heading
* is `Subheading` and a page's headline is `Heading`.
*/
function Title({
className,
render,
...props
}: useRender.ComponentProps<"h3">) {
return useRender({
defaultTagName: "h3",
render,
state: { slot: "title" },
props: mergeProps<"h3">(
{
className: cn(
"text-lg/7 font-medium tracking-tight text-pretty sm:text-xl/7",
className
),
},
props
),
})
}
export { Title }
import { Text } from "@/components/text/text"
import { Title } from "@/components/title/title"
const COPY = {
title: "Quarterly planning",
body: "Goals, owners and dates for the next twelve weeks, in one place.",
}
export default function TitleDemo() {
return (
<div className="grid max-w-sm gap-2 rounded-xl border bg-card p-6 text-card-foreground">
<Title>{COPY.title}</Title>
<Text variant="muted">{COPY.body}</Text>
</div>
)
}
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 { cn } from "cn"
// The paragraph under a Heading or Subheading, in a hero or a section
// header. No width of its own: give it one with a `max-w-*` class when the
// layout wants it. Inherits the surrounding ink, so it reads over art;
// muted steps it down on a flat ground.
const textVariants = cva("w-full min-w-0 text-pretty", {
variants: {
/**
* The text color. `default` (the default) keeps the inherited color.
* `muted` uses `muted-foreground`.
*/
variant: {
default: "",
muted: "text-muted-foreground",
},
/**
* The text size: `md` (the default) 16px with 28px lines, `lg` 18px
* with 32px lines, the lead under a page headline.
*/
size: {
md: "text-base/7",
lg: "text-lg/8",
},
},
defaultVariants: { variant: "default", size: "md" },
})
/**
* The paragraph under a heading, a `p` by default. For several paragraphs,
* pass `render={<div />}` and put your own `p` elements inside.
*
* `size` sets the text: `md` (the default) 16px with 28px lines, `lg` 18px
* with 32px lines for the lead under a page headline. `variant="muted"`
* uses the muted text color; the default inherits the ink around it.
*/
function Text({
className,
variant = "default",
size = "md",
render,
...props
}: useRender.ComponentProps<"p"> & VariantProps<typeof textVariants>) {
return useRender({
defaultTagName: "p",
render,
state: { slot: "text", variant, size },
props: mergeProps<"p">(
{ className: cn(textVariants({ variant, size }), className) },
props
),
})
}
export { Text }
Installation
pnpm dlx shadcn@latest add @01orbital/titlenpx shadcn@latest add @01orbital/titleyarn dlx shadcn@latest add @01orbital/titlebunx --bun shadcn@latest add @01orbital/titleUsage
import { Text } from "@/components/text/text"
import { Title } from "@/components/title/title"
const COPY = {
title: "Quarterly planning",
body: "Goals, owners and dates for the next twelve weeks, in one place.",
}
export default function TitleDemo() {
return (
<div className="grid max-w-sm gap-2 rounded-xl border bg-card p-6 text-card-foreground">
<Title>{COPY.title}</Title>
<Text variant="muted">{COPY.body}</Text>
</div>
)
}This example installs with everything it uses:
pnpm dlx shadcn@latest add @01orbital/title-demonpx shadcn@latest add @01orbital/title-demoyarn dlx shadcn@latest add @01orbital/title-demobunx --bun shadcn@latest add @01orbital/title-demoAPI reference
The title of a card, panel or list group, rendered as an <h3> in the body font: 18px with a 28px line, 20px from the sm breakpoint, medium weight. One size, no props beyond the element's own; pass render to use another heading level. Inside a stock Card, use CardTitle; a section's heading is Subheading and a page's headline is Heading.
It accepts the props of the Base UI part it wraps, and the HTML attributes of the element it renders.
Dependencies
npm: @base-ui/react, cn. The CLI installs them for you.
Used in blocks
3 blocks are built with Title:
Last updated on