Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mj12albert committed Nov 28, 2024
1 parent 1fbadad commit 150e54c
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 149 deletions.
59 changes: 59 additions & 0 deletions docs/data/components/accordion/AccordionIntroduction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use client';
import * as React from 'react';
import { Accordion } from '@base-ui-components/react/accordion';
import classes from './styles.module.css';

export default function AccordionIntroduction() {
return (
<Accordion.Root className={classes.root} aria-label="Base UI Accordion">
<Accordion.Item className={classes.item}>
<Accordion.Header className={classes.header}>
<Accordion.Trigger className={classes.trigger}>
Trigger 1
<ExpandMoreIcon />
</Accordion.Trigger>
</Accordion.Header>
<Accordion.Panel className={classes.panel}>
This is the contents of Accordion.Panel 1
</Accordion.Panel>
</Accordion.Item>
<Accordion.Item className={classes.item}>
<Accordion.Header className={classes.header}>
<Accordion.Trigger className={classes.trigger}>
Trigger 2
<ExpandMoreIcon />
</Accordion.Trigger>
</Accordion.Header>
<Accordion.Panel className={classes.panel}>
This is the contents of Accordion.Panel 2
</Accordion.Panel>
</Accordion.Item>
<Accordion.Item className={classes.item}>
<Accordion.Header className={classes.header}>
<Accordion.Trigger className={classes.trigger}>
Trigger 3
<ExpandMoreIcon />
</Accordion.Trigger>
</Accordion.Header>
<Accordion.Panel className={classes.panel}>
This is the contents of Accordion.Panel 3
</Accordion.Panel>
</Accordion.Item>
</Accordion.Root>
);
}

function ExpandMoreIcon(props) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
className={classes.icon}
{...props}
>
<path d="M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z" fill="currentColor" />
</svg>
);
}
59 changes: 59 additions & 0 deletions docs/data/components/accordion/AccordionIntroduction.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use client';
import * as React from 'react';
import { Accordion } from '@base-ui-components/react/accordion';
import classes from './styles.module.css';

export default function AccordionIntroduction() {
return (
<Accordion.Root className={classes.root} aria-label="Base UI Accordion">
<Accordion.Item className={classes.item}>
<Accordion.Header className={classes.header}>
<Accordion.Trigger className={classes.trigger}>
Trigger 1
<ExpandMoreIcon />
</Accordion.Trigger>
</Accordion.Header>
<Accordion.Panel className={classes.panel}>
This is the contents of Accordion.Panel 1
</Accordion.Panel>
</Accordion.Item>
<Accordion.Item className={classes.item}>
<Accordion.Header className={classes.header}>
<Accordion.Trigger className={classes.trigger}>
Trigger 2
<ExpandMoreIcon />
</Accordion.Trigger>
</Accordion.Header>
<Accordion.Panel className={classes.panel}>
This is the contents of Accordion.Panel 2
</Accordion.Panel>
</Accordion.Item>
<Accordion.Item className={classes.item}>
<Accordion.Header className={classes.header}>
<Accordion.Trigger className={classes.trigger}>
Trigger 3
<ExpandMoreIcon />
</Accordion.Trigger>
</Accordion.Header>
<Accordion.Panel className={classes.panel}>
This is the contents of Accordion.Panel 3
</Accordion.Panel>
</Accordion.Item>
</Accordion.Root>
);
}

function ExpandMoreIcon(props: React.SVGProps<SVGSVGElement>) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
className={classes.icon}
{...props}
>
<path d="M16.59 8.59 12 13.17 7.41 8.59 6 10l6 6 6-6z" fill="currentColor" />
</svg>
);
}
61 changes: 0 additions & 61 deletions docs/data/components/accordion/UnstyledAccordionIntroduction.js

This file was deleted.

61 changes: 0 additions & 61 deletions docs/data/components/accordion/UnstyledAccordionIntroduction.tsx

This file was deleted.

38 changes: 25 additions & 13 deletions docs/data/components/accordion/accordion.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ packageName: '@base-ui-components/react'

## Introduction

<Demo demo="UnstyledAccordionIntroduction" defaultCodeOpen="false" bg="gradient" />
<Demo demo="AccordionIntroduction" defaultCodeOpen="false" bg="gradient" />

## Installation

Expand All @@ -31,7 +31,7 @@ Accordions are implemented using a collection of related components:
- `<Accordion.Header />` is a heading (`h3` by default) that wraps the `Trigger`
- `<Accordion.Panel />` is the element that contains content in a `Item`

```tsx
```jsx
<Accordion.Root>
<Accordion.Item>
<Accordion.Header>
Expand All @@ -57,7 +57,7 @@ The open state of the accordion is represented an array holding the `value`s of

You can optionally specify a custom `value` prop on `Item`:

