From 93d8a586bd35b7626ecb8aac112a0b237235ddc1 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Sat, 4 Mar 2023 13:34:50 -0500 Subject: [PATCH 1/6] Convert aria component docs to TypeScript --- packages/@react-aria/calendar/src/index.ts | 2 +- packages/@react-aria/datepicker/src/index.ts | 4 +-- .../datepicker/src/useDateField.ts | 4 +-- packages/dev/docs/src/docs.css | 8 +++++ .../react-aria-components/docs/Calendar.mdx | 9 ++++-- .../react-aria-components/docs/Checkbox.mdx | 4 ++- .../docs/CheckboxGroup.mdx | 11 +++++-- .../react-aria-components/docs/ComboBox.mdx | 24 +++++++++++---- .../react-aria-components/docs/DateField.mdx | 11 +++++-- .../react-aria-components/docs/DatePicker.mdx | 15 +++++++--- .../docs/DateRangePicker.mdx | 18 ++++++++---- .../react-aria-components/docs/GridList.mdx | 26 ++++++++++++----- .../react-aria-components/docs/ListBox.mdx | 23 ++++++++++----- packages/react-aria-components/docs/Menu.mdx | 22 ++++++++++---- packages/react-aria-components/docs/Meter.mdx | 8 ++++- .../docs/NumberField.mdx | 13 +++++++-- .../react-aria-components/docs/Popover.mdx | 4 ++- .../docs/ProgressBar.mdx | 8 ++++- .../react-aria-components/docs/RadioGroup.mdx | 9 +++++- .../docs/RangeCalendar.mdx | 10 +++++-- .../docs/SearchField.mdx | 11 +++++-- .../react-aria-components/docs/Select.mdx | 24 +++++++++++---- .../react-aria-components/docs/Slider.mdx | 9 +++++- .../react-aria-components/docs/Switch.mdx | 4 ++- packages/react-aria-components/docs/Table.mdx | 29 +++++++++++++++---- packages/react-aria-components/docs/Tabs.mdx | 10 +++---- .../react-aria-components/docs/TextField.mdx | 11 +++++-- .../react-aria-components/docs/TimeField.mdx | 12 ++++++-- .../react-aria-components/docs/Tooltip.mdx | 4 ++- .../react-aria-components/src/Calendar.tsx | 3 +- .../react-aria-components/src/Collection.tsx | 10 +++++-- .../react-aria-components/src/DateField.tsx | 3 +- .../react-aria-components/src/DatePicker.tsx | 3 +- packages/react-aria-components/src/Dialog.tsx | 5 ++++ .../react-aria-components/src/GridList.tsx | 8 +++-- .../react-aria-components/src/ListBox.tsx | 1 + packages/react-aria-components/src/Menu.tsx | 1 + .../react-aria-components/src/SearchField.tsx | 4 +-- packages/react-aria-components/src/Select.tsx | 4 +-- packages/react-aria-components/src/Slider.tsx | 4 +-- packages/react-aria-components/src/Table.tsx | 17 ++++++----- packages/react-aria-components/src/index.ts | 3 ++ packages/react-aria-components/src/utils.tsx | 7 +++++ packages/react-aria/src/index.ts | 2 +- scripts/extractExamples.mjs | 2 +- 45 files changed, 316 insertions(+), 108 deletions(-) diff --git a/packages/@react-aria/calendar/src/index.ts b/packages/@react-aria/calendar/src/index.ts index 75be3d28cdb..1676e603a42 100644 --- a/packages/@react-aria/calendar/src/index.ts +++ b/packages/@react-aria/calendar/src/index.ts @@ -15,7 +15,7 @@ export {useRangeCalendar} from './useRangeCalendar'; export {useCalendarGrid} from './useCalendarGrid'; export {useCalendarCell} from './useCalendarCell'; -export type {AriaCalendarProps, AriaRangeCalendarProps, CalendarProps, RangeCalendarProps} from '@react-types/calendar'; +export type {AriaCalendarProps, AriaRangeCalendarProps, CalendarProps, DateValue, RangeCalendarProps} from '@react-types/calendar'; export type {CalendarAria} from './useCalendarBase'; export type {AriaCalendarGridProps, CalendarGridAria} from './useCalendarGrid'; export type {AriaCalendarCellProps, CalendarCellAria} from './useCalendarCell'; diff --git a/packages/@react-aria/datepicker/src/index.ts b/packages/@react-aria/datepicker/src/index.ts index b691f77391a..5db0fc7368a 100644 --- a/packages/@react-aria/datepicker/src/index.ts +++ b/packages/@react-aria/datepicker/src/index.ts @@ -16,8 +16,8 @@ export {useDateField, useTimeField} from './useDateField'; export {useDateRangePicker} from './useDateRangePicker'; export {useDisplayNames} from './useDisplayNames'; -export type {AriaDatePickerProps, AriaDateRangePickerProps} from '@react-types/datepicker'; -export type {AriaDateFieldProps, DateFieldAria} from './useDateField'; +export type {AriaDateFieldProps, AriaDatePickerProps, AriaDateRangePickerProps, DateRange, DateValue, TimeValue} from '@react-types/datepicker'; +export type {AriaDateFieldOptions, DateFieldAria} from './useDateField'; export type {DatePickerAria} from './useDatePicker'; export type {DateRangePickerAria} from './useDateRangePicker'; export type {DateSegmentAria} from './useDateSegment'; diff --git a/packages/@react-aria/datepicker/src/useDateField.ts b/packages/@react-aria/datepicker/src/useDateField.ts index 99ffe8787e7..a7001615ca5 100644 --- a/packages/@react-aria/datepicker/src/useDateField.ts +++ b/packages/@react-aria/datepicker/src/useDateField.ts @@ -24,7 +24,7 @@ import {useFocusWithin} from '@react-aria/interactions'; import {useLocalizedStringFormatter} from '@react-aria/i18n'; // Allows this hook to also be used with TimeField -export interface AriaDateFieldProps extends Omit, 'value' | 'defaultValue' | 'onChange' | 'minValue' | 'maxValue' | 'placeholderValue'> {} +export interface AriaDateFieldOptions extends Omit, 'value' | 'defaultValue' | 'onChange' | 'minValue' | 'maxValue' | 'placeholderValue'> {} export interface DateFieldAria { /** Props for the field's visible label element, if any. */ @@ -57,7 +57,7 @@ export const focusManagerSymbol = '__focusManager_' + Date.now(); * A date field allows users to enter and edit date and time values using a keyboard. * Each part of a date value is displayed in an individually editable segment. */ -export function useDateField(props: AriaDateFieldProps, state: DateFieldState, ref: RefObject): DateFieldAria { +export function useDateField(props: AriaDateFieldOptions, state: DateFieldState, ref: RefObject): DateFieldAria { let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({ ...props, labelElementType: 'span' diff --git a/packages/dev/docs/src/docs.css b/packages/dev/docs/src/docs.css index 1040ad83c4c..b14eb68382c 100644 --- a/packages/dev/docs/src/docs.css +++ b/packages/dev/docs/src/docs.css @@ -365,6 +365,10 @@ footer li:last-child:after { margin-bottom: 0; } +.propTable td[data-column="CSS Selector"] code { + white-space: nowrap; +} + .type-description { margin-top: 0; } @@ -720,6 +724,10 @@ h2.sectionHeader { main { margin-right: 0; } + + .propTable td[data-column="CSS Selector"] code { + white-space: normal; + } } @define-mixin small-propTable { diff --git a/packages/react-aria-components/docs/Calendar.mdx b/packages/react-aria-components/docs/Calendar.mdx index ea208e2453c..ba96b296379 100644 --- a/packages/react-aria-components/docs/Calendar.mdx +++ b/packages/react-aria-components/docs/Calendar.mdx @@ -382,9 +382,14 @@ If you will use a Calendar in multiple places in your app, you can wrap all of t This example also shows how to use the `errorMessage` slot to render help text in case of a validation error ([see below for details](#error-message)). ```tsx example export=true +import type {CalendarProps, DateValue} from 'react-aria-components'; import {Text} from 'react-aria-components'; -function MyCalendar({errorMessage, ...props}) { +interface MyCalendarProps extends CalendarProps { + errorMessage?: string +} + +function MyCalendar({errorMessage, ...props}: MyCalendarProps) { return (
@@ -468,7 +473,7 @@ The below example displays a `Calendar` in the Hindi language, using the Indian import {I18nProvider} from '@react-aria/i18n'; function Example() { - let [date, setDate] = React.useState(null); + let [date, setDate] = React.useState(null); return ( diff --git a/packages/react-aria-components/docs/Checkbox.mdx b/packages/react-aria-components/docs/Checkbox.mdx index a0a1bd121bf..2aa3e0ebd57 100644 --- a/packages/react-aria-components/docs/Checkbox.mdx +++ b/packages/react-aria-components/docs/Checkbox.mdx @@ -260,7 +260,9 @@ If you will use a Checkbox in multiple places in your app, you can wrap all of t This example wraps `Checkbox` and all of its children together into a single component. It also shows how to use render props to conditionally render a different indicator icon when the checkbox is in an indeterminate state. ```tsx example export=true -function MyCheckbox({children, ...props}) { +import type {CheckboxProps} from 'react-aria-components'; + +function MyCheckbox({children, ...props}: CheckboxProps) { return ( {({isIndeterminate}) => <> diff --git a/packages/react-aria-components/docs/CheckboxGroup.mdx b/packages/react-aria-components/docs/CheckboxGroup.mdx index 1830b64e06e..0f17f4a9b53 100644 --- a/packages/react-aria-components/docs/CheckboxGroup.mdx +++ b/packages/react-aria-components/docs/CheckboxGroup.mdx @@ -341,15 +341,22 @@ If you will use a CheckboxGroup in multiple places in your app, you can wrap all This example wraps `CheckboxGroup` and all of its children together into a single component which accepts a `label` prop, which is passed to the right place. It also shows how to use the `description` and `errorMessage` slots to render help text ([see below for details](#help-text)). ```tsx example export=true +import type {CheckboxGroupProps, CheckboxProps} from 'react-aria-components'; import {Text} from 'react-aria-components'; +interface MyCheckboxGroupProps extends CheckboxGroupProps { + label?: string, + description?: string, + errorMessage?: string +} + function MyCheckboxGroup({ label, description, errorMessage, children, ...props -}) { +}: MyCheckboxGroupProps) { return ( {label} @@ -360,7 +367,7 @@ function MyCheckboxGroup({ ); } -function MyCheckbox({children, ...props}) { +function MyCheckbox({children, ...props}: CheckboxProps) { return (