Skip to content

Commit 6dd8f01

Browse files
authored
Implement React Aria Components (#4171)
1 parent 4a75768 commit 6dd8f01

File tree

128 files changed

+27826
-54
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+27826
-54
lines changed

.eslintrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ module.exports = {
2828
sourceType: 'module'
2929
},
3030
rules: {
31-
'jsdoc/require-description-complete-sentence': [ERROR, {abbreviations: ['e.g', 'etc', 'i.e']}],
31+
'jsdoc/require-description-complete-sentence': [ERROR, {abbreviations: ['e.g', 'i.e']}],
3232
'jsdoc/check-alignment': ERROR,
3333
'jsdoc/check-indentation': ERROR,
34-
'jsdoc/check-tag-names': ERROR,
34+
'jsdoc/check-tag-names': [ERROR, {definedTags: ['selector']}],
3535
// enable this rule to see literally everything missing jsdocs, this rule needs some refinement but is good as a sanity check.
3636
// 'jsdoc/require-jsdoc': [ERROR, {contexts:['TSInterfaceDeclaration TSPropertySignature', 'TSInterfaceDeclaration TSMethodSignature']}],
3737
'jsdoc/require-description': [ERROR, {exemptedBy: ['deprecated'], checkConstructors: false}],

.storybook/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = {
33
core: {
44
builder: "storybook-builder-parcel",
55
},
6-
stories: ['../packages/*/*/stories/*.stories.{js,jsx,ts,tsx}'],
6+
stories: ['../packages/**/stories/*.stories.{js,jsx,ts,tsx}'],
77
addons: [
88
'@storybook/addon-actions',
99
'@storybook/addon-a11y',

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"build:storybook-17": "build-storybook -c .storybook -o dist/$(git rev-parse HEAD)/storybook-17",
1818
"start:chromatic": "CHROMATIC=1 NODE_ENV=storybook start-storybook -p 9004 --ci -c '.chromatic'",
1919
"build:chromatic": "CHROMATIC=1 build-storybook -c .chromatic -o dist/$(git rev-parse HEAD)/chromatic",
20-
"start:docs": "DOCS_ENV=dev parcel 'packages/@react-{spectrum,aria,stately}/*/docs/*.mdx' 'packages/@internationalized/*/docs/*.mdx' 'packages/dev/docs/pages/**/*.mdx'",
21-
"build:docs": "DOCS_ENV=staging parcel build 'packages/@react-{spectrum,aria,stately}/*/docs/*.mdx' 'packages/@internationalized/*/docs/*.mdx' 'packages/dev/docs/pages/**/*.mdx'",
20+
"start:docs": "DOCS_ENV=dev parcel 'packages/@react-{spectrum,aria,stately}/*/docs/*.mdx' 'packages/react-aria-components/docs/*.mdx' 'packages/@internationalized/*/docs/*.mdx' 'packages/dev/docs/pages/**/*.mdx'",
21+
"build:docs": "DOCS_ENV=staging parcel build 'packages/@react-{spectrum,aria,stately}/*/docs/*.mdx' 'packages/react-aria-components/docs/*.mdx' 'packages/@internationalized/*/docs/*.mdx' 'packages/dev/docs/pages/**/*.mdx'",
2222
"test": "yarn jest",
2323
"test-strict": "cross-env STRICT_MODE=1 yarn jest",
2424
"build": "make build",
@@ -47,6 +47,7 @@
4747
"workspaces": [
4848
"packages/react-stately",
4949
"packages/react-aria",
50+
"packages/react-aria-components",
5051
"packages/*/*"
5152
],
5253
"devDependencies": {

packages/@adobe/spectrum-css-temp/components/table/skin.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ tbody.spectrum-Table-body {
180180
/* Box shadow for bottom border for non-selected rows that aren't immediately above a selected row. Can't omit the bottom border for last row unlike listview
181181
* due to how table rows always reserve 1px for the bottom border (results in a white gap on hover otherwise).
182182
*/
183-
&:after {
183+
&:not(tr):after {
184184
box-shadow: inset 0 -1px 0 0 var(--spectrum-table-cell-border-color);
185185
content: '';
186186
display: block;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +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
2526
---
2627

2728
# Drag and Drop

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +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
2324
---
2425

2526
# useClipboard

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +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
2324
---
2425

2526
# useDrag

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +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
2526
---
2627

2728
# useDraggableCollection

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +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
2324
---
2425

2526
# useDrop

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +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
2526
---
2627

2728
# useDroppableCollection

packages/@react-aria/gridlist/docs/useGridList.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ This behavior is slightly different when `selectionBehavior="replace"`, where si
486486

487487
### Asynchronous loading
488488

489-
This example uses the [useAsyncList](../react-stately/useAsyncList.html) hook to handle loadiasynchronous loading of data from a server. You may additionally want to display a spinner to indicate the loading state to the user, or support features like infinite scroll to load more data.
489+
This example uses the [useAsyncList](../react-stately/useAsyncList.html) hook to handle asynchronous loading of data from a server. You may additionally want to display a spinner to indicate the loading state to the user, or support features like infinite scroll to load more data.
490490

491491
```tsx example
492492
import {useAsyncList} from '@react-stately/data';

packages/@react-spectrum/link/docs/Link.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Actual navigation will be handled by the wrapped element.
4949
<Link><a href="https://www.adobe.com" target="_blank">Adobe.com</a></Link>
5050
```
5151

52-
To use in [React Router](https://reacttraining.com/react-router/)
52+
To use in [React Router](https://reactrouter.com/en/main)
5353

5454
```tsx
5555
import {Link} from '@react-spectrum/link';
Lines changed: 8 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

packages/dev/docs/src/Layout.js

Lines changed: 94 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
import ChevronLeft from '@spectrum-icons/ui/ChevronLeftLarge';
14+
import ChevronRight from '@spectrum-icons/workflow/ChevronRight';
1415
import clsx from 'clsx';
1516
import {Divider} from '@react-spectrum/divider';
1617
import docStyles from './docs.css';
@@ -36,6 +37,7 @@ import {ToC} from './ToC';
3637
import typographyStyles from '@adobe/spectrum-css-temp/components/typography/vars.css';
3738
import {VersionBadge} from './VersionBadge';
3839

40+
const ENABLE_PAGE_TYPES = false;
3941
const INDEX_RE = /^(?:[^/]+\/)?index\.html$/;
4042
const TLD = 'react-spectrum.adobe.com';
4143
const HERO = {
@@ -288,16 +290,29 @@ function Nav({currentPageName, pages}) {
288290
}
289291

290292
// Key by category
291-
let pageMap = {};
293+
let pagesByType = {};
292294
let rootPages = [];
295+
let pageCategories = new Set();
293296
pages.forEach(p => {
294297
let cat = p.category;
295298
if (cat) {
296-
if (cat in pageMap) {
297-
pageMap[cat].push(p);
299+
let type = p.type || 'other';
300+
if (!ENABLE_PAGE_TYPES && p.type !== 'component') {
301+
type = 'other';
302+
}
303+
let pages = pagesByType[type];
304+
if (!pages) {
305+
pages = {};
306+
pagesByType[type] = pages;
307+
}
308+
309+
if (cat in pages) {
310+
pages[cat].push(p);
298311
} else {
299-
pageMap[cat] = [p];
312+
pages[cat] = [p];
300313
}
314+
315+
pageCategories.add(cat);
301316
} else {
302317
rootPages.push(p);
303318
}
@@ -306,10 +321,10 @@ function Nav({currentPageName, pages}) {
306321
// Order categories so specific ones come first, then all the others in sorted order.
307322
let categories = [];
308323
for (let category of CATEGORY_ORDER) {
309-
if (pageMap[category]) {
324+
if (pageCategories.has(category)) {
310325
categories.push(category);
311326
} else if (category === '...') {
312-
for (let category of Object.keys(pageMap).sort()) {
327+
for (let category of [...pageCategories].sort()) {
313328
if (!CATEGORY_ORDER.includes(category)) {
314329
categories.push(category);
315330
}
@@ -343,6 +358,57 @@ function Nav({currentPageName, pages}) {
343358
);
344359
}
345360

361+
let isActive = (pageMap) => {
362+
for (let key in pageMap) {
363+
if (pageMap[key].some(p => p.name === currentPageName)) {
364+
return true;
365+
}
366+
}
367+
};
368+
369+
let sections = [];
370+
if (currentPageName.startsWith('react-aria') && ENABLE_PAGE_TYPES) {
371+
let {Introduction, Concepts, Interactions, Focus, Internationalization, 'Server Side Rendering': ssr, Utilities, ...hooks} = pagesByType.other;
372+
sections.push({pages: {Introduction, Concepts}});
373+
sections.push({
374+
title: 'Components',
375+
pages: pagesByType.component,
376+
isActive: isActive(pagesByType.component)
377+
});
378+
sections.push({
379+
title: 'Hooks',
380+
pages: hooks,
381+
isActive: isActive(hooks)
382+
});
383+
sections.push({
384+
title: 'Patterns',
385+
pages: pagesByType.pattern,
386+
isActive: isActive(pagesByType.pattern)
387+
});
388+
sections.push({
389+
title: 'Interactions',
390+
pages: {Interactions, Focus},
391+
isActive: isActive({Interactions, Focus})
392+
});
393+
sections.push({
394+
title: 'Utilities',
395+
pages: {Internationalization, 'Server Side Rendering': ssr, Utilities},
396+
isActive: isActive({Internationalization, 'Server Side Rendering': ssr, Utilities})
397+
});
398+
} else {
399+
sections.push({
400+
pages: pagesByType.other
401+
});
402+
403+
if (pagesByType.component) {
404+
sections.push({
405+
title: 'Components',
406+
pages: pagesByType.component,
407+
isActive: isActive(pagesByType.component)
408+
});
409+
}
410+
}
411+
346412
return (
347413
<nav className={docStyles.nav} aria-labelledby="nav-title-id">
348414
<header>
@@ -362,20 +428,33 @@ function Nav({currentPageName, pages}) {
362428
</h2>
363429
</a>
364430
</header>
365-
<ul className={sideNavStyles['spectrum-SideNav']}>
366-
{rootPages.map(p => <SideNavItem {...p} />)}
367-
{categories.map(key => {
368-
const headingId = `${key.trim().toLowerCase().replace(/\s+/g, '-')}-heading`;
431+
{sections.map(section => {
432+
let contents = categories.filter(c => section.pages[c]?.length).map(key => {
433+
const headingId = `${section.title ? section.title.toLowerCase() + '-' : ''}${key.trim().toLowerCase().replace(/\s+/g, '-')}-heading`;
369434
return (
370-
<li key={headingId} className={sideNavStyles['spectrum-SideNav-item']}>
435+
<>
371436
<h3 className={sideNavStyles['spectrum-SideNav-heading']} id={headingId}>{key}</h3>
372437
<ul className={sideNavStyles['spectrum-SideNav']} aria-labelledby={headingId}>
373-
{pageMap[key].sort((a, b) => (a.order || 0) < (b.order || 0) || a.title < b.title ? -1 : 1).map(p => <SideNavItem key={p.title} {...p} />)}
438+
{section.pages[key].sort((a, b) => (a.order || 0) < (b.order || 0) || a.title < b.title ? -1 : 1).map(p => <SideNavItem {...p} preRelease={section.title === 'Components' ? '' : p.preRelease} />)}
374439
</ul>
375-
</li>
440+
</>
376441
);
377-
})}
378-
</ul>
442+
});
443+
444+
if (section.title) {
445+
return (
446+
<details open={section.isActive}>
447+
<summary style={{fontWeight: 'bold'}}>
448+
<ChevronRight size="S" /> {section.title}
449+
{section.title === 'Components' && <VersionBadge version={Object.values(section.pages)[0][0].preRelease} style={{marginLeft: 'auto', fontWeight: 'normal'}} />}
450+
</summary>
451+
{contents}
452+
</details>
453+
);
454+
} else {
455+
return <>{contents}</>;
456+
}
457+
})}
379458
</nav>
380459
);
381460
}

packages/dev/docs/src/StateTable.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright 2020 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import clsx from 'clsx';
14+
import React from 'react';
15+
import {renderHTMLfromMarkdown} from './types';
16+
import styles from './docs.css';
17+
import tableStyles from '@adobe/spectrum-css-temp/components/table/vars.css';
18+
import typographyStyles from '@adobe/spectrum-css-temp/components/typography/vars.css';
19+
20+
export function StateTable({properties}) {
21+
return (
22+
<table className={`${tableStyles['spectrum-Table']} ${tableStyles['spectrum-Table--quiet']} ${styles.propTable}`}>
23+
<thead>
24+
<tr>
25+
<td role="columnheader" className={tableStyles['spectrum-Table-headCell']}>Name</td>
26+
<td role="columnheader" className={tableStyles['spectrum-Table-headCell']}>CSS Selector</td>
27+
<td role="columnheader" className={tableStyles['spectrum-Table-headCell']}>Description</td>
28+
</tr>
29+
</thead>
30+
<tbody className={tableStyles['spectrum-Table-body']}>
31+
{Object.values(properties).map((prop, index) => (
32+
<tr key={index} className={clsx(tableStyles['spectrum-Table-row'], styles.tableRow)}>
33+
<td role="rowheader" className={clsx(tableStyles['spectrum-Table-cell'], styles.tableCell)} data-column="Name">
34+
<code className={`${typographyStyles['spectrum-Code4']}`}>
35+
<span className="token hljs-variable">{prop.name}</span>
36+
</code>
37+
</td>
38+
<td role="rowheader" className={clsx(tableStyles['spectrum-Table-cell'], styles.tableCell)} data-column="CSS Selector">
39+
<code className={`${typographyStyles['spectrum-Code4']}`}>
40+
<span className={prop.selector ? 'token hljs-string' : null}>{prop.selector || '—'}</span>
41+
</code>
42+
</td>
43+
<td className={clsx(tableStyles['spectrum-Table-cell'], styles.tableCell)}>{renderHTMLfromMarkdown(prop.description, {forceInline: false})}</td>
44+
</tr>
45+
))}
46+
</tbody>
47+
</table>
48+
);
49+
}

packages/dev/docs/src/docs.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,14 @@ details[open] > summary svg {
555555
transform: rotate(90deg);
556556
}
557557

558+
.nav summary {
559+
margin-left: -12px !important;
560+
}
561+
562+
.nav details:last-child {
563+
margin-bottom: 60px;
564+
}
565+
558566
.headingAnchor {
559567
transition: all 125ms ease-in-out;
560568
margin-left: 4px;
@@ -914,3 +922,9 @@ h2.sectionHeader {
914922
gap: 24px;
915923
}
916924
}
925+
926+
.cardGroup[data-size=small] {
927+
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
928+
gap: 16px;
929+
max-width: 800px;
930+
}

packages/dev/docs/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ export * from './TypeLink';
2323
export * from './ClassAPI';
2424
export * from './PostListing';
2525
export * from './PageDescription';
26+
export * from './StateTable';

0 commit comments

Comments
 (0)