@instructure/ui-tree-browser 11.6.0 → 11.6.1-snapshot-129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -288
- package/es/TreeBrowser/{TreeButton → v1/TreeButton}/index.js +2 -2
- package/es/TreeBrowser/{TreeCollection → v1/TreeCollection}/index.js +1 -1
- package/es/TreeBrowser/{TreeNode → v1/TreeNode}/index.js +2 -2
- package/es/TreeBrowser/{index.js → v1/index.js} +1 -1
- package/es/TreeBrowser/v2/TreeBrowserContext.js +39 -0
- package/es/TreeBrowser/v2/TreeButton/index.js +202 -0
- package/es/TreeBrowser/v2/TreeButton/props.js +26 -0
- package/es/TreeBrowser/v2/TreeButton/styles.js +306 -0
- package/es/TreeBrowser/v2/TreeCollection/index.js +367 -0
- package/es/TreeBrowser/v2/TreeCollection/props.js +26 -0
- package/es/TreeBrowser/v2/TreeCollection/styles.js +143 -0
- package/es/TreeBrowser/v2/TreeNode/index.js +156 -0
- package/es/{index.js → TreeBrowser/v2/TreeNode/props.js} +3 -4
- package/es/TreeBrowser/v2/index.js +347 -0
- package/es/TreeBrowser/v2/props.js +35 -0
- package/es/TreeBrowser/v2/styles.js +71 -0
- package/es/exports/a.js +27 -0
- package/es/exports/b.js +27 -0
- package/lib/TreeBrowser/{TreeButton → v1/TreeButton}/index.js +3 -3
- package/lib/TreeBrowser/{TreeCollection → v1/TreeCollection}/index.js +1 -1
- package/lib/TreeBrowser/{TreeNode → v1/TreeNode}/index.js +3 -3
- package/lib/TreeBrowser/{index.js → v1/index.js} +3 -3
- package/lib/TreeBrowser/v2/TreeBrowserContext.js +44 -0
- package/lib/TreeBrowser/v2/TreeButton/index.js +208 -0
- package/lib/TreeBrowser/v2/TreeButton/props.js +31 -0
- package/lib/TreeBrowser/v2/TreeButton/styles.js +312 -0
- package/lib/TreeBrowser/v2/TreeCollection/index.js +372 -0
- package/lib/TreeBrowser/v2/TreeCollection/props.js +31 -0
- package/lib/TreeBrowser/v2/TreeCollection/styles.js +149 -0
- package/lib/TreeBrowser/v2/TreeNode/index.js +162 -0
- package/lib/TreeBrowser/v2/TreeNode/props.js +31 -0
- package/lib/TreeBrowser/v2/index.js +353 -0
- package/lib/TreeBrowser/v2/props.js +40 -0
- package/lib/TreeBrowser/v2/styles.js +77 -0
- package/lib/{index.js → exports/a.js} +5 -5
- package/lib/exports/b.js +33 -0
- package/package.json +40 -18
- package/src/TreeBrowser/{TreeButton → v1/TreeButton}/index.tsx +2 -2
- package/src/TreeBrowser/{TreeCollection → v1/TreeCollection}/index.tsx +1 -1
- package/src/TreeBrowser/{TreeNode → v1/TreeNode}/index.tsx +2 -2
- package/src/TreeBrowser/{index.tsx → v1/index.tsx} +1 -1
- package/src/TreeBrowser/v2/README.md +712 -0
- package/src/TreeBrowser/v2/TreeBrowserContext.ts +53 -0
- package/src/TreeBrowser/v2/TreeButton/index.tsx +210 -0
- package/src/TreeBrowser/v2/TreeButton/props.ts +95 -0
- package/src/TreeBrowser/v2/TreeButton/styles.ts +331 -0
- package/src/TreeBrowser/v2/TreeCollection/index.tsx +416 -0
- package/src/TreeBrowser/v2/TreeCollection/props.ts +88 -0
- package/src/TreeBrowser/v2/TreeCollection/styles.ts +157 -0
- package/src/TreeBrowser/v2/TreeNode/index.tsx +158 -0
- package/src/TreeBrowser/v2/TreeNode/props.ts +84 -0
- package/src/TreeBrowser/v2/index.tsx +438 -0
- package/src/TreeBrowser/v2/props.ts +245 -0
- package/src/TreeBrowser/v2/styles.ts +79 -0
- package/src/exports/a.ts +32 -0
- package/src/exports/b.ts +32 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/TreeBrowser/v1/TreeBrowserContext.d.ts.map +1 -0
- package/types/TreeBrowser/v1/TreeButton/index.d.ts.map +1 -0
- package/types/TreeBrowser/v1/TreeButton/props.d.ts.map +1 -0
- package/types/TreeBrowser/v1/TreeButton/styles.d.ts.map +1 -0
- package/types/TreeBrowser/v1/TreeButton/theme.d.ts.map +1 -0
- package/types/TreeBrowser/{TreeCollection → v1/TreeCollection}/index.d.ts +1 -1
- package/types/TreeBrowser/v1/TreeCollection/index.d.ts.map +1 -0
- package/types/TreeBrowser/v1/TreeCollection/props.d.ts.map +1 -0
- package/types/TreeBrowser/v1/TreeCollection/styles.d.ts.map +1 -0
- package/types/TreeBrowser/v1/TreeCollection/theme.d.ts.map +1 -0
- package/types/TreeBrowser/v1/TreeNode/index.d.ts.map +1 -0
- package/types/TreeBrowser/v1/TreeNode/props.d.ts.map +1 -0
- package/types/TreeBrowser/v1/index.d.ts.map +1 -0
- package/types/TreeBrowser/v1/props.d.ts.map +1 -0
- package/types/TreeBrowser/v1/styles.d.ts.map +1 -0
- package/types/TreeBrowser/v1/theme.d.ts.map +1 -0
- package/types/TreeBrowser/v2/TreeBrowserContext.d.ts +24 -0
- package/types/TreeBrowser/v2/TreeBrowserContext.d.ts.map +1 -0
- package/types/TreeBrowser/v2/TreeButton/index.d.ts +44 -0
- package/types/TreeBrowser/v2/TreeButton/index.d.ts.map +1 -0
- package/types/TreeBrowser/v2/TreeButton/props.d.ts +37 -0
- package/types/TreeBrowser/v2/TreeButton/props.d.ts.map +1 -0
- package/types/TreeBrowser/v2/TreeButton/styles.d.ts +19 -0
- package/types/TreeBrowser/v2/TreeButton/styles.d.ts.map +1 -0
- package/types/TreeBrowser/v2/TreeCollection/index.d.ts +66 -0
- package/types/TreeBrowser/v2/TreeCollection/index.d.ts.map +1 -0
- package/types/TreeBrowser/v2/TreeCollection/props.d.ts +24 -0
- package/types/TreeBrowser/v2/TreeCollection/props.d.ts.map +1 -0
- package/types/TreeBrowser/v2/TreeCollection/styles.d.ts +18 -0
- package/types/TreeBrowser/v2/TreeCollection/styles.d.ts.map +1 -0
- package/types/TreeBrowser/v2/TreeNode/index.d.ts +41 -0
- package/types/TreeBrowser/v2/TreeNode/index.d.ts.map +1 -0
- package/types/TreeBrowser/v2/TreeNode/props.d.ts +25 -0
- package/types/TreeBrowser/v2/TreeNode/props.d.ts.map +1 -0
- package/types/TreeBrowser/v2/index.d.ts +70 -0
- package/types/TreeBrowser/v2/index.d.ts.map +1 -0
- package/types/TreeBrowser/v2/props.d.ts +163 -0
- package/types/TreeBrowser/v2/props.d.ts.map +1 -0
- package/types/TreeBrowser/v2/styles.d.ts +16 -0
- package/types/TreeBrowser/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +9 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +9 -0
- package/types/exports/b.d.ts.map +1 -0
- package/src/index.ts +0 -32
- package/types/TreeBrowser/TreeBrowserContext.d.ts.map +0 -1
- package/types/TreeBrowser/TreeButton/index.d.ts.map +0 -1
- package/types/TreeBrowser/TreeButton/props.d.ts.map +0 -1
- package/types/TreeBrowser/TreeButton/styles.d.ts.map +0 -1
- package/types/TreeBrowser/TreeButton/theme.d.ts.map +0 -1
- package/types/TreeBrowser/TreeCollection/index.d.ts.map +0 -1
- package/types/TreeBrowser/TreeCollection/props.d.ts.map +0 -1
- package/types/TreeBrowser/TreeCollection/styles.d.ts.map +0 -1
- package/types/TreeBrowser/TreeCollection/theme.d.ts.map +0 -1
- package/types/TreeBrowser/TreeNode/index.d.ts.map +0 -1
- package/types/TreeBrowser/TreeNode/props.d.ts.map +0 -1
- package/types/TreeBrowser/index.d.ts.map +0 -1
- package/types/TreeBrowser/props.d.ts.map +0 -1
- package/types/TreeBrowser/styles.d.ts.map +0 -1
- package/types/TreeBrowser/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -9
- package/types/index.d.ts.map +0 -1
- /package/es/TreeBrowser/{TreeBrowserContext.js → v1/TreeBrowserContext.js} +0 -0
- /package/es/TreeBrowser/{TreeButton → v1/TreeButton}/props.js +0 -0
- /package/es/TreeBrowser/{TreeButton → v1/TreeButton}/styles.js +0 -0
- /package/es/TreeBrowser/{TreeButton → v1/TreeButton}/theme.js +0 -0
- /package/es/TreeBrowser/{TreeCollection → v1/TreeCollection}/props.js +0 -0
- /package/es/TreeBrowser/{TreeCollection → v1/TreeCollection}/styles.js +0 -0
- /package/es/TreeBrowser/{TreeCollection → v1/TreeCollection}/theme.js +0 -0
- /package/es/TreeBrowser/{TreeNode → v1/TreeNode}/props.js +0 -0
- /package/es/TreeBrowser/{props.js → v1/props.js} +0 -0
- /package/es/TreeBrowser/{styles.js → v1/styles.js} +0 -0
- /package/es/TreeBrowser/{theme.js → v1/theme.js} +0 -0
- /package/lib/TreeBrowser/{TreeBrowserContext.js → v1/TreeBrowserContext.js} +0 -0
- /package/lib/TreeBrowser/{TreeButton → v1/TreeButton}/props.js +0 -0
- /package/lib/TreeBrowser/{TreeButton → v1/TreeButton}/styles.js +0 -0
- /package/lib/TreeBrowser/{TreeButton → v1/TreeButton}/theme.js +0 -0
- /package/lib/TreeBrowser/{TreeCollection → v1/TreeCollection}/props.js +0 -0
- /package/lib/TreeBrowser/{TreeCollection → v1/TreeCollection}/styles.js +0 -0
- /package/lib/TreeBrowser/{TreeCollection → v1/TreeCollection}/theme.js +0 -0
- /package/lib/TreeBrowser/{TreeNode → v1/TreeNode}/props.js +0 -0
- /package/lib/TreeBrowser/{props.js → v1/props.js} +0 -0
- /package/lib/TreeBrowser/{styles.js → v1/styles.js} +0 -0
- /package/lib/TreeBrowser/{theme.js → v1/theme.js} +0 -0
- /package/src/TreeBrowser/{README.md → v1/README.md} +0 -0
- /package/src/TreeBrowser/{TreeBrowserContext.ts → v1/TreeBrowserContext.ts} +0 -0
- /package/src/TreeBrowser/{TreeButton → v1/TreeButton}/props.ts +0 -0
- /package/src/TreeBrowser/{TreeButton → v1/TreeButton}/styles.ts +0 -0
- /package/src/TreeBrowser/{TreeButton → v1/TreeButton}/theme.ts +0 -0
- /package/src/TreeBrowser/{TreeCollection → v1/TreeCollection}/props.ts +0 -0
- /package/src/TreeBrowser/{TreeCollection → v1/TreeCollection}/styles.ts +0 -0
- /package/src/TreeBrowser/{TreeCollection → v1/TreeCollection}/theme.ts +0 -0
- /package/src/TreeBrowser/{TreeNode → v1/TreeNode}/props.ts +0 -0
- /package/src/TreeBrowser/{props.ts → v1/props.ts} +0 -0
- /package/src/TreeBrowser/{styles.ts → v1/styles.ts} +0 -0
- /package/src/TreeBrowser/{theme.ts → v1/theme.ts} +0 -0
- /package/types/TreeBrowser/{TreeBrowserContext.d.ts → v1/TreeBrowserContext.d.ts} +0 -0
- /package/types/TreeBrowser/{TreeButton → v1/TreeButton}/index.d.ts +0 -0
- /package/types/TreeBrowser/{TreeButton → v1/TreeButton}/props.d.ts +0 -0
- /package/types/TreeBrowser/{TreeButton → v1/TreeButton}/styles.d.ts +0 -0
- /package/types/TreeBrowser/{TreeButton → v1/TreeButton}/theme.d.ts +0 -0
- /package/types/TreeBrowser/{TreeCollection → v1/TreeCollection}/props.d.ts +0 -0
- /package/types/TreeBrowser/{TreeCollection → v1/TreeCollection}/styles.d.ts +0 -0
- /package/types/TreeBrowser/{TreeCollection → v1/TreeCollection}/theme.d.ts +0 -0
- /package/types/TreeBrowser/{TreeNode → v1/TreeNode}/index.d.ts +0 -0
- /package/types/TreeBrowser/{TreeNode → v1/TreeNode}/props.d.ts +0 -0
- /package/types/TreeBrowser/{index.d.ts → v1/index.d.ts} +0 -0
- /package/types/TreeBrowser/{props.d.ts → v1/props.d.ts} +0 -0
- /package/types/TreeBrowser/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/TreeBrowser/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { Component, ContextType, ReactElement, SyntheticEvent } from 'react'
|
|
26
|
+
|
|
27
|
+
import { withStyle } from '@instructure/emotion'
|
|
28
|
+
import { safeCloneElement } from '@instructure/ui-react-utils'
|
|
29
|
+
|
|
30
|
+
import { TreeButton } from '../TreeButton'
|
|
31
|
+
|
|
32
|
+
import generateStyles from './styles'
|
|
33
|
+
import type { TreeBrowserCollectionProps, TreeCollectionState } from './props'
|
|
34
|
+
import type { CompareObject } from '../props'
|
|
35
|
+
import { allowedProps } from './props'
|
|
36
|
+
import { CollectionItem, CollectionProps, CollectionData } from '../props'
|
|
37
|
+
import TreeBrowserContext from '../TreeBrowserContext'
|
|
38
|
+
|
|
39
|
+
type AriaSelectedType = { 'aria-selected'?: boolean }
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
---
|
|
43
|
+
parent: TreeBrowser
|
|
44
|
+
id: TreeBrowser.Collection
|
|
45
|
+
---
|
|
46
|
+
**/
|
|
47
|
+
@withStyle(generateStyles, 'TreeBrowserTreeCollection')
|
|
48
|
+
class TreeCollection extends Component<
|
|
49
|
+
TreeBrowserCollectionProps,
|
|
50
|
+
TreeCollectionState
|
|
51
|
+
> {
|
|
52
|
+
static readonly componentId = 'TreeBrowser.Collection'
|
|
53
|
+
|
|
54
|
+
static allowedProps = allowedProps
|
|
55
|
+
|
|
56
|
+
static contextType = TreeBrowserContext
|
|
57
|
+
declare context: ContextType<typeof TreeBrowserContext>
|
|
58
|
+
|
|
59
|
+
static defaultProps = {
|
|
60
|
+
collections: [],
|
|
61
|
+
items: [],
|
|
62
|
+
expanded: false,
|
|
63
|
+
selection: '',
|
|
64
|
+
size: 'medium',
|
|
65
|
+
variant: 'folderTree',
|
|
66
|
+
getItemProps: (props: unknown) => props,
|
|
67
|
+
getCollectionProps: (props: unknown) => props,
|
|
68
|
+
isCollectionFlattened: false
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
ref: Element | null = null
|
|
72
|
+
|
|
73
|
+
constructor(props: TreeBrowserCollectionProps) {
|
|
74
|
+
super(props)
|
|
75
|
+
this.state = { focused: '' }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
componentDidMount() {
|
|
79
|
+
this.props.makeStyles?.({ animation: this.context?.animation })
|
|
80
|
+
}
|
|
81
|
+
componentDidUpdate() {
|
|
82
|
+
this.props.makeStyles?.({ animation: this.context?.animation })
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get itemsLevel() {
|
|
86
|
+
const { level, isCollectionFlattened } = this.props
|
|
87
|
+
return isCollectionFlattened ? level : level + 1
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
handleFocus = (e: SyntheticEvent, item: CollectionData) => {
|
|
91
|
+
e.stopPropagation()
|
|
92
|
+
this.setState({ focused: `${item.type}_${item.id}` })
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
handleBlur = (e: SyntheticEvent, _item: CollectionData) => {
|
|
96
|
+
e.stopPropagation()
|
|
97
|
+
this.setState({ focused: '' })
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
handleCollectionClick = (e: React.MouseEvent) => {
|
|
101
|
+
const { id, onCollectionClick, expanded } = this.props
|
|
102
|
+
const collection = {
|
|
103
|
+
id,
|
|
104
|
+
expanded: !expanded,
|
|
105
|
+
type: 'collection' as const
|
|
106
|
+
}
|
|
107
|
+
if (onCollectionClick && typeof onCollectionClick === 'function') {
|
|
108
|
+
onCollectionClick(e, collection)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
handleCollectionKeyDown = (e: React.KeyboardEvent) => {
|
|
113
|
+
const { id, onKeyDown, expanded } = this.props
|
|
114
|
+
const collection = {
|
|
115
|
+
id,
|
|
116
|
+
expanded: !expanded,
|
|
117
|
+
type: 'collection' as const
|
|
118
|
+
}
|
|
119
|
+
if (onKeyDown && typeof onKeyDown === 'function') {
|
|
120
|
+
onKeyDown(e, collection)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
get collectionsCount() {
|
|
125
|
+
const collections = this.props.collections
|
|
126
|
+
return collections && collections.length > 0 ? collections.length : 0
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
get itemsCount() {
|
|
130
|
+
const items = this.props.items
|
|
131
|
+
return items && items.length > 0 ? items.length : 0
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
get childCount() {
|
|
135
|
+
return (
|
|
136
|
+
this.collectionsCount +
|
|
137
|
+
this.itemsCount +
|
|
138
|
+
(this.props.renderBeforeItems ? 1 : 0) +
|
|
139
|
+
(this.props.renderAfterItems ? 1 : 0)
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
sortChildren() {
|
|
143
|
+
const { collections, items, compareFunc } = this.props
|
|
144
|
+
if (!compareFunc) return []
|
|
145
|
+
const collections_: CompareObject[] = collections
|
|
146
|
+
? collections.map((collection) => {
|
|
147
|
+
return { ...collection, type: 'collection' }
|
|
148
|
+
})
|
|
149
|
+
: []
|
|
150
|
+
const items_: CompareObject[] = items
|
|
151
|
+
? items.map((item) => {
|
|
152
|
+
return { ...item, type: 'item' }
|
|
153
|
+
})
|
|
154
|
+
: []
|
|
155
|
+
const renderQueue = collections_.concat(items_)
|
|
156
|
+
renderQueue.sort(compareFunc)
|
|
157
|
+
return renderQueue
|
|
158
|
+
}
|
|
159
|
+
renderChildren() {
|
|
160
|
+
const {
|
|
161
|
+
collections,
|
|
162
|
+
items,
|
|
163
|
+
id,
|
|
164
|
+
renderBeforeItems,
|
|
165
|
+
renderAfterItems,
|
|
166
|
+
compareFunc
|
|
167
|
+
} = this.props
|
|
168
|
+
|
|
169
|
+
let position = 1
|
|
170
|
+
const sortedChildren = this.sortChildren()
|
|
171
|
+
return (
|
|
172
|
+
<>
|
|
173
|
+
{renderBeforeItems &&
|
|
174
|
+
this.renderCollectionChildren(
|
|
175
|
+
id,
|
|
176
|
+
renderBeforeItems,
|
|
177
|
+
position++,
|
|
178
|
+
'before'
|
|
179
|
+
)}
|
|
180
|
+
{!compareFunc &&
|
|
181
|
+
collections!.map((collection) => {
|
|
182
|
+
return this.renderCollectionNode(collection, position++)
|
|
183
|
+
})}
|
|
184
|
+
{!compareFunc &&
|
|
185
|
+
items!.map((item) => {
|
|
186
|
+
return this.renderItemNode(item, position++)
|
|
187
|
+
})}
|
|
188
|
+
{compareFunc &&
|
|
189
|
+
sortedChildren.map((child) => {
|
|
190
|
+
if (child.type === 'collection') {
|
|
191
|
+
return this.renderCollectionNode(
|
|
192
|
+
child as CollectionProps,
|
|
193
|
+
position++
|
|
194
|
+
)
|
|
195
|
+
} else {
|
|
196
|
+
return this.renderItemNode(child as CollectionItem, position++)
|
|
197
|
+
}
|
|
198
|
+
})}
|
|
199
|
+
{renderAfterItems &&
|
|
200
|
+
this.renderCollectionChildren(
|
|
201
|
+
id,
|
|
202
|
+
renderAfterItems,
|
|
203
|
+
position++,
|
|
204
|
+
'after'
|
|
205
|
+
)}
|
|
206
|
+
</>
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
renderCollectionChildren(
|
|
211
|
+
collectionId: string | number | undefined,
|
|
212
|
+
child: ReactElement<any>,
|
|
213
|
+
position: number,
|
|
214
|
+
keyword: 'before' | 'after'
|
|
215
|
+
) {
|
|
216
|
+
const { selection, onKeyDown, getItemProps, styles } = this.props
|
|
217
|
+
const key = `${collectionId}_${keyword}`
|
|
218
|
+
const ariaSelected: AriaSelectedType = {}
|
|
219
|
+
if (selection) {
|
|
220
|
+
ariaSelected['aria-selected'] = selection === `child_${key}`
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const itemHash: CollectionData = { id: key, type: 'child' }
|
|
224
|
+
|
|
225
|
+
const itemProps = getItemProps!({
|
|
226
|
+
key: key,
|
|
227
|
+
selected: selection === `child_${key}`,
|
|
228
|
+
focused: this.state.focused === `child_${key}`,
|
|
229
|
+
level: this.itemsLevel,
|
|
230
|
+
size: this.props.size,
|
|
231
|
+
variant: this.props.variant
|
|
232
|
+
})
|
|
233
|
+
return (
|
|
234
|
+
<li
|
|
235
|
+
id={key}
|
|
236
|
+
/* eslint-disable-next-line jsx-a11y/role-has-required-aria-props */
|
|
237
|
+
role="treeitem"
|
|
238
|
+
css={styles?.item}
|
|
239
|
+
tabIndex={-1}
|
|
240
|
+
key={key}
|
|
241
|
+
aria-posinset={position}
|
|
242
|
+
aria-setsize={this.childCount}
|
|
243
|
+
aria-level={this.itemsLevel}
|
|
244
|
+
{...ariaSelected}
|
|
245
|
+
onClick={(e) => {
|
|
246
|
+
if (typeof child.props.onClick === 'function') {
|
|
247
|
+
child.props.onClick(e)
|
|
248
|
+
} else {
|
|
249
|
+
e.stopPropagation()
|
|
250
|
+
}
|
|
251
|
+
}}
|
|
252
|
+
onFocus={(e) => this.handleFocus(e, itemHash)}
|
|
253
|
+
onKeyDown={(e) => {
|
|
254
|
+
if (typeof child.props.onKeyDown === 'function') {
|
|
255
|
+
child.props.onKeyDown(e)
|
|
256
|
+
} else {
|
|
257
|
+
onKeyDown?.(e, itemHash)
|
|
258
|
+
}
|
|
259
|
+
}}
|
|
260
|
+
onBlur={(e) => this.handleBlur(e, itemHash)}
|
|
261
|
+
>
|
|
262
|
+
{safeCloneElement(child, itemProps)}
|
|
263
|
+
</li>
|
|
264
|
+
)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
renderCollectionNode(collection: CollectionProps, position: number) {
|
|
268
|
+
return (
|
|
269
|
+
<TreeCollection
|
|
270
|
+
{...this.props}
|
|
271
|
+
key={`c${position}`}
|
|
272
|
+
id={collection.id}
|
|
273
|
+
name={collection.name}
|
|
274
|
+
descriptor={collection.descriptor}
|
|
275
|
+
expanded={collection.expanded}
|
|
276
|
+
items={collection.items}
|
|
277
|
+
collections={collection.collections}
|
|
278
|
+
numChildren={this.childCount}
|
|
279
|
+
level={this.itemsLevel}
|
|
280
|
+
containerRef={collection.containerRef}
|
|
281
|
+
position={position}
|
|
282
|
+
renderBeforeItems={collection.renderBeforeItems}
|
|
283
|
+
renderAfterItems={collection.renderAfterItems}
|
|
284
|
+
isCollectionFlattened={false} // only the root needs to be flattened
|
|
285
|
+
compareFunc={collection.compareFunc}
|
|
286
|
+
/>
|
|
287
|
+
)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
renderItemNode(item: CollectionItem, position: number) {
|
|
291
|
+
const { selection, onItemClick, onKeyDown, getItemProps, styles } =
|
|
292
|
+
this.props
|
|
293
|
+
|
|
294
|
+
const ariaSelected: AriaSelectedType = {}
|
|
295
|
+
|
|
296
|
+
if (selection) {
|
|
297
|
+
ariaSelected['aria-selected'] = selection === `item_${item.id}`
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const itemHash: CollectionData = { id: item.id, type: 'item' }
|
|
301
|
+
|
|
302
|
+
const itemProps = getItemProps!({
|
|
303
|
+
...this.getCommonButtonProps(),
|
|
304
|
+
id: item.id,
|
|
305
|
+
name: item.name,
|
|
306
|
+
descriptor: item.descriptor,
|
|
307
|
+
thumbnail: item.thumbnail,
|
|
308
|
+
selected: selection === `item_${item.id}`,
|
|
309
|
+
focused: this.state.focused === `item_${item.id}`,
|
|
310
|
+
type: 'item' as const
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
return (
|
|
314
|
+
<li
|
|
315
|
+
key={`i${position}`}
|
|
316
|
+
tabIndex={-1}
|
|
317
|
+
/* eslint-disable-next-line jsx-a11y/role-has-required-aria-props */
|
|
318
|
+
role="treeitem"
|
|
319
|
+
aria-label={item.name}
|
|
320
|
+
css={styles?.item}
|
|
321
|
+
aria-level={this.itemsLevel}
|
|
322
|
+
aria-posinset={position}
|
|
323
|
+
aria-setsize={this.childCount}
|
|
324
|
+
onClick={(e) => onItemClick?.(e, itemHash)}
|
|
325
|
+
onKeyDown={(e) => onKeyDown?.(e, itemHash)}
|
|
326
|
+
onFocus={(e) => this.handleFocus(e, itemHash)}
|
|
327
|
+
onBlur={(e) => this.handleBlur(e, itemHash)}
|
|
328
|
+
{...ariaSelected}
|
|
329
|
+
>
|
|
330
|
+
<TreeButton {...itemProps} />
|
|
331
|
+
</li>
|
|
332
|
+
)
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
getCommonButtonProps() {
|
|
336
|
+
return {
|
|
337
|
+
id: this.props.id,
|
|
338
|
+
name: this.props.name,
|
|
339
|
+
descriptor: this.props.descriptor,
|
|
340
|
+
size: this.props.size,
|
|
341
|
+
variant: this.props.variant,
|
|
342
|
+
itemIcon: this.props.itemIcon,
|
|
343
|
+
level: this.itemsLevel,
|
|
344
|
+
renderContent: this.props.renderContent
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
render() {
|
|
349
|
+
const {
|
|
350
|
+
id,
|
|
351
|
+
name,
|
|
352
|
+
expanded,
|
|
353
|
+
collectionIcon,
|
|
354
|
+
collectionIconExpanded,
|
|
355
|
+
isCollectionFlattened,
|
|
356
|
+
getCollectionProps,
|
|
357
|
+
level,
|
|
358
|
+
position,
|
|
359
|
+
styles
|
|
360
|
+
} = this.props
|
|
361
|
+
|
|
362
|
+
const collectionProps = getCollectionProps!({
|
|
363
|
+
...this.getCommonButtonProps(),
|
|
364
|
+
expanded: expanded,
|
|
365
|
+
collectionIcon: collectionIcon,
|
|
366
|
+
collectionIconExpanded: collectionIconExpanded,
|
|
367
|
+
type: 'collection' as const,
|
|
368
|
+
containerRef: this.props.containerRef,
|
|
369
|
+
selected: this.props.selection === `collection_${id}`,
|
|
370
|
+
focused: this.state.focused === `collection_${id}`,
|
|
371
|
+
level
|
|
372
|
+
})
|
|
373
|
+
|
|
374
|
+
const ariaSelected: AriaSelectedType = { 'aria-selected': undefined }
|
|
375
|
+
if (this.props.selection)
|
|
376
|
+
ariaSelected['aria-selected'] =
|
|
377
|
+
this.props.selection === `collection_${id}`
|
|
378
|
+
|
|
379
|
+
return isCollectionFlattened ? (
|
|
380
|
+
this.renderChildren()
|
|
381
|
+
) : (
|
|
382
|
+
<li
|
|
383
|
+
ref={(el) => {
|
|
384
|
+
this.ref = el
|
|
385
|
+
}}
|
|
386
|
+
css={styles?.treeCollection}
|
|
387
|
+
tabIndex={-1}
|
|
388
|
+
/* eslint-disable-next-line jsx-a11y/role-has-required-aria-props */
|
|
389
|
+
role="treeitem"
|
|
390
|
+
aria-label={`${this.props.name}${
|
|
391
|
+
this.props.descriptor ? ` ${this.props.descriptor}` : ''
|
|
392
|
+
}`}
|
|
393
|
+
aria-level={level}
|
|
394
|
+
aria-posinset={position}
|
|
395
|
+
aria-setsize={this.props.numChildren}
|
|
396
|
+
aria-expanded={expanded}
|
|
397
|
+
onClick={this.handleCollectionClick}
|
|
398
|
+
onKeyDown={this.handleCollectionKeyDown}
|
|
399
|
+
onFocus={(e) => this.handleFocus(e, { id: id, type: 'collection' })}
|
|
400
|
+
onBlur={(e) => this.handleBlur(e, { id: id, type: 'collection' })}
|
|
401
|
+
{...ariaSelected}
|
|
402
|
+
data-cid="TreeCollection"
|
|
403
|
+
>
|
|
404
|
+
<TreeButton {...collectionProps} />
|
|
405
|
+
{expanded && this.childCount > 0 && (
|
|
406
|
+
<ul aria-label={name} css={styles?.list} role="group">
|
|
407
|
+
{this.renderChildren()}
|
|
408
|
+
</ul>
|
|
409
|
+
)}
|
|
410
|
+
</li>
|
|
411
|
+
)
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
export default TreeCollection
|
|
416
|
+
export { TreeCollection }
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import React from 'react'
|
|
26
|
+
|
|
27
|
+
import type { CollectionData } from '../props'
|
|
28
|
+
import type { TreeBrowserCollectionTheme } from '@instructure/shared-types'
|
|
29
|
+
import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
30
|
+
import { CollectionProps, TreeBrowserBaseProps } from '../props'
|
|
31
|
+
|
|
32
|
+
type TreeBrowserCollectionOwnProps = {
|
|
33
|
+
level: number
|
|
34
|
+
onKeyDown?: (e: React.KeyboardEvent, data: CollectionData) => void
|
|
35
|
+
// TODO it would be nice to use the same handler as in TreeBrowser
|
|
36
|
+
onItemClick?: (e: React.MouseEvent, data: CollectionData) => void
|
|
37
|
+
numChildren?: number
|
|
38
|
+
position?: number
|
|
39
|
+
selection?: string
|
|
40
|
+
} & CollectionProps &
|
|
41
|
+
TreeBrowserBaseProps
|
|
42
|
+
|
|
43
|
+
type PropKeys = keyof TreeBrowserCollectionOwnProps
|
|
44
|
+
|
|
45
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
46
|
+
|
|
47
|
+
type TreeBrowserCollectionProps = TreeBrowserCollectionOwnProps &
|
|
48
|
+
WithStyleProps<TreeBrowserCollectionTheme, TreeBrowserCollectionStyle>
|
|
49
|
+
|
|
50
|
+
type TreeBrowserCollectionStyle = ComponentStyle<
|
|
51
|
+
'treeCollection' | 'list' | 'item'
|
|
52
|
+
>
|
|
53
|
+
const allowedProps: AllowedPropKeys = [
|
|
54
|
+
'id',
|
|
55
|
+
'name',
|
|
56
|
+
'descriptor',
|
|
57
|
+
'items',
|
|
58
|
+
'collections',
|
|
59
|
+
'expanded',
|
|
60
|
+
'selection',
|
|
61
|
+
'size',
|
|
62
|
+
'variant',
|
|
63
|
+
'collectionIcon',
|
|
64
|
+
'collectionIconExpanded',
|
|
65
|
+
'itemIcon',
|
|
66
|
+
'getItemProps',
|
|
67
|
+
'getCollectionProps',
|
|
68
|
+
'onItemClick',
|
|
69
|
+
'onCollectionClick',
|
|
70
|
+
'onKeyDown',
|
|
71
|
+
'numChildren',
|
|
72
|
+
'level',
|
|
73
|
+
'position',
|
|
74
|
+
'renderBeforeItems',
|
|
75
|
+
'renderAfterItems',
|
|
76
|
+
'containerRef',
|
|
77
|
+
'isCollectionFlattened',
|
|
78
|
+
'renderContent'
|
|
79
|
+
]
|
|
80
|
+
|
|
81
|
+
type TreeCollectionState = { focused: string }
|
|
82
|
+
|
|
83
|
+
export type {
|
|
84
|
+
TreeBrowserCollectionProps,
|
|
85
|
+
TreeBrowserCollectionStyle,
|
|
86
|
+
TreeCollectionState
|
|
87
|
+
}
|
|
88
|
+
export { allowedProps }
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { keyframes, calcFocusOutlineStyles } from '@instructure/emotion'
|
|
26
|
+
|
|
27
|
+
import type { NewComponentTypes, SharedTokens } from '@instructure/ui-themes'
|
|
28
|
+
import type {
|
|
29
|
+
TreeBrowserCollectionProps,
|
|
30
|
+
TreeBrowserCollectionStyle
|
|
31
|
+
} from './props'
|
|
32
|
+
|
|
33
|
+
const list = keyframes`
|
|
34
|
+
to {
|
|
35
|
+
transform: scaleY(1);
|
|
36
|
+
}`
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* ---
|
|
40
|
+
* private: true
|
|
41
|
+
* ---
|
|
42
|
+
* Generates the style object from the theme and provided additional information
|
|
43
|
+
* @param {Object} componentTheme The theme variable object.
|
|
44
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
45
|
+
* @param {Object} sharedTokens Shared token object that stores common values for the theme.
|
|
46
|
+
* @param {Object} state the state of the component, the style is applied to
|
|
47
|
+
* @return {Object} The final style object, which will be used in the component
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
const generateStyles = (
|
|
51
|
+
componentTheme: NewComponentTypes['TreeBrowserTreeCollection'],
|
|
52
|
+
props: TreeBrowserCollectionProps,
|
|
53
|
+
sharedTokens: SharedTokens,
|
|
54
|
+
state: { animation?: boolean }
|
|
55
|
+
): TreeBrowserCollectionStyle => {
|
|
56
|
+
const { size, variant } = props
|
|
57
|
+
const sizeMap = {
|
|
58
|
+
small: {
|
|
59
|
+
indent: {
|
|
60
|
+
marginInlineStart: `calc(${componentTheme.baseSpacingSmall} * 3)`,
|
|
61
|
+
marginInlineEnd: 0
|
|
62
|
+
},
|
|
63
|
+
folderTree: {
|
|
64
|
+
marginInlineStart: `calc(${componentTheme.baseSpacingSmall} * 2)`,
|
|
65
|
+
marginInlineEnd: 0,
|
|
66
|
+
paddingTop: `calc(1.75 * ${componentTheme.baseSpacingSmall})`,
|
|
67
|
+
marginTop: `calc(-1.75 * ${componentTheme.baseSpacingSmall})`
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
medium: {
|
|
71
|
+
indent: {
|
|
72
|
+
marginInlineStart: `calc(${componentTheme.baseSpacingMedium} * 3)`,
|
|
73
|
+
marginInlineEnd: 0
|
|
74
|
+
},
|
|
75
|
+
folderTree: {
|
|
76
|
+
marginInlineStart: `calc(${componentTheme.baseSpacingMedium} * 2)`,
|
|
77
|
+
marginInlineEnd: 0,
|
|
78
|
+
paddingTop: componentTheme.baseSpacingMedium,
|
|
79
|
+
marginTop: `calc(-1 * ${componentTheme.baseSpacingMedium})`
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
large: {
|
|
83
|
+
indent: {
|
|
84
|
+
marginInlineStart: `calc(${componentTheme.baseSpacingLarge} * 3)`,
|
|
85
|
+
marginInlineEnd: 0
|
|
86
|
+
},
|
|
87
|
+
folderTree: {
|
|
88
|
+
marginInlineStart: `calc(${componentTheme.baseSpacingLarge} * 2)`,
|
|
89
|
+
marginInlineEnd: 0,
|
|
90
|
+
paddingTop: `calc(0.875 * ${componentTheme.baseSpacingMedium})`,
|
|
91
|
+
marginTop: `calc(-0.875 * ${componentTheme.baseSpacingMedium})`
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
treeCollection: {
|
|
97
|
+
label: 'treeCollection',
|
|
98
|
+
fontFamily: componentTheme.fontFamily,
|
|
99
|
+
margin: 0,
|
|
100
|
+
padding: 0,
|
|
101
|
+
'&:focus': {
|
|
102
|
+
outline: 0,
|
|
103
|
+
'> button, > div': {
|
|
104
|
+
...calcFocusOutlineStyles(sharedTokens.focusOutline, {
|
|
105
|
+
withFocusOutline: true
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
list: {
|
|
111
|
+
label: 'treeCollection__list',
|
|
112
|
+
fontFamily: 'inherit',
|
|
113
|
+
boxSizing: 'border-box',
|
|
114
|
+
margin: 0,
|
|
115
|
+
padding: 0,
|
|
116
|
+
listStyleType: 'none',
|
|
117
|
+
position: 'relative',
|
|
118
|
+
...(variant === 'folderTree' && {
|
|
119
|
+
'&::before': {
|
|
120
|
+
content: '""',
|
|
121
|
+
position: 'absolute',
|
|
122
|
+
top: '0.25rem',
|
|
123
|
+
bottom: '1.1875rem',
|
|
124
|
+
insetInlineStart: '0',
|
|
125
|
+
insetInlineEnd: 'auto',
|
|
126
|
+
...(state.animation
|
|
127
|
+
? {
|
|
128
|
+
transform: 'scaleY(0.01)',
|
|
129
|
+
transformOrigin: 'center top',
|
|
130
|
+
animationName: list,
|
|
131
|
+
animationDuration: '0.2s',
|
|
132
|
+
animationFillMode: 'forwards',
|
|
133
|
+
animationTimingFunction: 'ease-out'
|
|
134
|
+
}
|
|
135
|
+
: {}),
|
|
136
|
+
pointerEvents: 'none',
|
|
137
|
+
width: componentTheme.borderWidth,
|
|
138
|
+
background: componentTheme.borderColor // Tree vertical lines
|
|
139
|
+
}
|
|
140
|
+
}),
|
|
141
|
+
...sizeMap[size!][variant!]
|
|
142
|
+
},
|
|
143
|
+
item: {
|
|
144
|
+
label: 'treeCollection__label',
|
|
145
|
+
'&:focus': {
|
|
146
|
+
outline: 0,
|
|
147
|
+
'> button, > div': {
|
|
148
|
+
...calcFocusOutlineStyles(sharedTokens.focusOutline, {
|
|
149
|
+
withFocusOutline: true
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export default generateStyles
|