From 8ee13f339a0d218294b6b67ab386d53ae1b8c1c5 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Thu, 26 Sep 2024 12:01:40 -0700 Subject: [PATCH] 3.37 audit (#7092) * Add some missing docs descriptions * Rename strange interface in props * Fix sizes of pending button spinner * Add docs for --tree-item-level custom property in Tree * fix ts * Require children for disclosures * Make it so Accordion isn't labellable * fix button typescript * narrow test utils exports and future proof * Remove isPending from ActionButton --------- Co-authored-by: Robert Snow Co-authored-by: GitHub --- packages/@react-aria/test-utils/src/index.ts | 8 ++++--- .../accordion/src/Accordion.tsx | 4 ++-- .../@react-spectrum/s2/src/ActionButton.tsx | 2 +- packages/@react-spectrum/s2/src/Button.tsx | 22 +++++++++++++++---- .../@react-spectrum/s2/src/ProgressCircle.tsx | 10 +++++---- .../s2/src/SegmentedControl.tsx | 4 ++-- packages/@react-spectrum/s2/src/Skeleton.tsx | 3 +++ .../s2/src/SkeletonCollection.tsx | 4 ++++ .../@react-spectrum/s2/src/ToggleButton.tsx | 3 ++- .../@react-stately/data/docs/useTreeData.mdx | 6 ++--- .../disclosure/src/useDisclosureGroupState.ts | 4 ++++ packages/react-aria-components/docs/Tree.mdx | 8 +++++++ packages/react-aria-components/src/Button.tsx | 9 ++++---- .../react-aria-components/src/Disclosure.tsx | 10 ++++++++- .../stories/Breadcrumbs.stories.tsx | 6 ++--- 15 files changed, 75 insertions(+), 28 deletions(-) diff --git a/packages/@react-aria/test-utils/src/index.ts b/packages/@react-aria/test-utils/src/index.ts index 7a62396f4db..962abbf72c3 100644 --- a/packages/@react-aria/test-utils/src/index.ts +++ b/packages/@react-aria/test-utils/src/index.ts @@ -11,6 +11,8 @@ */ export {triggerLongPress} from './events'; -export * from './testSetup'; -export * from './userEventMaps'; -export * from './user'; +export {installMouseEvent, installPointerEvent} from './testSetup'; +export {pointerMap} from './userEventMaps'; +export {User} from './user'; + +export type {UserOpts} from './user'; diff --git a/packages/@react-spectrum/accordion/src/Accordion.tsx b/packages/@react-spectrum/accordion/src/Accordion.tsx index 01d23b3806d..8b88dd39588 100644 --- a/packages/@react-spectrum/accordion/src/Accordion.tsx +++ b/packages/@react-spectrum/accordion/src/Accordion.tsx @@ -20,7 +20,7 @@ import styles from '@adobe/spectrum-css-temp/components/accordion/vars.css'; import {useLocale} from '@react-aria/i18n'; import {useProviderProps} from '@react-spectrum/provider'; -export interface SpectrumAccordionProps extends Omit, StyleProps, DOMProps, AriaLabelingProps { +export interface SpectrumAccordionProps extends Omit, StyleProps, DOMProps { /** The disclosures within the accordion group. */ children: React.ReactNode } @@ -76,7 +76,7 @@ function DisclosurePanel(props: SpectrumDisclosurePanelProps, ref: DOMRef, StyleProps, ActionButtonStyleProps { +export interface ActionButtonProps extends Omit, StyleProps, ActionButtonStyleProps { /** The content to display in the ActionButton. */ children?: ReactNode } diff --git a/packages/@react-spectrum/s2/src/Button.tsx b/packages/@react-spectrum/s2/src/Button.tsx index 2f6fb3d15ac..3787e73bbc9 100644 --- a/packages/@react-spectrum/s2/src/Button.tsx +++ b/packages/@react-spectrum/s2/src/Button.tsx @@ -10,7 +10,7 @@ * governing permissions and limitations under the License. */ -import {baseColor, fontRelative, style} from '../style/spectrum-theme' with {type: 'macro'}; +import {baseColor, fontRelative, size as sizeValue, style} from '../style/spectrum-theme' with {type: 'macro'}; import {ButtonRenderProps, ContextValue, Link, LinkProps, OverlayTriggerStateContext, Provider, Button as RACButton, ButtonProps as RACButtonProps} from 'react-aria-components'; import {centerBaseline} from './CenterBaseline'; import {centerPadding, focusRing, getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'}; @@ -370,8 +370,21 @@ function Button(props: ButtonProps, ref: FocusableRef) { isProgressVisible: 1 } })({isProgressVisible, isPending})}> - {/* TODO: size based on t-shirt size once ProgressCircle supports custom sizes */} - + } @@ -405,7 +418,8 @@ function LinkButton(props: LinkButtonProps, ref: FocusableRef variant: props.variant || 'primary', fillStyle: props.fillStyle || 'fill', size: props.size || 'M', - staticColor: props.staticColor + staticColor: props.staticColor, + isPending: false }, props.styles)}> ({ L: 64 } }, - aspectRatio: 'square', - display: 'inline-block' + aspectRatio: 'square' }, getAllowedOverrides({height: true})); const track = style({ @@ -73,7 +72,10 @@ const fill = style({ transformOrigin: 'center' }); -export interface ProgressCircleProps extends Omit, ProgressCircleStyleProps, StyleProps {} +export interface ProgressCircleProps extends Omit, ProgressCircleStyleProps, UnsafeStyles { + /** Spectrum-defined styles, returned by the `style()` macro. */ + styles?: StylesPropWithHeight +} const rotationAnimation = keyframes(` 0% { diff --git a/packages/@react-spectrum/s2/src/SegmentedControl.tsx b/packages/@react-spectrum/s2/src/SegmentedControl.tsx index 16b43a26036..6a6027eeb2f 100644 --- a/packages/@react-spectrum/s2/src/SegmentedControl.tsx +++ b/packages/@react-spectrum/s2/src/SegmentedControl.tsx @@ -259,13 +259,13 @@ function SegmentedControlItem(props: SegmentedControlItemProps, ref: FocusableRe } /** - * A control items represents an individual control within a segmented control. + * A SegmentedControlItem represents an option within a SegmentedControl. */ const _SegmentedControlItem = /*#__PURE__*/ forwardRef(SegmentedControlItem); export {_SegmentedControlItem as SegmentedControlItem}; /** - * A segmented control is a mutually exclusive group of buttons, with or without a track. + * A SegmentedControl is a mutually exclusive group of buttons used for view switching. */ const _SegmentedControl = /*#__PURE__*/ forwardRef(SegmentedControl); export {_SegmentedControl as SegmentedControl}; diff --git a/packages/@react-spectrum/s2/src/Skeleton.tsx b/packages/@react-spectrum/s2/src/Skeleton.tsx index ff218feefd3..d37703b2dd6 100644 --- a/packages/@react-spectrum/s2/src/Skeleton.tsx +++ b/packages/@react-spectrum/s2/src/Skeleton.tsx @@ -64,6 +64,9 @@ export interface SkeletonProps { isLoading: boolean } +/** + * A Skeleton wraps around content to render it as a placeholder. + */ export function Skeleton({children, isLoading}: SkeletonProps) { // Disable all form components inside a skeleton. return ( diff --git a/packages/@react-spectrum/s2/src/SkeletonCollection.tsx b/packages/@react-spectrum/s2/src/SkeletonCollection.tsx index fc6c5ea7be9..a3e3ada3381 100644 --- a/packages/@react-spectrum/s2/src/SkeletonCollection.tsx +++ b/packages/@react-spectrum/s2/src/SkeletonCollection.tsx @@ -19,6 +19,10 @@ export interface SkeletonCollectionProps { } let cache = new WeakMap(); + +/** + * A SkeletonCollection generates placeholder content within a collection component such as CardView. + */ export const SkeletonCollection = createLeafComponent('skeleton', (props: SkeletonCollectionProps, ref, node) => { // Cache rendering based on node object identity. This allows the children function to randomize // its content (e.g. heights) and preserve on re-renders. diff --git a/packages/@react-spectrum/s2/src/ToggleButton.tsx b/packages/@react-spectrum/s2/src/ToggleButton.tsx index e5bc90b4ab7..668db013738 100644 --- a/packages/@react-spectrum/s2/src/ToggleButton.tsx +++ b/packages/@react-spectrum/s2/src/ToggleButton.tsx @@ -48,7 +48,8 @@ function ToggleButton(props: ToggleButtonProps, ref: FocusableRef ; + items?: Array; } -let tree = useTreeData({ +let tree = useTreeData({ initialItems: [ { name: 'People', diff --git a/packages/@react-stately/disclosure/src/useDisclosureGroupState.ts b/packages/@react-stately/disclosure/src/useDisclosureGroupState.ts index d00189503f4..5a7ea94020a 100644 --- a/packages/@react-stately/disclosure/src/useDisclosureGroupState.ts +++ b/packages/@react-stately/disclosure/src/useDisclosureGroupState.ts @@ -38,6 +38,10 @@ export interface DisclosureGroupState { setExpandedKeys(keys: Set): void } +/** + * Manages state for a group of disclosures, e.g. an accordion. + * It supports both single and multiple expanded items. + */ export function useDisclosureGroupState(props: DisclosureGroupProps): DisclosureGroupState { let {allowsMultipleExpanded = false, isDisabled = false} = props; let [expandedKeys, setExpandedKeys] = useControlledState( diff --git a/packages/react-aria-components/docs/Tree.mdx b/packages/react-aria-components/docs/Tree.mdx index 6033f1a3a17..01695fe824f 100644 --- a/packages/react-aria-components/docs/Tree.mdx +++ b/packages/react-aria-components/docs/Tree.mdx @@ -312,3 +312,11 @@ A `Tree` can be targeted with the `.react-aria-Tree` CSS selector, or by overrid A `TreeItem` can be targeted with the `.react-aria-TreeItem` CSS selector, or by overriding with a custom `className`. It supports the following states and render props: + +TreeItem also exposes a `--tree-item-level` CSS custom property, which you can use to adjust the indentation. + +```css render=false +.react-aria-TreeItem { + padding-left: calc((var(--tree-item-level) - 1) * 20px); +} +``` diff --git a/packages/react-aria-components/src/Button.tsx b/packages/react-aria-components/src/Button.tsx index 453d928f876..e5e32df176e 100644 --- a/packages/react-aria-components/src/Button.tsx +++ b/packages/react-aria-components/src/Button.tsx @@ -59,10 +59,10 @@ export interface ButtonRenderProps { */ isDisabled: boolean, /** - * If the button is currently in the `isPending` state. + * Whether the button is currently in a pending state. * @selector [data-pending] */ - isPending?: boolean + isPending: boolean } export interface ButtonProps extends Omit, HoverEvents, SlotProps, RenderProps { @@ -89,7 +89,8 @@ export interface ButtonProps extends Omit) { isFocused, isFocusVisible, isDisabled: props.isDisabled || false, - isPending + isPending: isPending ?? false }; let renderProps = useRenderProps({ diff --git a/packages/react-aria-components/src/Disclosure.tsx b/packages/react-aria-components/src/Disclosure.tsx index 47dd395aa63..8fc4a461277 100644 --- a/packages/react-aria-components/src/Disclosure.tsx +++ b/packages/react-aria-components/src/Disclosure.tsx @@ -71,7 +71,9 @@ export {_DisclosureGroup as DisclosureGroup}; export interface DisclosureProps extends Omit, RenderProps, SlotProps { /** An id for the disclosure when used within a DisclosureGroup, matching the id used in `expandedKeys`. */ - id?: Key + id?: Key, + /** The children of the component. A function may be provided to alter the children based on component state. */ + children: ReactNode | ((values: DisclosureRenderProps & {defaultChildren: ReactNode | undefined}) => ReactNode) } export interface DisclosureRenderProps { @@ -185,6 +187,9 @@ export interface DisclosurePanelProps extends RenderProps<{}> { * @default 'group' */ role?: 'group' | 'region', + /** + * The children of the component. + */ children: ReactNode } @@ -225,5 +230,8 @@ function DisclosurePanel(props: DisclosurePanelProps, ref: ForwardedRef ( ); -interface Iitem { +interface ItemValue { id: string, url: string } -let items: Array = [ +let items: Array = [ {id: 'Home', url: '/'}, {id: 'React Aria', url: '/react-aria'}, {id: 'Breadcrumbs', url: '/react-aria/breadcrumbs'} @@ -44,7 +44,7 @@ let items: Array = [ export const DynamicBreadcrumbsExample = (args: any) => ( - {(item: Iitem) => ( + {(item: ItemValue) => ( {item.id}