@grucloud/bau-ui 0.40.0 → 0.42.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 (87) hide show
  1. package/README.md +4 -2
  2. package/accordion/accordion.js +162 -0
  3. package/accordion/index.d.ts +26 -0
  4. package/accordion/index.js +1 -0
  5. package/alert/alert.js +65 -55
  6. package/alert/index.d.ts +8 -9
  7. package/alertStack/alertStack.js +5 -3
  8. package/alertStack/index.d.ts +5 -2
  9. package/animate/animate.js +47 -33
  10. package/animate/index.d.ts +2 -3
  11. package/autocomplete/autocomplete.js +222 -0
  12. package/autocomplete/index.d.ts +21 -0
  13. package/autocomplete/index.js +1 -0
  14. package/avatar/avatar.js +46 -6
  15. package/avatar/index.d.ts +5 -2
  16. package/badge/badge.js +43 -0
  17. package/badge/index.d.ts +12 -0
  18. package/badge/index.js +1 -0
  19. package/bau-ui.d.ts +14 -7
  20. package/breadcrumbs/breadcrumbs.js +30 -6
  21. package/breadcrumbs/index.d.ts +8 -2
  22. package/button/button.js +38 -105
  23. package/button/index.d.ts +4 -7
  24. package/buttonGroup/buttonGroup.js +68 -0
  25. package/buttonGroup/index.d.ts +10 -0
  26. package/buttonGroup/index.js +1 -0
  27. package/calendar/calendar.js +51 -0
  28. package/calendar/index.d.ts +13 -0
  29. package/calendar/index.js +1 -0
  30. package/checkbox/checkbox.js +66 -39
  31. package/checkbox/index.d.ts +5 -2
  32. package/chip/chip.js +60 -0
  33. package/chip/index.d.ts +10 -0
  34. package/chip/index.js +1 -0
  35. package/constants.d.ts +13 -0
  36. package/constants.js +3 -0
  37. package/context.d.ts +12 -0
  38. package/context.js +17 -0
  39. package/drawer/drawer.js +10 -5
  40. package/drawer/index.d.ts +5 -2
  41. package/drillDownMenu/drillDownMenu.js +157 -138
  42. package/drillDownMenu/index.d.ts +11 -3
  43. package/fileInput/fileInput.js +25 -11
  44. package/fileInput/index.d.ts +9 -3
  45. package/form/form.js +31 -0
  46. package/form/index.d.ts +10 -0
  47. package/form/index.js +1 -0
  48. package/globalStyle/globalStyle.js +133 -61
  49. package/globalStyle/index.d.ts +14 -0
  50. package/input/index.d.ts +6 -8
  51. package/input/input.js +78 -107
  52. package/list/index.d.ts +10 -0
  53. package/list/index.js +1 -0
  54. package/list/list.js +66 -0
  55. package/modal/index.d.ts +5 -2
  56. package/modal/modal.js +47 -10
  57. package/package.json +4 -4
  58. package/pages/login/index.d.ts +4 -5
  59. package/pages/login/login.js +1 -1
  60. package/popover/index.d.ts +18 -0
  61. package/popover/index.js +1 -0
  62. package/popover/popover.js +69 -0
  63. package/select/index.d.ts +16 -0
  64. package/select/index.js +1 -0
  65. package/select/select.js +176 -0
  66. package/slider/index.d.ts +10 -0
  67. package/slider/index.js +1 -0
  68. package/slider/slider.js +47 -0
  69. package/spinner/index.d.ts +7 -4
  70. package/spinner/spinner.js +13 -5
  71. package/switch/index.d.ts +5 -2
  72. package/switch/switch.js +101 -18
  73. package/tableContainer/index.d.ts +9 -0
  74. package/tableContainer/index.js +1 -0
  75. package/tableContainer/tableContainer.js +78 -0
  76. package/tablePagination/index.d.ts +17 -0
  77. package/tablePagination/index.js +1 -0
  78. package/tablePagination/tablePagination.js +131 -0
  79. package/tabs/index.d.ts +3 -1
  80. package/tabs/tabs.js +34 -15
  81. package/themeSwitch/index.d.ts +3 -1
  82. package/themeSwitch/themeSwitch.js +58 -15
  83. package/tooltip/index.d.ts +24 -0
  84. package/tooltip/index.js +1 -0
  85. package/tooltip/tooltip.js +184 -0
  86. package/treeView/index.d.ts +7 -2
  87. package/treeView/treeView.js +37 -9
