-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(TreeList): added missed initial state for elements (#1524)
- Loading branch information
1 parent
9e93c91
commit 5d3b154
Showing
4 changed files
with
135 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/components/TreeList/__stories__/stories/WithDisabledElementsStory.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React from 'react'; | ||
|
||
import {Button} from '../../../Button'; | ||
import {Flex} from '../../../layout'; | ||
import {useListState} from '../../../useList'; | ||
import type {ListItemType} from '../../../useList'; | ||
import {TreeList} from '../../TreeList'; | ||
import type {TreeListProps} from '../../types'; | ||
|
||
export interface WithDisabledElementsStoryProps | ||
extends Omit<TreeListProps<{text: string}>, 'items' | 'mapItemDataToProps'> {} | ||
|
||
const items: ListItemType<{text: string}>[] = [ | ||
{ | ||
text: 'one', | ||
disabled: true, | ||
}, | ||
{ | ||
text: 'two', | ||
}, | ||
{ | ||
text: 'free', | ||
}, | ||
{ | ||
text: 'four', | ||
}, | ||
{ | ||
text: 'five', | ||
}, | ||
]; | ||
|
||
export const WithDisabledElementsStory = ({...props}: WithDisabledElementsStoryProps) => { | ||
const {disabledById: _disabledById, setDisabled: _setDisabled, ...listState} = useListState(); | ||
const containerRef = React.useRef<HTMLDivElement>(null); | ||
|
||
return ( | ||
<Flex width="500" gap="5" direction="column" alignItems="flex-start"> | ||
<Flex alignItems="center" gap="1"> | ||
<Button | ||
onClick={() => { | ||
containerRef.current?.focus(); | ||
}} | ||
> | ||
focus elements | ||
</Button>{' '} | ||
to control from keyboard | ||
</Flex> | ||
<TreeList | ||
{...props} | ||
containerRef={containerRef} | ||
items={items} | ||
{...listState} | ||
mapItemDataToProps={({text}) => ({title: text})} | ||
onItemClick={({data, id, selected}) => { | ||
listState.setSelected({[id]: !selected}); | ||
alert(`Clicked by item with id :"${id}" and data: ${JSON.stringify(data)}`); | ||
}} | ||
/> | ||
</Flex> | ||
); | ||
}; |