@grucloud/bau-ui 0.27.0 → 0.29.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/alertStack/alertStack.js +5 -2
- 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/modal/modal.js +1 -1
- package/package.json +4 -4
- package/tabs/tabs.js +5 -3
- 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 -42
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.
|
package/alertStack/alertStack.js
CHANGED
|
@@ -89,8 +89,11 @@ export default (context, { limit = 10, deleteAfterDuration = 15e3 } = {}) => {
|
|
|
89
89
|
},
|
|
90
90
|
bau.bind({
|
|
91
91
|
deps: [messagesState],
|
|
92
|
-
render:
|
|
93
|
-
|
|
92
|
+
render:
|
|
93
|
+
({ renderItem }) =>
|
|
94
|
+
(arr) =>
|
|
95
|
+
div(arr.map(renderItem)),
|
|
96
|
+
renderItem: () => AlertItem,
|
|
94
97
|
})
|
|
95
98
|
);
|
|
96
99
|
};
|
|
@@ -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/modal/modal.js
CHANGED
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.29.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.29.0",
|
|
21
|
+
"@grucloud/bau-css": "^0.29.0"
|
|
22
22
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "366971382c70242ac47853d97b29b25263143922"
|
|
24
24
|
}
|
package/tabs/tabs.js
CHANGED
|
@@ -60,7 +60,6 @@ export default function (context, { tabDefs }) {
|
|
|
60
60
|
cursor: not-allowed;
|
|
61
61
|
font-style: italic;
|
|
62
62
|
color: var(--font-color-disabled);
|
|
63
|
-
background-color: white;
|
|
64
63
|
transform: none;
|
|
65
64
|
&:hover {
|
|
66
65
|
color: var(--font-color-disabled);
|
|
@@ -101,8 +100,11 @@ export default function (context, { tabDefs }) {
|
|
|
101
100
|
// Header
|
|
102
101
|
bau.bind({
|
|
103
102
|
deps: [tabsState],
|
|
104
|
-
render:
|
|
105
|
-
|
|
103
|
+
render:
|
|
104
|
+
({ renderItem }) =>
|
|
105
|
+
(arr) =>
|
|
106
|
+
ul(arr.map(renderItem)),
|
|
107
|
+
renderItem: () => TabHeader,
|
|
106
108
|
}),
|
|
107
109
|
// Content
|
|
108
110
|
() => (tabCurrentState.val.Content ? tabCurrentState.val.Content({}) : "")
|
|
@@ -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`
|
|
@@ -36,21 +28,27 @@ const createStyles = ({ css, createGlobalStyles }) => {
|
|
|
36
28
|
padding-left: var(--menu-link-padding-horizontal);
|
|
37
29
|
border-radius: 0.25rem;
|
|
38
30
|
> div {
|
|
31
|
+
width: 100%;
|
|
39
32
|
display: flex;
|
|
33
|
+
justify-content: space-between;
|
|
34
|
+
transition: background-color var(--transition-fast) ease-in-out;
|
|
40
35
|
&:hover {
|
|
41
|
-
background: var(--
|
|
36
|
+
background: var(--color-emphasis-100);
|
|
37
|
+
}
|
|
38
|
+
&::after {
|
|
39
|
+
transition: transform var(--transition-fast) linear;
|
|
40
|
+
background: var(--menu-link-sublist-icon) 50% / 2rem 2rem;
|
|
41
|
+
width: 1.25rem;
|
|
42
|
+
padding: 0.5rem;
|
|
42
43
|
}
|
|
43
|
-
> a
|
|
44
|
+
> a,
|
|
45
|
+
span {
|
|
44
46
|
display: flex;
|
|
47
|
+
flex-grow: 1;
|
|
45
48
|
text-decoration: none;
|
|
46
49
|
color: var(--menu-color);
|
|
47
50
|
padding: var(--menu-link-padding-vertical)
|
|
48
51
|
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
52
|
}
|
|
55
53
|
}
|
|
56
54
|
}
|
|
@@ -59,19 +57,19 @@ const createStyles = ({ css, createGlobalStyles }) => {
|
|
|
59
57
|
|
|
60
58
|
return {
|
|
61
59
|
nav,
|
|
62
|
-
|
|
63
|
-
> div
|
|
64
|
-
&::
|
|
60
|
+
expanded: css`
|
|
61
|
+
> div {
|
|
62
|
+
&::after {
|
|
65
63
|
content: "";
|
|
66
|
-
transform: rotate(
|
|
64
|
+
transform: rotate(180deg);
|
|
67
65
|
}
|
|
68
66
|
}
|
|
69
67
|
`,
|
|
70
68
|
collapsed: css`
|
|
71
|
-
> div
|
|
72
|
-
&::
|
|
69
|
+
> div {
|
|
70
|
+
&::after {
|
|
73
71
|
content: "";
|
|
74
|
-
transform: rotate(
|
|
72
|
+
transform: rotate(90deg);
|
|
75
73
|
}
|
|
76
74
|
}
|
|
77
75
|
`,
|
|
@@ -79,51 +77,89 @@ const createStyles = ({ css, createGlobalStyles }) => {
|
|
|
79
77
|
};
|
|
80
78
|
|
|
81
79
|
export default function (context, { renderMenuItem }) {
|
|
82
|
-
const { bau, css, createGlobalStyles } = context;
|
|
83
|
-
const { ul, li, nav } = bau.tags;
|
|
80
|
+
const { bau, css, createGlobalStyles, window } = context;
|
|
81
|
+
const { ul, li, nav, div } = bau.tags;
|
|
84
82
|
|
|
85
83
|
const styles = createStyles({ css, createGlobalStyles });
|
|
86
84
|
|
|
85
|
+
const collapseOrExpandSection = ({ element, closeState }) => {
|
|
86
|
+
closeState.val ? collapseSection(element) : expandSection(element);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
function collapseSection(element) {
|
|
90
|
+
element.style.height = element.scrollHeight + "px";
|
|
91
|
+
const animationEndHandler = () => {
|
|
92
|
+
element.removeEventListener("transitionend", animationEndHandler);
|
|
93
|
+
};
|
|
94
|
+
element.addEventListener("transitionend", animationEndHandler);
|
|
95
|
+
window.requestAnimationFrame(() => {
|
|
96
|
+
element.style.height = "0px";
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function expandSection(element) {
|
|
101
|
+
const animationEndHandler = () => {
|
|
102
|
+
element.removeEventListener("transitionend", animationEndHandler);
|
|
103
|
+
element.style.height = null;
|
|
104
|
+
};
|
|
105
|
+
element.addEventListener("transitionend", animationEndHandler);
|
|
106
|
+
element.style.height = element.scrollHeight + "px";
|
|
107
|
+
}
|
|
108
|
+
|
|
87
109
|
const Tree =
|
|
88
|
-
({ depth =
|
|
110
|
+
({ depth = 1, maxDepth }) =>
|
|
89
111
|
(item) => {
|
|
90
|
-
const { children } = item;
|
|
91
|
-
const closeState = bau.state(
|
|
112
|
+
const { children, expanded } = item;
|
|
113
|
+
const closeState = bau.state(!expanded);
|
|
92
114
|
return li(
|
|
93
115
|
{
|
|
94
116
|
class: () =>
|
|
95
117
|
classNames(
|
|
96
118
|
children
|
|
97
119
|
? closeState.val
|
|
98
|
-
? styles.
|
|
99
|
-
: styles.
|
|
120
|
+
? styles.collapsed
|
|
121
|
+
: styles.expanded
|
|
100
122
|
: ""
|
|
101
123
|
),
|
|
102
|
-
onclick: (event) => {
|
|
103
|
-
closeState.val = !closeState.val;
|
|
104
|
-
event.preventDefault();
|
|
105
|
-
},
|
|
106
124
|
},
|
|
107
|
-
|
|
125
|
+
div(
|
|
126
|
+
{
|
|
127
|
+
class: css`
|
|
128
|
+
cursor: pointer;
|
|
129
|
+
`,
|
|
130
|
+
onclick: (event) => {
|
|
131
|
+
if (children) {
|
|
132
|
+
closeState.val = !closeState.val;
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
renderMenuItem(item.data)
|
|
137
|
+
),
|
|
108
138
|
children &&
|
|
139
|
+
depth < maxDepth &&
|
|
109
140
|
ul(
|
|
110
141
|
{
|
|
111
|
-
|
|
142
|
+
bauMounted: ({ element }) => {
|
|
112
143
|
closeState.val
|
|
113
|
-
?
|
|
114
|
-
:
|
|
144
|
+
? (element.style.height = "0px")
|
|
145
|
+
: (element.style.height = element.scrollHeight + "px");
|
|
146
|
+
},
|
|
147
|
+
"aria-expanded": ({ element }) => {
|
|
148
|
+
collapseOrExpandSection({ element, closeState });
|
|
115
149
|
return !closeState.val;
|
|
116
150
|
},
|
|
117
151
|
},
|
|
118
|
-
children.map(Tree({ depth: depth + 1 }))
|
|
152
|
+
children.map(Tree({ depth: depth + 1, maxDepth }))
|
|
119
153
|
)
|
|
120
154
|
);
|
|
121
155
|
};
|
|
122
156
|
|
|
123
|
-
return function TreeView({ tree, ...otherProps }) {
|
|
157
|
+
return function TreeView({ tree, maxDepth = Infinity, ...otherProps }) {
|
|
124
158
|
return nav(
|
|
125
|
-
{
|
|
126
|
-
|
|
159
|
+
{
|
|
160
|
+
class: classNames(styles.nav, otherProps.class),
|
|
161
|
+
},
|
|
162
|
+
tree.children && ul(tree.children.map(Tree({ maxDepth })))
|
|
127
163
|
);
|
|
128
164
|
};
|
|
129
165
|
}
|