Skip to content

Commit

Permalink
fix: updated List story
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Kharitonov committed Jan 30, 2024
1 parent 147fff3 commit aca7595
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
14 changes: 2 additions & 12 deletions src/components/List/__stories__/List.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {List, listDefaultProps} from '..';
import type {ListProps} from '..';

import {ListShowcase} from './ListShowcase';
import {ListWithLoader} from './ListWithLoader';

type ComponentType = React.JSXElementConstructor<ListProps<string>>;

Expand Down Expand Up @@ -46,18 +47,7 @@ RenderItem.args = {
renderItem: (item) => `🔥🔥🔥 ${item} 🔥🔥🔥`,
};

const TemplateWithState: ComponentStory<ComponentType> = (args) => {
const [items, setItems] = React.useState(args.items);

const onLoadMore = () => {
// delay for fetching new real items
setTimeout(() => {
setItems([...items, ...args.items]);
}, 300);
};

return <List {...args} items={items} onLoadMore={onLoadMore} />;
};
const TemplateWithState: ComponentStory<ComponentType> = (args) => <ListWithLoader {...args} />;

export const WithLoadingMoreItems = TemplateWithState.bind({});
WithLoadingMoreItems.args = {
Expand Down
6 changes: 6 additions & 0 deletions src/components/List/__stories__/ListWithLoader.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@use '../../variables';
@use '../../../../styles/mixins';

.list-with-loader {
overflow: auto;
}
26 changes: 26 additions & 0 deletions src/components/List/__stories__/ListWithLoader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';

import {cn} from '../../utils/cn';
import {List} from '../List';
import type {ListProps} from '../types';

import './ListWithLoader.scss';

const b = cn('list-with-loader');

export const ListWithLoader = (args: ListProps<string>) => {
const [items, setItems] = React.useState(args.items);

const onLoadMore = () => {
// delay for fetching new real items
setTimeout(() => {
setItems([...items, ...args.items]);
}, 300);
};

return (
<div className={b()}>
<List {...args} items={items} onLoadMore={onLoadMore} />
</div>
);
};

0 comments on commit aca7595

Please sign in to comment.