@grucloud/bau-ui 0.21.0
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/README.md +5 -0
- package/package.json +39 -0
- package/src/alert/alert.js +96 -0
- package/src/alert/index.js +1 -0
- package/src/alertStack/alertStack.js +97 -0
- package/src/alertStack/index.js +1 -0
- package/src/animate/animate.js +42 -0
- package/src/animate/index.js +1 -0
- package/src/avatar/avatar.js +36 -0
- package/src/avatar/index.js +1 -0
- package/src/button/button.js +158 -0
- package/src/button/index.js +1 -0
- package/src/checkbox/checkbox.js +51 -0
- package/src/checkbox/index.js +1 -0
- package/src/drawer/drawer.js +70 -0
- package/src/drawer/index.js +1 -0
- package/src/fileInput/fileInput.js +66 -0
- package/src/fileInput/index.js +1 -0
- package/src/input/index.js +1 -0
- package/src/input/input.js +122 -0
- package/src/modal/index.js +1 -0
- package/src/modal/modal.js +44 -0
- package/src/my-component/component.js +8 -0
- package/src/my-component/index.js +1 -0
- package/src/spinner/index.js +1 -0
- package/src/spinner/spinner.js +63 -0
- package/src/switch/index.js +1 -0
- package/src/switch/switch.js +46 -0
- package/src/tabs/index.js +1 -0
- package/src/tabs/tabs.js +162 -0
- package/src/treeView/index.js +1 -0
- package/src/treeView/treeView.js +129 -0
- package/src/utils/classNames.js +3 -0
- package/src/utils/context.js +13 -0
- package/src/utils/globalStyle.js +100 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { classNames } from "../utils/classNames";
|
|
2
|
+
|
|
3
|
+
const createStyles = ({ css, createGlobalStyles }) => {
|
|
4
|
+
createGlobalStyles`
|
|
5
|
+
:root {
|
|
6
|
+
--input-border-bottom-size: 2px;
|
|
7
|
+
}
|
|
8
|
+
`;
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
base: css`
|
|
12
|
+
position: relative;
|
|
13
|
+
display: inline-block;
|
|
14
|
+
min-height: 3rem;
|
|
15
|
+
|
|
16
|
+
& input {
|
|
17
|
+
font-size: 1.2rem;
|
|
18
|
+
background: var(--color-emphasis-100);
|
|
19
|
+
box-shadow: var(--global-shadow-lw);
|
|
20
|
+
border-radius: var(--global-radius);
|
|
21
|
+
border: var(--input-border-bottom-size) solid transparent;
|
|
22
|
+
border-bottom: var(--input-border-bottom-size) solid
|
|
23
|
+
var(--color-emphasis-900);
|
|
24
|
+
box-sizing: border-box;
|
|
25
|
+
padding: 26px 10px 4px 10px;
|
|
26
|
+
outline: none;
|
|
27
|
+
transition: background-color var(--transition-fast) ease-in-out;
|
|
28
|
+
&:hover {
|
|
29
|
+
background: var(--color-emphasis-200);
|
|
30
|
+
}
|
|
31
|
+
&:focus,
|
|
32
|
+
&:valid {
|
|
33
|
+
border-bottom: var(--input-border-bottom-size) solid
|
|
34
|
+
var(--color-primary);
|
|
35
|
+
}
|
|
36
|
+
&:focus + label,
|
|
37
|
+
&:valid + label,
|
|
38
|
+
&:disabled + label {
|
|
39
|
+
top: 1rem;
|
|
40
|
+
font-size: 0.8rem;
|
|
41
|
+
font-weight: bold;
|
|
42
|
+
color: var(--color-primary);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
& label {
|
|
46
|
+
display: block;
|
|
47
|
+
top: 1.5rem;
|
|
48
|
+
line-height: 0;
|
|
49
|
+
position: absolute;
|
|
50
|
+
pointer-events: none;
|
|
51
|
+
padding: 0px 10px;
|
|
52
|
+
transition: var(--transition-fast) ease-in-out;
|
|
53
|
+
color: var(--font-color-secondary);
|
|
54
|
+
&:focus {
|
|
55
|
+
font-style: normal;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
& div[data-input-error] {
|
|
59
|
+
margin: 0.2rem 0;
|
|
60
|
+
position: absolute;
|
|
61
|
+
background: var(--background-color);
|
|
62
|
+
}
|
|
63
|
+
`,
|
|
64
|
+
disabled: css`
|
|
65
|
+
& * {
|
|
66
|
+
color: var(--font-color-disabled) !important;
|
|
67
|
+
}
|
|
68
|
+
& input {
|
|
69
|
+
border-bottom: var(--input-border-bottom-size) dashed
|
|
70
|
+
var(--font-color-disabled);
|
|
71
|
+
}
|
|
72
|
+
`,
|
|
73
|
+
error: css`
|
|
74
|
+
color: var(--color-danger) !important;
|
|
75
|
+
& * {
|
|
76
|
+
color: var(--color-danger) !important;
|
|
77
|
+
}
|
|
78
|
+
& input {
|
|
79
|
+
border-bottom: var(--input-border-bottom-size) dashed
|
|
80
|
+
var(--color-danger) !important;
|
|
81
|
+
}
|
|
82
|
+
`,
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export default function (context, options = {}) {
|
|
87
|
+
const { bau, css, createGlobalStyles } = context;
|
|
88
|
+
const { div, input, label } = bau.tags;
|
|
89
|
+
|
|
90
|
+
const styles = createStyles({ css, createGlobalStyles });
|
|
91
|
+
|
|
92
|
+
return function Input(props) {
|
|
93
|
+
const {
|
|
94
|
+
name,
|
|
95
|
+
id,
|
|
96
|
+
disabled,
|
|
97
|
+
label: labelValue = "",
|
|
98
|
+
error = "",
|
|
99
|
+
...otherProps
|
|
100
|
+
} = props;
|
|
101
|
+
return div(
|
|
102
|
+
{
|
|
103
|
+
class: classNames(
|
|
104
|
+
styles.base,
|
|
105
|
+
disabled && styles.disabled,
|
|
106
|
+
error && styles.error,
|
|
107
|
+
props.class
|
|
108
|
+
),
|
|
109
|
+
},
|
|
110
|
+
input({
|
|
111
|
+
id,
|
|
112
|
+
name,
|
|
113
|
+
type: "text",
|
|
114
|
+
required: true,
|
|
115
|
+
disabled,
|
|
116
|
+
...otherProps,
|
|
117
|
+
}),
|
|
118
|
+
label({ htmlFor: id }, labelValue),
|
|
119
|
+
div({ "data-input-error": name }, error)
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./modal";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export default function (context, options = {}) {
|
|
2
|
+
const { bau, css } = context;
|
|
3
|
+
const { dialog } = bau.tags;
|
|
4
|
+
|
|
5
|
+
const style = css`
|
|
6
|
+
box-shadow: var(--global-shadow-lw);
|
|
7
|
+
background-color: var(--background-color);
|
|
8
|
+
top: 0;
|
|
9
|
+
left: 0;
|
|
10
|
+
max-height: 90vh;
|
|
11
|
+
max-width: 95vw;
|
|
12
|
+
transition: transform 0.3s ease-out;
|
|
13
|
+
border-radius: 10px;
|
|
14
|
+
min-width: 400px;
|
|
15
|
+
padding: 0px;
|
|
16
|
+
border: 0px;
|
|
17
|
+
& header {
|
|
18
|
+
padding: 1rem;
|
|
19
|
+
font-size: 1.8rem;
|
|
20
|
+
font-weight: 800;
|
|
21
|
+
text-align: center;
|
|
22
|
+
background-color: var(--color-primary);
|
|
23
|
+
color: var(--font-color-base);
|
|
24
|
+
}
|
|
25
|
+
& footer {
|
|
26
|
+
display: flex;
|
|
27
|
+
justify-content: flex-end;
|
|
28
|
+
margin: 0px;
|
|
29
|
+
box-shadow: var(--global-shadow-lw);
|
|
30
|
+
> * {
|
|
31
|
+
margin: 12px;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
& > main {
|
|
35
|
+
margin: 12px;
|
|
36
|
+
flex-grow: 1;
|
|
37
|
+
overflow: scroll;
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
return function Modal({ open }, ...children) {
|
|
42
|
+
return dialog({ class: style }, ...children);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./component";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./spinner";
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export default function (context, options = {}) {
|
|
2
|
+
const { bau, css } = context;
|
|
3
|
+
|
|
4
|
+
const { svg, animate, animateTransform, rect } = bau.tagsNS(
|
|
5
|
+
"http://www.w3.org/2000/svg"
|
|
6
|
+
);
|
|
7
|
+
return function Spinner({
|
|
8
|
+
size = 36,
|
|
9
|
+
color = "primary",
|
|
10
|
+
visibility = true,
|
|
11
|
+
} = {}) {
|
|
12
|
+
return svg(
|
|
13
|
+
{
|
|
14
|
+
class: css`
|
|
15
|
+
visibility: ${visibility ? "visible" : "hidden"};
|
|
16
|
+
color: var(--color-${color});
|
|
17
|
+
`,
|
|
18
|
+
version: "1.1",
|
|
19
|
+
id: "L6",
|
|
20
|
+
x: "0px",
|
|
21
|
+
y: "0px",
|
|
22
|
+
width: size,
|
|
23
|
+
height: size,
|
|
24
|
+
viewBox: `0 0 100 100`,
|
|
25
|
+
enableBackground: `new 0 0 100 100`,
|
|
26
|
+
},
|
|
27
|
+
rect(
|
|
28
|
+
{
|
|
29
|
+
fill: "none",
|
|
30
|
+
stroke: "currentColor",
|
|
31
|
+
strokeWidth: "4",
|
|
32
|
+
x: "25",
|
|
33
|
+
y: "25",
|
|
34
|
+
width: "50",
|
|
35
|
+
height: "50",
|
|
36
|
+
},
|
|
37
|
+
animateTransform({
|
|
38
|
+
attributeName: "transform",
|
|
39
|
+
dur: "0.4s",
|
|
40
|
+
from: "0 50 50",
|
|
41
|
+
to: "180 50 50",
|
|
42
|
+
type: "rotate",
|
|
43
|
+
id: "strokeBox",
|
|
44
|
+
attributeType: "XML",
|
|
45
|
+
begin: "rectBox.end",
|
|
46
|
+
})
|
|
47
|
+
),
|
|
48
|
+
rect(
|
|
49
|
+
{ x: "27", y: "27", fill: "currentColor", width: "46", height: "50" },
|
|
50
|
+
animate({
|
|
51
|
+
attributeName: "height",
|
|
52
|
+
dur: "1.3s",
|
|
53
|
+
attributeType: "XML",
|
|
54
|
+
from: "50",
|
|
55
|
+
to: "0",
|
|
56
|
+
id: "rectBox",
|
|
57
|
+
fill: "freeze",
|
|
58
|
+
begin: "0s;strokeBox.end",
|
|
59
|
+
})
|
|
60
|
+
)
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./switch";
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export default function (context, options = {}) {
|
|
2
|
+
const { bau, css } = context;
|
|
3
|
+
const { input } = bau.tags;
|
|
4
|
+
|
|
5
|
+
const style = css`
|
|
6
|
+
position: relative;
|
|
7
|
+
width: 2rem;
|
|
8
|
+
height: 1rem;
|
|
9
|
+
background-color: var(--color-gray-300);
|
|
10
|
+
border-radius: var(--global-radius);
|
|
11
|
+
appearance: none;
|
|
12
|
+
outline: none;
|
|
13
|
+
transition: all var(--transition-fast);
|
|
14
|
+
box-shadow: var(--global-shadow-md);
|
|
15
|
+
&::after {
|
|
16
|
+
content: "";
|
|
17
|
+
background: var(--background-color);
|
|
18
|
+
transform: translateX(0%) scale(1.3);
|
|
19
|
+
width: 1rem;
|
|
20
|
+
height: 1rem;
|
|
21
|
+
border-radius: 50%;
|
|
22
|
+
position: absolute;
|
|
23
|
+
box-shadow: var(--global-shadow-md);
|
|
24
|
+
background-color: var(--color-gray-700);
|
|
25
|
+
transition: all var(--transition-fast);
|
|
26
|
+
}
|
|
27
|
+
&:checked {
|
|
28
|
+
background-color: var(--color-primary-lighter);
|
|
29
|
+
}
|
|
30
|
+
&:checked::after {
|
|
31
|
+
content: "";
|
|
32
|
+
transform: translateX(100%) scale(1.3);
|
|
33
|
+
background-color: var(--color-primary);
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
return function Switch({ id, ...otherProps }, ...children) {
|
|
38
|
+
return input({
|
|
39
|
+
class: style,
|
|
40
|
+
type: "checkbox",
|
|
41
|
+
required: "required",
|
|
42
|
+
id,
|
|
43
|
+
...otherProps,
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./tabs";
|
package/src/tabs/tabs.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { classNames } from "../utils/classNames";
|
|
2
|
+
|
|
3
|
+
export default function (context, { tabDefs }) {
|
|
4
|
+
const { bau, css } = context;
|
|
5
|
+
const { div, ul, li } = bau.tags;
|
|
6
|
+
const tabsState = bau.state(tabDefs);
|
|
7
|
+
|
|
8
|
+
const tabCurrentState = bau.state(tabDefs[0]);
|
|
9
|
+
|
|
10
|
+
const tabByName = (name) => tabsState.val.find((tab) => tab.name == name);
|
|
11
|
+
|
|
12
|
+
const style = {
|
|
13
|
+
base: css`
|
|
14
|
+
display: flex;
|
|
15
|
+
flex-direction: column;
|
|
16
|
+
& ul {
|
|
17
|
+
display: flex;
|
|
18
|
+
align-items: flex-end;
|
|
19
|
+
justify-content: flex-start;
|
|
20
|
+
padding: 0;
|
|
21
|
+
list-style: none;
|
|
22
|
+
border-bottom: 2px solid var(--color-emphasis-100);
|
|
23
|
+
& li {
|
|
24
|
+
text-align: center;
|
|
25
|
+
padding: 0.5rem;
|
|
26
|
+
padding-bottom: 0rem;
|
|
27
|
+
cursor: pointer;
|
|
28
|
+
font-weight: var(--font-weight-semibold);
|
|
29
|
+
transition: var(--transition-fast) ease-in-out;
|
|
30
|
+
overflow: hidden;
|
|
31
|
+
|
|
32
|
+
&:hover {
|
|
33
|
+
color: var(--color-primary-light);
|
|
34
|
+
background-color: var(--color-emphasis-100);
|
|
35
|
+
&::after {
|
|
36
|
+
transform: translateY(0%);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
&::after {
|
|
40
|
+
transition: var(--transition-fast) ease-in-out;
|
|
41
|
+
transform: translateY(400%);
|
|
42
|
+
background-color: var(--color-primary);
|
|
43
|
+
opacity: 1;
|
|
44
|
+
content: "";
|
|
45
|
+
margin-top: 0.3rem;
|
|
46
|
+
height: 2px;
|
|
47
|
+
width: 100%;
|
|
48
|
+
display: block;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
& .active {
|
|
52
|
+
color: var(--color-primary);
|
|
53
|
+
font-weight: bolder;
|
|
54
|
+
&::after {
|
|
55
|
+
background-color: var(--color-primary);
|
|
56
|
+
transform: translateY(0%);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
& .disabled {
|
|
60
|
+
cursor: not-allowed;
|
|
61
|
+
font-style: italic;
|
|
62
|
+
color: var(--font-color-disabled);
|
|
63
|
+
background-color: white;
|
|
64
|
+
transform: none;
|
|
65
|
+
&:hover {
|
|
66
|
+
color: var(--font-color-disabled);
|
|
67
|
+
border: none;
|
|
68
|
+
&::after {
|
|
69
|
+
transform: none;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
`,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return function Tabs(props, ...children) {
|
|
78
|
+
const TabHeader = (tab) => {
|
|
79
|
+
const { Header, disabled, name } = tab;
|
|
80
|
+
return li(
|
|
81
|
+
{
|
|
82
|
+
class: {
|
|
83
|
+
deps: [tabCurrentState],
|
|
84
|
+
renderProp: () => (tabCurrent) => {
|
|
85
|
+
return classNames(
|
|
86
|
+
tabCurrent.name == name && "active",
|
|
87
|
+
disabled && "disabled"
|
|
88
|
+
);
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
onclick: (event) =>
|
|
92
|
+
event.srcElement.dispatchEvent(
|
|
93
|
+
new CustomEvent("tab.select", {
|
|
94
|
+
detail: { tabName: name },
|
|
95
|
+
bubbles: true,
|
|
96
|
+
})
|
|
97
|
+
),
|
|
98
|
+
},
|
|
99
|
+
Header(tab)
|
|
100
|
+
);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const rootEl = div(
|
|
104
|
+
{ class: classNames(style.base, props.class) },
|
|
105
|
+
// Header
|
|
106
|
+
bau.bind({
|
|
107
|
+
deps: [tabsState],
|
|
108
|
+
render:
|
|
109
|
+
({ renderItem }) =>
|
|
110
|
+
(arr) =>
|
|
111
|
+
ul(arr.map(renderItem())),
|
|
112
|
+
renderItem: () => TabHeader,
|
|
113
|
+
}),
|
|
114
|
+
// Content
|
|
115
|
+
bau.bind({
|
|
116
|
+
deps: [tabCurrentState],
|
|
117
|
+
render:
|
|
118
|
+
() =>
|
|
119
|
+
({ Content }) =>
|
|
120
|
+
Content ? Content({}) : "",
|
|
121
|
+
})
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
rootEl.addEventListener(
|
|
125
|
+
"tab.select",
|
|
126
|
+
(event) => {
|
|
127
|
+
const { tabName } = event.detail;
|
|
128
|
+
const nextTab = tabByName(tabName);
|
|
129
|
+
if (!nextTab) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
tabCurrentState.val.exit?.call();
|
|
133
|
+
tabCurrentState.val = nextTab;
|
|
134
|
+
nextTab.enter?.call();
|
|
135
|
+
},
|
|
136
|
+
false
|
|
137
|
+
);
|
|
138
|
+
rootEl.addEventListener(
|
|
139
|
+
"tab.add",
|
|
140
|
+
(event) => {
|
|
141
|
+
const { tab } = event.detail;
|
|
142
|
+
tab.enter?.call();
|
|
143
|
+
tabsState.val.push(tab);
|
|
144
|
+
},
|
|
145
|
+
false
|
|
146
|
+
);
|
|
147
|
+
rootEl.addEventListener(
|
|
148
|
+
"tab.remove",
|
|
149
|
+
(event) => {
|
|
150
|
+
const index = tabsState.val.findIndex(
|
|
151
|
+
(tab) => tab.name == event.detail.tabName
|
|
152
|
+
);
|
|
153
|
+
if (index > 0) {
|
|
154
|
+
tabsState.val[index].exit?.call();
|
|
155
|
+
tabsState.val.splice(index, 1);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
false
|
|
159
|
+
);
|
|
160
|
+
return rootEl;
|
|
161
|
+
};
|
|
162
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./treeView";
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { classNames } from "../utils/classNames";
|
|
2
|
+
|
|
3
|
+
function collapseSection(element) {
|
|
4
|
+
element.style.height = "0px";
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function expandSection(element) {
|
|
8
|
+
element.style.height = element.scrollHeight + "px";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const createStyles = ({ css, createGlobalStyles }) => {
|
|
12
|
+
createGlobalStyles`
|
|
13
|
+
:root {
|
|
14
|
+
--menu-color: var(--font-color-base);
|
|
15
|
+
--menu-color-active: var(--color-primary);
|
|
16
|
+
--menu-color-background-active: var(--hover-overlay);
|
|
17
|
+
--menu-color-background-hover: var(--hover-overlay);
|
|
18
|
+
--menu-link-padding-horizontal: 0.75rem;
|
|
19
|
+
--menu-link-padding-vertical: 0.375rem;
|
|
20
|
+
--menu-link-sublist-icon: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16px" height="16px" viewBox="0 0 24 24"><path fill="rgba(0,0,0,0.5)" d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"></path></svg>');
|
|
21
|
+
}
|
|
22
|
+
`;
|
|
23
|
+
|
|
24
|
+
const nav = css`
|
|
25
|
+
font-weight: var(--font-weight-semibold);
|
|
26
|
+
overflow-x: hidden;
|
|
27
|
+
& ul {
|
|
28
|
+
display: block;
|
|
29
|
+
list-style: none;
|
|
30
|
+
margin: 0;
|
|
31
|
+
padding-left: 0;
|
|
32
|
+
overflow: hidden;
|
|
33
|
+
will-change: height;
|
|
34
|
+
transition: height var(--transition-fast) ease-out;
|
|
35
|
+
& li {
|
|
36
|
+
padding-left: var(--menu-link-padding-horizontal);
|
|
37
|
+
border-radius: 0.25rem;
|
|
38
|
+
> div {
|
|
39
|
+
display: flex;
|
|
40
|
+
&:hover {
|
|
41
|
+
background: var(--menu-color-background-hover);
|
|
42
|
+
}
|
|
43
|
+
> a {
|
|
44
|
+
display: flex;
|
|
45
|
+
text-decoration: none;
|
|
46
|
+
color: var(--menu-color);
|
|
47
|
+
padding: var(--menu-link-padding-vertical)
|
|
48
|
+
var(--menu-link-padding-horizontal);
|
|
49
|
+
&::before {
|
|
50
|
+
transition: transform var(--transition-fast) linear;
|
|
51
|
+
background: var(--menu-link-sublist-icon) 50% / 2rem 2rem;
|
|
52
|
+
height: 1.25rem;
|
|
53
|
+
width: 1.25rem;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
`;
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
nav,
|
|
63
|
+
collapsable: css`
|
|
64
|
+
> div > a {
|
|
65
|
+
&::before {
|
|
66
|
+
content: "";
|
|
67
|
+
transform: rotate(90deg);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
`,
|
|
71
|
+
collapsed: css`
|
|
72
|
+
> div > a {
|
|
73
|
+
&::before {
|
|
74
|
+
content: "";
|
|
75
|
+
transform: rotate(180deg);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
`,
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export default function (context, { renderMenuItem }) {
|
|
83
|
+
const { bau, css, createGlobalStyles } = context;
|
|
84
|
+
const { ul, li, nav } = bau.tags;
|
|
85
|
+
|
|
86
|
+
const styles = createStyles({ css, createGlobalStyles });
|
|
87
|
+
|
|
88
|
+
const Tree =
|
|
89
|
+
({ depth = 0 }) =>
|
|
90
|
+
(item) => {
|
|
91
|
+
const { children } = item;
|
|
92
|
+
const closeState = bau.state(true);
|
|
93
|
+
return li(
|
|
94
|
+
{
|
|
95
|
+
class: {
|
|
96
|
+
deps: [closeState],
|
|
97
|
+
renderProp: () => (close) =>
|
|
98
|
+
classNames(
|
|
99
|
+
children ? (close ? styles.collapsable : styles.collapsed) : ""
|
|
100
|
+
),
|
|
101
|
+
},
|
|
102
|
+
onclick: (event) => {
|
|
103
|
+
closeState.val = !closeState.val;
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
renderMenuItem(item),
|
|
108
|
+
children &&
|
|
109
|
+
ul(
|
|
110
|
+
{
|
|
111
|
+
"aria-expanded": {
|
|
112
|
+
deps: [closeState],
|
|
113
|
+
renderProp:
|
|
114
|
+
({ dom }) =>
|
|
115
|
+
(close) => {
|
|
116
|
+
close ? collapseSection(dom) : expandSection(dom);
|
|
117
|
+
return !close;
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
children.map(Tree({ depth: depth + 1 }))
|
|
122
|
+
)
|
|
123
|
+
);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return function TreeView(tree) {
|
|
127
|
+
return nav({ class: styles.nav }, ul(tree.children.map(Tree({}))));
|
|
128
|
+
};
|
|
129
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//import Bau from "@grucloud/bau";
|
|
2
|
+
import Bau from "../../../bau/src/bau";
|
|
3
|
+
|
|
4
|
+
import BauCss from "@grucloud/bau-css";
|
|
5
|
+
|
|
6
|
+
export function createContext(extra = {}) {
|
|
7
|
+
return {
|
|
8
|
+
bau: Bau(),
|
|
9
|
+
...BauCss(),
|
|
10
|
+
tr: (text) => text,
|
|
11
|
+
...extra,
|
|
12
|
+
};
|
|
13
|
+
}
|