Skip to content

Commit 97717d7

Browse files
docs: Type check examples (#9299)
* docs: Type check examples * fix some type errors * more typescript fixes * more typescript fixes * more typescript fixes * more typescript fixes * API bugs - will revert this one after API audit fixes are merged * more typescript fixes * more typescript fixes * more typescript fixes * more typescript fixes * final typescript fixes * Revert "API bugs - will revert this one after API audit fixes are merged" This reverts commit f7ec69e. * RowProps types fix * remaining typescript fixes * cleanup types * cleanup types * fix SelectBoxGroupProps prop types * address review comments * homepage fixes * fix dnd types * fix merge * id required fix --------- Co-authored-by: Reid Barber <[email protected]>
1 parent 498d65e commit 97717d7

File tree

113 files changed

+555
-419
lines changed

Some content is hidden

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

113 files changed

+555
-419
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ website-production:
124124
mv starters/tailwind/react-aria-tailwind-starter.zip dist/production/docs/react-aria-tailwind-starter.$$(git rev-parse --short HEAD).zip
125125

126126
check-examples:
127-
node scripts/extractExamples.mjs
127+
node scripts/extractExamplesS2.mjs
128128
yarn tsc --project dist/docs-examples/tsconfig.json
129129

130130
starter:

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
Provider
2222
} from 'react-aria-components';
2323
import {DOMRef, DOMRefValue, GlobalDOMAttributes, Key, Orientation} from '@react-types/shared';
24+
import {forwardRefType} from './types';
2425
import {getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};
2526
import {IllustrationContext} from '../src/Icon';
2627
import {pressScale} from './pressScale';
@@ -33,7 +34,7 @@ export interface SelectBoxGroupProps<T> extends StyleProps, Omit<ListBoxProps<T>
3334
/**
3435
* The SelectBox elements contained within the SelectBoxGroup.
3536
*/
36-
children: ReactNode,
37+
children: ReactNode | ((item: T) => ReactNode),
3738
/**
3839
* The layout direction of the content in each SelectBox.
3940
* @default 'vertical'
@@ -384,7 +385,7 @@ export function SelectBox(props: SelectBoxProps): ReactNode {
384385
/**
385386
* SelectBoxGroup allows users to select one or more options from a list.
386387
*/
387-
export const SelectBoxGroup = /*#__PURE__*/ forwardRef(function SelectBoxGroup<T extends object>(props: SelectBoxGroupProps<T>, ref: DOMRef<HTMLDivElement>) {
388+
export const SelectBoxGroup = /*#__PURE__*/ (forwardRef as forwardRefType)(function SelectBoxGroup<T extends object>(props: SelectBoxGroupProps<T>, ref: DOMRef<HTMLDivElement>) {
388389
[props, ref] = useSpectrumContextProps(props, ref, SelectBoxGroupContext);
389390

390391
let {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import Chevron from '../ui-icons/Chevron';
5858
import Close from '../s2wf-icons/S2_Icon_Close_20_N.svg';
5959
import {ColumnSize} from '@react-types/table';
6060
import {CustomDialog, DialogContainer} from '..';
61-
import {DOMProps, DOMRef, DOMRefValue, forwardRefType, GlobalDOMAttributes, LoadingState, Node} from '@react-types/shared';
61+
import {DOMProps, DOMRef, DOMRefValue, forwardRefType, GlobalDOMAttributes, LinkDOMProps, LoadingState, Node} from '@react-types/shared';
6262
import {getActiveElement, getOwnerDocument, useLayoutEffect, useObjectRef} from '@react-aria/utils';
6363
import {GridNode} from '@react-types/grid';
6464
import {IconContext} from './Icon';
@@ -1446,7 +1446,7 @@ const row = style<RowRenderProps & S2TableProps>({
14461446
forcedColorAdjust: 'none'
14471447
});
14481448

1449-
export interface RowProps<T> extends Pick<RACRowProps<T>, 'id' | 'columns' | 'children' | 'textValue' | 'dependencies' | keyof GlobalDOMAttributes> {}
1449+
export interface RowProps<T> extends Pick<RACRowProps<T>, 'id' | 'columns' | 'isDisabled' | 'onAction' | 'children' | 'textValue' | 'dependencies' | keyof GlobalDOMAttributes>, LinkDOMProps {}
14501450

14511451
/**
14521452
* A row within a `<Table>`.

packages/dev/s2-docs/pages/WelcomeHeader.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {ProductCard, Content, Footer, Text, LinkButton} from '@react-spectrum/s2';
22
import {style} from '@react-spectrum/s2/style' with {type: 'macro'};
3+
// @ts-ignore
34
import {TAB_DEFS} from '../src/constants';
45
// @ts-ignore
56
import url from 'url:../assets/wallpaper_collaborative_S2_desktop.webp';

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,6 @@ function AsyncLoadingExample() {
10811081
return (
10821082
<Autocomplete
10831083
/*- begin highlight -*/
1084-
filter={null}
10851084
inputValue={list.filterText}
10861085
onInputChange={list.setFilterText}>
10871086
{/*- end highlight -*/}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ Use the `value` or `defaultValue` prop to set the color value, and `onChange` to
4242
```tsx render
4343
"use client";
4444
import {ColorField} from 'vanilla-starter/ColorField';
45-
import {parseColor} from 'react-aria-components';
45+
import {parseColor, type Color} from 'react-aria-components';
4646
import {useState} from 'react';
4747

4848
function Example() {
49-
let [value, setValue] = useState(parseColor('#e73623'));
49+
let [value, setValue] = useState<Color | null>(parseColor('#e73623'));
5050

5151
return (
5252
<div>
@@ -68,11 +68,11 @@ By default, ColorField displays a hex value. Set the `colorSpace` and `channel`
6868
```tsx render
6969
"use client";
7070
import {ColorField} from 'vanilla-starter/ColorField';
71-
import {parseColor} from 'react-aria-components';
71+
import {parseColor, type Color} from 'react-aria-components';
7272
import {useState} from 'react';
7373

7474
function Example() {
75-
let [color, setColor] = useState(parseColor('#7f007f'));
75+
let [color, setColor] = useState<Color | null>(parseColor('#7f007f'));
7676

7777
return (
7878
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
@@ -109,7 +109,7 @@ Use the `name` prop to submit the text value to the server. Set the `isRequired`
109109

110110
```tsx render
111111
"use client";
112-
import {ColorField, Button, Form} from 'vanilla-starter/ColorField';
112+
import {ColorField} from 'vanilla-starter/ColorField';
113113
import {Button} from 'vanilla-starter/Button';
114114
import {Form} from 'vanilla-starter/Form';
115115

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ Use the `defaultSelectedKey` or `selectedKey` prop to set the selected item. The
113113

114114
```tsx render
115115
"use client";
116-
import type {Key} from 'react-aria-components';
117116
import {ComboBox, ComboBoxItem} from 'vanilla-starter/ComboBox';
118117
import {useState} from 'react';
118+
import type {Key} from 'react-aria-components';
119119

120120
function Example() {
121-
let [animal, setAnimal] = useState<Key>("bison");
121+
let [animal, setAnimal] = useState<Key | null>("bison");
122122

123123
return (
124124
<div>
@@ -148,12 +148,11 @@ Use the `inputValue` or `defaultInputValue` prop to set the value of the input f
148148

149149
```tsx render wide docs={vanillaDocs.exports.ComboBox} links={vanillaDocs.links} props={['allowsCustomValue']} initialProps={{defaultSelectedKey: 'kangaroo'}}
150150
"use client";
151-
import type {Key} from 'react-aria-components';
152151
import {ComboBox, ComboBoxItem} from 'vanilla-starter/ComboBox';
153152
import {useState} from 'react';
154153

155154
function Example(props) {
156-
let [value, setValue] = useState<Key>('Kangaroo');
155+
let [value, setValue] = useState('Kangaroo');
157156

158157
return (
159158
<div>
@@ -204,15 +203,15 @@ function ControlledComboBox() {
204203
];
205204
/*- end collapse -*/
206205

207-
let [fieldState, setFieldState] = useState({
206+
let [fieldState, setFieldState] = useState<{selectedKey: Key | null, inputValue: string}>({
208207
selectedKey: null,
209208
inputValue: ''
210209
});
211210

212-
let onSelectionChange = (id: Key) => {
211+
let onSelectionChange = (id: Key | null) => {
213212
// Update inputValue when selectedKey changes.
214213
setFieldState({
215-
inputValue: options.find(o => o.id === id)?.name ?? '',
214+
inputValue: id == null ? '' : options.find(o => o.id === id)?.name ?? '',
216215
selectedKey: id
217216
});
218217
};
@@ -227,7 +226,7 @@ function ControlledComboBox() {
227226

228227
return (
229228
<div>
230-
<ComboBox
229+
<ComboBox
231230
label="Engineering major"
232231
placeholder="Select a major"
233232
/*- begin highlight -*/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ Use the `value` or `defaultValue` prop to set the date value, using objects in t
4141

4242
```tsx render
4343
"use client";
44-
import {parseDate, getLocalTimeZone} from '@internationalized/date';
44+
import {parseDate, getLocalTimeZone, type CalendarDate} from '@internationalized/date';
4545
import {useDateFormatter} from 'react-aria';
4646
import {DateField} from 'vanilla-starter/DateField';
4747
import {useState} from 'react';
4848

4949
function Example() {
50-
let [date, setDate] = useState(parseDate('2020-02-03'));
50+
let [date, setDate] = useState<CalendarDate | null>(parseDate('2020-02-03'));
5151
let formatter = useDateFormatter({ dateStyle: 'full' });
5252

5353
return (

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ Use the `value` or `defaultValue` prop to set the date value, using objects in t
4141

4242
```tsx render
4343
"use client";
44-
import {parseDate, getLocalTimeZone} from '@internationalized/date';
44+
import {parseDate, getLocalTimeZone, type CalendarDate} from '@internationalized/date';
4545
import {useDateFormatter} from 'react-aria';
4646
import {DatePicker} from 'vanilla-starter/DatePicker';
4747
import {useState} from 'react';
4848

4949
function Example() {
50-
let [date, setDate] = useState(parseDate('2020-02-03'));
50+
let [date, setDate] = useState<CalendarDate | null>(parseDate('2020-02-03'));
5151
let formatter = useDateFormatter({ dateStyle: 'full' });
5252

5353
return (

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ Use the `value` or `defaultValue` prop to set the selected date range, using obj
4141

4242
```tsx render
4343
"use client";
44-
import {parseDate, getLocalTimeZone} from '@internationalized/date';
45-
import {useDateFormatter} from 'react-aria';
44+
import {parseDate, getLocalTimeZone, type CalendarDate} from '@internationalized/date';
45+
import {useDateFormatter, type RangeValue} from 'react-aria';
4646
import {DateRangePicker} from 'vanilla-starter/DateRangePicker';
4747
import {useState} from 'react';
4848

4949
function Example() {
50-
let [range, setRange] = useState({
50+
let [range, setRange] = useState<RangeValue<CalendarDate> | null>({
5151
start: parseDate('2025-02-03'),
5252
end: parseDate('2025-02-12')
5353
});
@@ -60,10 +60,10 @@ function Example() {
6060
value={range}
6161
onChange={setRange} />
6262
{/*- end highlight -*/}
63-
<p>Selected range: {formatter.formatRange(
63+
<p>Selected range: {range ? formatter.formatRange(
6464
range.start.toDate(getLocalTimeZone()),
6565
range.end.toDate(getLocalTimeZone())
66-
)}</p>
66+
) : '--'}</p>
6767
</>
6868
);
6969
}

0 commit comments

Comments
 (0)