```tsx
```jsx
<Accordion.Root>
<Accordion.Item value="one">
<Accordion.Header>
Expand All @@ -78,7 +78,7 @@ You can optionally specify a custom `value` prop on `Item`:

When uncontrolled, use the `defaultValue` prop to set the initial state of the accordion:

```tsx
```jsx
<Accordion.Root defaultValue={[0]}>
<Accordion.Item {/* `value={0}` by default */}>
<Accordion.Header>
Expand Down Expand Up @@ -115,7 +115,7 @@ When uncontrolled, use the `defaultValue` prop to set the initial state of the a

When controlled, pass the `value` and `onValueChange` props to `Accordion.Root`:

```tsx
```jsx
const [value, setValue] = React.useState(['a']);

return (
Expand All @@ -142,15 +142,15 @@ return (

By default, all accordion items can be opened at the same time. Use the `openMultiple` prop to only allow one open item at a time:

```tsx
```jsx
<Accordion.Root openMultiple={false}>{/* subcomponents */}</Accordion.Root>
```

### At least one `Item` remains open

Use controlled mode to always keep one `Item` open:

```tsx
```jsx
const [value, setValue] = React.useState([0]);

const handleValueChange = (newValue) => {
Expand All @@ -168,21 +168,31 @@ return (

## Horizontal

Use the `orientation` prop to configure a horizontal accordion. In a horizontal accordion, focus will move between `Accordion.Trigger`s with the <kbd class="key">Right Arrow</kbd> and <kbd class="key">Left Arrow</kbd> keys, instead of Down/Up.
Use the `orientation` prop to configure a horizontal accordion. In a horizontal accordion, focus will move between `Accordion.Trigger`s with the <kbd className="key">Right Arrow</kbd> and <kbd className="key">Left Arrow</kbd> keys, instead of Down/Up.

Check warning on line 171 in docs/data/components/accordion/accordion.mdx

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [Google.Will] Avoid using 'will'. Raw Output: {"message": "[Google.Will] Avoid using 'will'.", "location": {"path": "docs/data/components/accordion/accordion.mdx", "range": {"start": {"line": 171, "column": 98}}}, "severity": "WARNING"}

```tsx
```jsx
<Accordion.Root orientation="horizontal">{/* subcomponents */}</Accordion.Root>
```

## RTL

Use the `direction` prop to configure a RTL accordion:

```tsx
```jsx
<Accordion.Root direction="rtl">{/* subcomponents */}</Accordion.Root>
```

When a horizontal accordion is set to `direction="rtl"`, keyboard actions are reversed accordingly - <kbd class="key">Left Arrow</kbd> moves focus to the next trigger and <kbd class="key">Right Arrow</kbd> moves focus to the previous trigger.
When a horizontal accordion is set to `direction="rtl"`, keyboard actions are reversed accordingly - <kbd className="key">Left Arrow</kbd> moves focus to the next trigger and <kbd className="key">Right Arrow</kbd> moves focus to the previous trigger.

## Hidden state

`<Accordion.Panel />`s are unmounted from the DOM by default when they are closed. The `keepMounted` prop can be used to keep them mounted when closed, and instead rely on the `hidden` attribute to hide the content:

```jsx
<Accordion.Root keepMounted>{/* accordion items */}</Accordion.Root>
```

Alternatively `keepMounted` can be passed to `Accordion.Panel`s directly to enable this for only one `Item` instead of the whole accordion.

## Improving searchability of hidden content

Expand All @@ -198,6 +208,8 @@ Content hidden by `Accordion.Panel` components can be made accessible only to a
<Accordion.Root hiddenUntilFound>{/* subcomponents */}</Accordion.Root>
```

When `hiddenUntilFound` is used, `Accordion.Panel`s remain mounted even when closed, overriding the `keepMounted` prop on the root or the panel.

Alternatively `hiddenUntilFound` can be passed to `Accordion.Panel`s directly to enable this for only one `Item` instead of the whole accordion.

We recommend using [CSS animations](#css-animations) for animated accordions that use this feature. Currently there is browser bug that does not highlight the found text inside elements that have a [CSS transition](#css-transitions) applied.
Expand Down Expand Up @@ -290,13 +302,13 @@ When using CSS transitions, styles for the `Panel` must be applied to three stat

### JavaScript Animations

When using external libraries for animation, for example `framer-motion`, be aware that `Accordion.Item`s hides content using the HTML `hidden` attribute in the closed state, and does not unmount from the DOM.
Use the `keepMounted` prop lets an external library control the mounting, for example `framer-motion`:

```js
function App() {
const [value, setValue] = useState([0]);
return (
<Accordion.Root value={value} onValueChange={setValue}>
<Accordion.Root value={value} onValueChange={setValue} keepMounted>
<Accordion.Item>
<Accordion.Header>
<Accordion.Trigger>Toggle</Accordion.Trigger>
Expand Down
Loading

0 comments on commit 150e54c

Please sign in to comment.