@@ -1,5 +1,8 @@
1
+ import { toPropsAndChildren } from "@grucloud/bau/bau.js";
1
2
  import cn from "@grucloud/bau-css/classNames.js";
2
3
  import animate from "../animate/animate.js";
4
+ import button from "../button/button.js";
5
+ import list from "../list/list.js";
3
6
 
4
7
  const animationDuration = "0.3s";
5
8
 
@@ -36,18 +39,7 @@ const findSubTree = (initialPathname) => (tree) => {
36
39
  }
37
40
  };
38
41
 
39
- const isActive = ({ window, subTree }) =>
40
- window.location.pathname === subTree?.data?.href;
41
-
42
- const createStyles = ({ createGlobalStyles, keyframes }) => {
43
- createGlobalStyles`
44
- :root {
45
- --drill-down-menu-color: var(--font-color-base);
46
- --drill-down-menu-padding: 0.4rem;
47
- --drill-down-menu-bg-active: var(--color-emphasis-50);
48
- --drill-down-menu-bg-hover: var(--color-emphasis-50);
49
- }
50
- `;
42
+ const createStyles = ({ keyframes }) => {
51
43
  return {
52
44
  hideToLeft: keyframes`
53
45
  from {
@@ -58,16 +50,6 @@ const createStyles = ({ createGlobalStyles, keyframes }) => {
58
50
  transform: translateX(-100%);
59
51
  opacity: 0;
60
52
  }
61
- `,
62
- showFromLeft: keyframes`
63
- from {
64
- transform: translateX(-100%);
65
- opacity: 0;
66
- }
67
- to {
68
- transform: translateX(0%);
69
- opacity: 1;
70
- }
71
53
  `,
72
54
  hideToRight: keyframes`
73
55
  from {
@@ -79,59 +61,86 @@ const createStyles = ({ createGlobalStyles, keyframes }) => {
79
61
  opacity: 0;
80
62
  }
81
63
  `,
82
- showFromRight: keyframes`
83
- from {
84
- transform: translateX(100%);
85
- opacity: 0;
86
-
87
- }
88
- to {
89
- transform: translateX(0%);
90
- opacity: 1;
91
- }
92
- `,
93
64
  };
94
65
  };
95
66
 
96
- export default function (context, { renderMenuItem }) {
67
+ export default function (context, options) {
97
68
  const { bau, css, window } = context;
98
- const { ul, li, nav, div, header, a } = bau.tags;
69
+ const { base = "" } = options;
70
+
71
+ const renderHeaderDefault = ({ currentTree, data }) =>
72
+ header(
73
+ Button(
74
+ {
75
+ variant: "plain",
76
+ href: `${base}${currentTree.parentTree.children[0].data.href}`,
77
+ class: css`
78
+ flex-grow: 0;
79
+ `,
80
+ "data-buttonback": true,
81
+ },
82
+ "\u2190"
83
+ ),
84
+ Button(
85
+ {
86
+ variant: "plain",
87
+ href: `${base}${data.href}`,
88
+ class: css`
89
+ flex-grow: 1;
90
+ `,
91
+ "data-ischild": true,
92
+ },
93
+ data.name
94
+ )
95
+ );
96
+
97
+ const renderMenuItemDefault = ({ data: { name, href }, children = [] }) =>
98
+ Button(
99
+ {
100
+ href: `${base}${href}`,
101
+ "data-ischild": !children.length,
102
+ },
103
+ name
104
+ );
105
+
106
+ const isActiveDefault = ({ subTree }) =>
107
+ window.location.pathname.replace(base, "") === subTree?.data?.href;
108
+
109
+ const {
110
+ renderHeader = renderHeaderDefault,
111
+ renderMenuItem = renderMenuItemDefault,
112
+ isActive = isActiveDefault,
113
+ } = options;
114
+
115
+ const { li, nav, div, header, a } = bau.tags;
99
116
  const Animate = animate(context);
117
+ const List = list(context);
100
118
 
101
- const { hideToLeft, hideToRight, showFromRight, showFromLeft } =
102
- createStyles(context);
119
+ const Button = button(context, {
120
+ class: css`
121
+ &.button {
122
+ justify-content: flex-start;
123
+ }
124
+ `,
125
+ });
126
+ const { hideToLeft, hideToRight } = createStyles(context);
103
127
 
104
128
  const className = css`
105
129
  font-weight: var(--font-weight-semibold);
106
130
  overflow: hidden;
107
131
  position: relative;
108
- & a,
109
- span {
110
- flex-grow: 1;
111
- text-decoration: none;
112
- color: var(--drill-down-menu-color);
113
- }
132
+
114
133
  & header {
115
134
  display: flex;
116
135
  align-items: center;
117
- cursor: pointer;
118
136
  font-weight: var(--font-weight-bold);
119
- border-bottom: 1px solid var(--color-emphasis-100);
120
- padding: var(--drill-down-menu-padding);
121
- transition: background-color var(--transition-slow) ease-in-out;
122
- &:hover {
123
- background: var(--drill-down-menu-bg-hover);
124
- }
125
- &::before {
126
- content: "\u2190";
127
- margin-right: 0.5rem;
137
+ border-bottom: 1px solid var(--color-emphasis-200);
138
+ & a {
139
+ padding: 0.6rem;
140
+ border-radius: 0;
128
141
  }
129
142
  }
130
143
  & ul {
131
- display: block;
132
- list-style: none;
133
- margin: 0;
134
- padding-left: 0;
135
144
  overflow: hidden;
136
145
  & .has-children {
137
146
  &::after {
@@ -139,112 +148,122 @@ export default function (context, { renderMenuItem }) {
139
148
  padding: 0 0.5rem 0 0.5rem;
140
149
  }
141
150
  }
142
- & .is-active {
143
- background-color: var(--drill-down-menu-bg-active);
144
- }
145
151
  & li {
146
- padding: var(--drill-down-menu-padding);
147
- cursor: pointer;
148
- display: flex;
149
- justify-content: space-between;
150
- align-items: center;
151
- background-color: transparent;
152
- transition: background-color var(--transition-slow) ease-in-out;
153
- &:hover {
154
- background-color: var(--drill-down-menu-bg-hover);
155
- cursor: pointer;
152
+ padding: 0;
153
+ & a {
154
+ width: 100%;
156
155
  }
157
156
  }
158
157
  }
159
158
  `;
160
159
 
161
- const Menu = ({ onclickItem, onclickBack, currentTree }) => {
160
+ const Menu = ({ variant, color, size, currentTree, pathnameState }) => {
162
161
  const { children, parentTree, data } = currentTree;
162
+ //console.log("Menu", currentTree, pathnameState.val);
163
163
  return div(
164
- { class: "drillDownMenu" },
165
- parentTree &&
166
- header(
167
- {
168
- onclick: onclickBack({ currentTree }),
169
- },
170
- a({ href: currentTree.parentTree.children[0].data.href }, data.name)
171
- ),
164
+ { class: cn("drillDownMenu", variant, color, size) },
165
+ parentTree && renderHeader({ data, currentTree }),
172
166
  children &&
173
- ul(
167
+ List(
168
+ { class: cn(variant, color, size) },
174
169
  children.map((subTree) =>
175
170
  li(
176
171
  {
177
- class: cn(
178
- subTree.children && "has-children",
179
- isActive({ window, subTree }) && "is-active"
180
- ),
181
- onclick:
182
- subTree.children && onclickItem({ currentTree: subTree }),
172
+ class: () =>
173
+ cn(
174
+ subTree.children && "has-children",
175
+ isActive({ pathname: pathnameState.val, subTree }) &&
176
+ "active"
177
+ ),
183
178
  },
184
- renderMenuItem(subTree.data)
179
+ renderMenuItem(subTree)
185
180
  )
186
181
  )
187
182
  )
188
183
  );
189
184
  };
190
185
 
191
- return function DrillDownMenu({
192
- tree,
193
- pathnameState = bau.state(window.location.pathname),
194
- ...otherProps
195
- }) {
196
- const onclickItem =
197
- ({ currentTree }) =>
198
- (event) =>
199
- replaceChildren(event, navEl, currentTree, true);
200
-
201
- const onclickBack =
202
- ({ currentTree }) =>
203
- (event) =>
204
- replaceChildren(event, navEl, currentTree.parentTree, false);
205
-
206
- const replaceChildren = (event, navEl, currentTree, right) => {
207
- // If the navEl is replaced, the bau binding is lost.
208
- navEl.firstChild.replaceChildren(
209
- Animate(
210
- {
211
- parent: navEl,
212
- animationHide: `${
213
- right ? hideToLeft : hideToRight
214
- } ${animationDuration}`,
215
- animationShow: `${
216
- right ? showFromRight : showFromLeft
217
- } ${animationDuration}`,
218
- },
219
- Menu({
220
- currentTree,
221
- onclickItem,
222
- onclickBack,
223
- })
224
- )
225
- );
186
+ const findInitialTree = ({ tree, pathname }) => {
187
+ let currentTree = treeAddParent({})(structuredClone(tree));
188
+ let subTree = findSubTree(pathname)(currentTree);
189
+ if (!subTree) {
190
+ console.log("drilldown no sub tree", pathname);
191
+ subTree = currentTree;
192
+ }
193
+ return subTree;
194
+ };
195
+
196
+ return function DrillDownMenu(props) {
197
+ const {
198
+ variant = "plain",
199
+ color = "neutral",
200
+ size = "md",
201
+ tree,
202
+ pathnameState = bau.state(window.location.pathname),
203
+ ...otherProps
204
+ } = props;
205
+
206
+ let direction = 1;
207
+
208
+ const onclick = (event) => {
209
+ const { dataset } = event.target;
210
+ if (dataset.buttonback == "true") {
211
+ direction = -1;
212
+ } else if (dataset.ischild == "false") {
213
+ direction = 1;
214
+ } else if (dataset.ischild == "true") {
215
+ direction = 0;
216
+ }
217
+ };
218
+
219
+ const treeState = bau.derive(() =>
220
+ findInitialTree({
221
+ tree,
222
+ pathname: pathnameState.val,
223
+ })
224
+ );
225
+
226
+ const animationHide = (direction) => {
227
+ switch (direction) {
228
+ case 1:
229
+ return `${hideToLeft} ${animationDuration}`;
230
+ case -1:
231
+ return `${hideToRight} ${animationDuration}`;
232
+ default:
233
+ return "";
234
+ }
226
235
  };
227
236
 
228
- const navEl = nav(
237
+ const animationShow = (direction) => {
238
+ switch (direction) {
239
+ case 1:
240
+ return `${hideToRight} ${animationDuration} reverse`;
241
+ case -1:
242
+ return `${hideToLeft} ${animationDuration} reverse`;
243
+ default:
244
+ return "";
245
+ }
246
+ };
247
+
248
+ return nav(
229
249
  {
230
- class: cn(className, otherProps.class),
250
+ class: cn(className, options?.class, otherProps.class),
251
+ onclick,
231
252
  },
232
- () => {
233
- let currentTree = treeAddParent({})(tree);
234
- let subTree = findSubTree(pathnameState.val)(currentTree);
235
- if (!subTree) {
236
- subTree = currentTree;
237
- }
238
- return div(
253
+ Animate(
254
+ {
255
+ animationHide: () => animationHide(direction),
256
+ animationShow: () => animationShow(direction),
257
+ },
258
+ () =>
239
259
  Menu({
240
- currentTree: subTree,
241
- onclickItem,
242
- onclickBack,
260
+ variant,
261
+ color,
262
+ size,
263
+ currentTree: treeState.val,
264
+ pathnameState,
243
265
  })
244
- );
245
- }
266
+ )
246
267
  );
247
-
248
- return navEl;
249
268
  };
250
269
  }
@@ -1,18 +1,26 @@
1
1
  declare module "@grucloud/bau-ui/drillDownMenu" {
2
+ type DefaultDesignProps = import("../constants").DefaultDesignProps;
3
+ type ComponentOption = import("../bau-ui").ComponentOption;
4
+
2
5
  type Tree = {
3
6
  data?: object;
4
7
  children?: Tree[];
5
8
  };
9
+
6
10
  export type TreeViewProps = {
7
11
  tree: Tree;
8
- };
12
+ } & DefaultDesignProps;
9
13
 
10
14
  type Component = import("../bau-ui").Component<TreeViewProps>;
11
15
 
12
16
  type ComponentGeneric = import("../bau-ui").ComponentGeneric;
13
17
 
14
18
  type Option = {
15
- renderMenuItem: ComponentGeneric;
16
- };
19
+ renderHeader?: ComponentGeneric;
20
+ renderMenuItem?: ComponentGeneric;
21
+ isActive?: (input: { subTree: object }) => boolean;
22
+ base?: string;
23
+ } & ComponentOption;
24
+
17
25
  export default function (context: Object, option: Option): Component;
18
26
  }
@@ -1,13 +1,13 @@
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 function (context, options = {}) {
4
+ export default function (context, options) {
4
5
  const { bau, css } = context;
5
6
  const { div, span, label, input } = bau.tags;
6
7
 
7
8
  const style = {
8
9
  base: css`
9
10
  display: inline-block;
10
- width: 20rem;
11
11
  > * {
12
12
  margin: 1rem 0;
13
13
  }
@@ -31,18 +31,17 @@ export default function (context, options = {}) {
31
31
  justify-content: center;
32
32
  align-items: center;
33
33
  cursor: pointer;
34
- border: var(--global-border-width) dotted;
35
- box-shadow: var(--shadow-s);
34
+ transition: all var(--transition-slow) ease-out;
35
+ &:hover.solid {
36
+ filter: brightness(var(--brightness-hover-always)) !important;
37
+ }
36
38
  &:hover {
37
- box-shadow: var(--shadow-m);
39
+ filter: brightness(var(--brightness-hover));
38
40
  }
39
41
  }
40
42
  `,
41
43
  disabled: css`
42
- color: var(--color-gray-500);
43
44
  & label {
44
- background-color: var(--color-gray-100);
45
- border: var(--global-border-width) var(--color-gray-500) dotted;
46
45
  &:hover {
47
46
  box-shadow: var(--shadow-s);
48
47
  }
@@ -52,13 +51,28 @@ export default function (context, options = {}) {
52
51
  };
53
52
 
54
53
  return function FileInput(props, ...children) {
55
- const { Component, disabled, ...otherProps } = props;
54
+ const {
55
+ variant = "outline",
56
+ color = "neutral",
57
+ size = "md",
58
+ Component,
59
+ disabled,
60
+ ...otherProps
61
+ } = props;
56
62
 
57
63
  return div(
58
64
  {
59
- class: classNames(style.base, disabled && style.disabled, props.class),
65
+ class: classNames(
66
+ style.base,
67
+ disabled && style.disabled,
68
+ options?.class,
69
+ props.class
70
+ ),
60
71
  },
61
72
  label(
73
+ {
74
+ class: classNames(variant, color, size),
75
+ },
62
76
  Component({ disabled }),
63
77
  input({ type: "file", disabled, ...otherProps })
64
78
  ),
@@ -1,9 +1,15 @@
1
1
  declare module "@grucloud/bau-ui/fileInput" {
2
+ type DefaultDesignProps = import("../constants").DefaultDesignProps;
3
+ type ComponentOption = import("../bau-ui").ComponentOption;
4
+
2
5
  export type FileInputProps = {
3
6
  disabled?: boolean;
4
- };
7
+ } & DefaultDesignProps;
5
8
 
6
- type Component = import("../bau-ui").Component<FileInputProps>;
9
+ type Component = import("../bau-ui").Component<
10
+ FileInputProps,
11
+ HTMLInputElement
12
+ >;
7
13
 
8
- export default function (context: any): Component;
14
+ export default function (context: any, option?: ComponentOption): Component;
9
15
  }
package/form/form.js ADDED
@@ -0,0 +1,31 @@
1
+ import classNames from "@grucloud/bau-css/classNames.js";
2
+ import { toPropsAndChildren } from "@grucloud/bau/bau.js";
3
+
4
+ export default function (context, options) {
5
+ const { bau, css } = context;
6
+ const { form } = bau.tags;
7
+
8
+ const className = css``;
9
+
10
+ return function Form(...args) {
11
+ let [
12
+ { color, variant = "outline", size = "md", content, ...props },
13
+ ...children
14
+ ] = toPropsAndChildren(args);
15
+ return form(
16
+ {
17
+ ...props,
18
+ class: classNames(
19
+ "form",
20
+ color,
21
+ variant,
22
+ size,
23
+ className,
24
+ options?.class,
25
+ props?.class
26
+ ),
27
+ },
28
+ ...children
29
+ );
30
+ };
31
+ }
@@ -0,0 +1,10 @@
1
+ declare module "@grucloud/bau-ui/form" {
2
+ type DefaultDesignProps = import("../constants").DefaultDesignProps;
3
+ type ComponentOption = import("../bau-ui").ComponentOption;
4
+
5
+ export type FormProps = {} & DefaultDesignProps;
6
+
7
+ type Component = import("../bau-ui").Component<FormProps>;
8
+
9
+ export default function (context: any, option?: ComponentOption): Component;
10
+ }
package/form/index.js ADDED
@@ -0,0 +1 @@
1
+ export { default } from "./form";