@grucloud/bau-ui 0.77.0 → 0.79.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/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.77.0",
4
+ "version": "0.79.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.77.0",
24
- "@grucloud/bau-css": "^0.77.0"
23
+ "@grucloud/bau": "^0.79.0",
24
+ "@grucloud/bau-css": "^0.79.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "typedoc": "0.24.8"
28
28
  },
29
- "gitHead": "9e58b0716a9f5c791e1e6ae7a69b52c69c621c12"
29
+ "gitHead": "7d03eae6745c3be0e08eb40e005c168c92184e9a"
30
30
  }
@@ -13,7 +13,7 @@ export default function (context, options = {}) {
13
13
  &.radio-button.${color} {
14
14
  accent-color: var(--color-${color});
15
15
  }
16
- `
16
+ `
17
17
  ).join("\n");
18
18
 
19
19
  const className = css`
@@ -5,7 +5,7 @@ declare module "@grucloud/bau-ui/radioButtonGroup" {
5
5
  type RadioComponent = import("../bau-ui").ComponentGeneric;
6
6
 
7
7
  type RadioItem = {
8
- id: string;
8
+ value: string;
9
9
  Label: RadioComponent | RadioComponent[];
10
10
  };
11
11
  export type RadioButtonGroupProps = {
@@ -44,7 +44,6 @@ export default function (context, options = {}) {
44
44
  color = options.color ?? "neutral",
45
45
  name,
46
46
  oninput,
47
- value,
48
47
  radios = [],
49
48
  ...props
50
49
  },
@@ -52,7 +51,6 @@ export default function (context, options = {}) {
52
51
 
53
52
  return div(
54
53
  {
55
- ...props,
56
54
  class: classNames(
57
55
  "radioButtonGroup",
58
56
  size,
@@ -63,16 +61,17 @@ export default function (context, options = {}) {
63
61
  props?.class
64
62
  ),
65
63
  },
66
- radios.map(({ id, Label }) =>
64
+ radios.map(({ value, Label }) =>
67
65
  label(
68
66
  RadioButton({
67
+ ...props,
69
68
  size,
70
69
  variant,
71
70
  color,
72
- id,
71
+ id: value,
73
72
  name,
74
- checked: value == id,
75
- value: id,
73
+ checked: value == props.value,
74
+ value,
76
75
  oninput,
77
76
  }),
78
77
  Label()
@@ -0,0 +1,15 @@
1
+ declare module "@grucloud/bau-ui/resizable" {
2
+ type DefaultDesignProps = import("../constants").DefaultDesignProps;
3
+ type ComponentOption = import("../bau-ui").ComponentOption;
4
+
5
+ export type ResizableProps = {
6
+ direction?: "vertical" | "horizontal";
7
+ } & DefaultDesignProps;
8
+
9
+ type Component = import("../bau-ui").Component<ResizableProps>;
10
+
11
+ export default function (
12
+ context: any,
13
+ option?: ComponentOption & ResizableProps
14
+ ): { Panel: Component; PanelGroup: Component; Handle: Component };
15
+ }
@@ -0,0 +1 @@
1
+ export { default } from "./resizable";
@@ -0,0 +1,172 @@
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, window } = context;
6
+ const { section, article, div } = bau.tags;
7
+ const { document } = window;
8
+ const { direction = "horizontal" } = options;
9
+ const className = css`
10
+ & .resizablePanel {
11
+ box-sizing: border-box;
12
+ }
13
+ & .handle {
14
+ position: relative;
15
+ width: 1px;
16
+ cursor: col-resize;
17
+ display: flex;
18
+ justify-content: center;
19
+ align-items: center;
20
+ &::after {
21
+ content: "";
22
+ position: absolute;
23
+ background-color: var(--color-emphasis-100);
24
+ }
25
+ }
26
+ & .horizontal {
27
+ width: 1rem;
28
+ cursor: col-resize;
29
+ &::after {
30
+ height: 100%;
31
+ width: 1px;
32
+ }
33
+ }
34
+ & .vertical {
35
+ height: 1rem;
36
+ width: 100%;
37
+ cursor: row-resize;
38
+ &::after {
39
+ height: 1px;
40
+ width: 100%;
41
+ }
42
+ }
43
+ `;
44
+
45
+ function PanelGroup(...args) {
46
+ let [props, ...children] = toPropsAndChildren(args);
47
+
48
+ return section(
49
+ {
50
+ ...props,
51
+ class: classNames(
52
+ "resizablePanelGroup",
53
+ props?.class,
54
+ options?.class,
55
+ className
56
+ ),
57
+ },
58
+ children
59
+ );
60
+ }
61
+
62
+ function Panel(...args) {
63
+ let [props, ...children] = toPropsAndChildren(args);
64
+
65
+ return article(
66
+ {
67
+ ...props,
68
+ class: classNames("resizablePanel", props?.class),
69
+ },
70
+ children
71
+ );
72
+ }
73
+
74
+ function Handle(...args) {
75
+ let [props, ...children] = toPropsAndChildren(args);
76
+
77
+ // The current position of mouse
78
+ let _x = 0;
79
+ let _y = 0;
80
+ let _panelGroup;
81
+ let _nextPanel;
82
+ let _nextPanelRect;
83
+ let _previousPanel;
84
+ let _previousPanelRect;
85
+
86
+ const isHorizontal = () => direction === "horizontal";
87
+
88
+ const mouseMoveHandler = (event) =>
89
+ isHorizontal()
90
+ ? mouseMoveHandlerHorizontal(event)
91
+ : mouseMoveHandlerVertical(event);
92
+
93
+ const mouseMoveHandlerHorizontal = (event) => {
94
+ const dx = event.clientX - _x;
95
+ if (_previousPanelRect) {
96
+ _previousPanel.style.width = `${_previousPanelRect.width + dx}px`;
97
+ }
98
+ if (_nextPanelRect) {
99
+ _nextPanel.style.width = `${_nextPanelRect.width - dx}px`;
100
+ }
101
+ };
102
+
103
+ const mouseMoveHandlerVertical = (event) => {
104
+ const dy = event.clientY - _y;
105
+ console.log("mouseMoveHandlerHorizontal dy", dy, "width");
106
+ if (_previousPanelRect) {
107
+ _previousPanel.style.height = `${_previousPanelRect.height + dy}px`;
108
+ }
109
+ if (_nextPanelRect) {
110
+ _nextPanel.style.height = `${_nextPanelRect.height - dy}px`;
111
+ }
112
+ };
113
+
114
+ const mouseUpHandler = () => {
115
+ console.log("mouseUpHandler");
116
+ _nextPanel = null;
117
+ _previousPanel = null;
118
+ _nextPanelRect = null;
119
+ _previousPanelRect = null;
120
+ _panelGroup.style.cursor = null;
121
+ _panelGroup.style["user-select"] = "auto";
122
+ document.removeEventListener("mousemove", mouseMoveHandler);
123
+ document.removeEventListener("mouseup", mouseUpHandler);
124
+ };
125
+
126
+ const mouseDownHandler = (event) => {
127
+ // Get the current mouse position
128
+ _x = event.clientX;
129
+ _y = event.clientY;
130
+
131
+ const { target } = event;
132
+ const handleEl = target.closest(".handle");
133
+ _panelGroup = target.closest(".resizablePanelGroup");
134
+ console.log("mouseDownHandler", _x, _y, _panelGroup);
135
+ _panelGroup.style.cursor = isHorizontal() ? "col-resize" : "row-resize";
136
+ _panelGroup.style["user-select"] = "none";
137
+
138
+ _nextPanel = handleEl.nextSibling;
139
+ _previousPanel = handleEl.previousSibling;
140
+
141
+ if (_previousPanel) {
142
+ _previousPanelRect = _previousPanel.getBoundingClientRect();
143
+ }
144
+ if (_nextPanel) {
145
+ _nextPanelRect = _nextPanel.getBoundingClientRect();
146
+ }
147
+ document.addEventListener("mousemove", mouseMoveHandler);
148
+ document.addEventListener("mouseup", mouseUpHandler);
149
+ };
150
+
151
+ return div(
152
+ {
153
+ ...props,
154
+ class: classNames("handle", direction),
155
+ role: "separator",
156
+ bauMounted: ({ element }) => {
157
+ element.addEventListener("mousedown", mouseDownHandler);
158
+ },
159
+ bauUnmounted: ({ element }) => {
160
+ element.removeEventListener("mousedown", mouseDownHandler);
161
+ },
162
+ },
163
+ children
164
+ );
165
+ }
166
+
167
+ return {
168
+ PanelGroup,
169
+ Panel,
170
+ Handle,
171
+ };
172
+ }
package/select/index.d.ts CHANGED
@@ -10,9 +10,10 @@ declare module "@grucloud/bau-ui/select" {
10
10
  getOptionLabel: (item: object | string) => HTMLElement | string;
11
11
  getOptionValue: (item: object | string) => string;
12
12
  Option: (props) => HTMLElement;
13
+ onSelect?: (item: object | string) => any;
13
14
  } & DefaultDesignProps;
14
15
 
15
- type Component = import("../bau-ui").Component<SelectProps, HTMLInputElement>;
16
+ type Component = import("../bau-ui").Component<SelectProps>;
16
17
 
17
18
  export default function (context: any, option?: ComponentOption): Component;
18
19
  }