Skip to content

Commit f0d808e

Browse files
authored
docs: React Aria separator docs (#9288)
* update starter example * add separator docs * fix css conflict * add min height
1 parent a73ac97 commit f0d808e

File tree

6 files changed

+68
-3
lines changed

6 files changed

+68
-3
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {Layout} from '../../src/Layout';
2+
export default Layout;
3+
4+
import docs from 'docs:react-aria-components';
5+
import {Separator as VanillaSeparator} from 'vanilla-starter/Separator';
6+
import {Separator as TailwindSeparator} from 'tailwind-starter/Separator';
7+
import tailwindDocs from 'docs:tailwind-starter/Separator';
8+
import vanillaDocs from 'docs:vanilla-starter/Separator';
9+
import '../../tailwind/tailwind.css';
10+
11+
export const relatedPages = [{'title': 'useSeparator', 'url': 'https://react-spectrum.adobe.com/react-aria/useSeparator.html'}];
12+
export const description = 'A separator is a visual divider between two groups of content.';
13+
14+
# Separator
15+
16+
<PageDescription>{docs.exports.Separator.description}</PageDescription>
17+
18+
<ExampleSwitcher examples={['Vanilla', 'Tailwind']}>
19+
<VisualExample
20+
component={VanillaSeparator}
21+
docs={vanillaDocs.exports.Separator}
22+
links={vanillaDocs.links}
23+
props={['orientation']}
24+
type="vanilla"
25+
files={["starters/docs/src/Separator.tsx", "starters/docs/src/Separator.css"]} />
26+
<VisualExample
27+
component={TailwindSeparator}
28+
docs={tailwindDocs.exports.Separator}
29+
links={tailwindDocs.links}
30+
props={['orientation']}
31+
type="tailwind"
32+
files={["starters/tailwind/src/Separator.tsx"]} />
33+
</ExampleSwitcher>
34+
35+
## API
36+
37+
<PropTable component={docs.exports.Separator} links={docs.links}/>

packages/react-aria-components/src/Separator.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ export class SeparatorNode extends CollectionNode<any> {
4242
}
4343
}
4444

45+
/**
46+
* A separator is a visual divider between two groups of content, e.g. groups of menu items or sections of a page.
47+
*/
4548
export const Separator = /*#__PURE__*/ createLeafComponent(SeparatorNode, function Separator(props: SeparatorProps, ref: ForwardedRef<HTMLElement>) {
4649
[props, ref] = useContextProps(props, ref, SeparatorContext);
4750

starters/docs/src/Menu.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,14 @@
170170
}
171171
}
172172

173-
.react-aria-Separator {
173+
.react-aria-Menu .react-aria-Separator {
174174
grid-column-start: 1;
175175
grid-column-end: -1;
176176
margin: 0 var(--spacing-2);
177177
border: 0;
178178
border-top: 0.5px solid var(--border-color);
179+
height: auto;
180+
width: auto;
179181

180182
.react-aria-MenuItem + & {
181183
margin-block-start: var(--spacing-1);

starters/docs/src/Separator.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@import "./theme.css";
2+
3+
.react-aria-Separator {
4+
background-color: var(--gray-800);
5+
border-style: none;
6+
border-radius: 1px;
7+
height: 2px;
8+
width: 100%;
9+
10+
&[aria-orientation="vertical"] {
11+
width: 2px;
12+
min-height: 32px;
13+
height: 100%;
14+
}
15+
}

starters/docs/src/Separator.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use client';
2+
import {Separator as RACSeparator, SeparatorProps} from 'react-aria-components';
3+
import React from 'react';
4+
import './Separator.css';
5+
6+
export function Separator(props: SeparatorProps) {
7+
return <RACSeparator {...props} />
8+
}

starters/tailwind/src/Separator.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { Separator as RACSeparator, SeparatorProps } from 'react-aria-components
44
import { tv } from 'tailwind-variants';
55

66
const styles = tv({
7-
base: 'bg-neutral-300 dark:bg-neutral-600 forced-colors:bg-[ButtonBorder]',
7+
base: 'bg-neutral-300 dark:bg-neutral-600 forced-colors:bg-[ButtonBorder] border-none',
88
variants: {
99
orientation: {
1010
horizontal: 'h-px w-full',
11-
vertical: 'w-px'
11+
vertical: 'w-px min-h-8 h-full'
1212
}
1313
},
1414
defaultVariants: {

0 commit comments

Comments
 (0)