Skip to content

Commit

Permalink
docs(TreeSelect): simple docs to start (#1734)
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaevAlexandr authored Aug 6, 2024
1 parent 69283f1 commit 61ca828
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/components/TreeSelect/__stories__/Docs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {Meta, Markdown} from '@storybook/addon-docs';

import TreeSelectDocs from './TreeSelectDocs.md?raw';

<Meta title="Lab/TreeSelect" />

<Markdown>{TreeSelectDocs}</Markdown>
61 changes: 61 additions & 0 deletions src/components/TreeSelect/__stories__/TreeSelectDocs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# TreeList

Rewritten component [Select](https://preview.gravity-ui.com/uikit/?path=/docs/components-inputs-select--docs) without feature-specific logic using TreeList inside.

`Storybook` provides complex examples how to use this components from this documentation.

### Import:

```tsx
import {unstable_TreeSelect as TreeSelect} from '@gravity-ui/uikit/unstable';
```

### Basic example:

```tsx
import {
type unstable_ListItemType as ListItemType,
unstable_TreeSelect as TreeSelect,
} from '@gravity-ui/uikit/unstable';

const items: ListItemType<string>[] = ['one', 'two', 'free', 'four', 'five'];

<TreeSelect items={items} mapItemDataToContentProps={(item) => ({title: item})} />;
```

### With full list item view override:

```tsx
import {Text} from '@gravity-ui/uikit';
import {
type unstable_ListItemType as ListItemType,
type unstable_ListItemView as ListItemView,
unstable_TreeSelect as TreeSelect,
} from '@gravity-ui/uikit/unstable';

interface Entity {
id: string;
title: string;
}

const items: ListItemType<Entity>[] = [
{title: 'one', id: '1'},
{title: 'two', id: '2'},
{title: 'free', id: '3'},
{title: 'four', id: '4'},
{title: 'five', id: '5'},
];

const Component = () => {
return (
<TreeSelect
items={items}
getItemId={({id}) => id}
mapItemDataToContentProps={({title}) => ({title})}
renderItem={({data: {title}, props}) => (
<ListItemView {...props} content={<Text>{title}</Text>} />
)}
/>
);
};
```

0 comments on commit 61ca828

Please sign in to comment.