@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.
Files changed (79) hide show
  1. package/accordion/accordion.js +162 -0
  2. package/accordion/index.d.ts +26 -0
  3. package/accordion/index.js +1 -0
  4. package/alert/alert.js +65 -55
  5. package/alert/index.d.ts +8 -9
  6. package/alertStack/alertStack.js +5 -3
  7. package/alertStack/index.d.ts +5 -2
  8. package/autocomplete/autocomplete.js +222 -0
  9. package/autocomplete/index.d.ts +21 -0
  10. package/autocomplete/index.js +1 -0
  11. package/avatar/avatar.js +46 -6
  12. package/avatar/index.d.ts +5 -2
  13. package/badge/badge.js +43 -0
  14. package/badge/index.d.ts +16 -0
  15. package/badge/index.js +1 -0
  16. package/bau-ui.d.ts +14 -7
  17. package/breadcrumbs/breadcrumbs.js +30 -6
  18. package/breadcrumbs/index.d.ts +8 -2
  19. package/button/button.js +30 -106
  20. package/button/index.d.ts +4 -7
  21. package/buttonGroup/buttonGroup.js +68 -0
  22. package/buttonGroup/index.d.ts +10 -0
  23. package/buttonGroup/index.js +1 -0
  24. package/calendar/calendar.js +51 -0
  25. package/calendar/index.d.ts +13 -0
  26. package/calendar/index.js +1 -0
  27. package/checkbox/checkbox.js +66 -39
  28. package/checkbox/index.d.ts +5 -2
  29. package/chip/chip.js +60 -0
  30. package/chip/index.d.ts +10 -0
  31. package/chip/index.js +1 -0
  32. package/constants.d.ts +13 -0
  33. package/constants.js +3 -0
  34. package/context.d.ts +12 -0
  35. package/context.js +13 -0
  36. package/drawer/drawer.js +10 -5
  37. package/drawer/index.d.ts +5 -2
  38. package/drillDownMenu/drillDownMenu.js +117 -79
  39. package/drillDownMenu/index.d.ts +11 -3
  40. package/fileInput/fileInput.js +20 -10
  41. package/fileInput/index.d.ts +9 -3
  42. package/globalStyle/globalStyle.js +110 -60
  43. package/input/index.d.ts +6 -8
  44. package/input/input.js +78 -107
  45. package/list/index.d.ts +10 -0
  46. package/list/index.js +1 -0
  47. package/list/list.js +66 -0
  48. package/modal/index.d.ts +5 -2
  49. package/modal/modal.js +47 -10
  50. package/package.json +4 -4
  51. package/pages/login/index.d.ts +2 -0
  52. package/popover/index.d.ts +18 -0
  53. package/popover/index.js +1 -0
  54. package/popover/popover.js +69 -0
  55. package/select/index.d.ts +16 -0
  56. package/select/index.js +1 -0
  57. package/select/select.js +176 -0
  58. package/slider/index.d.ts +10 -0
  59. package/slider/index.js +1 -0
  60. package/slider/slider.js +47 -0
  61. package/spinner/index.d.ts +7 -4
  62. package/spinner/spinner.js +13 -5
  63. package/switch/index.d.ts +5 -2
  64. package/switch/switch.js +101 -18
  65. package/tableContainer/index.d.ts +9 -0
  66. package/tableContainer/index.js +1 -0
  67. package/tableContainer/tableContainer.js +78 -0
  68. package/tablePagination/index.d.ts +17 -0
  69. package/tablePagination/index.js +1 -0
  70. package/tablePagination/tablePagination.js +131 -0
  71. package/tabs/index.d.ts +3 -1
  72. package/tabs/tabs.js +34 -15
  73. package/themeSwitch/index.d.ts +3 -1
  74. package/themeSwitch/themeSwitch.js +58 -15
  75. package/tooltip/index.d.ts +24 -0
  76. package/tooltip/index.js +1 -0
  77. package/tooltip/tooltip.js +184 -0
  78. package/treeView/index.d.ts +7 -2
  79. 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 classNames from "@grucloud/bau-css/classNames";
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
- info: "\u2139",
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
- export default function (context) {
67
- const { bau, css, createGlobalStyles, tr } = context;
68
- const { div } = bau.tags;
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
- const styles = createStyles({ css, createGlobalStyles });
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 { severity = "info", onRemove, ...otherProps } = props;
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(styles.base, `alert-${severity}`, props.class),
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
- div({ class: "icon" }, severityMap[severity]),
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 (context: Object): Component;
11
+ export default function (
12
+ context: Object,
13
+ option?: ComponentOption
14
+ ): Component;
16
15
  }
@@ -1,7 +1,9 @@
1
- import classNames from "@grucloud/bau-css/classNames";
1
+ import { toPropsAndChildren } from "@grucloud/bau/bau.js";
2
+ import classNames from "@grucloud/bau-css/classNames.js";
2
3
 
3
- export default (context, { limit = 10, deleteAfterDuration = 15e3 } = {}) => {
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
  );
@@ -1,10 +1,13 @@
1
1
  declare module "@grucloud/bau-ui/alertStack" {
2
- export type AlertStackProps = {};
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";