@grucloud/bau-ui 0.49.0 → 0.51.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.
@@ -0,0 +1,48 @@
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 { div } = bau.tags;
7
+ const className = css`
8
+ display: flex;
9
+ align-items: center;
10
+ .content {
11
+ margin: 1rem;
12
+ font-weight: 400;
13
+ font-size: 0.875rem;
14
+ }
15
+ &::before,
16
+ &::after {
17
+ content: "";
18
+ width: 100%;
19
+ height: 0px;
20
+ border-top: 1px solid var(--color-emphasis-200);
21
+ }
22
+ `;
23
+
24
+ return function Divider(...args) {
25
+ let [
26
+ {
27
+ size = options.size ?? "md",
28
+ variant = options.variant ?? "plain",
29
+ color = options.color ?? "neutral",
30
+ ...props
31
+ },
32
+ ...children
33
+ ] = toPropsAndChildren(args);
34
+ return div(
35
+ {
36
+ ...props,
37
+ class: classNames(
38
+ "divider",
39
+ size,
40
+ className,
41
+ options?.class,
42
+ props?.class
43
+ ),
44
+ },
45
+ div({ class: "content" }, ...children)
46
+ );
47
+ };
48
+ }
@@ -0,0 +1,10 @@
1
+ declare module "@grucloud/bau-ui/divider" {
2
+ type DefaultDesignProps = import("../constants").DefaultDesignProps;
3
+ type ComponentOption = import("../bau-ui").ComponentOption;
4
+
5
+ export type DividerProps = {} & DefaultDesignProps;
6
+
7
+ type Component = import("../bau-ui").Component<DividerProps>;
8
+
9
+ export default function (context: any, option?: ComponentOption): Component;
10
+ }
@@ -0,0 +1 @@
1
+ export { default } from "./divider";
@@ -0,0 +1,142 @@
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 list from "../list/list.js";
6
+
7
+ import { Colors } from "../constants.js";
8
+
9
+ const colorsToCss = () =>
10
+ Colors.map(
11
+ (color) =>
12
+ `
13
+ `
14
+ ).join("\n");
15
+
16
+ export default function (context, componentOptions = {}) {
17
+ const { bau, css } = context;
18
+ const { div, li } = bau.tags;
19
+ const Button = button(context);
20
+ const Popover = popover(context);
21
+ const List = list(context);
22
+
23
+ const className = css`
24
+ ${colorsToCss()}
25
+ `;
26
+
27
+ return function DropdownMenu(...args) {
28
+ let [
29
+ {
30
+ size = componentOptions.size ?? "md",
31
+ variant = componentOptions.variant ?? "outline",
32
+ color = componentOptions.color ?? "neutral",
33
+ label,
34
+ ListItem,
35
+ items,
36
+ ...props
37
+ },
38
+ ...children
39
+ ] = toPropsAndChildren(args);
40
+
41
+ const itemIndexActive = bau.state(0);
42
+
43
+ const dialogOpen = () => {
44
+ popoverEl.openDialog();
45
+ popoverEl.focus();
46
+ };
47
+
48
+ const dialogClose = () => {
49
+ popoverEl.closeDialog();
50
+ };
51
+
52
+ const toggleDialog = () => {
53
+ popoverEl.open ? dialogClose() : dialogOpen();
54
+ };
55
+
56
+ const onclickButton = (event) => {
57
+ toggleDialog();
58
+ event.preventDefault();
59
+ };
60
+
61
+ const onclickItem =
62
+ ({ item, index }) =>
63
+ (event) => {
64
+ itemIndexActive.val = index;
65
+ dialogClose();
66
+ event.preventDefault();
67
+ };
68
+
69
+ const onkeydown = (event) => {
70
+ event.preventDefault();
71
+ switch (event.key) {
72
+ case "Escape":
73
+ dialogClose();
74
+ break;
75
+ case "ArrowDown":
76
+ if (itemIndexActive.val < options.length - 1) {
77
+ itemIndexActive.val++;
78
+ } else {
79
+ itemIndexActive.val = 0;
80
+ }
81
+ break;
82
+ case "ArrowUp":
83
+ if (itemIndexActive.val <= 0) {
84
+ itemIndexActive.val = options.length - 1;
85
+ } else {
86
+ itemIndexActive.val--;
87
+ }
88
+ break;
89
+ case "Enter":
90
+ toggleDialog();
91
+ break;
92
+ }
93
+ };
94
+
95
+ const Content = () =>
96
+ List(
97
+ { tabindex: "0", class: classNames(color, variant) },
98
+ items.map((item, index) =>
99
+ li(
100
+ {
101
+ class: () => classNames(itemIndexActive.val == index && "active"),
102
+ onclick: onclickItem({ item, index }),
103
+ },
104
+ ListItem(item)
105
+ )
106
+ )
107
+ );
108
+
109
+ const buttonEl = Button(
110
+ {
111
+ type: "button",
112
+ onclick: onclickButton,
113
+ color,
114
+ variant,
115
+ size,
116
+ },
117
+ label
118
+ );
119
+
120
+ const popoverEl = Popover({
121
+ triggerEl: buttonEl,
122
+ contentEl: Content(),
123
+ });
124
+
125
+ return div(
126
+ {
127
+ ...props,
128
+ class: classNames(
129
+ "dropdownMenu",
130
+ color,
131
+ size,
132
+ className,
133
+ componentOptions?.class,
134
+ props?.class
135
+ ),
136
+ onkeydown,
137
+ },
138
+ buttonEl,
139
+ popoverEl
140
+ );
141
+ };
142
+ }
@@ -0,0 +1,18 @@
1
+ declare module "@grucloud/bau-ui/dropdownMenu" {
2
+ type DefaultDesignProps = import("../constants").DefaultDesignProps;
3
+ type ComponentOption = import("../bau-ui").ComponentOption;
4
+
5
+ export type DropdownMenuProps = {
6
+ items: object[];
7
+ id?: string;
8
+ label: string;
9
+ ListItem: (props) => HTMLElement;
10
+ } & DefaultDesignProps;
11
+
12
+ type Component = import("../bau-ui").Component<
13
+ DropdownMenuProps,
14
+ HTMLInputElement
15
+ >;
16
+
17
+ export default function (context: any, option?: ComponentOption): Component;
18
+ }
@@ -0,0 +1 @@
1
+ export { default } from "./dropdownMenu";
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.49.0",
4
+ "version": "0.51.0",
5
5
  "type": "module",
6
6
  "license": "BSD",
7
7
  "keywords": [
@@ -20,11 +20,11 @@
20
20
  "directory": "bau-ui"
21
21
  },
22
22
  "dependencies": {
23
- "@grucloud/bau": "^0.49.0",
24
- "@grucloud/bau-css": "^0.49.0"
23
+ "@grucloud/bau": "^0.51.0",
24
+ "@grucloud/bau-css": "^0.51.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "typedoc": "0.24.8"
28
28
  },
29
- "gitHead": "e2ae7c556efa95e6c178f948d139ec889bc3e413"
29
+ "gitHead": "0067842470f5744aa1420bb096f020446be12275"
30
30
  }