|
| 1 | +/* |
| 2 | + * Copyright 2024 Adobe. All rights reserved. |
| 3 | + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. You may obtain a copy |
| 5 | + * of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | + * |
| 7 | + * Unless required by applicable law or agreed to in writing, software distributed under |
| 8 | + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS |
| 9 | + * OF ANY KIND, either express or implied. See the License for the specific language |
| 10 | + * governing permissions and limitations under the License. |
| 11 | + */ |
| 12 | + |
| 13 | +import {ActionMenu, Content, Heading, IllustratedMessage, Link, MenuItem, Text, TreeView, TreeViewItem} from '../src'; |
| 14 | +import Delete from '../s2wf-icons/S2_Icon_Delete_20_N.svg'; |
| 15 | +import Edit from '../s2wf-icons/S2_Icon_Edit_20_N.svg'; |
| 16 | +import FileTxt from '../s2wf-icons/S2_Icon_FileText_20_N.svg'; |
| 17 | +import Folder from '../s2wf-icons/S2_Icon_Folder_20_N.svg'; |
| 18 | +import FolderOpen from '../spectrum-illustrations/linear/FolderOpen'; |
| 19 | +import type {Meta} from '@storybook/react'; |
| 20 | + |
| 21 | +const meta: Meta<typeof TreeView> = { |
| 22 | + component: TreeView, |
| 23 | + parameters: { |
| 24 | + chromaticProvider: {disableAnimations: true} |
| 25 | + }, |
| 26 | + title: 'S2 Chromatic/TreeView' |
| 27 | +}; |
| 28 | + |
| 29 | +export default meta; |
| 30 | + |
| 31 | +function TreeExample(props) { |
| 32 | + return ( |
| 33 | + <div style={{width: '300px', height: '320px'}}> |
| 34 | + <TreeView |
| 35 | + {...props} |
| 36 | + disabledKeys={['projects-1']} |
| 37 | + aria-label="test static tree" |
| 38 | + expandedKeys={['projects']}> |
| 39 | + <TreeViewItem id="Photos" textValue="Photos"> |
| 40 | + <Text>Photos</Text> |
| 41 | + <Folder /> |
| 42 | + <ActionMenu> |
| 43 | + <MenuItem id="edit"> |
| 44 | + <Edit /> |
| 45 | + <Text>Edit</Text> |
| 46 | + </MenuItem> |
| 47 | + <MenuItem id="delete"> |
| 48 | + <Delete /> |
| 49 | + <Text>Delete</Text> |
| 50 | + </MenuItem> |
| 51 | + </ActionMenu> |
| 52 | + </TreeViewItem> |
| 53 | + <TreeViewItem id="projects" textValue="Projects"> |
| 54 | + <Text>Projects</Text> |
| 55 | + <Folder /> |
| 56 | + <ActionMenu> |
| 57 | + <MenuItem id="edit"> |
| 58 | + <Edit /> |
| 59 | + <Text>Edit</Text> |
| 60 | + </MenuItem> |
| 61 | + <MenuItem id="delete"> |
| 62 | + <Delete /> |
| 63 | + <Text>Delete</Text> |
| 64 | + </MenuItem> |
| 65 | + </ActionMenu> |
| 66 | + <TreeViewItem id="projects-1" textValue="Projects-1"> |
| 67 | + <Text>Projects-1</Text> |
| 68 | + <Folder /> |
| 69 | + <ActionMenu> |
| 70 | + <MenuItem id="edit"> |
| 71 | + <Edit /> |
| 72 | + <Text>Edit</Text> |
| 73 | + </MenuItem> |
| 74 | + <MenuItem id="delete"> |
| 75 | + <Delete /> |
| 76 | + <Text>Delete</Text> |
| 77 | + </MenuItem> |
| 78 | + </ActionMenu> |
| 79 | + <TreeViewItem id="projects-1A" textValue="Projects-1A"> |
| 80 | + <Text>Projects-1A</Text> |
| 81 | + <FileTxt /> |
| 82 | + <ActionMenu> |
| 83 | + <MenuItem id="edit"> |
| 84 | + <Edit /> |
| 85 | + <Text>Edit</Text> |
| 86 | + </MenuItem> |
| 87 | + <MenuItem id="delete"> |
| 88 | + <Delete /> |
| 89 | + <Text>Delete</Text> |
| 90 | + </MenuItem> |
| 91 | + </ActionMenu> |
| 92 | + </TreeViewItem> |
| 93 | + </TreeViewItem> |
| 94 | + <TreeViewItem id="projects-2" textValue="Projects-2"> |
| 95 | + <Text>Projects-2</Text> |
| 96 | + <FileTxt /> |
| 97 | + <ActionMenu> |
| 98 | + <MenuItem id="edit"> |
| 99 | + <Edit /> |
| 100 | + <Text>Edit</Text> |
| 101 | + </MenuItem> |
| 102 | + <MenuItem id="delete"> |
| 103 | + <Delete /> |
| 104 | + <Text>Delete</Text> |
| 105 | + </MenuItem> |
| 106 | + </ActionMenu> |
| 107 | + </TreeViewItem> |
| 108 | + <TreeViewItem id="projects-3" textValue="Projects-3"> |
| 109 | + <Text>Projects-3</Text> |
| 110 | + <FileTxt /> |
| 111 | + <ActionMenu> |
| 112 | + <MenuItem id="edit"> |
| 113 | + <Edit /> |
| 114 | + <Text>Edit</Text> |
| 115 | + </MenuItem> |
| 116 | + <MenuItem id="delete"> |
| 117 | + <Delete /> |
| 118 | + <Text>Delete</Text> |
| 119 | + </MenuItem> |
| 120 | + </ActionMenu> |
| 121 | + </TreeViewItem> |
| 122 | + </TreeViewItem> |
| 123 | + </TreeView> |
| 124 | + </div> |
| 125 | + ); |
| 126 | +} |
| 127 | + |
| 128 | + |
| 129 | +export const TreeStatic = { |
| 130 | + render: (args) => <TreeExample {...args} /> |
| 131 | +}; |
| 132 | + |
| 133 | +export const TreeSelection = { |
| 134 | + ...TreeStatic, |
| 135 | + args: { |
| 136 | + selectionMode: 'multiple', |
| 137 | + defaultSelectedKeys: ['projects-2', 'projects-3'] |
| 138 | + } |
| 139 | +}; |
| 140 | + |
| 141 | +export const TreeIsDetached = { |
| 142 | + ...TreeStatic, |
| 143 | + args: { |
| 144 | + isDetached: true, |
| 145 | + selectionMode: 'multiple', |
| 146 | + defaultSelectedKeys: ['projects-2', 'projects-3'] |
| 147 | + } |
| 148 | +}; |
| 149 | + |
| 150 | +export const TreeIsEmphasized = { |
| 151 | + ...TreeStatic, |
| 152 | + args: { |
| 153 | + isEmphasized: true, |
| 154 | + selectionMode: 'multiple', |
| 155 | + defaultSelectedKeys: ['projects-2', 'projects-3'] |
| 156 | + } |
| 157 | +}; |
| 158 | + |
| 159 | +export const TreeIsDetachedIsEmphasized = { |
| 160 | + ...TreeStatic, |
| 161 | + args: { |
| 162 | + isDetached: true, |
| 163 | + isEmphasized: true, |
| 164 | + selectionMode: 'multiple', |
| 165 | + defaultSelectedKeys: ['projects-2', 'projects-3'] |
| 166 | + } |
| 167 | +}; |
| 168 | + |
| 169 | +export const TreeIsDetachedMobile = { |
| 170 | + ...TreeStatic, |
| 171 | + args: { |
| 172 | + isDetached: true, |
| 173 | + selectionMode: 'multiple', |
| 174 | + defaultSelectedKeys: ['projects-2', 'projects-3'] |
| 175 | + } |
| 176 | +}; |
| 177 | + |
| 178 | + |
| 179 | +let rows = [ |
| 180 | + {id: 'projects', name: 'Projects', icon: <Folder />, childItems: [ |
| 181 | + {id: 'project-1', name: 'Project 1 Level 1', icon: <FileTxt />}, |
| 182 | + {id: 'project-2', name: 'Project 2 Level 1', icon: <Folder />, childItems: [ |
| 183 | + {id: 'project-2A', name: 'Project 2A Level 2', icon: <FileTxt />}, |
| 184 | + {id: 'project-2B', name: 'Project 2B Level 2', icon: <FileTxt />}, |
| 185 | + {id: 'project-2C', name: 'Project 2C Level 3', icon: <FileTxt />} |
| 186 | + ]}, |
| 187 | + {id: 'project-3', name: 'Project 3', icon: <FileTxt />}, |
| 188 | + {id: 'project-4', name: 'Project 4', icon: <FileTxt />}, |
| 189 | + {id: 'project-5', name: 'Project 5', icon: <Folder />, childItems: [ |
| 190 | + {id: 'project-5A', name: 'Project 5A', icon: <FileTxt />}, |
| 191 | + {id: 'project-5B', name: 'Project 5B', icon: <FileTxt />}, |
| 192 | + {id: 'project-5C', name: 'Project 5C', icon: <FileTxt />} |
| 193 | + ]} |
| 194 | + ]}, |
| 195 | + {id: 'reports', name: 'Reports', icon: <Folder />, childItems: [ |
| 196 | + {id: 'reports-1', name: 'Reports 1', icon: <Folder />, childItems: [ |
| 197 | + {id: 'reports-1A', name: 'Reports 1A', icon: <Folder />, childItems: [ |
| 198 | + {id: 'reports-1AB', name: 'Reports 1AB', icon: <Folder />, childItems: [ |
| 199 | + {id: 'reports-1ABC', name: 'Reports 1ABC', icon: <FileTxt />} |
| 200 | + ]} |
| 201 | + ]}, |
| 202 | + {id: 'reports-1B', name: 'Reports 1B', icon: <FileTxt />}, |
| 203 | + {id: 'reports-1C', name: 'Reports 1C', icon: <FileTxt />} |
| 204 | + ]}, |
| 205 | + {id: 'reports-2', name: 'Reports 2', icon: <FileTxt />}, |
| 206 | + ...Array.from({length: 100}, (_, i) => ({id: `reports-repeat-${i}`, name: `Reports ${i}`, icon: <FileTxt />})) |
| 207 | + ]} |
| 208 | +]; |
| 209 | + |
| 210 | +const TreeExampleDynamic = (args) => ( |
| 211 | + <div style={{width: '300px', height: '320px', display: 'flex', flexDirection: 'column'}}> |
| 212 | + <TreeView aria-label="test dynamic tree" items={rows} {...args}> |
| 213 | + {(item: any) => ( |
| 214 | + <TreeViewItem childItems={item.childItems} textValue={item.name}> |
| 215 | + <Text>{item.name}</Text> |
| 216 | + {item.icon} |
| 217 | + </TreeViewItem> |
| 218 | + )} |
| 219 | + </TreeView> |
| 220 | + </div> |
| 221 | +); |
| 222 | + |
| 223 | +export const Dynamic = { |
| 224 | + render: (args) => <TreeExampleDynamic {...args} />, |
| 225 | + args: { |
| 226 | + disabledKeys: ['project-2C', 'project-5'], |
| 227 | + defaultExpandedKeys: ['projects', 'projects-2', 'projects-5'] |
| 228 | + } |
| 229 | +}; |
| 230 | + |
| 231 | + |
| 232 | +function renderEmptyState() { |
| 233 | + return ( |
| 234 | + <IllustratedMessage> |
| 235 | + <FolderOpen /> |
| 236 | + <Heading> |
| 237 | + No results |
| 238 | + </Heading> |
| 239 | + <Content> |
| 240 | + <Content>No results found, press <Link href="https://adobe.com">here</Link> for more info.</Content> |
| 241 | + </Content> |
| 242 | + </IllustratedMessage> |
| 243 | + ); |
| 244 | +} |
| 245 | + |
| 246 | +export const Empty = { |
| 247 | + render: TreeExampleDynamic, |
| 248 | + args: { |
| 249 | + renderEmptyState, |
| 250 | + items: [] |
| 251 | + } |
| 252 | +}; |
0 commit comments