# Pricing plans

Three tiers for a field-notes app, each a `Card` with a `Heading`, a price, a feature list and a `Button`. A `RadioGroup` styled as a segmented control switches between monthly and yearly billing, with a `Badge` for the yearly saving, and the most popular tier carries an accent border.

**Example: Fieldnote plans** (`examples/recipes/pricing-plans.tsx`)

```tsx
'use client'

import { Badge, Body, BodySmall, Box, Button, Card, Heading, Radio, RadioGroup, Stack, Text, toastSuccess } from '@blocks/design-system'
import { Check } from 'lucide-react'
import { useId, useState } from 'react'
import styles from './pricing-plans.module.css'

type Billing = 'monthly' | 'yearly'

interface Plan {
  name: string
  summary: string
  /** Per seat, per month. `null` means the price is quoted. */
  price: Record<Billing, number> | null
  features: string[]
  cta: string
  popular?: boolean
}

const plans: Plan[] = [
  {
    name: 'Starter',
    summary: 'For a small crew’s field notes.',
    price: { monthly: 10, yearly: 8 },
    features: ['5 projects', 'Offline on 2 devices', '2 GB of photos', 'Email support'],
    cta: 'Start free trial',
  },
  {
    name: 'Team',
    summary: 'For crews sharing routes and maps.',
    price: { monthly: 25, yearly: 20 },
    features: ['Unlimited projects', 'Offline everywhere', 'Shared map layers', 'Review and sign-off', 'Priority support'],
    cta: 'Start free trial',
    popular: true,
  },
  {
    name: 'Enterprise',
    summary: 'For agencies across many regions.',
    price: null,
    features: ['Everything in Team', 'SAML single sign-on', 'Audit log export', 'Data residency', 'Success manager'],
    cta: 'Contact us',
  },
]

// Three tiers that share one billing choice. The toggle is a RadioGroup
// styled as a segmented control, so arrow keys move between the options.
export default function PricingPlans() {
  const [billing, setBilling] = useState<Billing>('yearly')
  const headingId = useId()

  return (
    <Stack as="section" gap="lg" aria-labelledby={headingId} dangerouslySetClassName={styles.root}>
      <Stack gap="sm" align="center" textAlign="center">
        <Heading as="h2" id={headingId} fontSize="xl">
          Plans for every field&nbsp;season
        </Heading>
        <Body margin="none" color="text-muted">
          Every plan starts with a 14-day trial. Change seats any time.
        </Body>
        <RadioGroup
          aria-label="Billing period"
          value={billing}
          onValueChange={(value) => setBilling(value as Billing)}
          dangerouslySetClassName={styles.segmented}
        >
          <Radio value="monthly" dangerouslySetClassName={styles.segmentInput}>
            Monthly
          </Radio>
          <Radio value="yearly" dangerouslySetClassName={styles.segmentInput}>
            Yearly <Badge tone="success">Save 20%</Badge>
          </Radio>
        </RadioGroup>
      </Stack>

      <div className={styles.plans}>
        {plans.map((plan) => (
          <PlanCard key={plan.name} plan={plan} billing={billing} />
        ))}
      </div>
    </Stack>
  )
}

function PlanCard({ plan, billing }: { plan: Plan; billing: Billing }) {
  const nameId = useId()
  const price = plan.price?.[billing]

  return (
    <Card
      as="article"
      aria-labelledby={nameId}
      padding="lg"
      display="flex"
      flexDirection="column"
      gap="lg"
      borderColor={plan.popular ? 'accent' : 'border-subtle'}
      borderWidth={plan.popular ? 'md' : 'sm'}
      borderRadius="xl"
      backgroundColor="bg"
    >
      <Stack gap="xs">
        <Stack direction="row" justify="space-between" align="center" gap="sm" wrap="wrap">
          <Heading as="h3" id={nameId} fontSize="lg">
            {plan.name}
          </Heading>
          {plan.popular && (
            <Badge tone="accent" variant="solid">
              Most popular
            </Badge>
          )}
        </Stack>
        <BodySmall margin="none" color="text-muted">
          {plan.summary}
        </BodySmall>
      </Stack>

      {/* Every tier has the same three lines: amount, period, billing note. */}
      <Stack gap="xxs">
        <Text fontSize="xxl" fontWeight="bold" lineHeight="heading" dangerouslySetClassName={styles.amount}>
          {price === undefined ? 'Custom' : `$${price}`}
        </Text>
        <Text fontSize="sm" color="text-muted" dangerouslySetClassName={styles.nowrap}>
          {price === undefined ? 'From 50 seats' : 'per seat / month'}
        </Text>
        <Text fontSize="xs" color="text-muted" dangerouslySetClassName={styles.nowrap}>
          {price === undefined ? 'Volume discounts' : billing === 'yearly' ? `$${price * 12} billed yearly` : 'Billed monthly'}
        </Text>
      </Stack>

      <Stack as="ul" gap="sm" aria-label={`${plan.name} features`} dangerouslySetClassName={styles.features}>
        {plan.features.map((feature) => (
          <Stack as="li" key={feature} direction="row" gap="sm" align="start">
            <Check aria-hidden className={styles.check} />
            <Text fontSize="sm">{feature}</Text>
          </Stack>
        ))}
      </Stack>

      <Box marginTop="auto">
        {price === undefined ? (
          <Button as="a" href="#pricing-plans-sales" size="lg" dangerouslySetClassName={styles.cta}>
            {plan.cta}
          </Button>
        ) : (
          <Button
            type="button"
            size="lg"
            variant={plan.popular ? 'primary' : 'base'}
            dangerouslySetClassName={styles.cta}
            onClick={() => toastSuccess(`${plan.name} trial started`, { description: `Billed ${billing} after 14 days.` })}
          >
            {plan.cta}
          </Button>
        )}
      </Box>
    </Card>
  )
}
```

