Skip to content

Commit 63ed5b1

Browse files
authored
docs: Add examples section (#9094)
* docs: Add examples section * Support size() macro in CSS strings * Remove font-variation-settings * Support standalone Cards as links * Fix border width of tertiary cards * Fix WaterfallLayout bugs * Add descriptions to search menu cards * Default search menu category to current page category * lint * Fix mobile search menu * Fix mobile
1 parent 9da8c73 commit 63ed5b1

Some content is hidden

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

95 files changed

+22086
-426
lines changed

packages/@react-spectrum/s2/src/Card.tsx

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {AvatarContext} from './Avatar';
1515
import {ButtonContext, LinkButtonContext} from './Button';
1616
import {Checkbox} from './Checkbox';
1717
import {color, focusRing, lightDark, space, style} from '../style' with {type: 'macro'};
18-
import {composeRenderProps, ContextValue, DEFAULT_SLOT, type GridListItem, GridListItemProps, Provider} from 'react-aria-components';
18+
import {composeRenderProps, ContextValue, DEFAULT_SLOT, type GridListItem, GridListItemProps, Link, Provider} from 'react-aria-components';
1919
import {ContentContext, FooterContext, TextContext} from './Content';
2020
import {createContext, CSSProperties, forwardRef, ReactNode, useContext} from 'react';
2121
import {DividerContext} from './Divider';
@@ -95,18 +95,19 @@ let card = style({
9595
variant: {
9696
tertiary: {
9797
// Render border with box-shadow to avoid affecting layout.
98-
default: `[0 0 0 1px ${color('gray-100')}]`,
99-
isHovered: `[0 0 0 1px ${color('gray-200')}]`,
100-
isFocusVisible: `[0 0 0 1px ${color('gray-200')}]`,
98+
default: `[0 0 0 2px ${color('gray-100')}]`,
99+
isHovered: `[0 0 0 2px ${color('gray-200')}]`,
100+
isFocusVisible: `[0 0 0 2px ${color('gray-200')}]`,
101101
isSelected: 'none',
102-
forcedColors: '[0 0 0 1px ButtonBorder]'
102+
forcedColors: '[0 0 0 2px ButtonBorder]'
103103
},
104104
quiet: 'none'
105105
}
106106
},
107107
forcedColorAdjust: 'none',
108108
transition: 'default',
109109
fontFamily: 'sans',
110+
textDecoration: 'none',
110111
overflow: {
111112
default: 'clip',
112113
variant: {
@@ -424,6 +425,28 @@ export const Card = forwardRef(function Card(props: CardProps, ref: DOMRef<HTMLD
424425
</Provider>
425426
);
426427

428+
let press = pressScale(domRef, UNSAFE_style);
429+
if (ElementType === 'div' && !isSkeleton && props.href) {
430+
// Standalone Card that has an href should be rendered as a Link.
431+
// NOTE: In this case, the card must not contain interactive elements.
432+
return (
433+
<Link
434+
{...filterDOMProps(otherProps, {isLink: true})}
435+
ref={domRef as any}
436+
className={renderProps => UNSAFE_className + card({...renderProps, size, density, variant, isCardView: false, isLink: true}, styles)}
437+
style={renderProps =>
438+
// Only the preview in quiet cards scales down on press
439+
variant === 'quiet' ? UNSAFE_style : press(renderProps)
440+
}>
441+
{(renderProps) => (
442+
<InternalCardContext.Provider value={{size, isQuiet, isCheckboxSelection: false, isSelected: false, ...renderProps}}>
443+
{children}
444+
</InternalCardContext.Provider>
445+
)}
446+
</Link>
447+
);
448+
}
449+
427450
if (ElementType === 'div' || isSkeleton) {
428451
return (
429452
<div
@@ -441,7 +464,6 @@ export const Card = forwardRef(function Card(props: CardProps, ref: DOMRef<HTMLD
441464
);
442465
}
443466

444-
let press = pressScale(domRef, UNSAFE_style);
445467
return (
446468
<ElementType
447469
{...props}

packages/@react-spectrum/s2/style/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,14 @@
1111
*/
1212

1313
import type * as CSS from 'csstype';
14-
import {Inset, fontRelative as internalFontRelative, size as internalSize, space as internalSpace, Spacing, style} from './spectrum-theme';
14+
import {Inset, fontRelative as internalFontRelative, space as internalSpace, Spacing, style} from './spectrum-theme';
1515
import type {MacroContext} from '@parcel/macros';
1616
import {StyleString} from './types';
1717

18-
export {baseColor, color, edgeToText, lightDark, linearGradient, colorMix, style} from './spectrum-theme';
18+
export {baseColor, color, edgeToText, lightDark, linearGradient, colorMix, size, style} from './spectrum-theme';
1919
export type {StyleString} from './types';
2020

2121
// Wrap these functions in arbitrary value syntax when called from the outside.
22-
export function size(px: number): `[${string}]` {
23-
return `[${internalSize(px)}]`;
24-
}
25-
2622
export function space(px: number): `[${string}]` {
2723
return `[${internalSpace(px)}]`;
2824
}

packages/@react-spectrum/s2/style/spectrum-theme.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ const padding = {
330330
...relativeSpacing
331331
};
332332

333-
export function size(this: MacroContext | void, px: number): string {
333+
export function size(this: MacroContext | void, px: number): `calc(${string})` {
334334
return `calc(${pxToRem(px)} * var(--s2-scale))`;
335335
}
336336

@@ -767,9 +767,6 @@ export const style = createTheme({
767767
}, fontSize),
768768
fontWeight: new ExpandedProperty<keyof typeof fontWeight>(['fontWeight', 'fontVariationSettings', 'fontSynthesisWeight'], (value) => {
769769
return {
770-
// Set font-variation-settings in addition to font-weight to work around typekit issue.
771-
// (This was fixed, but leaving for backward compatibility for now.)
772-
fontVariationSettings: value === 'inherit' ? 'inherit' : `"wght" ${value}`,
773770
fontWeight: value as any,
774771
fontSynthesisWeight: 'none'
775772
};

packages/@react-stately/layout/src/WaterfallLayout.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ export interface WaterfallLayoutOptions {
4848

4949
class WaterfallLayoutInfo extends LayoutInfo {
5050
column = 0;
51+
index = 0;
5152

5253
copy(): WaterfallLayoutInfo {
5354
let res = super.copy() as WaterfallLayoutInfo;
5455
res.column = this.column;
56+
res.index = this.index;
5557
return res;
5658
}
5759
}
@@ -123,18 +125,19 @@ export class WaterfallLayout<T extends object, O extends WaterfallLayoutOptions
123125
// Setup an array of column heights
124126
let columnHeights = Array(numColumns).fill(minSpace.height);
125127
let newLayoutInfos = new Map();
128+
let index = 0;
126129
let addNode = (key: Key, node: Node<T>) => {
127130
let oldLayoutInfo = this.layoutInfos.get(key);
128131
let height = itemHeight;
129132
let estimatedSize = true;
130133
if (oldLayoutInfo) {
131-
height = oldLayoutInfo.rect.height;
134+
height = oldLayoutInfo.rect.height / oldLayoutInfo.rect.width * itemWidth;
132135
estimatedSize = invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || oldLayoutInfo.content !== node;
133136
}
134137

135138
// Figure out which column to place the item in, and compute its position.
136139
// Preserve the previous column index so items don't jump around during resizing unless the number of columns changed.
137-
let prevColumn = numColumns === this.numColumns && oldLayoutInfo && oldLayoutInfo.rect.y < this.virtualizer!.visibleRect.maxY ? oldLayoutInfo.column : undefined;
140+
let prevColumn = numColumns === this.numColumns && oldLayoutInfo && oldLayoutInfo.index === index && oldLayoutInfo.rect.y < this.virtualizer!.visibleRect.maxY ? oldLayoutInfo.column : undefined;
138141
let column = prevColumn ?? columnHeights.reduce((minIndex, h, i) => h < columnHeights[minIndex] ? i : minIndex, 0);
139142
let x = horizontalSpacing + column * (itemWidth + horizontalSpacing) + this.margin;
140143
let y = columnHeights[column];
@@ -145,6 +148,7 @@ export class WaterfallLayout<T extends object, O extends WaterfallLayoutOptions
145148
layoutInfo.allowOverflow = true;
146149
layoutInfo.content = node;
147150
layoutInfo.column = column;
151+
layoutInfo.index = index++;
148152
newLayoutInfos.set(key, layoutInfo);
149153

150154
columnHeights[column] += layoutInfo.rect.height + minSpace.height;

packages/dev/s2-docs/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@react-spectrum/utils": "^3.12.6",
3939
"@react-types/shared": "^3.30.0",
4040
"@react-types/textfield": "^3.12.3",
41+
"emojibase-data": "^16.0.3",
4142
"fast-glob": "^3.3.3",
4243
"globals-docs": "^2.4.1",
4344
"gray-matter": "^4.0.3",

packages/dev/s2-docs/pages/error.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default Layout;
55
import docs from 'docs:@react-spectrum/s2';
66

77
export const hideFromSearch = true;
8+
export const hideNav = true;
89
export const description = 'Page not found';
910

1011
<Error />

packages/dev/s2-docs/pages/react-aria/Autocomplete.mdx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,8 @@ function Example(props) {
160160
"use client";
161161
import {Select, Label, SelectValue, Autocomplete, useFilter} from 'react-aria-components';
162162
import {Button} from 'vanilla-starter/Button';
163-
import {SelectItem} from 'vanilla-starter/Select';
163+
import {SelectListBox, SelectItem} from 'vanilla-starter/Select';
164164
import {Popover} from 'vanilla-starter/Popover';
165-
import {ListBox} from 'vanilla-starter/ListBox';
166165
import {SearchField} from 'vanilla-starter/SearchField';
167166
import {ChevronDown} from 'lucide-react';
168167

@@ -232,7 +231,7 @@ function Example(props) {
232231
<SelectValue />
233232
<ChevronDown size={18} />
234233
</Button>
235-
<Popover hideArrow style={{display: 'flex', flexDirection: 'column'}}>
234+
<Popover hideArrow className="select-popover" style={{display: 'flex', flexDirection: 'column'}}>
236235
{/*- begin highlight -*/}
237236
<Autocomplete {...props}/* PROPS */ filter={contains}>
238237
{/*- end highlight -*/}
@@ -241,12 +240,12 @@ function Example(props) {
241240
aria-label="Search states"
242241
placeholder="Search states"
243242
style={{margin: 4}} />
244-
<ListBox
243+
<SelectListBox
245244
items={states}
246245
renderEmptyState={() => 'No results.'}
247246
style={{flex: 1}}>
248247
{state => <SelectItem>{state.name}</SelectItem>}
249-
</ListBox>
248+
</SelectListBox>
250249
</Autocomplete>
251250
</Popover>
252251
</Select>
@@ -1101,6 +1100,10 @@ function AsyncLoadingExample() {
11011100
}
11021101
```
11031102

1103+
## Examples
1104+
1105+
<ExampleList tag="autocomplete" pages={props.pages} />
1106+
11041107
## API
11051108

11061109
```tsx links={{Autocomplete: '#autocomplete', SearchField: 'SearchField.html', TextField: 'TextField.html', Menu: 'Menu.html', ListBox: 'ListBox.html', TagGroup: 'TagGroup.html', GridList: 'GridList.html', Table: 'Table.html'}}

packages/dev/s2-docs/pages/react-aria/Button.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ import {Link} from 'react-aria-components';
120120
</Link>
121121
```
122122

123+
## Examples
124+
125+
<ExampleList tag="button" pages={props.pages} />
126+
123127
## API
124128

125129
<PropTable component={docs.exports.Button} links={docs.links} />

packages/dev/s2-docs/pages/react-aria/DropZone.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ export const tags = ['file', 'drag', 'dnd', 'upload'];
8989
```
9090
</ExampleSwitcher>
9191
92+
## Examples
93+
94+
<ExampleList tag="dropzone" pages={props.pages} />
95+
9296
## API
9397
9498
```tsx links={{DropZone: '#dropzone'}}

packages/dev/s2-docs/pages/react-aria/Form.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ function Example() {
194194
}
195195
```
196196

197+
## Examples
198+
199+
<ExampleList tag="form" pages={props.pages} />
200+
197201
## API
198202

199203
<PropTable component={docs.exports.Form} links={docs.links} />

0 commit comments

Comments
 (0)