Skip to content

chore: RAC storybook updates, Loader api fix #8381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/react-aria-components/src/GridList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ export interface GridListLoadingSentinelProps extends Omit<LoadMoreSentinelProps
isLoading?: boolean
}

export const UNSTABLE_GridListLoadingSentinel = createLeafComponent('loader', function GridListLoadingIndicator<T extends object>(props: GridListLoadingSentinelProps, ref: ForwardedRef<HTMLDivElement>, item: Node<T>) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the generic T seems to be unused if I've understood the types correctly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I think you are right, not sure why I used the generic tbh but this looks correct

export const UNSTABLE_GridListLoadingSentinel = /*#__PURE__*/ createLeafComponent('loader', function GridListLoadingIndicator(props: GridListLoadingSentinelProps, ref: ForwardedRef<Element>, item: Node<object>) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did the ref type here change to Element by the way? Since it gets attached explicitly to a div shouldn't the old type be ok?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, copy pasta

let state = useContext(ListStateContext)!;
let {isVirtualized} = useContext(CollectionRendererContext);
let {isLoading, onLoadMore, scrollOffset, ...otherProps} = props;
Expand Down Expand Up @@ -546,7 +546,7 @@ export const UNSTABLE_GridListLoadingSentinel = createLeafComponent('loader', fu
{...mergeProps(filterDOMProps(props as any))}
role="row"
aria-rowindex={isVirtualized ? item.index + 1 : undefined}
ref={ref}>
ref={ref as ForwardedRef<HTMLDivElement>}>
<div
aria-colindex={isVirtualized ? 1 : undefined}
role="gridcell">
Expand Down
4 changes: 2 additions & 2 deletions packages/react-aria-components/src/ListBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ export interface ListBoxLoadingSentinelProps extends Omit<LoadMoreSentinelProps,
isLoading?: boolean
}

export const UNSTABLE_ListBoxLoadingSentinel = createLeafComponent('loader', function ListBoxLoadingIndicator<T extends object>(props: ListBoxLoadingSentinelProps, ref: ForwardedRef<HTMLDivElement>, item: Node<T>) {
export const UNSTABLE_ListBoxLoadingSentinel = createLeafComponent('loader', function ListBoxLoadingIndicator(props: ListBoxLoadingSentinelProps, ref: ForwardedRef<Element>, item: Node<object>) {
let state = useContext(ListStateContext)!;
let {isVirtualized} = useContext(CollectionRendererContext);
let {isLoading, onLoadMore, scrollOffset, ...otherProps} = props;
Expand Down Expand Up @@ -524,7 +524,7 @@ export const UNSTABLE_ListBoxLoadingSentinel = createLeafComponent('loader', fun
// aria-selected isn't needed here since this option is not selectable.
// eslint-disable-next-line jsx-a11y/role-has-required-aria-props
role="option"
ref={ref}>
ref={ref as ForwardedRef<HTMLDivElement>}>
{renderProps.children}
</div>
)}
Expand Down
4 changes: 2 additions & 2 deletions packages/react-aria-components/src/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@ export interface TableLoadingSentinelProps extends Omit<LoadMoreSentinelProps, '
isLoading?: boolean
}

export const UNSTABLE_TableLoadingSentinel = createLeafComponent('loader', function TableLoadingIndicator<T extends object>(props: TableLoadingSentinelProps, ref: ForwardedRef<HTMLTableRowElement>, item: Node<T>) {
export const UNSTABLE_TableLoadingSentinel = createLeafComponent('loader', function TableLoadingIndicator(props: TableLoadingSentinelProps, ref: ForwardedRef<Element>, item: Node<object>) {
let state = useContext(TableStateContext)!;
let {isVirtualized} = useContext(CollectionRendererContext);
let {isLoading, onLoadMore, scrollOffset, ...otherProps} = props;
Expand Down Expand Up @@ -1409,7 +1409,7 @@ export const UNSTABLE_TableLoadingSentinel = createLeafComponent('loader', funct
{...mergeProps(filterDOMProps(props as any), rowProps)}
{...renderProps}
role="row"
ref={ref}>
ref={ref as ForwardedRef<HTMLTableRowElement>}>
<TD role="rowheader" {...rowHeaderProps} style={style}>
{renderProps.children}
</TD>
Expand Down
38 changes: 22 additions & 16 deletions packages/react-aria-components/stories/Autocomplete.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import {action} from '@storybook/addon-actions';
import {Autocomplete, Button, Collection, DialogTrigger, Header, Input, Keyboard, Label, ListBox, ListBoxSection, ListLayout, Menu, MenuItem, MenuSection, MenuTrigger, Popover, SearchField, Select, SelectValue, Separator, SubmenuTrigger, Text, TextField, Virtualizer} from 'react-aria-components';
import {Meta, StoryObj} from '@storybook/react';
import {MyListBoxItem, MyMenuItem} from './utils';
import React from 'react';
import styles from '../example/index.css';
Expand All @@ -20,6 +21,7 @@ import {useFilter} from 'react-aria';

export default {
title: 'React Aria Components',
component: Autocomplete,
args: {
onAction: action('onAction'),
selectionMode: 'multiple',
Expand All @@ -45,7 +47,11 @@ export default {
options: ['clearSelection', 'none']
}
}
};
} as Meta<typeof Autocomplete>;

export type AutocompleteStory = StoryObj<typeof Autocomplete>;
export type MenuStory = StoryObj<typeof Menu>;
export type ListBoxStory = StoryObj<typeof ListBox>;

let StaticMenu = (props) => {
return (
Expand Down Expand Up @@ -112,7 +118,7 @@ function AutocompleteWrapper(props) {
);
}

export const AutocompleteExample = {
export const AutocompleteExample: AutocompleteStory = {
render: (args) => {
return (
<AutocompleteWrapper>
Expand All @@ -130,7 +136,7 @@ export const AutocompleteExample = {
name: 'Autocomplete complex static with textfield'
};

export const AutocompleteSearchfield = {
export const AutocompleteSearchfield: AutocompleteStory = {
render: (args) => {
return (
<AutocompleteWrapper defaultInputValue="Ba">
Expand Down Expand Up @@ -288,7 +294,7 @@ let dynamicRenderFuncSections = (item: ItemNode) => {
}
};

export const AutocompleteMenuDynamic = {
export const AutocompleteMenuDynamic: AutocompleteStory = {
render: (args) => {
return (
<>
Expand All @@ -312,7 +318,7 @@ export const AutocompleteMenuDynamic = {
name: 'Autocomplete, dynamic menu'
};

export const AutocompleteOnActionOnMenuItems = {
export const AutocompleteOnActionOnMenuItems: AutocompleteStory = {
render: (args) => {
return (
<AutocompleteWrapper>
Expand Down Expand Up @@ -341,7 +347,7 @@ interface AutocompleteItem {

let items: AutocompleteItem[] = [{id: '1', name: 'Foo'}, {id: '2', name: 'Bar'}, {id: '3', name: 'Baz'}];

export const AutocompleteDisabledKeys = {
export const AutocompleteDisabledKeys: AutocompleteStory = {
render: (args) => {
return (
<AutocompleteWrapper>
Expand All @@ -361,7 +367,7 @@ export const AutocompleteDisabledKeys = {
name: 'Autocomplete, disabled key'
};

const AsyncExample = (args) => {
const AsyncExample = (args: any): React.ReactElement => {
let list = useAsyncList<AutocompleteItem>({
async load({filterText}) {
let json = await new Promise(resolve => {
Expand Down Expand Up @@ -412,7 +418,7 @@ const AsyncExample = (args) => {
);
};

export const AutocompleteAsyncLoadingExample = {
export const AutocompleteAsyncLoadingExample: StoryObj<typeof AsyncExample> = {
render: (args) => {
return <AsyncExample {...args} />;
},
Expand Down Expand Up @@ -444,14 +450,14 @@ const CaseSensitiveFilter = (args) => {
);
};

export const AutocompleteCaseSensitive = {
export const AutocompleteCaseSensitive: AutocompleteStory = {
render: (args) => {
return <CaseSensitiveFilter {...args} />;
},
name: 'Autocomplete, case sensitive filter'
};

export const AutocompleteWithListbox = {
export const AutocompleteWithListbox: AutocompleteStory = {
render: (args) => {
return (
<DialogTrigger>
Expand Down Expand Up @@ -528,7 +534,7 @@ function VirtualizedListBox(props) {
);
}

export const AutocompleteWithVirtualizedListbox = {
export const AutocompleteWithVirtualizedListbox: AutocompleteStory = {
render: (args) => {
return (
<DialogTrigger>
Expand Down Expand Up @@ -614,7 +620,7 @@ function ShellExample() {
);
}

export const AutocompleteInPopover = {
export const AutocompleteInPopover: MenuStory = {
render: () => {
return (
<MenuTrigger>
Expand Down Expand Up @@ -659,7 +665,7 @@ export const AutocompleteInPopover = {
}
};

export const AutocompleteInPopoverDialogTrigger = {
export const AutocompleteInPopoverDialogTrigger: MenuStory = {
render: () => {
return (
<DialogTrigger>
Expand Down Expand Up @@ -770,7 +776,7 @@ const MyMenu2 = () => {
);
};

export function AutocompleteWithExtraButtons() {
export function AutocompleteWithExtraButtons(): React.ReactElement {
return (
<div>
<input />
Expand All @@ -786,7 +792,7 @@ export function AutocompleteWithExtraButtons() {
// TODO: note that Space is used to select an item in a multiselect menu but that is also reserved for the
// autocomplete input field. Should we add logic to allow Space to select menu items when focus is in the Menu
// or is that a rare/unlikely use case for menus in general?
export const AutocompleteMenuInPopoverDialogTrigger = {
export const AutocompleteMenuInPopoverDialogTrigger: MenuStory = {
render: (args) => {
return (
<DialogTrigger>
Expand Down Expand Up @@ -830,7 +836,7 @@ export const AutocompleteMenuInPopoverDialogTrigger = {

let manyItems = [...Array(100)].map((_, i) => ({id: i, name: `Item ${i}`}));

export const AutocompleteSelect = () => (
export const AutocompleteSelect = (): React.ReactElement => (
<Select style={{marginBottom: 40, position: 'relative'}}>
<Label style={{display: 'block'}}>Test</Label>
<Button>
Expand Down
53 changes: 30 additions & 23 deletions packages/react-aria-components/stories/Breadcrumbs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,31 @@
*/

import {Breadcrumb, Breadcrumbs, Link} from 'react-aria-components';
import {Meta, StoryObj} from '@storybook/react';
import React from 'react';

export default {
title: 'React Aria Components',
component: Breadcrumbs
};
} as Meta<typeof Breadcrumbs>;

export type BreadcrumbsStory = StoryObj<typeof Breadcrumbs>;

export const BreadcrumbsExample = (args: any) => (
<Breadcrumbs {...args}>
<Breadcrumb>
<Link href="/">Home</Link>
</Breadcrumb>
<Breadcrumb>
<Link href="/react-aria">React Aria</Link>
</Breadcrumb>
<Breadcrumb>
<Link href="/react-aria">Breadcrumbs</Link>
</Breadcrumb>
</Breadcrumbs>
);
export const BreadcrumbsExample: BreadcrumbsStory = {
render: (args: any) => (
<Breadcrumbs {...args}>
<Breadcrumb>
<Link href="/">Home</Link>
</Breadcrumb>
<Breadcrumb>
<Link href="/react-aria">React Aria</Link>
</Breadcrumb>
<Breadcrumb>
<Link href="/react-aria">Breadcrumbs</Link>
</Breadcrumb>
</Breadcrumbs>
)
};

interface ItemValue {
id: string,
Expand All @@ -42,12 +47,14 @@ let items: Array<ItemValue> = [
{id: 'Breadcrumbs', url: '/react-aria/breadcrumbs'}
];

export const DynamicBreadcrumbsExample = (args: any) => (
<Breadcrumbs {...args} items={items}>
{(item: ItemValue) => (
<Breadcrumb>
<Link href={item.url}>{item.id}</Link>
</Breadcrumb>
)}
</Breadcrumbs>
);
export const DynamicBreadcrumbsExample: BreadcrumbsStory = {
render: (args: any) => (
<Breadcrumbs {...args} items={items}>
{(item: ItemValue) => (
<Breadcrumb>
<Link href={item.url}>{item.id}</Link>
</Breadcrumb>
)}
</Breadcrumbs>
)
};
24 changes: 14 additions & 10 deletions packages/react-aria-components/stories/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,25 @@
import {action} from '@storybook/addon-actions';
import {Button, ProgressBar, Text} from 'react-aria-components';
import {mergeProps} from '@react-aria/utils';
import {Meta, StoryObj} from '@storybook/react';
import React, {useEffect, useRef, useState} from 'react';
import * as styles from './button-ripple.css';
import * as styles2 from './button-pending.css';

export default {
title: 'React Aria Components'
};
title: 'React Aria Components',
component: Button
} as Meta<typeof Button>;

export const ButtonExample = () => {
return (
export type ButtonStory = StoryObj<typeof Button>;

export const ButtonExample: ButtonStory = {
render: () => (
<Button data-testid="button-example" onPress={action('onPress')} onClick={action('onClick')}>Press me</Button>
);
)
};

export const PendingButton = {
export const PendingButton: ButtonStory = {
render: (args) => <PendingButtonExample {...args} />,
args: {
children: 'Press me'
Expand Down Expand Up @@ -79,10 +83,10 @@ function PendingButtonExample(props) {
);
}

export const RippleButtonExample = () => {
return (
export const RippleButtonExample: ButtonStory = {
render: () => (
<RippleButton data-testid="button-example">Press me</RippleButton>
);
)
};

function RippleButton(props) {
Expand Down Expand Up @@ -148,7 +152,7 @@ function ButtonPerformanceExample() {
);
}

export const ButtonPerformance = {
export const ButtonPerformance: ButtonStory = {
render: (args) => <ButtonPerformanceExample {...args} />,
parameters: {
description: {
Expand Down
Loading