@grucloud/bau-ui 0.24.0 → 0.26.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/alert/alert.js CHANGED
@@ -1,3 +1,5 @@
1
+ import classNames from "@grucloud/bau-css/classNames";
2
+
1
3
  import button from "../button";
2
4
 
3
5
  const severityMap = {
@@ -61,7 +63,7 @@ ${severitiesToCss()}
61
63
  };
62
64
  };
63
65
 
64
- export default function (context, options = {}) {
66
+ export default function (context) {
65
67
  const { bau, css, createGlobalStyles, tr } = context;
66
68
  const { div } = bau.tags;
67
69
 
@@ -81,11 +83,10 @@ export default function (context, options = {}) {
81
83
 
82
84
  return function Alert(props, ...children) {
83
85
  const { severity = "info", onRemove, ...otherProps } = props;
84
-
85
86
  return div(
86
87
  {
87
88
  ...otherProps,
88
- class: `${styles.base} alert-${severity}`,
89
+ class: classNames(styles.base, `alert-${severity}`, props.class),
89
90
  role: "alert",
90
91
  },
91
92
  div({ class: "icon" }, severityMap[severity]),
@@ -0,0 +1,16 @@
1
+ declare module "@grucloud/bau-ui/alert" {
2
+ export type AnimateProps = {
3
+ severity:
4
+ | "primary"
5
+ | "secondary"
6
+ | "danger"
7
+ | "warning"
8
+ | "info"
9
+ | "success";
10
+ onRemove?: Function;
11
+ };
12
+
13
+ type Component = import("../bau-ui").Component<AnimateProps>;
14
+
15
+ export default function (context: Object): Component;
16
+ }
@@ -1,4 +1,6 @@
1
- export default (context, { limit = 10, deleteAfterDuration = 5e3 } = {}) => {
1
+ import classNames from "@grucloud/bau-css/classNames";
2
+
3
+ export default (context, { limit = 10, deleteAfterDuration = 15e3 } = {}) => {
2
4
  const { bau, css, keyframes } = context;
3
5
  const { div } = bau.tags;
4
6
  const messagesState = bau.state([]);
@@ -13,10 +15,11 @@ export default (context, { limit = 10, deleteAfterDuration = 5e3 } = {}) => {
13
15
  100% { transform: scale(0); opacity: 0 }
14
16
  `,
15
17
  };
18
+
16
19
  const styles = {
17
20
  stack: css`
18
21
  min-width: 300px;
19
- max-width: 600px;
22
+ max-width: 90% vw;
20
23
  position: fixed;
21
24
  right: var(--global-spacing);
22
25
  top: var(--global-spacing);
@@ -26,7 +29,7 @@ export default (context, { limit = 10, deleteAfterDuration = 5e3 } = {}) => {
26
29
  margin: 0.2rem;
27
30
  padding: 0.2rem;
28
31
  display: flex;
29
- justify-content: flex-start;
32
+ justify-content: flex-end;
30
33
  align-items: center;
31
34
  cursor: pointer;
32
35
  animation: ${animation.inserting} var(--transition-slow) ease-out;
@@ -36,19 +39,53 @@ export default (context, { limit = 10, deleteAfterDuration = 5e3 } = {}) => {
36
39
  `,
37
40
  };
38
41
 
39
- const AlertItem = (message) =>
40
- div(
41
- {
42
- class: styles.item,
43
- onclick: () => AlertStack.remove(message),
44
- },
45
- message.component()
46
- );
42
+ const setStatus = ({ id, status }) => {
43
+ const idx = messagesState.val.findIndex((message) => message.id === id);
44
+ if (idx != -1) {
45
+ messagesState.val[idx].status = status;
46
+ }
47
+ };
48
+
49
+ return function AlertStack(props = {}, ...children) {
50
+ const remove = ({ id }) => {
51
+ setStatus({ id, status: "removing" });
52
+ const idx = messagesState.val.findIndex((message) => message.id === id);
53
+ if (idx != -1) {
54
+ messagesState.val.splice(idx, 1);
55
+ }
56
+ };
57
+
58
+ const add = ({ Component }) => {
59
+ const message = {
60
+ id: Math.random().toString(10).split(".")[1],
61
+ Component,
62
+ status: "inserting",
63
+ };
64
+
65
+ if (messagesState.val.length >= limit) {
66
+ remove({ id: messagesState.val[0].id });
67
+ }
68
+
69
+ messagesState.val.push(message);
70
+
71
+ setTimeout(() => remove(message), deleteAfterDuration);
72
+ };
73
+
74
+ const AlertItem = (message) =>
75
+ div(
76
+ {
77
+ class: styles.item,
78
+ onclick: () => remove(message),
79
+ },
80
+ message.Component()
81
+ );
82
+
83
+ document.addEventListener("alert.add", (event) => add(event.detail));
84
+ document.addEventListener("alert.remove", (event) => remove(event.detail));
47
85
 
48
- const AlertStack = (props, ...children) =>
49
- div(
86
+ return div(
50
87
  {
51
- class: styles.stack,
88
+ class: classNames(styles.stack, props.class),
52
89
  },
53
90
  bau.bind({
54
91
  deps: [messagesState],
@@ -59,39 +96,5 @@ export default (context, { limit = 10, deleteAfterDuration = 5e3 } = {}) => {
59
96
  renderItem: () => AlertItem,
60
97
  })
61
98
  );
62
-
63
- AlertStack.add = ({ component }) => {
64
- const message = {
65
- id: Math.random().toString(10).split(".")[1],
66
- component,
67
- status: "inserting",
68
- };
69
-
70
- if (messagesState.val.length >= limit) {
71
- AlertStack.remove({ id: messagesState.val[0].id });
72
- }
73
-
74
- messagesState.val.push(message);
75
-
76
- setTimeout(() => AlertStack.remove(message), deleteAfterDuration);
77
99
  };
78
-
79
- const setStatus = ({ id, status }) => {
80
- const idx = messagesState.val.findIndex((message) => message.id === id);
81
- if (idx != -1) {
82
- messagesState.val[idx].status = status;
83
- }
84
- };
85
-
86
- AlertStack.remove = ({ id }) => {
87
- setStatus({ id, status: "removing" });
88
- const idx = messagesState.val.findIndex((message) => message.id === id);
89
- if (idx != -1) {
90
- messagesState.val.splice(idx, 1);
91
- } else {
92
- // console.log("remove: no id", id);
93
- }
94
- };
95
-
96
- return AlertStack;
97
100
  };
@@ -0,0 +1,10 @@
1
+ declare module "@grucloud/bau-ui/alertStack" {
2
+ export type AlertStackProps = {};
3
+
4
+ type AlertStack = import("../bau-ui").Component<AlertStackProps>;
5
+
6
+ export default function (
7
+ context: any,
8
+ options: { limit?: Number; deleteAfterDuration?: Number }
9
+ ): AlertStack;
10
+ }
@@ -1,6 +1,6 @@
1
1
  export default function (context, options = {}) {
2
- return function Animate({ Component, parent, animationHide, animationShow }) {
3
- const node = Component();
2
+ return function Animate({ parent, animationHide, animationShow }, child) {
3
+ const node = child;
4
4
  // Show
5
5
  node.style.animation = animationShow;
6
6
  const animationEndHandler = () => {
@@ -0,0 +1,11 @@
1
+ declare module "@grucloud/bau-ui/animate" {
2
+ export type AnimateProps = {
3
+ parent: Element;
4
+ animationHide: string;
5
+ animationShow: string;
6
+ };
7
+
8
+ type Component = import("../bau-ui").ComponentOneChild<AnimateProps>;
9
+
10
+ export default function (context: any): Component;
11
+ }
package/avatar/avatar.js CHANGED
@@ -1,8 +1,7 @@
1
- import { classNames } from "../utils/classNames";
1
+ import classNames from "@grucloud/bau-css/classNames";
2
2
 
3
3
  export default function (context, options = {}) {
4
- const { bau, css } = context;
5
- const { cssOverride } = options;
4
+ const { bau } = context;
6
5
  const { span, img } = bau.tags;
7
6
 
8
7
  const loadingState = bau.state(true);
@@ -17,7 +16,7 @@ export default function (context, options = {}) {
17
16
 
18
17
  return function Avatar({ width = 60, height = 60, ...props }, ...children) {
19
18
  return span(
20
- { class: classNames(cssOverride) },
19
+ { class: classNames(options.cssOverride, props.class) },
21
20
  bau.bind({
22
21
  deps: [loadingState],
23
22
  render: () => (loading) => {
@@ -0,0 +1,13 @@
1
+ declare module "@grucloud/bau-ui/avatar" {
2
+ export type AvatarProps = {
3
+ class?: string;
4
+ alt: string;
5
+ src: string;
6
+ width?: Number;
7
+ height?: Number;
8
+ };
9
+
10
+ type Component = import("../bau-ui").Component<AvatarProps>;
11
+
12
+ export default function (context: any): Component;
13
+ }
package/bau-ui.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ type Props = import("@grucloud/bau").Props;
2
+ type ChildDom = import("@grucloud/bau").ChildDom;
3
+
4
+ export type Component<TProps, TElement = HTMLElement> = (
5
+ props?: (TProps & Props) | ChildDom,
6
+ ...rest: readonly ChildDom[]
7
+ ) => TElement;
8
+
9
+ export type ComponentWithProp<TProps, TElement = HTMLElement> = (
10
+ props: (TProps & Props) | ChildDom,
11
+ ...rest: readonly ChildDom[]
12
+ ) => TElement | string | number | boolean | bigint | null | undefined;
13
+
14
+ export type ComponentOneChild<TProps, TElement = HTMLElement> = (
15
+ props: TProps & Props,
16
+ child: ChildDom
17
+ ) => TElement;
18
+
19
+ export type ComponentGeneric = (
20
+ props?: Props,
21
+ ...rest: readonly ChildDom[]
22
+ ) => HTMLElement | string | number | boolean | bigint | null | undefined;
package/button/button.js CHANGED
@@ -1,8 +1,7 @@
1
- import { classNames } from "../utils/classNames";
1
+ import classNames from "@grucloud/bau-css/classNames";
2
2
 
3
- export default function (context, options = {}) {
3
+ export default function (context) {
4
4
  const { bau, css } = context;
5
- const { span } = bau.tags;
6
5
 
7
6
  const styles = {
8
7
  root: css`
@@ -121,8 +120,6 @@ export default function (context, options = {}) {
121
120
 
122
121
  return function Button(props, ...children) {
123
122
  const {
124
- fullWidth,
125
- label,
126
123
  primary,
127
124
  accent,
128
125
  raised,
@@ -146,7 +143,6 @@ export default function (context, options = {}) {
146
143
  raised && accent && styles.raisedAccent,
147
144
  ripple && styles.rippledisabled && styles.disabled,
148
145
  disabled && raised && styles.raisedDisabled,
149
- fullWidth && styles.fullWidth,
150
146
  props.class
151
147
  ),
152
148
  href,
@@ -0,0 +1,19 @@
1
+ declare module "@grucloud/bau-ui/button" {
2
+ type Props = import("@grucloud/bau").Props;
3
+
4
+ type ButtonProps = {
5
+ raised?: boolean;
6
+ primary?: boolean;
7
+ accent?: boolean;
8
+ ripple?: boolean;
9
+ disabled?: boolean;
10
+ href?: string;
11
+ };
12
+
13
+ type Component = import("../bau-ui").Component<
14
+ ButtonProps,
15
+ HTMLButtonElement | HTMLAnchorElement
16
+ >;
17
+
18
+ export default function (context: any): Component;
19
+ }
@@ -1,3 +1,5 @@
1
+ import classNames from "@grucloud/bau-css/classNames";
2
+
1
3
  export default function (context, options = {}) {
2
4
  const { bau, css } = context;
3
5
  const { input } = bau.tags;
@@ -42,7 +44,7 @@ export default function (context, options = {}) {
42
44
 
43
45
  return function Checkbox(props, ...children) {
44
46
  return input({
45
- class: style.base,
47
+ class: classNames(style.base, props.class),
46
48
  type: "checkbox",
47
49
  required: "required",
48
50
  ...props,
@@ -0,0 +1,10 @@
1
+ declare module "@grucloud/bau-ui/checkbox" {
2
+ export type CheckboxProps = {};
3
+
4
+ type Component = import("../bau-ui").Component<
5
+ CheckboxProps,
6
+ HTMLInputElement
7
+ >;
8
+
9
+ export default function (context: any): Component;
10
+ }
package/drawer/drawer.js CHANGED
@@ -1,4 +1,4 @@
1
- import { classNames } from "../utils/classNames";
1
+ import cn from "@grucloud/bau-css/classNames";
2
2
 
3
3
  export default function (context) {
4
4
  const { bau, css } = context;
@@ -9,7 +9,8 @@ export default function (context) {
9
9
  left: 0px;
10
10
  z-index: 2;
11
11
  & .overlay {
12
- position: absolute;
12
+ position: fixed;
13
+ visibility: hidden;
13
14
  z-index: -1;
14
15
  opacity: 0;
15
16
  background-color: var(--background-color);
@@ -20,6 +21,7 @@ export default function (context) {
20
21
  transition: opacity var(--transition-fast) ease-out;
21
22
  }
22
23
  & .overlay-open {
24
+ visibility: visible;
23
25
  z-index: 1;
24
26
  opacity: 0.5;
25
27
  }
@@ -45,22 +47,25 @@ export default function (context) {
45
47
  }
46
48
  `;
47
49
 
48
- return function Drawer({ openState }, ...children) {
50
+ return function Drawer({ openState, ...otherProps }, ...children) {
49
51
  return div(
50
- { class: style },
52
+ { class: cn(style, otherProps.class) },
53
+ // Overlay
51
54
  div({
52
55
  class: {
53
56
  deps: [openState],
54
- renderProp: () => (open) =>
55
- classNames("overlay", open && "overlay-open"),
57
+ renderProp: () => (open) => cn("overlay", open && "overlay-open"),
58
+ },
59
+ onclick: () => {
60
+ openState.val = false;
56
61
  },
57
62
  }),
63
+ // Content
58
64
  div(
59
65
  {
60
66
  class: {
61
67
  deps: [openState],
62
- renderProp: () => (open) =>
63
- classNames("content", open && "content-open"),
68
+ renderProp: () => (open) => cn("content", open && "content-open"),
64
69
  },
65
70
  },
66
71
  ...children
@@ -0,0 +1,7 @@
1
+ declare module "@grucloud/bau-ui/drawer" {
2
+ export type DrawerProps = {};
3
+
4
+ type Component = import("../bau-ui").Component<DrawerProps>;
5
+
6
+ export default function (context: any): Component;
7
+ }
@@ -1,4 +1,4 @@
1
- import { classNames } from "../utils/classNames";
1
+ import classNames from "@grucloud/bau-css/classNames";
2
2
 
3
3
  export default function (context, options = {}) {
4
4
  const { bau, css } = context;
@@ -7,7 +7,7 @@ export default function (context, options = {}) {
7
7
  const style = {
8
8
  base: css`
9
9
  display: inline-block;
10
- width: 25rem;
10
+ width: 20rem;
11
11
  > * {
12
12
  margin: 1rem 0;
13
13
  }
@@ -55,7 +55,9 @@ export default function (context, options = {}) {
55
55
  const { Component, disabled, ...otherProps } = props;
56
56
 
57
57
  return div(
58
- { class: classNames(style.base, disabled && style.disabled) },
58
+ {
59
+ class: classNames(style.base, disabled && style.disabled, props.class),
60
+ },
59
61
  label(
60
62
  Component({ disabled }),
61
63
  input({ type: "file", disabled, ...otherProps })
@@ -0,0 +1,9 @@
1
+ declare module "@grucloud/bau-ui/fileInput" {
2
+ export type FileInputProps = {
3
+ disabled?: boolean;
4
+ };
5
+
6
+ type Component = import("../bau-ui").Component<FileInputProps>;
7
+
8
+ export default function (context: any): Component;
9
+ }
@@ -0,0 +1,12 @@
1
+ declare module "@grucloud/bau-ui/input" {
2
+ export type InputProps = {
3
+ name: string;
4
+ id: string;
5
+ label: string;
6
+ error?: string;
7
+ };
8
+
9
+ type Component = import("../bau-ui").Component<InputProps>;
10
+
11
+ export default function (context: any): Component;
12
+ }
package/input/input.js CHANGED
@@ -1,4 +1,4 @@
1
- import { classNames } from "../utils/classNames";
1
+ import classNames from "@grucloud/bau-css/classNames";
2
2
 
3
3
  const createStyles = ({ css, createGlobalStyles }) => {
4
4
  createGlobalStyles`
@@ -0,0 +1,7 @@
1
+ declare module "@grucloud/bau-ui/modal" {
2
+ export type ModalProps = {};
3
+
4
+ type Component = import("../bau-ui").Component<ModalProps, HTMLDialogElement>;
5
+
6
+ export default function (context: any): Component;
7
+ }
package/modal/modal.js CHANGED
@@ -1,4 +1,6 @@
1
- export default function (context, options = {}) {
1
+ import classNames from "@grucloud/bau-css/classNames";
2
+
3
+ export default function (context) {
2
4
  const { bau, css } = context;
3
5
  const { dialog } = bau.tags;
4
6
 
@@ -38,7 +40,7 @@ export default function (context, options = {}) {
38
40
  }
39
41
  `;
40
42
 
41
- return function Modal({ open }, ...children) {
42
- return dialog({ class: style }, ...children);
43
+ return function Modal(props, ...children) {
44
+ return dialog({ class: classNames(style, props.class) }, ...children);
43
45
  };
44
46
  }
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.24.0",
4
+ "version": "0.26.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.24.0",
21
- "@grucloud/bau-css": "^0.24.0"
20
+ "@grucloud/bau": "^0.26.0",
21
+ "@grucloud/bau-css": "^0.26.0"
22
22
  },
23
- "gitHead": "fef7cd2b409a192927fba381fd8d57e354bc96ad"
23
+ "gitHead": "1d9811e23ad200dfedb06eaa0ffd85376169780d"
24
24
  }
@@ -0,0 +1,11 @@
1
+ declare module "@grucloud/bau-ui/spinner" {
2
+ export type SpinnerProps = {
3
+ size?: Number;
4
+ color?: "primary" | "secondary" | "warning" | "danger" | "info" | "success";
5
+ visibility?: boolean;
6
+ };
7
+
8
+ type Component = import("../bau-ui").Component<SpinnerProps>;
9
+
10
+ export default function (context: any): Component;
11
+ }
@@ -1,20 +1,27 @@
1
+ import classNames from "@grucloud/bau-css/classNames";
2
+
1
3
  export default function (context, options = {}) {
2
4
  const { bau, css } = context;
3
5
 
4
6
  const { svg, animate, animateTransform, rect } = bau.tagsNS(
5
7
  "http://www.w3.org/2000/svg"
6
8
  );
9
+
7
10
  return function Spinner({
8
11
  size = 36,
9
12
  color = "primary",
10
13
  visibility = true,
14
+ ...otherProps
11
15
  } = {}) {
12
16
  return svg(
13
17
  {
14
- class: css`
15
- visibility: ${visibility ? "visible" : "hidden"};
16
- color: var(--color-${color});
17
- `,
18
+ class: classNames(
19
+ css`
20
+ visibility: ${visibility ? "visible" : "hidden"};
21
+ color: var(--color-${color});
22
+ `,
23
+ otherProps.class
24
+ ),
18
25
  version: "1.1",
19
26
  id: "L6",
20
27
  x: "0px",
@@ -0,0 +1,7 @@
1
+ declare module "@grucloud/bau-ui/switch" {
2
+ export type SwitchProps = {};
3
+
4
+ type Component = import("../bau-ui").Component<SwitchProps, HTMLInputElement>;
5
+
6
+ export default function (context: any): Component;
7
+ }
package/switch/switch.js CHANGED
@@ -1,4 +1,6 @@
1
- export default function (context, options = {}) {
1
+ import classNames from "@grucloud/bau-css/classNames";
2
+
3
+ export default function (context) {
2
4
  const { bau, css } = context;
3
5
  const { input } = bau.tags;
4
6
 
@@ -34,13 +36,15 @@ export default function (context, options = {}) {
34
36
  }
35
37
  `;
36
38
 
37
- return function Switch({ id, ...otherProps }, ...children) {
38
- return input({
39
- class: style,
40
- type: "checkbox",
41
- required: "required",
42
- id,
43
- ...otherProps,
44
- });
39
+ return function Switch(props, ...children) {
40
+ return input(
41
+ {
42
+ ...props,
43
+ class: classNames(style, props.class),
44
+ type: "checkbox",
45
+ required: "required",
46
+ },
47
+ ...children
48
+ );
45
49
  };
46
50
  }
@@ -0,0 +1,27 @@
1
+ declare module "@grucloud/bau-ui/tabs" {
2
+ export type TabsProps = {};
3
+
4
+ type Component = import("../bau-ui").Component<TabsProps>;
5
+
6
+ type TabPropBase = {
7
+ name: string;
8
+ disabled?: boolean;
9
+ enter?: Function;
10
+ exit?: Function;
11
+ };
12
+
13
+ type ComponentTab = import("../bau-ui").ComponentWithProp<TabPropBase>;
14
+
15
+ export type Tab = {
16
+ Header: ComponentTab;
17
+ Content: ComponentTab;
18
+ } & TabPropBase;
19
+
20
+ export type Tabs = Tab[];
21
+
22
+ type Option = {
23
+ tabDefs: Tab[];
24
+ };
25
+
26
+ export default function (context: any, option: Option): Component;
27
+ }
package/tabs/tabs.js CHANGED
@@ -1,4 +1,4 @@
1
- import { classNames } from "../utils/classNames";
1
+ import classNames from "@grucloud/bau-css/classNames";
2
2
 
3
3
  export default function (context, { tabDefs }) {
4
4
  const { bau, css } = context;
@@ -0,0 +1,14 @@
1
+ declare module "@grucloud/bau-ui/treeView" {
2
+ export type TreeViewProps = {
3
+ tree: { children: object[] };
4
+ };
5
+
6
+ type Component = import("../bau-ui").Component<TreeViewProps>;
7
+
8
+ type ComponentGeneric = import("../bau-ui").ComponentGeneric;
9
+
10
+ type Option = {
11
+ renderMenuItem: ComponentGeneric;
12
+ };
13
+ export default function (context: Object, option: Option): Component;
14
+ }
@@ -1,4 +1,4 @@
1
- import { classNames } from "../utils/classNames";
1
+ import classNames from "@grucloud/bau-css/classNames";
2
2
 
3
3
  function collapseSection(element) {
4
4
  element.style.height = "0px";
@@ -111,9 +111,9 @@ export default function (context, { renderMenuItem }) {
111
111
  "aria-expanded": {
112
112
  deps: [closeState],
113
113
  renderProp:
114
- ({ dom }) =>
114
+ ({ element }) =>
115
115
  (close) => {
116
- close ? collapseSection(dom) : expandSection(dom);
116
+ close ? collapseSection(element) : expandSection(element);
117
117
  return !close;
118
118
  },
119
119
  },
@@ -123,7 +123,10 @@ export default function (context, { renderMenuItem }) {
123
123
  );
124
124
  };
125
125
 
126
- return function TreeView(tree) {
127
- return nav({ class: styles.nav }, ul(tree.children.map(Tree({}))));
126
+ return function TreeView({ tree, ...otherProps }) {
127
+ return nav(
128
+ { class: classNames(styles.nav, otherProps.class) },
129
+ ul(tree.children.map(Tree({})))
130
+ );
128
131
  };
129
132
  }
@@ -1,3 +0,0 @@
1
- export function classNames(...cn) {
2
- return cn.filter((className) => className).join(" ");
3
- }