@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
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # BauUI
2
2
 
3
- A component library for built with Bau.
3
+ A component library for built with Bau,
4
4
 
5
- The library provides 20+ components such as button, input, tabs, tree etc ...
5
+ The library provides 25+ components such as button, input, tabs, tree etc ...
6
+
7
+ Visit the [bau-ui website](https://grucloud.github.io/bau/bau-ui/) to see the component gallery.
@@ -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
  }
@@ -1,43 +1,57 @@
1
+ import classNames from "@grucloud/bau-css/classNames.js";
2
+
1
3
  export default function (context, options = {}) {
2
- return function Animate({ parent, animationHide, animationShow }, node) {
3
- // Show
4
- node.style.animation = animationShow;
5
- const animationEndHandler = () => {
6
- node.removeEventListener("animationend", animationEndHandler);
7
- node.style.animation = "";
8
- };
9
- node.addEventListener("animationend", animationEndHandler);
4
+ const { bau } = context;
5
+ const { div } = bau.tags;
6
+ const noop = () => undefined;
10
7
 
11
- // Hide
12
- new MutationObserver((mutationList, observer) => {
13
- mutationList
14
- .filter((record) => record.removedNodes)
15
- .forEach((record) =>
16
- [...record.removedNodes].find((removedNode) => {
17
- parent.style.position = "relative";
18
- const nodeCloned = removedNode.cloneNode(true);
8
+ return function Animate(
9
+ { animationHide = noop, animationShow = noop, ...props },
10
+ child
11
+ ) {
12
+ return div(
13
+ {
14
+ class: classNames("animate", options?.class, props.class),
15
+ bauChildMutated: ({ record, element }) => {
16
+ // Removed Nodes
17
+ [...record.removedNodes].forEach((childNode) => {
18
+ if (!animationHide() || childNode.getAttribute("cloned")) return;
19
+ const nodeCloned = childNode.cloneNode(true);
20
+ nodeCloned.setAttribute("cloned", true);
19
21
  nodeCloned.style.top = 0;
20
22
  nodeCloned.style.left = 0;
23
+ nodeCloned.style.width = childNode.getAttribute("width");
24
+ nodeCloned.style.height = childNode.getAttribute("height");
21
25
  nodeCloned.style.position = "absolute";
22
- nodeCloned.style.animation = animationHide;
23
- if (record.previousSibling) {
24
- record.previousSibling.after(nodeCloned);
25
- } else if (record.nextSibling) {
26
- record.nextSibling.before(nodeCloned);
27
- } else if (record.target) {
28
- record.target.appendChild(nodeCloned);
29
- } else {
30
- }
31
-
26
+ nodeCloned.style.animation = animationHide();
27
+ record.target.appendChild(nodeCloned);
32
28
  nodeCloned.addEventListener("animationend", () =>
33
29
  nodeCloned.parentNode.removeChild(nodeCloned)
34
30
  );
35
- observer.disconnect();
36
- return true;
37
- })
38
- );
39
- }).observe(parent, { childList: true, subtree: true });
40
-
41
- return node;
31
+ });
32
+ // Added Nodes
33
+ [...record.addedNodes].forEach((childNode) => {
34
+ if (childNode.getAttribute("cloned")) return;
35
+ element.style.position = "relative";
36
+ const rect = childNode.getBoundingClientRect();
37
+ childNode.setAttribute("width", rect.width + "px");
38
+ childNode.setAttribute("height", rect.height + "px");
39
+ if (animationShow()) {
40
+ childNode.style.animation = animationShow();
41
+ const animationEndHandler = () => {
42
+ childNode.removeEventListener(
43
+ "animationend",
44
+ animationEndHandler
45
+ );
46
+ childNode.style.animation = "";
47
+ };
48
+ childNode.addEventListener("animationend", animationEndHandler);
49
+ }
50
+ });
51
+ },
52
+ ...props,
53
+ },
54
+ child
55
+ );
42
56
  };
43
57
  }
@@ -1,8 +1,7 @@
1
1
  declare module "@grucloud/bau-ui/animate" {
2
2
  export type AnimateProps = {
3
- parent: Element;
4
- animationHide: string;
5
- animationShow: string;
3
+ animationHide?: () => string;
4
+ animationShow?: () => string;
6
5
  };
7
6
 
8
7
  type Component = import("../bau-ui").ComponentOneChild<AnimateProps>;