树
@cloud-ru/ds-tree -=YTET -伊甸园字幕组=- 翻译:.
-=YTET -伊甸园字幕组=- 翻译: {\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢.
Когда
- =========================================================================================================================================================================================.
- 面包屑 面包屑 面包屑.
- {\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢
onDataLoad{\fn黑体\fs22\bord1\shad0\3ahbe\4ah00\fscx67\fscy66\2chffffff\3ch808080}你觉得呢.
Когда не нужен:
- 5 –20 элементов:
- используйте
ListилиSelect。 。 。 .
- используйте
- 2–7 одного:
- используйте
Tabs。 。 。 .
- используйте
- 校对:Soup
- используйте
Stepper。 。 。 .
- используйте
Анатомия
选择模式( 默认 — — — — — — )
undefined——只读 ,узлы.'single'- один, рендерится, рендеритсяRadio页:1showToggle{\fn黑体\fs20\shad2\2ah82\3ah20\4ah33\fscx95\3ch592001\be1}你觉得怎样.'multiple'множественный выборCheckbox{\fn黑体\fs22\bord1\shad0\3ahbe\4ah00\fscx67\fscy66\2chffffff\3ch808080}你说什么.
大小( 默认) m(中文(简体) )
s-=ytet -伊甸园字幕组=- 翻译:.m- стандартная для админок админок админок.l{\fn黑体\fs20\shad2\2ah82\3ah20\4ah33\fscx95\3ch592001\be1} - {\fn黑体\fs20\shad2\2ah82\3ah20\4ah33\fscx95\3ch592001\be1} - 时间轴:.
Текущая size соответствует 紧凑 缩略语compact/S=24px, (中文(简体) ), compact/M=32px, (中文(简体) ), compact/L=40px (原始内容存档于2018-09-21). rain-h. 密度 comfort (40/48/56px行-h) 26653:105451(中文(简体) ) не - \ API\ \ \ \ \ \ density。 。 。 音轨: QQ constants.ts осью DENSITY {\fn黑体\fs22\bord1\shad0\3ahbe\4ah00\fscx67\fscy66\2chffffff\3ch808080}你觉得呢 density-size-icon-* на.
显示行( 默认) false(中文(简体) )
Полосы └─{\fn华文仿宋\fs16\1cHD1D1D1}我... (原始内容存档于2016-10-12). QQQ (3++++++++++++++++++).
显示图标( 默认) true(中文(简体) )
(原始内容存档于2018-09-28). Folders/ file--иконки. Отключай,если也.
Установка
pnpm add @cloud-ru/ds-tree
import { SELECTION_MODE, SIZE, Tree } from '@cloud-ru/ds-tree'
Примеры
Базовый
只读 \\ \ \ \ 扩展上
import { Tree, TreeNodeProps } from '@cloud-ru/ds-tree';
import { useState } from 'react';
const DATA: TreeNodeProps[] = [
{
id: 'fruits',
title: 'Fruits',
nested: [
{ id: 'apple', title: 'Apple' },
{ id: 'banana', title: 'Banana' },
{
id: 'citrus',
title: 'Citrus',
nested: [
{ id: 'orange', title: 'Orange' },
{ id: 'lemon', title: 'Lemon' },
],
},
],
},
{
id: 'vegetables',
title: 'Vegetables',
nested: [
{ id: 'carrot', title: 'Carrot' },
{ id: 'potato', title: 'Potato' },
],
},
];
export function Basic() {
const [expanded, setExpanded] = useState<string[]>(['fruits']);
return <Tree data={DATA} expandedNodes={expanded} onExpand={setExpanded} showLines />;
}
Одиночный
选择模式=单一 + 显示 托格勒: + 电台 + QQ
import { SELECTION_MODE, Tree, TreeNodeProps } from '@cloud-ru/ds-tree';
import { useState } from 'react';
const DATA: TreeNodeProps[] = [
{
id: 'docs',
title: 'Documents',
nested: [
{ id: 'specs', title: 'Specs.pdf' },
{ id: 'budget', title: 'Budget.xlsx' },
{ id: 'roadmap', title: 'Roadmap.md' },
],
},
{
id: 'media',
title: 'Media',
nested: [
{ id: 'logo', title: 'Logo.svg' },
{ id: 'hero', title: 'Hero.png' },
],
},
];
export function SingleSelect() {
const [selected, setSelected] = useState<string | undefined>('specs');
const [expanded, setExpanded] = useState<string[]>(['docs', 'media']);
return (
<Tree
data={DATA}
selectionMode={SELECTION_MODE.Single}
selected={selected}
onSelect={setSelected}
expandedNodes={expanded}
onExpand={setExpanded}
showToggle
showLines
/>
);
}
Множественный
选择模式=多点: 复选框 QQ, QQ- 不确定
import { SELECTION_MODE, Tree, TreeNodeProps } from '@cloud-ru/ds-tree';
import { useState } from 'react';
const DATA: TreeNodeProps[] = [
{
id: 'compute',
title: 'Compute',
nested: [
{ id: 'vm', title: 'Virtual machines' },
{ id: 'k8s', title: 'Kubernetes' },
{ id: 'serverless', title: 'Serverless' },
],
},
{
id: 'storage',
title: 'Storage',
nested: [
{ id: 's3', title: 'Object storage' },
{ id: 'block', title: 'Block storage' },
],
},
];
export function MultiSelect() {
const [selected, setSelected] = useState<string[]>(['vm', 's3']);
const [expanded, setExpanded] = useState<string[]>(['compute', 'storage']);
return (
<Tree
data={DATA}
selectionMode={SELECTION_MODE.Multiple}
selected={selected}
onSelect={setSelected}
expandedNodes={expanded}
onExpand={setExpanded}
showLines
/>
);
}
Кастомные
图标 , 扩展Icon/collapsedIcon
import { FileSVG, FolderOpenSVG, FolderSVG } from '@cloud-ru/ds-icons/interface/system';
import { Tree, TreeNodeProps } from '@cloud-ru/ds-tree';
import { useState } from 'react';
const DATA: TreeNodeProps[] = [
{
id: 'src',
title: 'src',
expandedIcon: <FolderOpenSVG />,
collapsedIcon: <FolderSVG />,
nested: [
{ id: 'app.tsx', title: 'App.tsx', icon: <FileSVG /> },
{ id: 'main.tsx', title: 'main.tsx', icon: <FileSVG /> },
{
id: 'components',
title: 'components',
expandedIcon: <FolderOpenSVG />,
collapsedIcon: <FolderSVG />,
nested: [
{ id: 'button.tsx', title: 'Button.tsx', icon: <FileSVG /> },
{ id: 'tree.tsx', title: 'Tree.tsx', icon: <FileSVG /> },
],
},
],
},
];
export function WithIcons() {
const [expanded, setExpanded] = useState<string[]>(['src', 'components']);
return <Tree data={DATA} expandedNodes={expanded} onExpand={setExpanded} showLines />;
}
Контекстные
{\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}节点动作 {\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}盘旋/聚焦
import { Tree, TreeNodeProps } from '@cloud-ru/ds-tree';
import { useState } from 'react';
const DATA: TreeNodeProps[] = [
{
id: 'project',
title: 'Project Alpha',
nested: [
{ id: 'overview.md', title: 'overview.md' },
{ id: 'changelog.md', title: 'changelog.md' },
],
},
{ id: 'project-beta', title: 'Project Beta', nested: [{ id: 'todo.md', title: 'todo.md' }] },
];
export function WithActions() {
const [expanded, setExpanded] = useState<string[]>(['project']);
const [lastItemAction, setLastItemAction] = useState<string>('');
const nodeActions = (node: TreeNodeProps) => [
{ id: 'rename', content: { label: `Rename ${node.id}` }, onClick: () => setLastItemAction(`rename ${node.id}`) },
{ id: 'delete', content: { label: 'Delete' }, onClick: () => setLastItemAction(`delete ${node.id}`) },
];
return (
<>
<Tree data={DATA} expandedNodes={expanded} onExpand={setExpanded} nodeActions={nodeActions} showLines />
<small>Last clicked item action: {lastItemAction || '—'}</small>
</>
);
}
Асинхронная
{\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你应该知道
import { Tree, TreeNodeProps } from '@cloud-ru/ds-tree';
import { useState } from 'react';
const INITIAL: TreeNodeProps[] = [
{ id: 'region-eu', title: 'EU region', nested: [] },
{ id: 'region-ru', title: 'RU region', nested: [] },
];
export function AsyncLoad() {
const [data, setData] = useState(INITIAL);
const [expanded, setExpanded] = useState<string[]>([]);
const onDataLoad = async (node: TreeNodeProps) => {
await new Promise(r => setTimeout(r, 600));
setData(prev =>
prev.map((item): TreeNodeProps => {
if (item.id !== node.id) return item;
return {
id: item.id,
title: item.title as string,
nested: [
{ id: `${item.id}-vm1`, title: 'vm-prod-01' },
{ id: `${item.id}-vm2`, title: 'vm-prod-02' },
{ id: `${item.id}-vm3`, title: 'vm-staging-01' },
],
};
}),
);
};
return <Tree data={data} expandedNodes={expanded} onExpand={setExpanded} onDataLoad={onDataLoad} showLines />;
}
道具
树道
| Prop | 类型 | 默认 | 说明 |
|---|---|---|---|
className | string | —— 说 | 支助科 |
data | TreeNodeProps | —— 说 | {\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢 |
data-test-id | string | —— 说 | |
expandedNodes | TreeNodeId | —— 说 | {\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢 |
nodeActions | ((node: TreeNodeProps) => Item[]) | —— 说 | {\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢 |
onDataLoad | ((node: TreeNodeProps) => Promise<unknown>) | —— 说 | {\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢 |
onExpand | ((expandedKeys: string[], node: TreeNodeProps) => void) | —— 说 | Колбэк/закрытии |
onNodeClick | OnNodeClick | —— 说 | {\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢 |
onSelect | ((selectedKeys: string[], node: TreeNodeProps) => void) | ((selectedKey: string, node: TreeNodeProps) => void) | —— 说 | 说吧 - При 选择模式=: Multiple - возвращает массив - При 选择模式=: Single - возвращает строку |
parentActions | ((node: TreeNodeProps) => Item[]) | —— 说 | {\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢 |
selected | string | string[] | —— 说 | 说吧 - При 选择模式=: Multiple - принимает массив - При 选择模式=: Single - принимает строку |
selectionMode | "multiple" | "single" | —— 说 | 说吧 - 说吧 Single - одиночный выбор - 说吧 Multi - множественный выбор - 说吧 undefined - без выбора |
showIcons | boolean | true | {\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢 |
showLines | boolean | true | {\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢 |
showToggle | boolean | —— 说 | |
size | "l" | "m" | "s" | m | QQ (图像变体) size) (中文(简体) ). |
titleMaxLines | number | 1 | {\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢. (原始内容存档于2016-10-12). QQ 1 перенос; строка. |
相关类型
-
OnNodeClick=:(node: TreeNodeProps, e: MouseEvent) => void -
Size=:"l"|"m"|"s" -
TreeNodeId=:string -
TreeNodeProps=:ChildTreeNode | ParentTreeNode