Skip to content

Commit

Permalink
3.37 audit (adobe#7092)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: GitHub <[email protected]>
  • Loading branch information
3 people authored Sep 26, 2024
1 parent d3c4ffe commit 8ee13f3
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 28 deletions.
8 changes: 5 additions & 3 deletions packages/@react-aria/test-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
4 changes: 2 additions & 2 deletions packages/@react-spectrum/accordion/src/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<DisclosureGroupProps, 'className' | 'style' | 'children'>, StyleProps, DOMProps, AriaLabelingProps {
export interface SpectrumAccordionProps extends Omit<DisclosureGroupProps, 'className' | 'style' | 'children'>, StyleProps, DOMProps {
/** The disclosures within the accordion group. */
children: React.ReactNode
}
Expand Down Expand Up @@ -76,7 +76,7 @@ function DisclosurePanel(props: SpectrumDisclosurePanelProps, ref: DOMRef<HTMLDi
}

export interface SpectrumDisclosureHeaderProps extends DOMProps, AriaLabelingProps {
/**
/**
* The heading level of the disclosure header.
* @default 3
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/@react-spectrum/s2/src/ActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface ToggleButtonStyleProps {
isEmphasized?: boolean
}

export interface ActionButtonProps extends Omit<ButtonProps, 'className' | 'style' | 'children' | 'onHover' | 'onHoverStart' | 'onHoverEnd' | 'onHoverChange'>, StyleProps, ActionButtonStyleProps {
export interface ActionButtonProps extends Omit<ButtonProps, 'className' | 'style' | 'children' | 'onHover' | 'onHoverStart' | 'onHoverEnd' | 'onHoverChange' | 'isPending'>, StyleProps, ActionButtonStyleProps {
/** The content to display in the ActionButton. */
children?: ReactNode
}
Expand Down
22 changes: 18 additions & 4 deletions packages/@react-spectrum/s2/src/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'};
Expand Down Expand Up @@ -370,8 +370,21 @@ function Button(props: ButtonProps, ref: FocusableRef<HTMLButtonElement>) {
isProgressVisible: 1
}
})({isProgressVisible, isPending})}>
{/* TODO: size based on t-shirt size once ProgressCircle supports custom sizes */}
<ProgressCircle isIndeterminate aria-label={stringFormatter.format('button.pending')} size="S" staticColor={staticColor} UNSAFE_style={{display: 'block'}} />
<ProgressCircle
isIndeterminate
aria-label={stringFormatter.format('button.pending')}
size="S"
staticColor={staticColor}
styles={style({
size: {
size: {
S: sizeValue(14),
M: sizeValue(18),
L: 20,
XL: 24
}
}
})({size})} />
</div>
}
</Provider>
Expand Down Expand Up @@ -405,7 +418,8 @@ function LinkButton(props: LinkButtonProps, ref: FocusableRef<HTMLAnchorElement>
variant: props.variant || 'primary',
fillStyle: props.fillStyle || 'fill',
size: props.size || 'M',
staticColor: props.staticColor
staticColor: props.staticColor,
isPending: false
}, props.styles)}>
<Provider
values={[
Expand Down
10 changes: 6 additions & 4 deletions packages/@react-spectrum/s2/src/ProgressCircle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import {ContextValue, ProgressBar as RACProgressBar, ProgressBarProps as RACProgressBarProps} from 'react-aria-components';
import {createContext, forwardRef} from 'react';
import {DOMRef, DOMRefValue} from '@react-types/shared';
import {getAllowedOverrides, StyleProps} from './style-utils' with {type: 'macro'};
import {getAllowedOverrides, StylesPropWithHeight, UnsafeStyles} from './style-utils' with {type: 'macro'};
import {keyframes} from '../style/style-macro' with {type: 'macro'};
import {style} from '../style/spectrum-theme' with {type: 'macro'};
import {useDOMRef} from '@react-spectrum/utils';
Expand Down Expand Up @@ -45,8 +45,7 @@ const wrapper = style<ProgressCircleStyleProps>({
L: 64
}
},
aspectRatio: 'square',
display: 'inline-block'
aspectRatio: 'square'
}, getAllowedOverrides({height: true}));