## How it works

- The billing toggle is a real `RadioGroup` with two `Radio`s, so it is one tab stop and the arrow keys move between Monthly and Yearly. The app hides the radio dot visually but keeps it focusable, and draws the focus ring on the whole segment with `:has(:focus-visible)`.
- One `billing` state drives every card: the price, the billing note under it and the trial toast. Enterprise has no list price, so its call to action is a link to the sales page rather than a button.
- The popular tier is marked in text with a `Badge`, not only with the accent border. Each card is an `article` named by its plan heading, and each feature list has a label, so the tiers read well with a screen reader’s landmarks and lists.
- A container query lays the tiers out in three columns when the example is at least 36rem wide and stacks them on a phone.

## App-owned CSS

`examples/recipes/pricing-plans.module.css`:

```css
/* The plans sit in one column until the example is wide enough for three. */
.root {
  container-type: inline-size;
}

.plans {
  display: grid;
  gap: var(--ds-space-lg);
}

@container (min-width: 36rem) {
  .plans {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: stretch;
  }
}

/* A RadioGroup drawn as a segmented control: each label is a segment and
   the radio itself is visually hidden but still focusable. */
.root .segmented {
  flex-direction: row;
  gap: var(--ds-space-xs);
  padding: var(--ds-space-xs);
  margin-top: var(--ds-space-md);
  background-color: var(--ds-color-surface);
  border-radius: var(--ds-border-radius-pill);
}

.root .segmented > label {
  position: relative;
  gap: var(--ds-space-sm);
  padding: var(--ds-space-sm) var(--ds-space-lg);
  font-weight: var(--ds-font-weight-medium);
  color: var(--ds-color-text-muted);
  border-radius: var(--ds-border-radius-pill);
  transition: background-color var(--ds-duration-fast) var(--ds-easing-standard);
}

.root .segmented > label:has([data-checked]) {
  color: var(--ds-color-text);
  background-color: var(--ds-color-bg);
  box-shadow: var(--ds-shadow-sm);
}

.root .segmented > label:has(:focus-visible) {
  outline: var(--ds-border-width-md) solid var(--ds-color-focus-ring);
  outline-offset: var(--ds-space-xxs);
}

.root .segmentInput {
  position: absolute;
  width: var(--ds-space-xxs);
  height: var(--ds-space-xxs);
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.amount {
  font-variant-numeric: tabular-nums;
}

.nowrap {
  white-space: nowrap;
}

.features {
  margin: 0;
  padding: 0;
  list-style: none;
}

.check {
  flex-shrink: 0;
  width: var(--ds-icon-size-sm);
  height: var(--ds-icon-size-sm);
  margin-top: var(--ds-space-xs);
  color: var(--ds-color-success-text);
}

/* The call to action fills its card. */
.cta {
  width: 100%;
}

@media (prefers-reduced-motion: reduce) {
  .root .segmented > label {
    transition: none;
  }
}
```
