@grucloud/bau-ui 0.28.0 → 0.30.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/LICENSE +21 -0
- package/breadcrumbs/breadcrumbs.js +48 -0
- package/breadcrumbs/index.d.ts +13 -0
- package/breadcrumbs/index.js +1 -0
- package/globalStyle/globalStyle.js +9 -6
- package/package.json +4 -4
- package/tabs/tabs.js +0 -1
- package/themeSwitch/index.d.ts +10 -0
- package/themeSwitch/index.js +1 -0
- package/themeSwitch/themeSwitch.js +81 -0
- package/treeView/index.d.ts +6 -1
- package/treeView/treeView.js +78 -44
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Bau
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import classNames from "@grucloud/bau-css/classNames.js";
|
|
2
|
+
|
|
3
|
+
export default function (context) {
|
|
4
|
+
const { bau, css } = context;
|
|
5
|
+
const { ul, li, a, span } = bau.tags;
|
|
6
|
+
|
|
7
|
+
const className = css`
|
|
8
|
+
list-style: none;
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
padding-left: 0;
|
|
12
|
+
margin-bottom: 0;
|
|
13
|
+
& li {
|
|
14
|
+
display: flex;
|
|
15
|
+
align-items: center;
|
|
16
|
+
font-size: 0.9rem;
|
|
17
|
+
&::after {
|
|
18
|
+
content: "\u3009";
|
|
19
|
+
padding: 0.5rem;
|
|
20
|
+
}
|
|
21
|
+
&:last-child {
|
|
22
|
+
&::after {
|
|
23
|
+
content: "";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
> a,
|
|
27
|
+
span {
|
|
28
|
+
display: flex;
|
|
29
|
+
text-decoration: none;
|
|
30
|
+
border-radius: var(--global-radius);
|
|
31
|
+
padding: 0.5rem;
|
|
32
|
+
&:hover {
|
|
33
|
+
background-color: var(--color-emphasis-100);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
return function Breadcrumbs({ items, ...otherProps }) {
|
|
39
|
+
return ul(
|
|
40
|
+
{
|
|
41
|
+
"aria-label": "Breadcrumbs",
|
|
42
|
+
...otherProps,
|
|
43
|
+
class: classNames(className, otherProps.class),
|
|
44
|
+
},
|
|
45
|
+
items.map(({ href, name }) => li((href ? a : span)({ href }, name)))
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare module "@grucloud/bau-ui/breadcrumbs" {
|
|
2
|
+
export type BreadcrumbsProps = {
|
|
3
|
+
separator?: string;
|
|
4
|
+
//TODO
|
|
5
|
+
items: any[];
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
type Component = import("../bau-ui").Component<BreadcrumbsProps>;
|
|
9
|
+
|
|
10
|
+
type ComponentGeneric = import("../bau-ui").ComponentGeneric;
|
|
11
|
+
|
|
12
|
+
export default function (context: Object): Component;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./breadcrumbs";
|
|
@@ -19,20 +19,22 @@ const SHADES_DARK = [
|
|
|
19
19
|
];
|
|
20
20
|
|
|
21
21
|
const buildGrays = () =>
|
|
22
|
-
new Array(
|
|
22
|
+
new Array(20)
|
|
23
23
|
.fill("")
|
|
24
24
|
.map(
|
|
25
25
|
(v, index) =>
|
|
26
|
-
`--color-gray-${index *
|
|
26
|
+
`--color-gray-${index * 50}: hsl(0, 0%, ${100 - 5 * index}%);`
|
|
27
27
|
)
|
|
28
28
|
.join("\n");
|
|
29
29
|
|
|
30
|
-
const buildEmphasis = () =>
|
|
31
|
-
new Array(
|
|
30
|
+
export const buildEmphasis = ({ dark }) =>
|
|
31
|
+
new Array(20)
|
|
32
32
|
.fill("")
|
|
33
33
|
.map(
|
|
34
34
|
(v, index) =>
|
|
35
|
-
`--color-emphasis-${index *
|
|
35
|
+
`--color-emphasis-${index * 50}: var(--color-gray-${
|
|
36
|
+
dark ? 1000 - index * 50 : index * 50
|
|
37
|
+
});`
|
|
36
38
|
)
|
|
37
39
|
.join("\n");
|
|
38
40
|
|
|
@@ -70,7 +72,7 @@ export default function globalStyle(
|
|
|
70
72
|
--color-black: #000;
|
|
71
73
|
${colorPalette.map(([color, hsl]) => buildColor([color, hsl])).join("\n")}
|
|
72
74
|
${buildGrays()}
|
|
73
|
-
${buildEmphasis()}
|
|
75
|
+
${buildEmphasis({})}
|
|
74
76
|
--color-content: hsl(0, 0%, 10%);
|
|
75
77
|
--color-content-inverse: hsl(0, 0%, 90%);
|
|
76
78
|
--color-content-secondary: hsl(0, 0%, 30%);
|
|
@@ -99,6 +101,7 @@ export default function globalStyle(
|
|
|
99
101
|
0 2px 4px 0 rgba(0, 0, 0, 0.1);
|
|
100
102
|
--font-size-base: 100%;
|
|
101
103
|
--line-height-base: 1.65;
|
|
104
|
+
--link-color: var(--color-primary)
|
|
102
105
|
}
|
|
103
106
|
:root {
|
|
104
107
|
font-family: var(--font-family);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grucloud/bau-ui",
|
|
3
3
|
"description": "Components library built with Bau",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.30.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "BSD",
|
|
7
7
|
"keywords": [
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"url": "git@github.com:grucloud/bau.git"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@grucloud/bau": "^0.
|
|
21
|
-
"@grucloud/bau-css": "^0.
|
|
20
|
+
"@grucloud/bau": "^0.30.0",
|
|
21
|
+
"@grucloud/bau-css": "^0.30.0"
|
|
22
22
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "25a7c1f3d9681cf7344b3eb16d20383a6e319ba0"
|
|
24
24
|
}
|
package/tabs/tabs.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./themeSwitch";
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import classNames from "@grucloud/bau-css/classNames";
|
|
2
|
+
|
|
3
|
+
const defaultMode = "light";
|
|
4
|
+
|
|
5
|
+
export default function (context) {
|
|
6
|
+
const { bau, css, window } = context;
|
|
7
|
+
const { input } = bau.tags;
|
|
8
|
+
|
|
9
|
+
const setDataThemeAttribute = (theme) => {
|
|
10
|
+
window.document.documentElement.setAttribute("data-theme", theme);
|
|
11
|
+
localStorage.setItem("theme", theme);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const getStoredTheme = () => {
|
|
15
|
+
try {
|
|
16
|
+
return localStorage.getItem("theme");
|
|
17
|
+
} catch (err) {}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const storedTheme = getStoredTheme();
|
|
21
|
+
if (storedTheme) {
|
|
22
|
+
setDataThemeAttribute(storedTheme);
|
|
23
|
+
} else {
|
|
24
|
+
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
25
|
+
setDataThemeAttribute("dark");
|
|
26
|
+
} else if (window.matchMedia("(prefers-color-scheme: light)").matches) {
|
|
27
|
+
setDataThemeAttribute("light");
|
|
28
|
+
} else {
|
|
29
|
+
setDataThemeAttribute(defaultMode);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const style = css`
|
|
34
|
+
position: relative;
|
|
35
|
+
width: 2.5rem;
|
|
36
|
+
height: 2.5rem;
|
|
37
|
+
border: 1px var(--color-gray-200) dotted;
|
|
38
|
+
border-radius: var(--global-radius);
|
|
39
|
+
appearance: none;
|
|
40
|
+
transition: all var(--transition-fast);
|
|
41
|
+
&:hover {
|
|
42
|
+
cursor: pointer;
|
|
43
|
+
border: 1px var(--color-primary) dotted;
|
|
44
|
+
&::after {
|
|
45
|
+
color: var(--color-primary);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
&::after {
|
|
49
|
+
content: "\u2600";
|
|
50
|
+
font-size: x-large;
|
|
51
|
+
display: block;
|
|
52
|
+
width: 100%;
|
|
53
|
+
text-align: center;
|
|
54
|
+
transition: all var(--transition-fast);
|
|
55
|
+
color: var(--color-emphasis-400);
|
|
56
|
+
}
|
|
57
|
+
&:checked {
|
|
58
|
+
}
|
|
59
|
+
&:checked::after {
|
|
60
|
+
content: "\u263D";
|
|
61
|
+
font-size: xx-large;
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
return function ThemeSwitch(props, ...children) {
|
|
66
|
+
return input(
|
|
67
|
+
{
|
|
68
|
+
...props,
|
|
69
|
+
class: classNames(style, props.class),
|
|
70
|
+
type: "checkbox",
|
|
71
|
+
required: "required",
|
|
72
|
+
title: "Switch Theme",
|
|
73
|
+
checked: getStoredTheme() == "dark",
|
|
74
|
+
onclick: (event) => {
|
|
75
|
+
setDataThemeAttribute(event.target.checked ? "dark" : "light");
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
...children
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
}
|
package/treeView/index.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
declare module "@grucloud/bau-ui/treeView" {
|
|
2
|
+
type Tree = {
|
|
3
|
+
data?: object;
|
|
4
|
+
children?: Tree[];
|
|
5
|
+
expanded?: boolean;
|
|
6
|
+
};
|
|
2
7
|
export type TreeViewProps = {
|
|
3
|
-
tree:
|
|
8
|
+
tree: Tree;
|
|
4
9
|
};
|
|
5
10
|
|
|
6
11
|
type Component = import("../bau-ui").Component<TreeViewProps>;
|
package/treeView/treeView.js
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import classNames from "@grucloud/bau-css/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
|
-
}
|
|
1
|
+
import classNames from "@grucloud/bau-css/classNames.js";
|
|
10
2
|
|
|
11
3
|
const createStyles = ({ css, createGlobalStyles }) => {
|
|
12
4
|
createGlobalStyles`
|
|
@@ -17,7 +9,6 @@ const createStyles = ({ css, createGlobalStyles }) => {
|
|
|
17
9
|
--menu-color-background-hover: var(--hover-overlay);
|
|
18
10
|
--menu-link-padding-horizontal: 0.75rem;
|
|
19
11
|
--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
12
|
}
|
|
22
13
|
`;
|
|
23
14
|
|
|
@@ -36,21 +27,26 @@ const createStyles = ({ css, createGlobalStyles }) => {
|
|
|
36
27
|
padding-left: var(--menu-link-padding-horizontal);
|
|
37
28
|
border-radius: 0.25rem;
|
|
38
29
|
> div {
|
|
30
|
+
width: 100%;
|
|
39
31
|
display: flex;
|
|
32
|
+
justify-content: space-between;
|
|
33
|
+
transition: background-color var(--transition-fast) ease-in-out;
|
|
40
34
|
&:hover {
|
|
41
|
-
background: var(--
|
|
35
|
+
background: var(--color-emphasis-100);
|
|
36
|
+
}
|
|
37
|
+
&::after {
|
|
38
|
+
transition: transform var(--transition-fast) linear;
|
|
39
|
+
font-size: x-large;
|
|
40
|
+
margin-right: 0.5rem;
|
|
42
41
|
}
|
|
43
|
-
> a
|
|
42
|
+
> a,
|
|
43
|
+
span {
|
|
44
44
|
display: flex;
|
|
45
|
+
flex-grow: 1;
|
|
45
46
|
text-decoration: none;
|
|
46
47
|
color: var(--menu-color);
|
|
47
48
|
padding: var(--menu-link-padding-vertical)
|
|
48
49
|
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
|
-
width: 1.25rem;
|
|
53
|
-
}
|
|
54
50
|
}
|
|
55
51
|
}
|
|
56
52
|
}
|
|
@@ -59,19 +55,19 @@ const createStyles = ({ css, createGlobalStyles }) => {
|
|
|
59
55
|
|
|
60
56
|
return {
|
|
61
57
|
nav,
|
|
62
|
-
|
|
63
|
-
> div
|
|
64
|
-
&::
|
|
65
|
-
content: "";
|
|
58
|
+
expanded: css`
|
|
59
|
+
> div {
|
|
60
|
+
&::after {
|
|
61
|
+
content: "\u203A";
|
|
66
62
|
transform: rotate(90deg);
|
|
67
63
|
}
|
|
68
64
|
}
|
|
69
65
|
`,
|
|
70
66
|
collapsed: css`
|
|
71
|
-
> div
|
|
72
|
-
&::
|
|
73
|
-
content: "";
|
|
74
|
-
transform: rotate(
|
|
67
|
+
> div {
|
|
68
|
+
&::after {
|
|
69
|
+
content: "\u203A";
|
|
70
|
+
transform: rotate(0deg);
|
|
75
71
|
}
|
|
76
72
|
}
|
|
77
73
|
`,
|
|
@@ -79,51 +75,89 @@ const createStyles = ({ css, createGlobalStyles }) => {
|
|
|
79
75
|
};
|
|
80
76
|
|
|
81
77
|
export default function (context, { renderMenuItem }) {
|
|
82
|
-
const { bau, css, createGlobalStyles } = context;
|
|
83
|
-
const { ul, li, nav } = bau.tags;
|
|
78
|
+
const { bau, css, createGlobalStyles, window } = context;
|
|
79
|
+
const { ul, li, nav, div } = bau.tags;
|
|
84
80
|
|
|
85
81
|
const styles = createStyles({ css, createGlobalStyles });
|
|
86
82
|
|
|
83
|
+
const collapseOrExpandSection = ({ element, closeState }) => {
|
|
84
|
+
closeState.val ? collapseSection(element) : expandSection(element);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
function collapseSection(element) {
|
|
88
|
+
element.style.height = element.scrollHeight + "px";
|
|
89
|
+
const animationEndHandler = () => {
|
|
90
|
+
element.removeEventListener("transitionend", animationEndHandler);
|
|
91
|
+
};
|
|
92
|
+
element.addEventListener("transitionend", animationEndHandler);
|
|
93
|
+
window.requestAnimationFrame(() => {
|
|
94
|
+
element.style.height = "0px";
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function expandSection(element) {
|
|
99
|
+
const animationEndHandler = () => {
|
|
100
|
+
element.removeEventListener("transitionend", animationEndHandler);
|
|
101
|
+
element.style.height = null;
|
|
102
|
+
};
|
|
103
|
+
element.addEventListener("transitionend", animationEndHandler);
|
|
104
|
+
element.style.height = element.scrollHeight + "px";
|
|
105
|
+
}
|
|
106
|
+
|
|
87
107
|
const Tree =
|
|
88
|
-
({ depth =
|
|
108
|
+
({ depth = 1, maxDepth }) =>
|
|
89
109
|
(item) => {
|
|
90
|
-
const { children } = item;
|
|
91
|
-
const closeState = bau.state(
|
|
110
|
+
const { children, expanded } = item;
|
|
111
|
+
const closeState = bau.state(!expanded);
|
|
92
112
|
return li(
|
|
93
113
|
{
|
|
94
114
|
class: () =>
|
|
95
115
|
classNames(
|
|
96
116
|
children
|
|
97
117
|
? closeState.val
|
|
98
|
-
? styles.
|
|
99
|
-
: styles.
|
|
118
|
+
? styles.collapsed
|
|
119
|
+
: styles.expanded
|
|
100
120
|
: ""
|
|
101
121
|
),
|
|
102
|
-
onclick: (event) => {
|
|
103
|
-
closeState.val = !closeState.val;
|
|
104
|
-
event.preventDefault();
|
|
105
|
-
},
|
|
106
122
|
},
|
|
107
|
-
|
|
123
|
+
div(
|
|
124
|
+
{
|
|
125
|
+
class: css`
|
|
126
|
+
cursor: pointer;
|
|
127
|
+
`,
|
|
128
|
+
onclick: (event) => {
|
|
129
|
+
if (children) {
|
|
130
|
+
closeState.val = !closeState.val;
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
renderMenuItem(item.data)
|
|
135
|
+
),
|
|
108
136
|
children &&
|
|
137
|
+
depth < maxDepth &&
|
|
109
138
|
ul(
|
|
110
139
|
{
|
|
111
|
-
|
|
140
|
+
bauMounted: ({ element }) => {
|
|
112
141
|
closeState.val
|
|
113
|
-
?
|
|
114
|
-
:
|
|
142
|
+
? (element.style.height = "0px")
|
|
143
|
+
: (element.style.height = element.scrollHeight + "px");
|
|
144
|
+
},
|
|
145
|
+
"aria-expanded": ({ element }) => {
|
|
146
|
+
collapseOrExpandSection({ element, closeState });
|
|
115
147
|
return !closeState.val;
|
|
116
148
|
},
|
|
117
149
|
},
|
|
118
|
-
children.map(Tree({ depth: depth + 1 }))
|
|
150
|
+
children.map(Tree({ depth: depth + 1, maxDepth }))
|
|
119
151
|
)
|
|
120
152
|
);
|
|
121
153
|
};
|
|
122
154
|
|
|
123
|
-
return function TreeView({ tree, ...otherProps }) {
|
|
155
|
+
return function TreeView({ tree, maxDepth = Infinity, ...otherProps }) {
|
|
124
156
|
return nav(
|
|
125
|
-
{
|
|
126
|
-
|
|
157
|
+
{
|
|
158
|
+
class: classNames(styles.nav, otherProps.class),
|
|
159
|
+
},
|
|
160
|
+
tree.children && ul(tree.children.map(Tree({ maxDepth })))
|
|
127
161
|
);
|
|
128
162
|
};
|
|
129
163
|
}
|