Skip to content

Commit efaf9ed

Browse files
authored
Generate a starter storybook from the docs (#5440)
1 parent 658423e commit efaf9ed

37 files changed

+812
-100
lines changed

.circleci/comment.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ async function run() {
5757
[Publish stats](https://reactspectrum.blob.core.windows.net/reactspectrum/${process.env.CIRCLE_SHA1}/verdaccio/publish-stats/publish.json)
5858
[Size diff since last release](https://reactspectrum.blob.core.windows.net/reactspectrum/${process.env.CIRCLE_SHA1}/verdaccio/publish-stats/size-diff.txt)
5959
[Docs](https://reactspectrum.blob.core.windows.net/reactspectrum/${process.env.CIRCLE_SHA1}/verdaccio/docs/index.html)
60-
[Storybook](https://reactspectrum.blob.core.windows.net/reactspectrum/${process.env.CIRCLE_SHA1}/storybook/index.html)`
60+
[Storybook](https://reactspectrum.blob.core.windows.net/reactspectrum/${process.env.CIRCLE_SHA1}/storybook/index.html)
61+
[RAC Starter Storybook](https://reactspectrum.blob.core.windows.net/reactspectrum/${process.env.CIRCLE_SHA1}/verdaccio/starter-storybook/index.html)`
6162
});
6263
}
6364
} catch (error) {

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ packages/react-aria-components/dist
1010
packages/react-stately/dist
1111
packages/dev/storybook-builder-parcel/preview.js
1212
examples/**
13+
starters/**

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,16 @@ website:
110110
yarn build:docs --public-url /reactspectrum/$$(git rev-parse HEAD)/docs --dist-dir dist/$$(git rev-parse HEAD)/docs
111111

112112
website-production:
113-
node scripts/buildWebsite.js
113+
node scripts/buildWebsite.js $$PUBLIC_URL
114114
cp packages/dev/docs/pages/robots.txt dist/production/docs/robots.txt
115+
$(MAKE) starter
116+
cd starters/docs && zip -r react-aria-starter.zip . -x .gitignore .DS_Store "node_modules/*" "storybook-static/*"
117+
mv starters/docs/react-aria-starter.zip dist/production/docs/react-aria-starter.$$(git rev-parse --short HEAD).zip
115118

116119
check-examples:
117120
node scripts/extractExamples.mjs
118121
yarn tsc --project dist/docs-examples/tsconfig.json
122+
123+
starter:
124+
node scripts/extractStarter.mjs
125+
cd starters/docs && yarn && yarn tsc

packages/@react-aria/example-theme/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"description": "Spectrum UI components in React",
55
"license": "Apache-2.0",
66
"source": "src/index.css",
7-
"dist": "dist/index.css",
7+
"out": "dist/index.css",
88
"main": "dist/index.css",
99
"targets": {
1010
"main": false,
11-
"dist": {
11+
"out": {
1212
"optimize": false
1313
}
1414
},

packages/dev/parcel-transformer-mdx-docs/processCSS.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module.exports = async function processCSS(cssCode, asset, options) {
3838
if (path.extname(specifier) === '') {
3939
// Assume this is a package.
4040
specifier += '/src/index.css';
41+
return require.resolve(specifier);
4142
}
4243

4344
let baseDir = process.env.DOCS_ENV === 'production' ? 'docs' : 'packages';

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import {Breadcrumbs, Breadcrumb, Link} from 'react-aria-components';
6565
margin: 0;
6666
padding: 0;
6767
font-size: 18px;
68+
color: var(--text-color);
6869

6970
.react-aria-Breadcrumb:not(:last-child)::after {
7071
content: '';

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import {Checkbox} from 'react-aria-components';
6868
align-items: center;
6969
gap: 0.571rem;
7070
font-size: 1.143rem;
71+
color: var(--text-color);
7172
forced-color-adjust: none;
7273

7374
.checkbox {

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,19 @@ import {CheckboxGroup, Checkbox, Label} from 'react-aria-components';
7272
<details>
7373
<summary style={{fontWeight: 'bold'}}><ChevronRight size="S" /> Show CSS</summary>
7474
```css hidden
75-
@import "@react-aria/example-theme";
7675
@import './Checkbox.mdx' layer(checkbox);
7776
@import './Form.mdx' layer(form);
7877
@import './Button.mdx' layer(button);
7978
```
8079

8180
```css
81+
@import "@react-aria/example-theme";
82+
8283
.react-aria-CheckboxGroup {
8384
display: flex;
8485
flex-direction: column;
8586
gap: 0.571rem;
87+
color: var(--text-color);
8688
}
8789
```
8890

@@ -294,9 +296,11 @@ import {Form, FieldError, Button} from 'react-aria-components';
294296
<summary style={{fontWeight: 'bold'}}><ChevronRight size="S" /> Show CSS</summary>
295297

296298
```css
297-
.react-aria-FieldError {
298-
font-size: 12px;
299-
color: var(--invalid-color);
299+
.react-aria-CheckboxGroup {
300+
.react-aria-FieldError {
301+
font-size: 12px;
302+
color: var(--invalid-color);
303+
}
300304
}
301305
```
302306

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,13 @@ import {ComboBox, Label, Input, Button, Popover, ListBox, ListBoxItem} from 'rea
8383
@import "@react-aria/example-theme";
8484

8585
.react-aria-ComboBox {
86+
color: var(--text-color);
87+
8688
.react-aria-Input {
8789
margin: 0;
8890
font-size: 1.072rem;
91+
background: var(--field-background);
92+
color: var(--field-text-color);
8993
border: 1px solid var(--border-color);
9094
border-radius: 6px;
9195
padding: 0.286rem 2rem 0.286rem 0.571rem;
@@ -109,11 +113,16 @@ import {ComboBox, Label, Input, Button, Popover, ListBox, ListBoxItem} from 'rea
109113
height: 1.429rem;
110114
padding: 0;
111115
font-size: 0.857rem;
116+
117+
&[data-pressed] {
118+
box-shadow: none;
119+
background: var(--highlight-background);
120+
}
112121
}
113122
}
114123

115124
.react-aria-Popover[data-trigger=ComboBox] {
116-
width: var(--trigger-width);
125+
width: var(--trigger-width);
117126

118127
.react-aria-ListBox {
119128
display: block;

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ import {DateField, Label, DateInput, DateSegment} from 'react-aria-components';
6565
```css
6666
@import "@react-aria/example-theme";
6767

68+
.react-aria-DateField {
69+
color: var(--text-color);
70+
}
71+
6872
.react-aria-DateInput {
6973
display: flex;
7074
padding: 4px;
@@ -415,9 +419,11 @@ import {Form, FieldError, Button} from 'react-aria-components';
415419
}
416420
}
417421

418-
.react-aria-FieldError {
419-
font-size: 12px;
420-
color: var(--invalid-color);
422+
.react-aria-DateField {
423+
.react-aria-FieldError {
424+
font-size: 12px;
425+
color: var(--invalid-color);
426+
}
421427
}
422428
```
423429

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ import {DatePicker, Label, Group, Popover, Dialog, Calendar, CalendarGrid, Calen
7777
<details>
7878
<summary style={{fontWeight: 'bold'}}><ChevronRight size="S" /> Show CSS</summary>
7979
```css hidden
80-
/* We only import styles up to one page away, we don't follow those pages dependencies, so
81-
* import everything and in the correct order of dependency so that layers don't overwrite each other. */
8280
@import './Button.mdx' layer(button);
8381
@import './Popover.mdx' layer(popover);
82+
@import './Dialog.mdx' layer(dialog);
8483
@import './DateField.mdx' layer(datefield);
8584
@import './Calendar.mdx' layer(calendar);
8685
@import './Form.mdx' layer(form);
@@ -90,6 +89,8 @@ import {DatePicker, Label, Group, Popover, Dialog, Calendar, CalendarGrid, Calen
9089
@import "@react-aria/example-theme";
9190

9291
.react-aria-DatePicker {
92+
color: var(--text-color);
93+
9394
.react-aria-Group {
9495
display: flex;
9596
width: fit-content;
@@ -110,6 +111,11 @@ import {DatePicker, Label, Group, Popover, Dialog, Calendar, CalendarGrid, Calen
110111
font-size: 0.857rem;
111112
box-sizing: content-box;
112113

114+
&[data-pressed] {
115+
box-shadow: none;
116+
background: var(--highlight-background);
117+
}
118+
113119
&[data-focus-visible] {
114120
outline: 2px solid var(--focus-ring-color);
115121
outline-offset: 2px;
@@ -123,7 +129,6 @@ import {DatePicker, Label, Group, Popover, Dialog, Calendar, CalendarGrid, Calen
123129

124130
.react-aria-Popover[data-trigger=DatePicker] {
125131
max-width: unset;
126-
padding: 1.25rem;
127132
}
128133
```
129134

@@ -529,11 +534,11 @@ import {Form, FieldError} from 'react-aria-components';
529534
text-align: end;
530535
}
531536
}
532-
}
533537

534-
.react-aria-FieldError {
535-
font-size: 12px;
536-
color: var(--invalid-color);
538+
.react-aria-FieldError {
539+
font-size: 12px;
540+
color: var(--invalid-color);
541+
}
537542
}
538543
```
539544

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,9 @@ import {DateRangePicker, Label, Group, Popover, Dialog, RangeCalendar, CalendarG
8080
<details>
8181
<summary style={{fontWeight: 'bold'}}><ChevronRight size="S" /> Show CSS</summary>
8282
```css hidden
83-
/* We only import styles up to one page away, we don't follow those pages dependencies, so
84-
* import everything and in the correct order of dependency so that layers don't overwrite each other. */
8583
@import './Button.mdx' layer(button);
8684
@import './Popover.mdx' layer(popover);
85+
@import './Dialog.mdx' layer(dialog);
8786
@import './DateField.mdx' layer(datefield);
8887
@import './RangeCalendar.mdx' layer(rangecalendar);
8988
@import './Form.mdx' layer(form);
@@ -110,6 +109,11 @@ import {DateRangePicker, Label, Group, Popover, Dialog, RangeCalendar, CalendarG
110109
background: var(--field-background);
111110
white-space: nowrap;
112111

112+
&[data-pressed] {
113+
box-shadow: none;
114+
background: var(--highlight-background);
115+
}
116+
113117
&[data-focus-within] {
114118
outline: 2px solid var(--focus-ring-color);
115119
outline-offset: -1px;
@@ -159,7 +163,6 @@ import {DateRangePicker, Label, Group, Popover, Dialog, RangeCalendar, CalendarG
159163

160164
.react-aria-Popover[data-trigger=DateRangePicker] {
161165
max-width: unset;
162-
padding: 1.25rem;
163166
}
164167
```
165168

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import {DialogTrigger, Modal, Dialog, Button, Heading, TextField, Label, Input}
6060
<Label>Last Name</Label>
6161
<Input />
6262
</TextField>
63-
<Button onPress={close}>
63+
<Button onPress={close} style={{marginTop: 8}}>
6464
Submit
6565
</Button>
6666
</form>
@@ -85,15 +85,10 @@ import {DialogTrigger, Modal, Dialog, Button, Heading, TextField, Label, Input}
8585
outline: none;
8686
padding: 30px;
8787

88-
.react-aria-Heading {
88+
.react-aria-Heading[slot=title] {
8989
line-height: 1em;
9090
margin-top: 0;
9191
}
92-
93-
.react-aria-Button {
94-
margin-top: 20px;
95-
margin-right: 8px;
96-
}
9792
}
9893
```
9994

@@ -169,7 +164,7 @@ Alert dialogs are a special type of dialog meant to present a prompt that the us
169164
<>
170165
<Heading slot="title">Delete file</Heading>
171166
<p>This will permanently delete the selected file. Continue?</p>
172-
<div>
167+
<div style={{display: 'flex', gap: 8}}>
173168
<Button onPress={close}>Cancel</Button>
174169
<Button onPress={close}>Delete</Button>
175170
</div>

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,22 @@ import {GridList, GridListItem, Button} from 'react-aria-components';
5151

5252
<GridList aria-label="Favorite pokemon" selectionMode="multiple">
5353
<GridListItem textValue="Charizard">
54-
<MyCheckbox />
54+
<MyCheckbox slot="selection" />
5555
Charizard
5656
<Button aria-label="Info">ⓘ</Button>
5757
</GridListItem>
5858
<GridListItem textValue="Blastoise">
59-
<MyCheckbox />
59+
<MyCheckbox slot="selection" />
6060
Blastoise
6161
<Button aria-label="Info">ⓘ</Button>
6262
</GridListItem>
6363
<GridListItem textValue="Venusaur">
64-
<MyCheckbox />
64+
<MyCheckbox slot="selection" />
6565
Venusaur
6666
<Button aria-label="Info">ⓘ</Button>
6767
</GridListItem>
6868
<GridListItem textValue="Pikachu">
69-
<MyCheckbox />
69+
<MyCheckbox slot="selection" />
7070
Pikachu
7171
<Button aria-label="Info">ⓘ</Button>
7272
</GridListItem>
@@ -298,7 +298,7 @@ If you will use a GridList in multiple places in your app, you can wrap all of t
298298
This example wraps `GridList` and all of its children together into a single component which accepts a `label` prop and `children`, which are passed through to the right places. The `GridListItem` component is also wrapped to include a custom [checkbox](Checkbox.html) component automatically when the item is multi-selectable, and a drag handle when [drag and drop](#drag-and-drop) is enabled.
299299

300300
```tsx example export=true
301-
import type {GridListProps, GridListItemProps} from 'react-aria-components';
301+
import type {GridListProps, GridListItemProps, CheckboxProps} from 'react-aria-components';
302302
import {Button, Checkbox} from 'react-aria-components';
303303

304304
function MyGridList<T extends object>({children, ...props}: GridListProps<T>) {
@@ -316,17 +316,17 @@ function MyItem({children, ...props}: GridListItemProps) {
316316
{({selectionMode, selectionBehavior, allowsDragging}) => <>
317317
{/* Add elements for drag and drop and selection. */}
318318
{allowsDragging && <Button slot="drag">≡</Button>}
319-
{selectionMode === 'multiple' && selectionBehavior === 'toggle' && <MyCheckbox />}
319+
{selectionMode === 'multiple' && selectionBehavior === 'toggle' && <MyCheckbox slot="selection" />}
320320
{children}
321321
</>}
322322
</GridListItem>
323323
);
324324
}
325325

326-
function MyCheckbox() {
326+
function MyCheckbox({children, ...props}: CheckboxProps) {
327327
return (
328-
<Checkbox slot="selection">
329-
{({isIndeterminate}) => (
328+
<Checkbox {...props}>
329+
{({isIndeterminate}) => <>
330330
<div className="checkbox">
331331
<svg viewBox="0 0 18 18" aria-hidden="true">
332332
{isIndeterminate
@@ -335,7 +335,8 @@ function MyCheckbox() {
335335
}
336336
</svg>
337337
</div>
338-
)}
338+
{children}
339+
</>}
339340
</Checkbox>
340341
);
341342
}

0 commit comments

Comments
 (0)