Skip to content

Commit 4e51283

Browse files
authored
Add styling guide for React Aria Components (#5016)
1 parent 2a98c9f commit 4e51283

File tree

11 files changed

+376
-159
lines changed

11 files changed

+376
-159
lines changed

packages/@react-aria/dnd/docs/dnd.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default Layout;
2222
category: Drag and Drop
2323
keywords: [drag, drop, dnd, drag and drop, aria, accessibility]
2424
navigationTitle: Introduction
25-
type: pattern
25+
type: interaction
2626
---
2727

2828
# Drag and Drop

packages/@react-aria/dnd/docs/useClipboard.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {Keyboard} from '@react-spectrum/text';
2020
---
2121
category: Drag and Drop
2222
keywords: [clipboard, copy, cut, paste, aria, accessibility]
23-
type: pattern
23+
type: interaction
2424
---
2525

2626
# useClipboard

packages/@react-aria/dnd/docs/useDrag.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {Keyboard} from '@react-spectrum/text';
2020
---
2121
category: Drag and Drop
2222
keywords: [drag, drop, dnd, drag and drop, aria, accessibility]
23-
type: pattern
23+
type: interaction
2424
---
2525

2626
# useDrag

packages/@react-aria/dnd/docs/useDraggableCollection.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {Keyboard} from '@react-spectrum/text';
2222
---
2323
category: Drag and Drop
2424
keywords: [drag, drop, dnd, drag and drop, aria, accessibility]
25-
type: pattern
25+
type: interaction
2626
---
2727

2828
# useDraggableCollection

packages/@react-aria/dnd/docs/useDrop.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {Keyboard} from '@react-spectrum/text';
2020
---
2121
category: Drag and Drop
2222
keywords: [drag, drop, dnd, drag and drop, aria, accessibility]
23-
type: pattern
23+
type: interaction
2424
---
2525

2626
# useDrop

packages/@react-aria/dnd/docs/useDroppableCollection.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {Keyboard} from '@react-spectrum/text';
2222
---
2323
category: Drag and Drop
2424
keywords: [drag, drop, dnd, drag and drop, aria, accessibility]
25-
type: pattern
25+
type: interaction
2626
---
2727

2828
# useDroppableCollection

packages/dev/docs/src/Layout.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ function Nav({currentPageName, pages}) {
383383
let sections = [];
384384
if (currentPageName.startsWith('react-aria') && ENABLE_PAGE_TYPES) {
385385
let {Introduction, Concepts, Interactions, Focus, Internationalization, 'Server Side Rendering': ssr, Utilities, ...hooks} = pagesByType.other;
386+
let interactions = {...pagesByType.interaction, Interactions, Focus};
387+
let utilities = {Internationalization, 'Server Side Rendering': ssr, Utilities};
386388
sections.push({pages: {Introduction, Concepts}});
387389
sections.push({
388390
title: 'Components',
@@ -394,20 +396,22 @@ function Nav({currentPageName, pages}) {
394396
pages: hooks,
395397
isActive: isActive(hooks)
396398
});
397-
sections.push({
398-
title: 'Patterns',
399-
pages: pagesByType.pattern,
400-
isActive: isActive(pagesByType.pattern)
401-
});
399+
if (pagesByType.pattern) {
400+
sections.push({
401+
title: 'Patterns',
402+
pages: pagesByType.pattern,
403+
isActive: isActive(pagesByType.pattern)
404+
});
405+
}
402406
sections.push({
403407
title: 'Interactions',
404-
pages: {Interactions, Focus},
405-
isActive: isActive({Interactions, Focus})
408+
pages: interactions,
409+
isActive: isActive(interactions)
406410
});
407411
sections.push({
408412
title: 'Utilities',
409-
pages: {Internationalization, 'Server Side Rendering': ssr, Utilities},
410-
isActive: isActive({Internationalization, 'Server Side Rendering': ssr, Utilities})
413+
pages: utilities,
414+
isActive: isActive(utilities)
411415
});
412416
} else {
413417
sections.push({

packages/react-aria-components/docs/GridList.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ HTML lists are meant for static content, rather than lists with rich interaction
315315
* **Item selection** – Single or multiple selection, with optional checkboxes, disabled rows, and both `toggle` and `replace` selection behaviors.
316316
* **Interactive children** – List items may include interactive elements such as buttons, checkboxes, menus, etc.
317317
* **Actions** – Items support optional row actions such as navigation via click, tap, double click, or <Keyboard>Enter</Keyboard> key.
318-
* **Async loading** – Support for loading items asynchronously, with infinite and virtualized scrolling.
318+
* **Async loading** – Support for loading items asynchronously.
319319
* **Keyboard navigation** – List items and focusable children can be navigated using the arrow keys, along with page up/down, home/end, etc. Typeahead, auto scrolling, and selection modifier keys are supported as well.
320320
* **Touch friendly** – Selection and actions adapt their behavior depending on the device. For example, selection is activated via long press on touch when item actions are present.
321321
* **Accessible** – Follows the [ARIA grid pattern](https://www.w3.org/WAI/ARIA/apg/patterns/grid/), with additional selection announcements via an ARIA live region. Extensively tested across many devices and [assistive technologies](accessibility.html#testing) to ensure announcements and behaviors are consistent.

packages/react-aria-components/docs/Table.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ HTML tables are meant for static content, rather than tables with rich interacti
388388
* **Columns** – Support for column sorting, [row header](https://www.w3.org/TR/wai-aria-1.1/#rowheader) columns, and nested column groups.
389389
* **Interactive children** – Table cells may include interactive elements such as buttons, menus, etc.
390390
* **Actions** – Rows and cells support optional actions such as navigation via click, tap, double click, or <Keyboard>Enter</Keyboard> key.
391-
* **Async loading** – Support for loading and sorting items asynchronously, with infinite and virtualized scrolling.
391+
* **Async loading** – Support for loading and sorting items asynchronously.
392392
* **Keyboard navigation** – Table rows, cells, and focusable children can be navigated using the arrow keys, along with page up/down, home/end, etc. Typeahead, auto scrolling, and selection modifier keys are supported as well.
393393
* **Touch friendly** – Selection and actions adapt their behavior depending on the device. For example, selection is activated via long press on touch when row actions are present.
394394
* **Accessible** – Follows the [ARIA grid pattern](https://www.w3.org/WAI/ARIA/apg/patterns/grid/), with additional selection announcements via an ARIA live region. Extensively tested across many devices and [assistive technologies](accessibility.html#testing) to ensure announcements and behaviors are consistent.

packages/react-aria-components/docs/react-aria-components.mdx

Lines changed: 4 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Compared with the React Aria hooks, the components provide a default DOM structu
6868

6969
## Status
7070

71-
React Aria Components is currently in **alpha**. This means APIs will likely change in future updates as we discover the best ways to use it, and there are some known bugs and limitations. That said, it is based on a solid and battle-tested foundation in React Aria, and we would love for you to try it out and give us feedback! This will directly help us shape the APIs and make it the best library it can be. Please report issues and feature requests [on GitHub](https://github.com/adobe/react-spectrum/issues).
71+
React Aria Components is currently in **beta**. This means most APIs are stable but some changes may still occur, and there are some known bugs. That said, it is based on a solid and battle-tested foundation in React Aria, and we would love for you to try it out and give us feedback! Please report issues and feature requests [on GitHub](https://github.com/adobe/react-spectrum/issues).
7272

7373
## Installation
7474

@@ -326,152 +326,14 @@ import {Select, SelectValue, Label, Button, Popover, ListBox, Item} from 'react-
326326

327327
</details>
328328

329-
## Styling
329+
### Styling
330330

331-
React Aria Components do not include any styles by default, allowing you to build custom designs to fit your application or design system. Each component accepts the standard `className` and `style` props which enable using vanilla CSS, utility classes (e.g. Tailwind), CSS-in-JS (e.g. Styled Components), etc.
332-
333-
When a custom `className` is not provided, each component includes a default class name following the `react-aria-ComponentName` naming convention. You can use this to style a component with standard CSS without needing any custom classes.
334-
335-
```css render=false
336-
.react-aria-Select {
337-
/* ... */
338-
}
339-
```
340-
341-
### States
342-
343-
Some components support multiple UI states (e.g. pressed, hovered, selected, etc.). React Aria Components exposes states using DOM attributes, which can be targeted by CSS selectors. These are ARIA attributes wherever possible, or data attributes when a relevant ARIA attribute does not exist. They can be thought of like custom CSS pseudo classes. For example:
344-
345-
```css render=false
346-
.react-aria-Item[data-selected] {
347-
/* ... */
348-
}
349-
350-
.react-aria-Item[data-focused] {
351-
/* ... */
352-
}
353-
```
354-
355-
If you're using Tailwind CSS, you can use [ARIA states](https://tailwindcss.com/docs/hover-focus-and-other-states#aria-states) and [data attributes](https://tailwindcss.com/docs/hover-focus-and-other-states#data-attributes) as modifiers.
356-
357-
```jsx
358-
<Item className="aria-selected:bg-blue-400 data-[focused]:bg-gray-100">
359-
Item
360-
</Item>
361-
````
362-
363-
You can also use our Tailwind CSS [plugin](#tailwind-css-plugin) to get shortened modifiers.
364-
365-
In order to ensure high quality interactions across browsers and devices, React Aria Components includes states such as `data-hovered` and `data-pressed` which are similar to CSS pseudo classes such as `:hover` and `:active`, but work consistently between mouse, touch, and keyboard modalities. You can read more about this in our [blog post series](../blog/building-a-button-part-1.html) and our [Interactions](interactions.html) overview.
366-
367-
All of the states and selectors for each component are listed in their respective documentation.
368-
369-
### Render props
370-
371-
The `className` and `style` props also accept functions which receive states for styling. This lets you dynamically determine the classes or styles to apply, which is useful when using utility CSS libraries like [Tailwind](https://tailwindcss.com/).
372-
373-
```jsx
374-
<Item className={({isSelected}) => isSelected ? 'bg-blue-400' : 'bg-gray-100'}>
375-
Item
376-
</Item>
377-
```
378-
379-
Render props may also be used as children to alter what elements are rendered based on the current state. For example, you could render a checkmark icon when an item is selected.
380-
381-
```jsx
382-
<Item>
383-
{({isSelected}) => (
384-
<>
385-
{isSelected && <CheckmarkIcon />}
386-
<span>Item</span>
387-
</>
388-
)}
389-
</Item>
390-
```
391-
392-
### Animation
393-
394-
Overlay components such as [Popover](Popover.html) and [Modal](Modal.html) support entry and exit animations via the `[data-entering]` and `[data-exiting]` states, or via the corresponding render prop functions. You can use these states to apply CSS keyframe animations. These components will automatically wait for any exit animations to complete before they are removed from the DOM.
395-
396-
```css render=false
397-
.react-aria-Popover[data-entering] {
398-
animation: slide 300ms;
399-
}
400-
401-
.react-aria-Popover[data-exiting] {
402-
animation: slide 300ms reverse;
403-
}
404-
405-
@keyframes slide {
406-
from {
407-
transform: translateY(-20px);
408-
opacity: 0;
409-
}
410-
411-
to {
412-
transform: translateY(0);
413-
opacity: 1;
414-
}
415-
}
416-
```
417-
418-
If you are using Tailwind CSS, we recommend using the [tailwindcss-animate](https://github.com/jamiebuilds/tailwindcss-animate) plugin. This includes utilities for building common animations such as fading, sliding, and zooming.
419-
420-
```jsx
421-
<Popover className="data-[entering]:animate-in data-[entering]:fade-in data-[exiting]:animate-out data-[exiting]:fade-out">
422-
{/* ... */}
423-
</Popover>
424-
```
331+
React Aria Components do not include any styles by default, allowing you to build custom designs to fit your application or design system. It works with any styling solution, including vanilla CSS, Tailwind CSS, CSS-in-JS, etc. See the [styling guide](styling.html) for full details.
425332

426333
## Examples
427334

428335
The documentation for each component includes many examples styled using vanilla CSS and the default class names. We also have an example of many of the components using Tailwind CSS. You can find the [code](https://github.com/adobe/react-spectrum/blob/main/examples/rac-tailwind/src/App.js) in the repo, as well as a [live demo](https://reactspectrum.blob.core.windows.net/reactspectrum/f239d0b1a96c3e6119135fe6bbf1994dc9984257/verdaccio/rac-tailwind/index.html).
429336

430-
## Tailwind CSS Plugin
431-
432-
There is a Tailwind CSS plugin available which makes styling different [states](#states) easier.
433-
434-
This allows an element with the `data-selected` attribute to be styled in Tailwind with `selected:` instead of `data-[selected]:`. Non-boolean data attributes follow the `{name}-{value}` pattern, so you can style an element with `data-orientation="horizontal"` using `orientation-horizontal:`.
435-
436-
To install:
437-
438-
```
439-
yarn add tailwindcss-react-aria-components
440-
```
441-
442-
Then add the plugin to your `tailwind.config.js` file:
443-
444-
```jsx
445-
/** @type {import('tailwindcss').Config} */
446-
module.exports = {
447-
plugins: [
448-
require('tailwindcss-react-aria-components')
449-
],
450-
}
451-
```
452-
453-
You can optionally specify a prefix using `require('tailwindcss-react-aria-components')({prefix: 'rac'})`. This will allow you to use `rac-selected:` instead of `selected:`.
454-
455-
### Boolean states
456-
457-
The `data-pressed` state can be styled with `pressed:` like this:
458-
459-
```jsx
460-
<Button className="pressed:bg-blue">
461-
{/* ... */}
462-
</Button>
463-
```
464-
465-
### Non-boolean states
466-
467-
The `data-orientation="vertical"` state can be styled with `orientation-vertical:` like this:
468-
469-
```jsx
470-
<Tabs className="orientation-vertical:flex-row">
471-
{/* ... */}
472-
</Tabs>
473-
```
474-
475337
## Components
476338

477339
### Buttons
@@ -757,4 +619,4 @@ The `data-orientation="vertical"` state can be styled with `orientation-vertical
757619
<DropZone />
758620
</ExampleCard>
759621

760-
</section>
622+
</section>

0 commit comments

Comments
 (0)