From b5f8772bde21b95dbfb3fc5fd7777c7ba052c26c Mon Sep 17 00:00:00 2001 From: Alexandr Isaev Date: Wed, 10 Jan 2024 12:41:25 +0300 Subject: [PATCH] feat: add simple examples in doc, fix some review issues --- src/components/TreeSelect/TreeSelect.scss | 6 + src/components/TreeSelect/TreeSelect.tsx | 24 +++- .../__stories__/TreeSelect.stories.tsx | 1 - .../WithFiltrationAndControlsExample.tsx | 32 ++--- src/components/TreeSelect/types.ts | 2 + .../__stories__/components/FlattenList.tsx | 2 +- .../components/PopupWithTogglerList.tsx | 2 +- .../__stories__/components/RecursiveList.tsx | 2 +- .../useList/__stories__/useList.mdx | 109 +++++++++++++++++- .../components/ListItemView/ListItemView.tsx | 8 +- .../__stories__/ListItemView.stories.tsx | 50 ++++++-- src/components/useList/types.ts | 2 +- 12 files changed, 199 insertions(+), 41 deletions(-) diff --git a/src/components/TreeSelect/TreeSelect.scss b/src/components/TreeSelect/TreeSelect.scss index a12d97fa41..ad7cf33af3 100644 --- a/src/components/TreeSelect/TreeSelect.scss +++ b/src/components/TreeSelect/TreeSelect.scss @@ -3,6 +3,12 @@ $block: '.#{variables.$ns}tree-select'; #{$block} { + max-width: 100%; + + &_width_max { + width: 100%; + } + &__popup { overflow: hidden; min-width: 300px; diff --git a/src/components/TreeSelect/TreeSelect.tsx b/src/components/TreeSelect/TreeSelect.tsx index aa7c34bef8..b785583774 100644 --- a/src/components/TreeSelect/TreeSelect.tsx +++ b/src/components/TreeSelect/TreeSelect.tsx @@ -16,7 +16,7 @@ import { useListKeydown, useListState, } from '../useList'; -import {block} from '../utils/cn'; +import {type CnMods, block} from '../utils/cn'; import {TreeListContainer} from './components/TreeListContainer/TreeListContainer'; import {useTreeSelectSelection, useValue} from './hooks/useTreeSelectSelection'; @@ -37,6 +37,8 @@ export const TreeSelect = React.forwardRef(function TreeSelect( size = 'm', items, defaultOpen, + className, + width, popupClassName, open: propsOpen, multiple, @@ -224,8 +226,24 @@ export const TreeSelect = React.forwardRef(function TreeSelect( /> ); + const mods: CnMods = { + ...(width === 'max' && {width}), + }; + + const inlineStyles: React.CSSProperties = {}; + + if (typeof width === 'number') { + inlineStyles.width = width; + } + return ( - + {togglerNode} ( }); // assign components scope logic - state.selectable = context.groupState + state.hasSelectionIcon = context.groupState ? groupsBehavior === 'selectable' : undefined; diff --git a/src/components/TreeSelect/__stories__/TreeSelect.stories.tsx b/src/components/TreeSelect/__stories__/TreeSelect.stories.tsx index 8a48680eb6..ee0de0674e 100644 --- a/src/components/TreeSelect/__stories__/TreeSelect.stories.tsx +++ b/src/components/TreeSelect/__stories__/TreeSelect.stories.tsx @@ -25,7 +25,6 @@ import { WithItemLinksAndActionsExampleProps, } from './components/WithItemLinksAndActionsExample'; -// TODO: пример с кастомной структурой данных export default { title: 'Unstable/TreeSelect', component: TreeSelect, diff --git a/src/components/TreeSelect/__stories__/components/WithFiltrationAndControlsExample.tsx b/src/components/TreeSelect/__stories__/components/WithFiltrationAndControlsExample.tsx index 0cd53c850f..b4f6abda50 100644 --- a/src/components/TreeSelect/__stories__/components/WithFiltrationAndControlsExample.tsx +++ b/src/components/TreeSelect/__stories__/components/WithFiltrationAndControlsExample.tsx @@ -7,7 +7,7 @@ import {Flex, spacing} from '../../../layout'; import {useListFilter} from '../../../useList'; import {createRandomizedData} from '../../../useList/__stories__/utils/makeData'; import {TreeSelect} from '../../TreeSelect'; -import type {TreeSelectProps} from '../../types'; +import type {RenderContainerProps, TreeSelectProps} from '../../types'; import {RenderVirtualizedContainer} from './RenderVirtualizedContainer'; @@ -23,7 +23,23 @@ export const WithFiltrationAndControlsExample = ({ itemsCount = 5, ...props }: WithFiltrationAndControlsExampleProps) => { - const items = React.useMemo(() => createRandomizedData({num: itemsCount}), [itemsCount]); + const {items, renderContainer} = React.useMemo(() => { + const baseItems = createRandomizedData({num: itemsCount}); + const containerRenderer = (props: RenderContainerProps<{title: string}>) => { + if (props.items.length === 0 && baseItems.length > 0) { + return ( + + Nothing found + + ); + } + + return ; + }; + + return {items: baseItems, renderContainer: containerRenderer}; + }, [itemsCount]); + const [open, onOpenChange] = React.useState(true); const [value, setValue] = React.useState([]); const filterState = useListFilter({items}); @@ -48,17 +64,7 @@ export const WithFiltrationAndControlsExample = ({ ref={filterState.filterRef} /> } - renderContainer={(props) => { - if (props.items.length === 0 && items.length > 0) { - return ( - - Nothing found - - ); - } - - return ; - }} + renderContainer={renderContainer} slotAfterListBody={