@grucloud/bau-ui 0.39.0 → 0.41.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/accordion/accordion.js +162 -0
- package/accordion/index.d.ts +26 -0
- package/accordion/index.js +1 -0
- package/alert/alert.js +65 -55
- package/alert/index.d.ts +8 -9
- package/alertStack/alertStack.js +5 -3
- package/alertStack/index.d.ts +5 -2
- package/autocomplete/autocomplete.js +222 -0
- package/autocomplete/index.d.ts +21 -0
- package/autocomplete/index.js +1 -0
- package/avatar/avatar.js +46 -6
- package/avatar/index.d.ts +5 -2
- package/badge/badge.js +43 -0
- package/badge/index.d.ts +16 -0
- package/badge/index.js +1 -0
- package/bau-ui.d.ts +14 -7
- package/breadcrumbs/breadcrumbs.js +30 -6
- package/breadcrumbs/index.d.ts +8 -2
- package/button/button.js +30 -106
- package/button/index.d.ts +4 -7
- package/buttonGroup/buttonGroup.js +68 -0
- package/buttonGroup/index.d.ts +10 -0
- package/buttonGroup/index.js +1 -0
- package/calendar/calendar.js +51 -0
- package/calendar/index.d.ts +13 -0
- package/calendar/index.js +1 -0
- package/checkbox/checkbox.js +66 -39
- package/checkbox/index.d.ts +5 -2
- package/chip/chip.js +60 -0
- package/chip/index.d.ts +10 -0
- package/chip/index.js +1 -0
- package/constants.d.ts +13 -0
- package/constants.js +3 -0
- package/context.d.ts +12 -0
- package/context.js +13 -0
- package/drawer/drawer.js +10 -5
- package/drawer/index.d.ts +5 -2
- package/drillDownMenu/drillDownMenu.js +117 -79
- package/drillDownMenu/index.d.ts +11 -3
- package/fileInput/fileInput.js +20 -10
- package/fileInput/index.d.ts +9 -3
- package/globalStyle/globalStyle.js +110 -60
- package/input/index.d.ts +6 -8
- package/input/input.js +78 -107
- package/list/index.d.ts +10 -0
- package/list/index.js +1 -0
- package/list/list.js +66 -0
- package/modal/index.d.ts +5 -2
- package/modal/modal.js +47 -10
- package/package.json +4 -4
- package/pages/login/index.d.ts +2 -0
- package/popover/index.d.ts +18 -0
- package/popover/index.js +1 -0
- package/popover/popover.js +69 -0
- package/select/index.d.ts +16 -0
- package/select/index.js +1 -0
- package/select/select.js +176 -0
- package/slider/index.d.ts +10 -0
- package/slider/index.js +1 -0
- package/slider/slider.js +47 -0
- package/spinner/index.d.ts +7 -4
- package/spinner/spinner.js +13 -5
- package/switch/index.d.ts +5 -2
- package/switch/switch.js +101 -18
- package/tableContainer/index.d.ts +9 -0
- package/tableContainer/index.js +1 -0
- package/tableContainer/tableContainer.js +78 -0
- package/tablePagination/index.d.ts +17 -0
- package/tablePagination/index.js +1 -0
- package/tablePagination/tablePagination.js +131 -0
- package/tabs/index.d.ts +3 -1
- package/tabs/tabs.js +34 -15
- package/themeSwitch/index.d.ts +3 -1
- package/themeSwitch/themeSwitch.js +58 -15
- package/tooltip/index.d.ts +24 -0
- package/tooltip/index.js +1 -0
- package/tooltip/tooltip.js +184 -0
- package/treeView/index.d.ts +7 -2
- package/treeView/treeView.js +37 -9
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { toPropsAndChildren } from "@grucloud/bau/bau.js";
|
|
2
|
+
import classNames from "@grucloud/bau-css/classNames.js";
|
|
3
|
+
import { Colors } from "../constants.js";
|
|
4
|
+
|
|
5
|
+
const colorsToCss = () =>
|
|
6
|
+
Colors.map(
|
|
7
|
+
(color) =>
|
|
8
|
+
`
|
|
9
|
+
& li.plain.${color} h3::after {
|
|
10
|
+
color: var(--color-${color});
|
|
11
|
+
}
|
|
12
|
+
& li.outline.${color} h3::after {
|
|
13
|
+
color: var(--color-${color});
|
|
14
|
+
}
|
|
15
|
+
& h3.solid.${color}:hover {
|
|
16
|
+
filter: brightness(var(--brightness-hover-always));
|
|
17
|
+
}
|
|
18
|
+
`
|
|
19
|
+
).join("\n");
|
|
20
|
+
|
|
21
|
+
export default function (context, options) {
|
|
22
|
+
const { bau, css } = context;
|
|
23
|
+
const { accordionDefs } = options;
|
|
24
|
+
const { div, ul, li, header, h3, button } = bau.tags;
|
|
25
|
+
const itemNameState = bau.state("");
|
|
26
|
+
|
|
27
|
+
const onclick = (name) => (event) => {
|
|
28
|
+
if (itemNameState.val == name) {
|
|
29
|
+
itemNameState.val = "";
|
|
30
|
+
} else {
|
|
31
|
+
itemNameState.val = name;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const collapseOrExpandSection = ({ element, open }) => {
|
|
35
|
+
const animationEndHandler = () => {
|
|
36
|
+
element.removeEventListener("transitionend", animationEndHandler);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
function collapseSection(element) {
|
|
40
|
+
element.addEventListener("transitionend", animationEndHandler);
|
|
41
|
+
window.requestAnimationFrame(() => {
|
|
42
|
+
element.style.height = "0px";
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function expandSection(element) {
|
|
47
|
+
element.addEventListener("transitionend", animationEndHandler);
|
|
48
|
+
element.style.height = element.scrollHeight + "px";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (element.scrollHeight == 0) return;
|
|
52
|
+
open ? expandSection(element) : collapseSection(element);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const className = css`
|
|
56
|
+
& ul {
|
|
57
|
+
display: flex;
|
|
58
|
+
flex-direction: column;
|
|
59
|
+
justify-content: flex-start;
|
|
60
|
+
padding: 0;
|
|
61
|
+
list-style: none;
|
|
62
|
+
|
|
63
|
+
& li {
|
|
64
|
+
display: flex;
|
|
65
|
+
flex-direction: column;
|
|
66
|
+
padding: 0.5rem;
|
|
67
|
+
margin: 0.2rem;
|
|
68
|
+
overflow: hidden;
|
|
69
|
+
border-radius: var(--global-radius);
|
|
70
|
+
transition: all var(--transition-slow) ease-out;
|
|
71
|
+
background-color: inherit;
|
|
72
|
+
&:hover.solid {
|
|
73
|
+
filter: brightness(var(--brightness-hover-always)) !important;
|
|
74
|
+
}
|
|
75
|
+
&:hover {
|
|
76
|
+
filter: brightness(var(--brightness-hover));
|
|
77
|
+
}
|
|
78
|
+
& h3 {
|
|
79
|
+
display: flex;
|
|
80
|
+
cursor: pointer;
|
|
81
|
+
align-items: center;
|
|
82
|
+
justify-content: space-between;
|
|
83
|
+
margin: 0;
|
|
84
|
+
&::after {
|
|
85
|
+
content: "\u203A";
|
|
86
|
+
transition: all var(--transition-slow) ease-out;
|
|
87
|
+
}
|
|
88
|
+
& button {
|
|
89
|
+
width: 100%;
|
|
90
|
+
border: none;
|
|
91
|
+
background-color: inherit;
|
|
92
|
+
text-align: left;
|
|
93
|
+
font-size: large;
|
|
94
|
+
cursor: pointer;
|
|
95
|
+
color: inherit;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
& h3.active {
|
|
99
|
+
font-weight: var(--font-weight-semibold);
|
|
100
|
+
&::after {
|
|
101
|
+
content: "\u203A";
|
|
102
|
+
transform: rotate(90deg);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
& .content {
|
|
106
|
+
height: 0px;
|
|
107
|
+
will-change: height;
|
|
108
|
+
transition: height var(--transition-fast) ease-out;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
${colorsToCss()}
|
|
113
|
+
`;
|
|
114
|
+
|
|
115
|
+
return function Accordion(...args) {
|
|
116
|
+
let [
|
|
117
|
+
{ color, variant = "outline", size = "md", content, ...props },
|
|
118
|
+
...children
|
|
119
|
+
] = toPropsAndChildren(args);
|
|
120
|
+
const AccordionItem = (item) => {
|
|
121
|
+
const { Header, Content, name } = item;
|
|
122
|
+
return li(
|
|
123
|
+
{
|
|
124
|
+
class: classNames(color, variant, size),
|
|
125
|
+
onclick: onclick(name),
|
|
126
|
+
},
|
|
127
|
+
h3(
|
|
128
|
+
{
|
|
129
|
+
class: () => classNames(itemNameState.val == name && "active"),
|
|
130
|
+
},
|
|
131
|
+
button(
|
|
132
|
+
{
|
|
133
|
+
type: "button",
|
|
134
|
+
"aria-controls": `bau-${name}`,
|
|
135
|
+
"aria-expanded": ({ element }) => itemNameState.val == name,
|
|
136
|
+
},
|
|
137
|
+
Header(item)
|
|
138
|
+
)
|
|
139
|
+
),
|
|
140
|
+
div(
|
|
141
|
+
{
|
|
142
|
+
class: "content",
|
|
143
|
+
role: "region",
|
|
144
|
+
id: `bau-${name}`,
|
|
145
|
+
"data-state": ({ element }) => {
|
|
146
|
+
const open = itemNameState.val == name;
|
|
147
|
+
collapseOrExpandSection({ element, open });
|
|
148
|
+
return open;
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
Content(item)
|
|
152
|
+
)
|
|
153
|
+
);
|
|
154
|
+
};
|
|
155
|
+
return div(
|
|
156
|
+
{
|
|
157
|
+
class: classNames("accordion", className, options?.class, props.class),
|
|
158
|
+
},
|
|
159
|
+
ul(accordionDefs.map(AccordionItem))
|
|
160
|
+
);
|
|
161
|
+
};
|
|
162
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
declare module "@grucloud/bau-ui/accordion" {
|
|
2
|
+
type DefaultDesignProps = import("../constants").DefaultDesignProps;
|
|
3
|
+
|
|
4
|
+
export type AccordionProps = {} & DefaultDesignProps;
|
|
5
|
+
|
|
6
|
+
type Component = import("../bau-ui").Component<AccordionProps>;
|
|
7
|
+
|
|
8
|
+
type AccordionItemPropBase = {
|
|
9
|
+
name: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type AccordionItem =
|
|
13
|
+
import("../bau-ui").ComponentWithProp<AccordionItemPropBase>;
|
|
14
|
+
|
|
15
|
+
export type Accordion = {
|
|
16
|
+
Header: AccordionItem;
|
|
17
|
+
Content: AccordionItem;
|
|
18
|
+
} & AccordionItemPropBase;
|
|
19
|
+
|
|
20
|
+
type Option = {
|
|
21
|
+
class?: string;
|
|
22
|
+
accordionDefs: Accordion[];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default function (context: any, option: Option): Component;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./accordion";
|
package/alert/alert.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { toPropsAndChildren } from "@grucloud/bau/bau.js";
|
|
2
|
+
import classNames from "@grucloud/bau-css/classNames.js";
|
|
3
|
+
import { Colors } from "../constants.js";
|
|
2
4
|
|
|
3
5
|
import button from "../button";
|
|
4
6
|
|
|
@@ -6,69 +8,62 @@ const severityMap = {
|
|
|
6
8
|
danger: "\u26A0",
|
|
7
9
|
warning: "\u26A0",
|
|
8
10
|
success: "\u2714",
|
|
9
|
-
|
|
11
|
+
primary: "\u2139",
|
|
12
|
+
neutral: "\u2139",
|
|
10
13
|
};
|
|
11
14
|
|
|
12
|
-
const darkVar = (severity) => `var(--color-${severity}-darkest)`;
|
|
13
|
-
|
|
14
|
-
const severitiesToCss = () =>
|
|
15
|
-
Object.keys(severityMap)
|
|
16
|
-
.map(
|
|
17
|
-
(severity) =>
|
|
18
|
-
`.alert-${severity} {
|
|
19
|
-
border-left: var(--alert-border-left-width) solid ${darkVar(severity)};
|
|
20
|
-
color: ${darkVar(severity)};
|
|
21
|
-
background-color: var(--background-color);
|
|
22
|
-
& .button-close {
|
|
23
|
-
color: ${darkVar(severity)};
|
|
24
|
-
}
|
|
25
|
-
}`
|
|
26
|
-
)
|
|
27
|
-
.join("\n");
|
|
28
|
-
|
|
29
15
|
const createStyles = ({ css, createGlobalStyles }) => {
|
|
30
16
|
createGlobalStyles`
|
|
31
17
|
:root {
|
|
32
18
|
--alert-border-left-width: 8px;
|
|
33
19
|
}
|
|
34
|
-
${severitiesToCss()}
|
|
35
20
|
`;
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
base: css`
|
|
39
|
-
display: flex;
|
|
40
|
-
max-width: 600px;
|
|
41
|
-
justify-content: flex-start;
|
|
42
|
-
align-items: center;
|
|
43
|
-
margin: 0.5rem;
|
|
44
|
-
font-weight: var(--font-weight-semibold);
|
|
45
|
-
box-shadow: var(--shadow-m);
|
|
46
|
-
border-radius: var(--global-radius);
|
|
47
|
-
& .icon {
|
|
48
|
-
padding: 0 1rem;
|
|
49
|
-
font-size: 2.5rem;
|
|
50
|
-
}
|
|
51
|
-
& .content {
|
|
52
|
-
padding: 0 0.5rem;
|
|
53
|
-
display: flex;
|
|
54
|
-
flex-grow: 1;
|
|
55
|
-
flex-direction: column;
|
|
56
|
-
align-items: flex-start;
|
|
57
|
-
justify-content: space-around;
|
|
58
|
-
}
|
|
59
|
-
& .button-close {
|
|
60
|
-
margin: 1rem;
|
|
61
|
-
}
|
|
62
|
-
`,
|
|
63
|
-
};
|
|
64
21
|
};
|
|
65
22
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
23
|
+
const colorsToCss = () =>
|
|
24
|
+
Colors.map(
|
|
25
|
+
(color) =>
|
|
26
|
+
`
|
|
27
|
+
&.alert.outline.${color} {
|
|
28
|
+
& .icon {
|
|
29
|
+
color: var(--color-${color})
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
`
|
|
33
|
+
).join("\n");
|
|
34
|
+
|
|
35
|
+
export default function (context, options) {
|
|
36
|
+
const { bau, css, createGlobalStyles } = context;
|
|
37
|
+
const { div, i } = bau.tags;
|
|
69
38
|
|
|
70
|
-
|
|
39
|
+
createStyles({ css, createGlobalStyles });
|
|
71
40
|
|
|
41
|
+
const className = css`
|
|
42
|
+
display: flex;
|
|
43
|
+
max-width: 600px;
|
|
44
|
+
justify-content: flex-start;
|
|
45
|
+
align-items: center;
|
|
46
|
+
margin: 0.5rem;
|
|
47
|
+
font-weight: var(--font-weight-semibold);
|
|
48
|
+
box-shadow: var(--shadow-m);
|
|
49
|
+
border-radius: var(--global-radius);
|
|
50
|
+
& .icon {
|
|
51
|
+
padding: 0 1rem;
|
|
52
|
+
font-size: 2.5rem;
|
|
53
|
+
}
|
|
54
|
+
& .content {
|
|
55
|
+
padding: 0 0.5rem;
|
|
56
|
+
display: flex;
|
|
57
|
+
flex-grow: 1;
|
|
58
|
+
flex-direction: column;
|
|
59
|
+
align-items: flex-start;
|
|
60
|
+
justify-content: space-around;
|
|
61
|
+
}
|
|
62
|
+
& .button-close {
|
|
63
|
+
margin: 1rem;
|
|
64
|
+
}
|
|
65
|
+
${colorsToCss()}
|
|
66
|
+
`;
|
|
72
67
|
const Button = button(context);
|
|
73
68
|
|
|
74
69
|
const CloseIcon = ({ onclick }) =>
|
|
@@ -82,14 +77,29 @@ export default function (context) {
|
|
|
82
77
|
);
|
|
83
78
|
|
|
84
79
|
return function Alert(props, ...children) {
|
|
85
|
-
const {
|
|
80
|
+
const {
|
|
81
|
+
variant = "outline",
|
|
82
|
+
color = "neutral",
|
|
83
|
+
size = "md",
|
|
84
|
+
onRemove,
|
|
85
|
+
...otherProps
|
|
86
|
+
} = props;
|
|
86
87
|
return div(
|
|
87
88
|
{
|
|
88
89
|
...otherProps,
|
|
89
|
-
class: classNames(
|
|
90
|
+
class: classNames(
|
|
91
|
+
`alert-${variant}`,
|
|
92
|
+
variant,
|
|
93
|
+
color,
|
|
94
|
+
size,
|
|
95
|
+
className,
|
|
96
|
+
options?.class,
|
|
97
|
+
props.class,
|
|
98
|
+
"alert"
|
|
99
|
+
),
|
|
90
100
|
role: "alert",
|
|
91
101
|
},
|
|
92
|
-
|
|
102
|
+
i({ class: "icon" }, severityMap[color]),
|
|
93
103
|
div({ class: "content" }, ...children),
|
|
94
104
|
onRemove && CloseIcon({ onclick: onRemove })
|
|
95
105
|
);
|
package/alert/index.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
declare module "@grucloud/bau-ui/alert" {
|
|
2
|
+
type DefaultDesignProps = import("../constants").DefaultDesignProps;
|
|
3
|
+
type ComponentOption = import("../bau-ui").ComponentOption;
|
|
4
|
+
|
|
2
5
|
export type AnimateProps = {
|
|
3
|
-
severity:
|
|
4
|
-
| "primary"
|
|
5
|
-
| "secondary"
|
|
6
|
-
| "danger"
|
|
7
|
-
| "warning"
|
|
8
|
-
| "info"
|
|
9
|
-
| "success";
|
|
10
6
|
onRemove?: Function;
|
|
11
|
-
};
|
|
7
|
+
} & DefaultDesignProps;
|
|
12
8
|
|
|
13
9
|
type Component = import("../bau-ui").Component<AnimateProps>;
|
|
14
10
|
|
|
15
|
-
export default function (
|
|
11
|
+
export default function (
|
|
12
|
+
context: Object,
|
|
13
|
+
option?: ComponentOption
|
|
14
|
+
): Component;
|
|
16
15
|
}
|
package/alertStack/alertStack.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { toPropsAndChildren } from "@grucloud/bau/bau.js";
|
|
2
|
+
import classNames from "@grucloud/bau-css/classNames.js";
|
|
2
3
|
|
|
3
|
-
export default (context,
|
|
4
|
+
export default (context, options = {}) => {
|
|
4
5
|
const { bau, css, keyframes } = context;
|
|
6
|
+
const { limit = 10, deleteAfterDuration = 15e3 } = options;
|
|
5
7
|
const { div } = bau.tags;
|
|
6
8
|
const messagesState = bau.state([]);
|
|
7
9
|
|
|
@@ -85,7 +87,7 @@ export default (context, { limit = 10, deleteAfterDuration = 15e3 } = {}) => {
|
|
|
85
87
|
|
|
86
88
|
return div(
|
|
87
89
|
{
|
|
88
|
-
class: classNames(styles.stack, props.class),
|
|
90
|
+
class: classNames(styles.stack, options?.class, props.class),
|
|
89
91
|
},
|
|
90
92
|
bau.loop(messagesState, div(), AlertItem)
|
|
91
93
|
);
|
package/alertStack/index.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
declare module "@grucloud/bau-ui/alertStack" {
|
|
2
|
-
|
|
2
|
+
type DefaultDesignProps = import("../constants").DefaultDesignProps;
|
|
3
|
+
type ComponentOption = import("../bau-ui").ComponentOption;
|
|
4
|
+
|
|
5
|
+
export type AlertStackProps = {} & DefaultDesignProps;
|
|
3
6
|
|
|
4
7
|
type AlertStack = import("../bau-ui").Component<AlertStackProps>;
|
|
5
8
|
|
|
6
9
|
export default function (
|
|
7
10
|
context: any,
|
|
8
|
-
options: { limit?: Number; deleteAfterDuration?: Number }
|
|
11
|
+
options: { limit?: Number; deleteAfterDuration?: Number } & ComponentOption
|
|
9
12
|
): AlertStack;
|
|
10
13
|
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import classNames from "@grucloud/bau-css/classNames.js";
|
|
2
|
+
import { toPropsAndChildren } from "@grucloud/bau/bau.js";
|
|
3
|
+
import popover from "../popover/popover.js";
|
|
4
|
+
import button from "../button/button.js";
|
|
5
|
+
import input from "../input/input.js";
|
|
6
|
+
import list from "../list/list.js";
|
|
7
|
+
|
|
8
|
+
import { Colors } from "../constants.js";
|
|
9
|
+
|
|
10
|
+
const colorsToCss = () =>
|
|
11
|
+
Colors.map(
|
|
12
|
+
(color) =>
|
|
13
|
+
`
|
|
14
|
+
& button.plain.${color}::after {
|
|
15
|
+
color: var(--color-${color});
|
|
16
|
+
}
|
|
17
|
+
& button.outline.${color}::after {
|
|
18
|
+
color: var(--color-${color});
|
|
19
|
+
}
|
|
20
|
+
`
|
|
21
|
+
).join("\n");
|
|
22
|
+
|
|
23
|
+
export default function (context, componentOptions) {
|
|
24
|
+
const { bau, css } = context;
|
|
25
|
+
const { div, li, ul } = bau.tags;
|
|
26
|
+
|
|
27
|
+
const Popover = popover(context);
|
|
28
|
+
const Button = button(context);
|
|
29
|
+
const Input = input(context);
|
|
30
|
+
const List = list(context);
|
|
31
|
+
|
|
32
|
+
const className = css`
|
|
33
|
+
& button {
|
|
34
|
+
&::after {
|
|
35
|
+
content: "\u25BC";
|
|
36
|
+
padding: 0 0.3rem;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
& .content {
|
|
40
|
+
height: fit-content;
|
|
41
|
+
& input {
|
|
42
|
+
padding: 0.8rem;
|
|
43
|
+
margin: 0.3rem;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
${colorsToCss()}
|
|
48
|
+
`;
|
|
49
|
+
|
|
50
|
+
const selectedState = bau.state("");
|
|
51
|
+
const inputState = bau.state("");
|
|
52
|
+
const openState = bau.state(false);
|
|
53
|
+
const itemIndexActive = bau.state(0);
|
|
54
|
+
|
|
55
|
+
const onClose = () => {
|
|
56
|
+
openState.val = false;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return function AutoComplete(...args) {
|
|
60
|
+
let [
|
|
61
|
+
{
|
|
62
|
+
variant = "outline",
|
|
63
|
+
color,
|
|
64
|
+
size = "md",
|
|
65
|
+
id,
|
|
66
|
+
label,
|
|
67
|
+
placeholder,
|
|
68
|
+
Option,
|
|
69
|
+
options,
|
|
70
|
+
getOptionLabel = ({ label }) => label,
|
|
71
|
+
...props
|
|
72
|
+
},
|
|
73
|
+
...children
|
|
74
|
+
] = toPropsAndChildren(args);
|
|
75
|
+
|
|
76
|
+
const optionsFilteredState = bau.state(options);
|
|
77
|
+
|
|
78
|
+
const dialogOpen = () => {
|
|
79
|
+
popoverEl.openDialog();
|
|
80
|
+
openState.val = true;
|
|
81
|
+
inputState.val = "";
|
|
82
|
+
optionsFilteredState.val = options;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const dialogClose = () => {
|
|
86
|
+
popoverEl.closeDialog();
|
|
87
|
+
openState.val = false;
|
|
88
|
+
inputState.val = "";
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const oninput = (event) => {
|
|
92
|
+
const { value } = event.target;
|
|
93
|
+
inputState.val = value;
|
|
94
|
+
if (value) {
|
|
95
|
+
optionsFilteredState.val = options.filter((option) =>
|
|
96
|
+
getOptionLabel(option).match(new RegExp(`${value}`, "i"))
|
|
97
|
+
);
|
|
98
|
+
} else {
|
|
99
|
+
optionsFilteredState.val = options;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const onclickButton = (event) => {
|
|
104
|
+
if (!openState.val) {
|
|
105
|
+
dialogOpen();
|
|
106
|
+
} else {
|
|
107
|
+
dialogClose();
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const onclickItem =
|
|
112
|
+
({ option, index }) =>
|
|
113
|
+
(event) => {
|
|
114
|
+
selectedState.val = getOptionLabel(option);
|
|
115
|
+
itemIndexActive.val = index;
|
|
116
|
+
dialogClose();
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const onkeydown = (event) => {
|
|
120
|
+
console.log("onkeydown", event.key, itemIndexActive.val);
|
|
121
|
+
switch (event.key) {
|
|
122
|
+
case "Escape":
|
|
123
|
+
dialogClose();
|
|
124
|
+
break;
|
|
125
|
+
case "ArrowDown":
|
|
126
|
+
if (itemIndexActive.val < optionsFilteredState.val.length - 1) {
|
|
127
|
+
itemIndexActive.val++;
|
|
128
|
+
} else {
|
|
129
|
+
itemIndexActive.val = 0;
|
|
130
|
+
}
|
|
131
|
+
break;
|
|
132
|
+
case "ArrowUp":
|
|
133
|
+
if (itemIndexActive.val <= 0) {
|
|
134
|
+
itemIndexActive.val = optionsFilteredState.val.length - 1;
|
|
135
|
+
} else {
|
|
136
|
+
itemIndexActive.val--;
|
|
137
|
+
}
|
|
138
|
+
break;
|
|
139
|
+
case "Enter":
|
|
140
|
+
selectedState.val = getOptionLabel(
|
|
141
|
+
optionsFilteredState.val[itemIndexActive.val]
|
|
142
|
+
);
|
|
143
|
+
inputState.val = "";
|
|
144
|
+
dialogClose();
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const buttonEl = Button(
|
|
150
|
+
{
|
|
151
|
+
type: "button",
|
|
152
|
+
role: "combobox",
|
|
153
|
+
"aria-autocomplete": "list",
|
|
154
|
+
"aria-expanded": openState,
|
|
155
|
+
"aria-label": label,
|
|
156
|
+
onclick: onclickButton,
|
|
157
|
+
variant,
|
|
158
|
+
color,
|
|
159
|
+
size,
|
|
160
|
+
},
|
|
161
|
+
() => !selectedState.val && label,
|
|
162
|
+
selectedState
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
const inputEl = Input({
|
|
166
|
+
id,
|
|
167
|
+
value: inputState,
|
|
168
|
+
placeholder,
|
|
169
|
+
autofocus: true,
|
|
170
|
+
type: "search",
|
|
171
|
+
autocomplete: "new-password",
|
|
172
|
+
autocapitalize: "none",
|
|
173
|
+
spellcheck: false,
|
|
174
|
+
role: "combobox",
|
|
175
|
+
"aria-autocomplete": "list",
|
|
176
|
+
"aria-expanded": openState,
|
|
177
|
+
oninput,
|
|
178
|
+
onkeydown,
|
|
179
|
+
variant,
|
|
180
|
+
color,
|
|
181
|
+
size,
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const Content = () =>
|
|
185
|
+
div({ class: classNames(variant, color, size, "content") }, inputEl, () =>
|
|
186
|
+
List(
|
|
187
|
+
{ class: classNames(variant, color, size) },
|
|
188
|
+
optionsFilteredState.val.map((option, index) =>
|
|
189
|
+
li(
|
|
190
|
+
{
|
|
191
|
+
class: () =>
|
|
192
|
+
classNames(itemIndexActive.val == index && "active"),
|
|
193
|
+
onclick: onclickItem({ option, index }),
|
|
194
|
+
},
|
|
195
|
+
Option(option)
|
|
196
|
+
)
|
|
197
|
+
)
|
|
198
|
+
)
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
const popoverEl = Popover({
|
|
202
|
+
id,
|
|
203
|
+
triggerEl: buttonEl,
|
|
204
|
+
contentEl: Content(),
|
|
205
|
+
onClose,
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
return div(
|
|
209
|
+
{
|
|
210
|
+
...props,
|
|
211
|
+
class: classNames(
|
|
212
|
+
"autocomplete",
|
|
213
|
+
className,
|
|
214
|
+
componentOptions?.class,
|
|
215
|
+
props?.class
|
|
216
|
+
),
|
|
217
|
+
},
|
|
218
|
+
buttonEl,
|
|
219
|
+
popoverEl
|
|
220
|
+
);
|
|
221
|
+
};
|
|
222
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare module "@grucloud/bau-ui/autocomplete" {
|
|
2
|
+
type DefaultDesignProps = import("../constants").DefaultDesignProps;
|
|
3
|
+
type ComponentOption = import("../bau-ui").ComponentOption;
|
|
4
|
+
|
|
5
|
+
export type Autocomplete = {
|
|
6
|
+
options: object[];
|
|
7
|
+
id: string;
|
|
8
|
+
label: string;
|
|
9
|
+
placeholder: string;
|
|
10
|
+
size?: string;
|
|
11
|
+
getOptionLabel?: (item: object | string) => string;
|
|
12
|
+
Option: (props) => HTMLElement;
|
|
13
|
+
} & DefaultDesignProps;
|
|
14
|
+
|
|
15
|
+
type Component = import("../bau-ui").Component<
|
|
16
|
+
Autocomplete,
|
|
17
|
+
HTMLInputElement
|
|
18
|
+
>;
|
|
19
|
+
|
|
20
|
+
export default function (context: any, option?: ComponentOption): Component;
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./autocomplete";
|