const track = style<ProgressCircleStyleProps>({
Expand All @@ -73,7 +72,10 @@ const fill = style<ProgressCircleStyleProps>({
transformOrigin: 'center'
});

export interface ProgressCircleProps extends Omit<RACProgressBarProps, 'children' | 'style' | 'valueLabel' | 'formatOptions' | 'label' | 'className'>, ProgressCircleStyleProps, StyleProps {}
export interface ProgressCircleProps extends Omit<RACProgressBarProps, 'children' | 'style' | 'valueLabel' | 'formatOptions' | 'label' | 'className'>, ProgressCircleStyleProps, UnsafeStyles {
/** Spectrum-defined styles, returned by the `style()` macro. */
styles?: StylesPropWithHeight
}

const rotationAnimation = keyframes(`
0% {
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-spectrum/s2/src/SegmentedControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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};
3 changes: 3 additions & 0 deletions packages/@react-spectrum/s2/src/Skeleton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 4 additions & 0 deletions packages/@react-spectrum/s2/src/SkeletonCollection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion packages/@react-spectrum/s2/src/ToggleButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ function ToggleButton(props: ToggleButtonProps, ref: FocusableRef<HTMLButtonElem
staticColor: props.staticColor,
size: props.size,
isQuiet: props.isQuiet,
isEmphasized: props.isEmphasized
isEmphasized: props.isEmphasized,
isPending: false
}, props.styles)}>
<Provider
values={[
Expand Down
6 changes: 3 additions & 3 deletions packages/@react-stately/data/docs/useTreeData.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ as the unique key for that item, and the `items` property as the children. In ad
for the listbox, which will automatically be updated when items are removed from the tree.

```tsx
interface Iitem {
interface ItemValue {
name: string;
items?: Array<Iitem>;
items?: Array<ItemValue>;
}

let tree = useTreeData<Iitem>({
let tree = useTreeData<ItemValue>({
initialItems: [
{
name: 'People',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export interface DisclosureGroupState {
setExpandedKeys(keys: Set<Key>): 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(
Expand Down
8 changes: 8 additions & 0 deletions packages/react-aria-components/docs/Tree.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<StateTable properties={docs.exports.TreeItemRenderProps.properties} showOptional />

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);
}
```
9 changes: 5 additions & 4 deletions packages/react-aria-components/src/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<AriaButtonProps, 'children' | 'href' | 'target' | 'rel' | 'elementType'>, HoverEvents, SlotProps, RenderProps<ButtonRenderProps> {
Expand All @@ -89,7 +89,8 @@ export interface ButtonProps extends Omit<AriaButtonProps, 'children' | 'href' |
/** The value associated with the button's name when it's submitted with the form data. */
value?: string,
/**
* Whether to disable events immediately and display the `ProgressBar`.
* Whether the button is in a pending state. This disables press and hover events
* while retaining focusability, and announces the pending state to screen readers.
*/
isPending?: boolean
}
Expand Down Expand Up @@ -119,7 +120,7 @@ function Button(props: ButtonProps, ref: ForwardedRef<HTMLButtonElement>) {
isFocused,
isFocusVisible,
isDisabled: props.isDisabled || false,
isPending
isPending: isPending ?? false
};

let renderProps = useRenderProps({
Expand Down
10 changes: 9 additions & 1 deletion packages/react-aria-components/src/Disclosure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ export {_DisclosureGroup as DisclosureGroup};

export interface DisclosureProps extends Omit<AriaDisclosureProps, 'children'>, RenderProps<DisclosureRenderProps>, 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 {
Expand Down Expand Up @@ -185,6 +187,9 @@ export interface DisclosurePanelProps extends RenderProps<{}> {
* @default 'group'
*/
role?: 'group' | 'region',
/**
* The children of the component.
*/
children: ReactNode
}

Expand Down Expand Up @@ -225,5 +230,8 @@ function DisclosurePanel(props: DisclosurePanelProps, ref: ForwardedRef<HTMLDivE
const _Disclosure = /*#__PURE__*/ (forwardRef as forwardRefType)(Disclosure);
export {_Disclosure as Disclosure};

/**
* A DisclosurePanel provides the content for a disclosure.
*/
const _DisclosurePanel = /*#__PURE__*/ (forwardRef as forwardRefType)(DisclosurePanel);
export {_DisclosurePanel as DisclosurePanel};
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ export const BreadcrumbsExample = (args: any) => (
</Breadcrumbs>
);

interface Iitem {
interface ItemValue {
id: string,
url: string
}
let items: Array<Iitem> = [
let items: Array<ItemValue> = [
{id: 'Home', url: '/'},
{id: 'React Aria', url: '/react-aria'},
{id: 'Breadcrumbs', url: '/react-aria/breadcrumbs'}
];

export const DynamicBreadcrumbsExample = (args: any) => (
<Breadcrumbs {...args} items={items}>
{(item: Iitem) => (
{(item: ItemValue) => (
<Breadcrumb>
<Link href={item.url}>{item.id}</Link>
</Breadcrumb>
Expand Down

0 comments on commit 8ee13f3

Please sign in to comment.