> To build a Wix site agentically, or add Wix features like bookings or a store to a site you already have, follow https://www.wix.com/headless/skill.md
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Card.Header Component

## Article: Card.Header Component

## Article Link: https://dev.wix.com/docs/wix-design-system/components/layout/card/card-header-component.md

## Article Content:

# Card.Header

_Components/Layout/Card_

Interactive docs page: <https://wix-pages.com/design-system-documentation/#/component/card-header>

## Overview

```jsx
<Card>
  <Card.Header
    title="Staff availability"
    subtitle="See the days, times & locations this staff member is available to take appointments."
    suffix={
      <Button size="small" priority="secondary" prefixIcon={<Icons.AddSmall />}>
        Add Availability
      </Button>
    }
  />
</Card>;
```

Card headers are used to state the card's topic. It's an optional compound component of cards.

### Do

- Use it to show the topic of the card or a summary of its content.
- Use it to help users scan the page and find relevant info quicker.
- Use the suffix to show actions that apply to the whole card.

### Don't

- Don't use it outside of the `<Card/>` component.

### Feature examples

#### Structure

Card headers consist of 3 parts:

- `title` is the main text of the card, showing its main topic.
- `subtitle` is an additional explanation or description of the card's topic.
- `suffix` is a container for buttons, links, or other components.

All 3 parts are optional and their position is fixed.

```jsx
<Card>
  <Card.Header
    title="Title"
    subtitle="Subtitle"
    suffix={
      <StorybookComponents.Placeholder width="50px" height="40px">
        Suffix
      </StorybookComponents.Placeholder>
    }
  />
</Card>;
```

#### Title and subtitle

Use a short title so the card's topic stands out and is easier to scan.

Add a subtitle to give further explanation.

```jsx
<Card>
  <Card.Header title="Title" subtitle="Subtitle" />
</Card>;
```

#### Suffix

Use a `suffix` container to add actions that apply to the whole card.

A variety of components can be used in the suffix, including:

- `<Button/>`
- `<TextButton/>`
- `<IconButton/>`
- `<ToggleSwitch/>` (use for collapsible cards)

```jsx
() => {
  const [toggleChecked, setToggleChecked] = React.useState(true);
  return (
    <StorybookComponents.Stack flexDirection="column">
      <Card>
        <Card.Header
          title="Title"
          suffix={
            <Button size="small" priority="secondary">
              Suffix
            </Button>
          }
        />
      </Card>
      <Card>
        <Card.Header
          title="Title"
          suffix={
            <TextButton size="small" priority="secondary">
              Suffix
            </TextButton>
          }
        />
      </Card>
      <Card>
        <Card.Header
          title="Title"
          suffix={
            <IconButton size="small" priority="secondary">
              <Icons.MoreSmall />
            </IconButton>
          }
        />
      </Card>
      <Card>
        <Card.Header
          title="Title"
          suffix={
            <ToggleSwitch
              checked={toggleChecked}
              onChange={() => setToggleChecked(!toggleChecked)}
              size="medium"
            />
          }
        />
      </Card>
    </StorybookComponents.Stack>
  );
};
```

### Mobile examples

#### Mobile header actions

`<Card.Header/>` renders whatever you pass to `suffix` next to the title, at every screen width, so on a narrow screen the actions squeeze the title and subtitle into a thin column. Read `mobile` from `WixDesignSystemContext` and move the actions out of the suffix on mobile instead.

On mobile, leave `suffix` empty so the title and subtitle take the full width, and render the actions in a `<Card.Content/>` right below the header. Make the primary action `fullWidth` for a large touch target, and collapse the secondary actions into a More `<IconButton/>` with a `<PopoverMenu/>` to its left. The desktop layout stays as it is.

_To see the change, toggle 'Enable mobile support' in the top bar of Storybook._

```jsx
() => {
  const { mobile } = React.useContext(WixDesignSystemContext);

  const secondaryActions = [
    {
      id: 'copy',
      text: 'Copy to other staff',
      prefixIcon: <Icons.DuplicateSmall />,
    },
    { id: 'block', text: 'Block time off', prefixIcon: <Icons.DateSmall /> },
  ];

  const primaryAction = (
    <Button size="small" prefixIcon={<Icons.AddSmall />} fullWidth={mobile}>
      Add Availability
    </Button>
  );

  const header = (
    <Card.Header
      title="Staff availability"
      subtitle="See the days, times & locations this staff member is available to take appointments."
      suffix={
        mobile ? null : (
          <Box gap="SP2">
            {secondaryActions.map((action) => (
              <Button
                key={action.id}
                size="small"
                priority="secondary"
                prefixIcon={action.prefixIcon}
              >
                {action.text}
              </Button>
            ))}
            {primaryAction}
          </Box>
        )
      }
    />
  );

  if (!mobile) {
    return <Card>{header}</Card>;
  }

  return (
    <Card>
      {header}
      <Card.Content size="medium">
        <Box gap="SP2" verticalAlign="middle">
          <PopoverMenu
            placement="bottom-start"
            triggerElement={
              <IconButton
                size="small"
                priority="secondary"
                ariaLabel="More actions"
              >
                <Icons.MoreSmall />
              </IconButton>
            }
          >
            {secondaryActions.map((action) => (
              <PopoverMenu.MenuItem
                key={action.id}
                text={action.text}
                prefixIcon={action.prefixIcon}
              />
            ))}
          </PopoverMenu>
          <Box flexGrow={1}>{primaryAction}</Box>
        </Box>
      </Card.Content>
    </Card>
  );
};
```

### Common use case examples

#### Collapsible cards

