|
| 1 | +import { faFileLines, faFolder, faFolderOpen, faPen, faTrash } from '@fortawesome/pro-regular-svg-icons'; |
1 | 2 | import { Dialog as DialogElement } from '@sl-design-system/dialog'; |
| 3 | +import { Icon as SlIcon } from '@sl-design-system/icon'; |
| 4 | +import { FlatTreeDataSource } from '@sl-design-system/tree'; |
2 | 5 | import { type Meta, type StoryObj, moduleMetadata } from '@storybook/angular'; |
3 | 6 | import { AccordionItemComponent } from '../src/accordion/accordion-item.component'; |
4 | 7 | import { AccordionComponent } from '../src/accordion/accordion.component'; |
@@ -28,6 +31,7 @@ import { TabComponent } from '../src/tabs/tab.component'; |
28 | 31 | import { TextAreaComponent } from '../src/text-area/text-area.component'; |
29 | 32 | import { TextFieldComponent } from '../src/text-field/text-field.component'; |
30 | 33 | import { TooltipComponent } from '../src/tooltip/tooltip.component'; |
| 34 | +import { TreeComponent } from '../src/tree/tree.component'; |
31 | 35 |
|
32 | 36 | export default { |
33 | 37 | title: 'Wrappers', |
@@ -61,12 +65,15 @@ export default { |
61 | 65 | TabPanelComponent, |
62 | 66 | TextFieldComponent, |
63 | 67 | TextAreaComponent, |
64 | | - TooltipComponent |
| 68 | + TooltipComponent, |
| 69 | + TreeComponent |
65 | 70 | ] |
66 | 71 | }) |
67 | 72 | ] |
68 | 73 | } as Meta; |
69 | 74 |
|
| 75 | +SlIcon.register(faFileLines, faFolder, faFolderOpen, faPen, faTrash); |
| 76 | + |
70 | 77 | export const Accordion: StoryObj = { |
71 | 78 | render: () => ({ |
72 | 79 | template: ` |
@@ -287,3 +294,52 @@ export const Tooltip: StoryObj = { |
287 | 294 | ` |
288 | 295 | }) |
289 | 296 | }; |
| 297 | + |
| 298 | +export const Tree: StoryObj = { |
| 299 | + render: () => { |
| 300 | + type Item = { id: number; expandable: boolean; level: number; name: string }; |
| 301 | + |
| 302 | + const flatData: Item[] = [ |
| 303 | + { id: 0, expandable: true, level: 0, name: 'Mathematics' }, |
| 304 | + { id: 1, expandable: true, level: 1, name: 'Algebra' }, |
| 305 | + { id: 2, expandable: false, level: 2, name: 'Lesson 1 - Linear equations.md' }, |
| 306 | + { id: 3, expandable: false, level: 2, name: 'Lesson 2 - Quadratic equations.md' }, |
| 307 | + { id: 4, expandable: true, level: 1, name: 'Geometry' }, |
| 308 | + { id: 5, expandable: false, level: 2, name: 'Lesson 1 - Triangles.md' }, |
| 309 | + { id: 6, expandable: false, level: 2, name: 'Lesson 2 - Circles.md' }, |
| 310 | + { id: 21, expandable: false, level: 1, name: 'Lesson 20 - Statistics and probability.md' }, |
| 311 | + { id: 7, expandable: true, level: 0, name: 'Science' }, |
| 312 | + { id: 8, expandable: true, level: 1, name: 'Physics' }, |
| 313 | + { id: 9, expandable: false, level: 2, name: 'Lesson 1 - Motion.md' }, |
| 314 | + { id: 10, expandable: false, level: 2, name: 'Lesson 2 - Forces.md' }, |
| 315 | + { id: 11, expandable: true, level: 1, name: 'Chemistry' }, |
| 316 | + { id: 12, expandable: false, level: 2, name: 'Lesson 1 - Atoms.md' }, |
| 317 | + { id: 13, expandable: false, level: 2, name: 'Lesson 2 - Reactions.md' }, |
| 318 | + { id: 14, expandable: true, level: 0, name: 'History' }, |
| 319 | + { id: 15, expandable: true, level: 1, name: 'Ancient Civilizations' }, |
| 320 | + { id: 16, expandable: false, level: 2, name: 'Egypt.md' }, |
| 321 | + { id: 17, expandable: false, level: 2, name: 'Rome.md' }, |
| 322 | + { id: 18, expandable: true, level: 1, name: 'Modern History' }, |
| 323 | + { id: 19, expandable: false, level: 2, name: 'World War I.md' }, |
| 324 | + { id: 20, expandable: false, level: 2, name: 'World War II.md' } |
| 325 | + ]; |
| 326 | + |
| 327 | + const dataSource = new FlatTreeDataSource<Item>(flatData, { |
| 328 | + getIcon: ({ name }: Item, expanded: boolean) => |
| 329 | + name.includes('.') ? 'far-file-lines' : `far-folder${expanded ? '-open' : ''}`, |
| 330 | + getId: (item: Item) => item.id, |
| 331 | + getLabel: ({ name }: Item) => name, |
| 332 | + getLevel: ({ level }: Item) => level, |
| 333 | + isExpandable: ({ expandable }: Item) => expandable, |
| 334 | + isExpanded: ({ name }: Item) => ['tree', 'src'].includes(name), |
| 335 | + selects: 'multiple' |
| 336 | + }); |
| 337 | + |
| 338 | + return { |
| 339 | + props: { dataSource }, |
| 340 | + template: ` |
| 341 | + <sl-tree [dataSource]="dataSource" aria-label="Subjects structure"></sl-tree> |
| 342 | + ` |
| 343 | + }; |
| 344 | + } |
| 345 | +}; |
0 commit comments