@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,202 @@
|
|
|
1
|
+
var _dec, _class, _TreeButton;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { Component } from 'react';
|
|
27
|
+
import { Img } from '@instructure/ui-img/latest';
|
|
28
|
+
import { withStyle } from '@instructure/emotion';
|
|
29
|
+
import { renderIconWithProps } from '@instructure/ui-icons';
|
|
30
|
+
import generateStyles from "./styles.js";
|
|
31
|
+
import { allowedProps } from "./props.js";
|
|
32
|
+
import TreeBrowserContext from "../TreeBrowserContext.js"; // Todo: merge TreeButton and TreeNode: TreeButton should be a special type of TreeNode
|
|
33
|
+
// Map TreeBrowser size tokens to icon size tokens
|
|
34
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
35
|
+
const treeBrowserSizeToIconSize = {
|
|
36
|
+
small: 'md',
|
|
37
|
+
medium: 'lg',
|
|
38
|
+
large: 'xl'
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
---
|
|
43
|
+
parent: TreeBrowser
|
|
44
|
+
id: TreeBrowser.Button
|
|
45
|
+
---
|
|
46
|
+
**/
|
|
47
|
+
let TreeButton = (_dec = withStyle(generateStyles, 'TreeBrowserTreeButton'), _dec(_class = (_TreeButton = class TreeButton extends Component {
|
|
48
|
+
constructor(...args) {
|
|
49
|
+
super(...args);
|
|
50
|
+
this.ref = null;
|
|
51
|
+
this.state = {
|
|
52
|
+
isHovered: false
|
|
53
|
+
};
|
|
54
|
+
this.handleRef = el => {
|
|
55
|
+
if (el && typeof this.props.containerRef === 'function') {
|
|
56
|
+
this.props.containerRef(el.parentElement);
|
|
57
|
+
}
|
|
58
|
+
this.ref = el;
|
|
59
|
+
};
|
|
60
|
+
this.handleMouseEnter = () => {
|
|
61
|
+
if (this.props.hoverable) {
|
|
62
|
+
this.setState({
|
|
63
|
+
isHovered: true
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
this.handleMouseLeave = () => {
|
|
68
|
+
if (this.props.hoverable) {
|
|
69
|
+
this.setState({
|
|
70
|
+
isHovered: false
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
componentDidMount() {
|
|
76
|
+
var _this$props$makeStyle, _this$props, _this$context;
|
|
77
|
+
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props, {
|
|
78
|
+
animation: (_this$context = this.context) === null || _this$context === void 0 ? void 0 : _this$context.animation,
|
|
79
|
+
hoverable: this.props.hoverable
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
componentDidUpdate() {
|
|
83
|
+
var _this$props$makeStyle2, _this$props2, _this$context2;
|
|
84
|
+
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2, {
|
|
85
|
+
animation: (_this$context2 = this.context) === null || _this$context2 === void 0 ? void 0 : _this$context2.animation,
|
|
86
|
+
hoverable: this.props.hoverable
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
defaultContentRenderer(props) {
|
|
90
|
+
const name = props.name,
|
|
91
|
+
descriptor = props.descriptor,
|
|
92
|
+
styles = props.styles;
|
|
93
|
+
return _jsxs("span", {
|
|
94
|
+
css: styles.layout,
|
|
95
|
+
children: [this.renderImage(), _jsxs("span", {
|
|
96
|
+
css: styles.text,
|
|
97
|
+
children: [_jsx("span", {
|
|
98
|
+
css: styles.textName,
|
|
99
|
+
children: name
|
|
100
|
+
}), descriptor ? _jsx("span", {
|
|
101
|
+
css: styles.textDescriptor,
|
|
102
|
+
title: descriptor,
|
|
103
|
+
children: descriptor
|
|
104
|
+
}) : null]
|
|
105
|
+
})]
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
getIconColor() {
|
|
109
|
+
const selected = this.props.selected;
|
|
110
|
+
const isHovered = this.state.isHovered;
|
|
111
|
+
|
|
112
|
+
// Priority: selected > hover > default
|
|
113
|
+
if (selected) return 'onColor';
|
|
114
|
+
if (isHovered) return 'inverseColor';
|
|
115
|
+
return 'baseColor';
|
|
116
|
+
}
|
|
117
|
+
renderImage() {
|
|
118
|
+
const type = this.props.type;
|
|
119
|
+
switch (type) {
|
|
120
|
+
case 'collection':
|
|
121
|
+
return this.renderCollectionIcon();
|
|
122
|
+
case 'item':
|
|
123
|
+
return this.renderItemImage();
|
|
124
|
+
default:
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
return void 0;
|
|
128
|
+
}
|
|
129
|
+
renderCollectionIcon() {
|
|
130
|
+
const _this$props3 = this.props,
|
|
131
|
+
expanded = _this$props3.expanded,
|
|
132
|
+
collectionIcon = _this$props3.collectionIcon,
|
|
133
|
+
collectionIconExpanded = _this$props3.collectionIconExpanded,
|
|
134
|
+
styles = _this$props3.styles,
|
|
135
|
+
size = _this$props3.size;
|
|
136
|
+
if (collectionIcon || collectionIconExpanded) {
|
|
137
|
+
const icon = expanded ? collectionIconExpanded : collectionIcon;
|
|
138
|
+
const iconSize = treeBrowserSizeToIconSize[size];
|
|
139
|
+
const iconColor = this.getIconColor();
|
|
140
|
+
const iconElement = renderIconWithProps(icon, iconSize, iconColor);
|
|
141
|
+
return _jsx("div", {
|
|
142
|
+
css: styles === null || styles === void 0 ? void 0 : styles.icon,
|
|
143
|
+
children: iconElement
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
return void 0;
|
|
147
|
+
}
|
|
148
|
+
renderItemImage() {
|
|
149
|
+
const _this$props4 = this.props,
|
|
150
|
+
thumbnail = _this$props4.thumbnail,
|
|
151
|
+
itemIcon = _this$props4.itemIcon,
|
|
152
|
+
styles = _this$props4.styles,
|
|
153
|
+
size = _this$props4.size;
|
|
154
|
+
if (thumbnail) {
|
|
155
|
+
return _jsx("div", {
|
|
156
|
+
css: styles === null || styles === void 0 ? void 0 : styles.thumbnail,
|
|
157
|
+
children: _jsx(Img, {
|
|
158
|
+
src: thumbnail,
|
|
159
|
+
constrain: "cover",
|
|
160
|
+
alt: ""
|
|
161
|
+
})
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
if (itemIcon) {
|
|
165
|
+
const iconSize = treeBrowserSizeToIconSize[size];
|
|
166
|
+
const iconColor = this.getIconColor();
|
|
167
|
+
const iconElement = renderIconWithProps(itemIcon, iconSize, iconColor);
|
|
168
|
+
return _jsx("div", {
|
|
169
|
+
css: styles === null || styles === void 0 ? void 0 : styles.icon,
|
|
170
|
+
children: iconElement
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return void 0;
|
|
174
|
+
}
|
|
175
|
+
render() {
|
|
176
|
+
const _this$props5 = this.props,
|
|
177
|
+
styles = _this$props5.styles,
|
|
178
|
+
renderContent = _this$props5.renderContent;
|
|
179
|
+
const buttonContent = renderContent ? renderContent(this.props) : this.defaultContentRenderer(this.props);
|
|
180
|
+
// VoiceOver can't navigate without the buttons, even though they don't do anything
|
|
181
|
+
return _jsx("button", {
|
|
182
|
+
ref: this.handleRef,
|
|
183
|
+
tabIndex: -1,
|
|
184
|
+
type: "button",
|
|
185
|
+
css: styles === null || styles === void 0 ? void 0 : styles.treeButton,
|
|
186
|
+
"data-cid": "TreeButton",
|
|
187
|
+
onMouseEnter: this.handleMouseEnter,
|
|
188
|
+
onMouseLeave: this.handleMouseLeave,
|
|
189
|
+
children: buttonContent
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}, _TreeButton.displayName = "TreeButton", _TreeButton.componentId = 'TreeBrowser.Button', _TreeButton.allowedProps = allowedProps, _TreeButton.contextType = TreeBrowserContext, _TreeButton.defaultProps = {
|
|
193
|
+
type: 'treeButton',
|
|
194
|
+
size: 'medium',
|
|
195
|
+
variant: 'folderTree',
|
|
196
|
+
selected: false,
|
|
197
|
+
focused: false,
|
|
198
|
+
expanded: false,
|
|
199
|
+
hoverable: true
|
|
200
|
+
}, _TreeButton)) || _class);
|
|
201
|
+
export default TreeButton;
|
|
202
|
+
export { TreeButton };
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
const allowedProps = ['id', 'name', 'descriptor', 'type', 'size', 'variant', 'collectionIcon', 'collectionIconExpanded', 'itemIcon', 'thumbnail', 'onClick', 'expanded', 'selected', 'focused', 'level', 'containerRef', 'renderContent', 'hoverable'];
|
|
26
|
+
export { allowedProps };
|
|
@@ -0,0 +1,306 @@
|
|
|
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
|
+
const transform = keyframes`
|
|
27
|
+
50% {
|
|
28
|
+
opacity: 0.5;
|
|
29
|
+
transform: translate3d(2%, 0, 0);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
100% {
|
|
33
|
+
opacity: 1;
|
|
34
|
+
transform: translate3d(0, 0, 0);
|
|
35
|
+
}`;
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* ---
|
|
39
|
+
* private: true
|
|
40
|
+
* ---
|
|
41
|
+
* Generates the style object from the theme and provided additional information
|
|
42
|
+
* @param {Object} componentTheme The theme variable object.
|
|
43
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
44
|
+
* @param {Object} state the state of the component, the style is applied to
|
|
45
|
+
* @return {Object} The final style object, which will be used in the component
|
|
46
|
+
*/
|
|
47
|
+
const generateStyles = (componentTheme, props, sharedTokens, state) => {
|
|
48
|
+
const size = props.size,
|
|
49
|
+
variant = props.variant,
|
|
50
|
+
selected = props.selected,
|
|
51
|
+
level = props.level;
|
|
52
|
+
const isRootButton = level && level === 1;
|
|
53
|
+
const sizeMap = {
|
|
54
|
+
small: {
|
|
55
|
+
folderTree: {
|
|
56
|
+
before: {
|
|
57
|
+
width: componentTheme.baseSpacingSmall
|
|
58
|
+
},
|
|
59
|
+
icon: {
|
|
60
|
+
marginInlineEnd: componentTheme.iconsMarginRightSmall,
|
|
61
|
+
marginInlineStart: '0'
|
|
62
|
+
},
|
|
63
|
+
thumbnail: {
|
|
64
|
+
height: `calc(${componentTheme.baseSpacingSmall} * 2)`,
|
|
65
|
+
width: `calc(${componentTheme.baseSpacingSmall}* 2)`,
|
|
66
|
+
marginInlineEnd: componentTheme.iconsMarginRightSmall,
|
|
67
|
+
marginInlineStart: '0'
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
indent: {
|
|
71
|
+
icon: {
|
|
72
|
+
marginInlineEnd: componentTheme.iconsMarginRightSmall,
|
|
73
|
+
marginInlineStart: '0'
|
|
74
|
+
},
|
|
75
|
+
thumbnail: {
|
|
76
|
+
height: `calc(${componentTheme.baseSpacingSmall} * 2)`,
|
|
77
|
+
width: `calc(${componentTheme.baseSpacingSmall} * 2)`,
|
|
78
|
+
marginInlineEnd: componentTheme.iconsMarginRightSmall,
|
|
79
|
+
marginInlineStart: '0'
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
textName: {
|
|
83
|
+
fontSize: componentTheme.nameFontSizeSmall
|
|
84
|
+
},
|
|
85
|
+
textDescriptor: {
|
|
86
|
+
fontSize: componentTheme.descriptorFontSizeSmall
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
medium: {
|
|
90
|
+
folderTree: {
|
|
91
|
+
before: {
|
|
92
|
+
width: componentTheme.baseSpacingMedium
|
|
93
|
+
},
|
|
94
|
+
icon: {
|
|
95
|
+
marginInlineEnd: componentTheme.iconsMarginRightMedium,
|
|
96
|
+
marginInlineStart: '0'
|
|
97
|
+
},
|
|
98
|
+
thumbnail: {
|
|
99
|
+
height: `calc(${componentTheme.baseSpacingMedium} * 2)`,
|
|
100
|
+
width: `calc(${componentTheme.baseSpacingMedium} * 2)`,
|
|
101
|
+
marginInlineEnd: componentTheme.iconsMarginRightMedium,
|
|
102
|
+
marginInlineStart: '0'
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
indent: {
|
|
106
|
+
icon: {
|
|
107
|
+
marginInlineEnd: componentTheme.iconsMarginRightMedium,
|
|
108
|
+
marginInlineStart: '0'
|
|
109
|
+
},
|
|
110
|
+
thumbnail: {
|
|
111
|
+
height: `calc(${componentTheme.baseSpacingMedium} * 2)`,
|
|
112
|
+
width: `calc(${componentTheme.baseSpacingMedium} * 2)`,
|
|
113
|
+
marginInlineEnd: componentTheme.iconsMarginRightMedium,
|
|
114
|
+
marginInlineStart: '0'
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
textName: {
|
|
118
|
+
fontSize: componentTheme.nameFontSizeMedium
|
|
119
|
+
},
|
|
120
|
+
textDescriptor: {
|
|
121
|
+
fontSize: componentTheme.descriptorFontSizeMedium
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
large: {
|
|
125
|
+
folderTree: {
|
|
126
|
+
before: {
|
|
127
|
+
width: componentTheme.baseSpacingLarge
|
|
128
|
+
},
|
|
129
|
+
icon: {
|
|
130
|
+
marginInlineEnd: componentTheme.iconsMarginRightLarge,
|
|
131
|
+
marginInlineStart: '0'
|
|
132
|
+
},
|
|
133
|
+
thumbnail: {
|
|
134
|
+
height: `calc(${componentTheme.baseSpacingLarge} * 2)`,
|
|
135
|
+
width: `calc(${componentTheme.baseSpacingLarge} * 2)`,
|
|
136
|
+
marginInlineEnd: componentTheme.iconsMarginRightLarge,
|
|
137
|
+
marginInlineStart: '0'
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
indent: {
|
|
141
|
+
icon: {
|
|
142
|
+
marginInlineEnd: componentTheme.iconsMarginRightLarge,
|
|
143
|
+
marginInlineStart: '0'
|
|
144
|
+
},
|
|
145
|
+
thumbnail: {
|
|
146
|
+
height: `calc(${componentTheme.baseSpacingLarge} * 2)`,
|
|
147
|
+
width: `calc(${componentTheme.baseSpacingLarge}* 2)`,
|
|
148
|
+
marginInlineEnd: componentTheme.iconsMarginRightLarge,
|
|
149
|
+
marginInlineStart: '0'
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
textName: {
|
|
153
|
+
fontSize: componentTheme.nameFontSizeLarge
|
|
154
|
+
},
|
|
155
|
+
textDescriptor: {
|
|
156
|
+
fontSize: componentTheme.descriptorFontSizeLarge
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
const textStyle = {
|
|
161
|
+
minWidth: '0.0625rem',
|
|
162
|
+
lineHeight: componentTheme.textLineHeight,
|
|
163
|
+
flex: 1
|
|
164
|
+
};
|
|
165
|
+
const textNameStyle = {
|
|
166
|
+
display: 'block',
|
|
167
|
+
overflow: 'hidden',
|
|
168
|
+
whiteSpace: 'nowrap',
|
|
169
|
+
textOverflow: 'ellipsis',
|
|
170
|
+
...sizeMap[size].textName
|
|
171
|
+
};
|
|
172
|
+
const layoutPadding = {
|
|
173
|
+
small: {
|
|
174
|
+
folderTree: {
|
|
175
|
+
padding: `calc(${componentTheme.baseSpacingSmall} / 3) ${componentTheme.baseSpacingSmall}`
|
|
176
|
+
},
|
|
177
|
+
indent: {
|
|
178
|
+
padding: `calc(${componentTheme.baseSpacingSmall} / 3) calc(${componentTheme.baseSpacingSmall} / 2)`
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
medium: {
|
|
182
|
+
folderTree: {
|
|
183
|
+
padding: `calc(${componentTheme.baseSpacingMedium} / 3) ${componentTheme.baseSpacingMedium}`
|
|
184
|
+
},
|
|
185
|
+
indent: {
|
|
186
|
+
padding: `calc(${componentTheme.baseSpacingMedium} / 3) calc(${componentTheme.baseSpacingMedium} / 2)`
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
large: {
|
|
190
|
+
folderTree: {
|
|
191
|
+
padding: `calc(${componentTheme.baseSpacingLarge} / 3) ${componentTheme.baseSpacingLarge}`
|
|
192
|
+
},
|
|
193
|
+
indent: {
|
|
194
|
+
padding: `calc(${componentTheme.baseSpacingLarge} / 3) calc(${componentTheme.baseSpacingLarge} / 2)`
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
return {
|
|
199
|
+
treeButton: {
|
|
200
|
+
label: 'treeButton',
|
|
201
|
+
boxSizing: 'border-box',
|
|
202
|
+
display: 'block',
|
|
203
|
+
width: '100%',
|
|
204
|
+
margin: '0',
|
|
205
|
+
backgroundColor: 'transparent',
|
|
206
|
+
textAlign: 'start',
|
|
207
|
+
fontFamily: 'inherit',
|
|
208
|
+
userSelect: 'none',
|
|
209
|
+
cursor: 'pointer',
|
|
210
|
+
border: 'none',
|
|
211
|
+
borderRadius: componentTheme.borderRadius,
|
|
212
|
+
position: 'relative',
|
|
213
|
+
zIndex: 1,
|
|
214
|
+
...(state !== null && state !== void 0 && state.animation ? {
|
|
215
|
+
transform: 'translate3d(-2%, 0, 0)',
|
|
216
|
+
opacity: 0.01,
|
|
217
|
+
transformOrigin: 'left center',
|
|
218
|
+
animationName: transform,
|
|
219
|
+
animationDuration: '0.2s',
|
|
220
|
+
animationFillMode: 'forwards',
|
|
221
|
+
animationTimingFunction: 'ease-out',
|
|
222
|
+
animationDelay: '0.2s'
|
|
223
|
+
} : {}),
|
|
224
|
+
outline: '0',
|
|
225
|
+
padding: '0',
|
|
226
|
+
...(sharedTokens !== null && sharedTokens !== void 0 && sharedTokens.focusOutline ? calcFocusOutlineStyles(sharedTokens.focusOutline) : {}),
|
|
227
|
+
...(variant === 'folderTree' && !isRootButton && {
|
|
228
|
+
'&::before': {
|
|
229
|
+
content: '""',
|
|
230
|
+
height: componentTheme.borderWidth,
|
|
231
|
+
background: componentTheme.borderColor,
|
|
232
|
+
// Tree horizontal lines
|
|
233
|
+
position: 'absolute',
|
|
234
|
+
insetInlineStart: '0',
|
|
235
|
+
insetInlineEnd: 'auto',
|
|
236
|
+
top: '50%',
|
|
237
|
+
...(selected && {
|
|
238
|
+
visibility: 'hidden'
|
|
239
|
+
}),
|
|
240
|
+
...sizeMap[size][variant].before
|
|
241
|
+
},
|
|
242
|
+
'&:hover::before': {
|
|
243
|
+
visibility: state !== null && state !== void 0 && state.hoverable ? 'hidden' : 'visible'
|
|
244
|
+
}
|
|
245
|
+
}),
|
|
246
|
+
...((state === null || state === void 0 ? void 0 : state.hoverable) !== false && {
|
|
247
|
+
'&:hover': {
|
|
248
|
+
backgroundColor: selected ? componentTheme.selectedBackgroundColor : componentTheme.hoverBackgroundColor,
|
|
249
|
+
'[class$=-treeButton__textName], [class$=-treeButton__textDescriptor], [class$=-treeButton__node]': {
|
|
250
|
+
color: selected ? componentTheme.selectedTextColor : componentTheme.hoverTextColor
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}),
|
|
254
|
+
...(selected && {
|
|
255
|
+
backgroundColor: componentTheme.selectedBackgroundColor
|
|
256
|
+
})
|
|
257
|
+
},
|
|
258
|
+
layout: {
|
|
259
|
+
label: 'treeButton__layout',
|
|
260
|
+
display: 'flex',
|
|
261
|
+
alignItems: 'center',
|
|
262
|
+
lineHeight: 1,
|
|
263
|
+
minHeight: '2rem',
|
|
264
|
+
...layoutPadding[size][variant]
|
|
265
|
+
},
|
|
266
|
+
text: {
|
|
267
|
+
label: 'treeButton__text',
|
|
268
|
+
...textStyle
|
|
269
|
+
},
|
|
270
|
+
textName: {
|
|
271
|
+
label: 'treeButton__textName',
|
|
272
|
+
...textNameStyle,
|
|
273
|
+
color: selected ? componentTheme.selectedTextColor : componentTheme.nameTextColor
|
|
274
|
+
},
|
|
275
|
+
textDescriptor: {
|
|
276
|
+
label: 'treeButton__textDescriptor',
|
|
277
|
+
display: 'block',
|
|
278
|
+
overflow: 'hidden',
|
|
279
|
+
whiteSpace: 'nowrap',
|
|
280
|
+
textOverflow: 'ellipsis',
|
|
281
|
+
marginTop: componentTheme.descriptorMarginTop,
|
|
282
|
+
color: selected ? componentTheme.selectedTextColor : componentTheme.descriptorTextColor,
|
|
283
|
+
...sizeMap[size].textDescriptor
|
|
284
|
+
},
|
|
285
|
+
icon: {
|
|
286
|
+
label: 'treeButton__icon',
|
|
287
|
+
minWidth: '0.0625rem',
|
|
288
|
+
position: 'relative',
|
|
289
|
+
zIndex: 1,
|
|
290
|
+
alignItems: 'center',
|
|
291
|
+
justifyContent: 'center',
|
|
292
|
+
...sizeMap[size][variant].icon
|
|
293
|
+
},
|
|
294
|
+
thumbnail: {
|
|
295
|
+
label: 'treeButton__thumbnail',
|
|
296
|
+
...sizeMap[size][variant].thumbnail
|
|
297
|
+
},
|
|
298
|
+
node: {
|
|
299
|
+
label: 'treeButton__node',
|
|
300
|
+
...textStyle,
|
|
301
|
+
...textNameStyle,
|
|
302
|
+
color: componentTheme.descriptorTextColor
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
};
|
|
306
|
+
export default generateStyles;
|