Skip to content
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

feat(Select): adobe example #1040

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 32 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"@gravity-ui/prettier-config": "^1.0.1",
"@gravity-ui/stylelint-config": "^2.0.0",
"@gravity-ui/tsconfig": "^1.0.0",
"@react-stately/data": "^3.10.2",
"@storybook/addon-essentials": "^7.3.2",
"@storybook/cli": "^7.3.2",
"@storybook/preset-scss": "^1.0.3",
Expand Down
7 changes: 7 additions & 0 deletions src/components/Select/__stories__/Select.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {Meta, StoryFn} from '@storybook/react';
import {Select} from '..';
import type {SelectProps} from '..';

import {SelectAsyncShowcase} from './SelectAsync';
import {SelectPopupWidthShowcase} from './SelectPopupWidthShowcase';
import {SelectShowcase} from './SelectShowcase';

Expand All @@ -25,9 +26,15 @@ const ShowcaseTemplate: StoryFn<SelectProps> = (args: SelectProps) => <SelectSho
const SelectPopupWidthShowcaseTemplate: StoryFn<SelectProps> = (args) => (
<SelectPopupWidthShowcase {...args} />
);

const SelectAsyncShowcaseTemplate: StoryFn<SelectProps> = (args) => (
<SelectAsyncShowcase {...args} />
);

export const Default = DefaultTemplate.bind({});
export const Showcase = ShowcaseTemplate.bind({});
export const PopupWidth = SelectPopupWidthShowcaseTemplate.bind({});
export const SelectAsync = SelectAsyncShowcaseTemplate.bind({});

Showcase.args = {
view: 'normal',
Expand Down
52 changes: 52 additions & 0 deletions src/components/Select/__stories__/SelectAsync.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react';

import {useAsyncList} from '@react-stately/data';
import range from 'lodash/range';

import {Select} from '../Select';
import type {SelectOption} from '../types';

const generateItems = (limit: number, pageNumber = 0): SelectOption[] => {
const offset = pageNumber * limit;
return range(0, limit).map((i) => ({
value: `val${i + offset + 1}`,
content: `Value ${i + offset + 1}`,
}));
};
type FetchExample = (pageNumber: number) => Promise<{
response: SelectOption[];
pageNumber: number | undefined;
}>;

const fetchExample: FetchExample = (pageNumber = 0) => {
const nextPagination = pageNumber <= 0 ? pageNumber + 1 : undefined;
const resp = {
response: generateItems(100, pageNumber),
pageNumber: nextPagination,
};

return new Promise((res) => {
setTimeout(() => {
res(resp);
}, 1000);
});
};

export const SelectAsyncShowcase = (args: any) => {
const {items, isLoading, loadMore} = useAsyncList<SelectOption, number | null>({

Check failure on line 36 in src/components/Select/__stories__/SelectAsync.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

'isLoading' is assigned a value but never used. Allowed unused vars must match /^_/u
async load({cursor}) {
console.log('!!', cursor);
// If no cursor is available, then we're loading the first page.
// Otherwise, the cursor is the next URL to load, as returned from the previous page.
if (cursor === undefined) return {items: [], cursor};
const {response, pageNumber} = await fetchExample(cursor ? cursor : 0);
console.log('>>', pageNumber);
return {
items: response,
cursor: pageNumber,
};
},
});

return <Select {...args} options={items} loading={true} onLoadMore={loadMore} />;
};
Loading