Use a `<ToggleSwitch/>` or a `<TextButton/>` (e.g., "Show more" or "Show less") in the header suffix to let users expand and collapse the card.

```jsx
() => {
  const [open, setOpen] = React.useState(true);
  const [selected, setSelected] = React.useState(1);
  const [checked, setChecked] = React.useState(false);

  const timezoneOptions = [
    { id: 1, value: '(GMT +02:00) Vilnius' },
    { id: 2, value: '(GMT +01:00) Warsaw' },
    { id: 3, value: '(GMT +00:00) London' },
  ];

  const infoIconText =
    'Not sure when your event is taking place? Show the time as To Be Determined (TBD).';

  const ActionArea = () => {
    return (
      <Box align="center" verticalAlign="middle" gap={1}>
        <Text size="small">Time is TBD</Text>
        <InfoIcon content={infoIconText} />
        <ToggleSwitch checked={!open} onChange={() => setOpen(!open)} />
      </Box>
    );
  };
  return (
    <Card>
      <Card.Header title="Date and time" suffix={<ActionArea />} />
      <Collapse open={open}>
        <Card.Divider />
        <Card.Content>
          <Layout alignItems="end">
            <Cell>
              <Layout alignItems="end">
                <Cell span={5}>
                  <FormField label="Date">
                    <DatePicker
                      value={new Date()}
                      width="100%"
                      onChange={() => {}}
                    />
                  </FormField>
                </Cell>
                <Cell span={3}>
                  <FormField label="Time">
                    <TimeInput width="auto" />
                  </FormField>
                </Cell>
                <Cell span={4}>
                  <Box height="36px">
                    <AddItem size="tiny">Add End Time</AddItem>
                  </Box>
                </Cell>
              </Layout>
            </Cell>
            <Cell>
              <Layout alignItems="end">
                <Cell span={5}>
                  <FormField label="Timezone">
                    <Dropdown
                      selectedId={selected}
                      placeholder="Select a timezone"
                      options={timezoneOptions}
                      onSelect={(option) => setSelected(Number(option.id))}
                    />
                  </FormField>
                </Cell>
                <Cell span={4}>
                  <Box gap={1} height="36px" verticalAlign="middle">
                    <Checkbox
                      checked={checked}
                      onChange={() => setChecked(!checked)}
                    >
                      Display timezone
                    </Checkbox>
                    <InfoIcon content="Timezone will be shown next to the event time." />
                  </Box>
                </Cell>
              </Layout>
            </Cell>
            <Cell>
              <Text size="small">
                To change the date and time format for all events, go to
                <a>Regional Settings</a>.
              </Text>
            </Cell>
          </Layout>
        </Card.Content>
      </Collapse>
    </Card>
  );
};
```

#### Subtitle links

Add links within the subtitle by using an inline `<TextButton/>`.

```jsx
<Card>
  <Card.Header
    title="FAQ buttons"
    subtitle={
      <Box direction="horizontal" gap="1">
        <Text secondary>
          Add questions and answers that show in the chatbox on your site.
        </Text>
        <TextButton underline="always">Learn more</TextButton>
      </Box>
    }
  />
  <Card.Divider />
  <Card.Content>
    <Box height={180} />
  </Card.Content>
</Card>;
```

### Accessibility examples

#### Control heading hierarchy

If a card appears directly below the page title (H1) with no page section title (H2) in between, change card title to H2 using `as` prop.

```jsx
<Page>
  <Page.Header title="Page title as H1" />
  <Page.Content>
    <Layout>
      <Cell span={8}>
        <Card stretchVertically={false}>
          <Card.Header
            title={
              <Heading size="medium" as="h2">
                Card title as H2
              </Heading>
            }
          />
          <Card.Divider />
          <Card.Content>
            <StorybookComponents.Placeholder height="120px" />
          </Card.Content>
        </Card>
      </Cell>
      <Cell span={4}>
        <Card stretchVertically={true}>
          <Card.Header
            title={
              <Heading size="medium" as="h2">
                Card title as H2
              </Heading>
            }
          />
          <Card.Divider />
          <Card.Content>
            <StorybookComponents.Placeholder height="120px" />
          </Card.Content>
        </Card>
      </Cell>
    </Layout>
  </Page.Content>
</Page>;
```

## Code

```jsx
import { CardHeader } from '@wix/design-system';
```

### Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `dataHook` | `string` | — | Applies a data-hook HTML attribute to be used in the tests. |
| `subtitle` | `ReactNode` | — | Sets card subtitle text value. Subtitle can also be overridden to any other component. |
| `suffix` | `ReactNode` | — | Adds an empty container on the right side of a header. Used to store action buttons or other components. |
| `title` | `ReactNode` | — | Sets card title text value. Title can also be overridden to any other component. |

## Testkit

Import the driver matching your test environment:

```jsx
// UniDriver
import { CardHeaderUniDriver } from '@wix/design-system/dist/testkit/unidriver';

// Vanilla
import { CardHeaderTestkit } from '@wix/design-system/dist/testkit';

// Puppeteer
import { CardHeaderTestkit } from '@wix/design-system/dist/testkit/puppeteer';

// Testing Library
import { CardHeaderTestkit } from '@wix/design-system/dist/testkit/testing-library';
```

### Driver methods

| Method | Description |
| --- | --- |
| `title` | Returns title text. |
| `subtitle` | Returns subtitle text. |
| `exists` | Checks whether the component found with the given data hook. |
| `element` | Gets the component root element. |
| `click` | Clicks on the component root element. |
| `base` | Returns UniDriver for the base element. |

## Changelog

No released changes have been recorded for this component.