@grucloud/bau-ui 0.43.4 → 0.45.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.
@@ -81,7 +81,7 @@ export default function (context, options = {}) {
81
81
 
82
82
  const itemNameState = bau.state("");
83
83
 
84
- const Collapsible = collapsible(context);
84
+ const Collapsible = collapsible(context, { size, variant, color });
85
85
 
86
86
  const onclick = (name) => (event) => {
87
87
  if (itemNameState.val == name) {
@@ -4,6 +4,7 @@ import popover from "../popover/popover.js";
4
4
  import button from "../button/button.js";
5
5
  import input from "../input/input.js";
6
6
  import list from "../list/list.js";
7
+ import spinner from "../spinner/spinner.js";
7
8
 
8
9
  import { Colors } from "../constants.js";
9
10
 
@@ -23,18 +24,26 @@ const colorsToCss = () =>
23
24
  export default function (context, componentOptions = {}) {
24
25
  const { bau, css } = context;
25
26
  const { div, li } = bau.tags;
26
-
27
27
  const className = css`
28
+ position: relative;
29
+ overflow: hidden;
30
+ height: fit-content;
28
31
  & button {
29
32
  &::after {
30
33
  content: "\u25BC";
31
- padding: 0 0.3rem;
34
+ }
35
+ &.loading::after {
36
+ display: none;
32
37
  }
33
38
  }
34
39
  & .content {
35
- height: fit-content;
40
+ display: flex;
41
+ flex-direction: column;
42
+ max-height: 100vh;
43
+ overflow: hidden;
36
44
  & ul {
37
45
  border-width: 0px !important;
46
+ overflow: auto;
38
47
  }
39
48
  & input {
40
49
  padding: 0.8rem;
@@ -49,14 +58,18 @@ export default function (context, componentOptions = {}) {
49
58
  let [
50
59
  {
51
60
  size = componentOptions.size ?? "md",
52
- variant = componentOptions.variant ?? "plain",
61
+ variant = componentOptions.variant ?? "outline",
53
62
  color = componentOptions.color ?? "neutral",
54
- id,
55
63
  label,
56
64
  placeholder,
57
65
  Option,
58
66
  options,
59
67
  getOptionLabel = ({ label }) => label,
68
+ onSelect = () => {},
69
+ id,
70
+ required,
71
+ name,
72
+ loading,
60
73
  ...props
61
74
  },
62
75
  ...children
@@ -66,8 +79,15 @@ export default function (context, componentOptions = {}) {
66
79
  const Button = button(context);
67
80
  const Input = input(context, { variant, color, size });
68
81
  const List = list(context);
82
+ const Spinner = spinner(context, { variant, color, size });
69
83
 
70
- const selectedState = bau.state("");
84
+ const selectedState = bau.state(props.value);
85
+ bau.derive(() => {
86
+ if (selectedState.val) {
87
+ inputShadowEl.value = getOptionLabel(selectedState.val);
88
+ onSelect(selectedState.val);
89
+ }
90
+ });
71
91
  const inputState = bau.state("");
72
92
  const openState = bau.state(false);
73
93
  const itemIndexActive = bau.state(0);
@@ -78,17 +98,28 @@ export default function (context, componentOptions = {}) {
78
98
 
79
99
  const optionsFilteredState = bau.state(options);
80
100
 
101
+ const isOptionSelected = (selectedState) => (options) =>
102
+ selectedState.val &&
103
+ getOptionLabel(options) == getOptionLabel(selectedState.val);
104
+
81
105
  const dialogOpen = () => {
82
106
  popoverEl.openDialog();
83
107
  openState.val = true;
84
108
  inputState.val = "";
85
109
  optionsFilteredState.val = options;
110
+ itemIndexActive.val = options.findIndex(isOptionSelected(selectedState));
111
+ const activeEl = contentEl.querySelector("li.selected");
112
+ if (activeEl) {
113
+ activeEl.scrollIntoView({ block: "center" });
114
+ inputEl.scrollIntoView({ block: "end" });
115
+ }
86
116
  };
87
117
 
88
118
  const dialogClose = () => {
89
119
  popoverEl.closeDialog();
90
120
  openState.val = false;
91
121
  inputState.val = "";
122
+ itemIndexActive.val = 0;
92
123
  };
93
124
 
94
125
  const oninput = (event) => {
@@ -104,23 +135,25 @@ export default function (context, componentOptions = {}) {
104
135
  };
105
136
 
106
137
  const onclickButton = (event) => {
107
- if (!openState.val) {
108
- dialogOpen();
109
- } else {
110
- dialogClose();
111
- }
138
+ popoverEl.open ? dialogClose() : dialogOpen();
112
139
  };
113
140
 
114
141
  const onclickItem =
115
142
  ({ option, index }) =>
116
143
  (event) => {
117
- selectedState.val = getOptionLabel(option);
144
+ selectedState.val = option;
118
145
  itemIndexActive.val = index;
119
146
  dialogClose();
120
147
  };
121
148
 
149
+ const scrollIntoView = () => {
150
+ const activeEl = contentEl.querySelector("li.active");
151
+ if (activeEl) {
152
+ activeEl.scrollIntoView({ block: "center", behavior: "smooth" });
153
+ }
154
+ };
155
+
122
156
  const onkeydown = (event) => {
123
- console.log("onkeydown", event.key, itemIndexActive.val);
124
157
  switch (event.key) {
125
158
  case "Escape":
126
159
  dialogClose();
@@ -131,6 +164,7 @@ export default function (context, componentOptions = {}) {
131
164
  } else {
132
165
  itemIndexActive.val = 0;
133
166
  }
167
+ scrollIntoView();
134
168
  break;
135
169
  case "ArrowUp":
136
170
  if (itemIndexActive.val <= 0) {
@@ -138,13 +172,17 @@ export default function (context, componentOptions = {}) {
138
172
  } else {
139
173
  itemIndexActive.val--;
140
174
  }
175
+ scrollIntoView();
141
176
  break;
142
177
  case "Enter":
143
- selectedState.val = getOptionLabel(
144
- optionsFilteredState.val[itemIndexActive.val]
145
- );
146
- inputState.val = "";
147
- dialogClose();
178
+ if (popoverEl.open) {
179
+ selectedState.val = optionsFilteredState.val[itemIndexActive.val];
180
+ inputState.val = "";
181
+ dialogClose();
182
+ } else {
183
+ dialogOpen();
184
+ }
185
+ event.preventDefault();
148
186
  break;
149
187
  }
150
188
  };
@@ -160,13 +198,14 @@ export default function (context, componentOptions = {}) {
160
198
  variant,
161
199
  color,
162
200
  size,
201
+ class: loading == true && "loading",
202
+ disabled: loading,
163
203
  },
164
- () => !selectedState.val && label,
165
- selectedState
204
+ () => (selectedState.val ? getOptionLabel(selectedState.val) : label),
205
+ () => loading == true && Spinner({ visibility: loading })
166
206
  );
167
207
 
168
208
  const inputEl = Input({
169
- id,
170
209
  value: inputState,
171
210
  placeholder,
172
211
  autofocus: true,
@@ -179,30 +218,53 @@ export default function (context, componentOptions = {}) {
179
218
  "aria-expanded": openState,
180
219
  oninput,
181
220
  onkeydown,
221
+ ...props,
182
222
  });
183
223
 
184
- const Content = () =>
185
- div({ class: classNames(variant, color, size, "content") }, inputEl, () =>
224
+ const inputShadowEl = Input({
225
+ class: css`
226
+ width: 1px;
227
+ opacity: 0;
228
+ left: 0;
229
+ bottom: 0;
230
+ position: absolute;
231
+ `,
232
+ tabindex: -1,
233
+ value: inputState,
234
+ required,
235
+ name,
236
+ });
237
+
238
+ const contentEl = div(
239
+ { class: classNames(variant, color, size, "content") },
240
+ inputEl,
241
+ () =>
186
242
  List(
187
243
  { class: classNames(variant, color, size) },
188
244
  optionsFilteredState.val.map((option, index) =>
189
245
  li(
190
246
  {
191
247
  class: () =>
192
- classNames(itemIndexActive.val == index && "active"),
248
+ classNames(
249
+ itemIndexActive.val == index && "active",
250
+ isOptionSelected(selectedState)(option) && "selected"
251
+ ),
193
252
  onclick: onclickItem({ option, index }),
194
253
  },
195
254
  Option(option)
196
255
  )
197
256
  )
198
257
  )
199
- );
258
+ );
200
259
 
201
260
  const popoverEl = Popover({
202
261
  id,
203
262
  triggerEl: buttonEl,
204
- contentEl: Content(),
263
+ contentEl,
205
264
  onClose,
265
+ class: css`
266
+ overflow: hidden;
267
+ `,
206
268
  });
207
269
 
208
270
  return div(
@@ -216,6 +278,7 @@ export default function (context, componentOptions = {}) {
216
278
  ),
217
279
  },
218
280
  buttonEl,
281
+ inputShadowEl,
219
282
  popoverEl
220
283
  );
221
284
  };
@@ -4,7 +4,7 @@ declare module "@grucloud/bau-ui/autocomplete" {
4
4
 
5
5
  export type Autocomplete = {
6
6
  options: object[];
7
- id: string;
7
+ id?: string;
8
8
  label: string;
9
9
  placeholder: string;
10
10
  size?: string;
package/button/button.js CHANGED
@@ -1,6 +1,31 @@
1
1
  import { toPropsAndChildren } from "@grucloud/bau/bau.js";
2
2
  import classNames from "@grucloud/bau-css/classNames.js";
3
3
 
4
+ import { Colors } from "../constants.js";
5
+
6
+ const colorsToCss = () =>
7
+ Colors.map(
8
+ (color) =>
9
+ `
10
+ &.button.plain.${color} {
11
+ &:focus {
12
+ outline: 4px auto var(--color-${color});
13
+ border: 1px solid var(--color-neutral);
14
+ };
15
+ }
16
+ &.button.outline.${color} {
17
+ &:focus {
18
+ outline: 4px auto var(--color-${color});
19
+ };
20
+ }
21
+ &.button.solid.${color} {
22
+ &:focus {
23
+ outline: 4px auto var(--color-${color}-lightest);
24
+ };
25
+ }
26
+ `
27
+ ).join("\n");
28
+
4
29
  export default function (context, options = {}) {
5
30
  const { bau, css } = context;
6
31
 
@@ -48,11 +73,12 @@ export default function (context, options = {}) {
48
73
  padding: 0.2rem 0.8rem;
49
74
  }
50
75
  &.lg {
51
- padding: 0.2rem 2rem;
76
+ padding: 0.4rem 2rem;
52
77
  }
53
78
  & i {
54
79
  font-style: normal;
55
80
  }
81
+ ${colorsToCss()}
56
82
  `;
57
83
 
58
84
  return function Button(...args) {
package/button/index.d.ts CHANGED
@@ -3,7 +3,6 @@ declare module "@grucloud/bau-ui/button" {
3
3
  type ComponentOption = import("../bau-ui").ComponentOption;
4
4
 
5
5
  type ButtonProps = {
6
- disabled?: boolean;
7
6
  href?: string;
8
7
  } & DefaultDesignProps;
9
8
 
@@ -1,7 +1,7 @@
1
1
  import classNames from "@grucloud/bau-css/classNames.js";
2
2
  import { toPropsAndChildren } from "@grucloud/bau/bau.js";
3
3
 
4
- export default function (context, options) {
4
+ export default function (context, options = {}) {
5
5
  const { bau, css } = context;
6
6
  const { div } = bau.tags;
7
7
  const className = css`
@@ -65,9 +65,9 @@ export default function (context, options) {
65
65
  return function Collapsible(...args) {
66
66
  let [
67
67
  {
68
- color,
69
- variant = "plain",
70
- size = "md",
68
+ size = options.size ?? "md",
69
+ variant = options.variant ?? "plain",
70
+ color = options.color ?? "neutral",
71
71
  Header,
72
72
  Content,
73
73
  close = true,
@@ -280,7 +280,14 @@ export default function (context, options = {}) {
280
280
 
281
281
  return nav(
282
282
  {
283
- class: cn(className, options?.class, otherProps.class),
283
+ class: cn(
284
+ className,
285
+ variant,
286
+ color,
287
+ size,
288
+ options?.class,
289
+ otherProps.class
290
+ ),
284
291
  onclick,
285
292
  },
286
293
  Animate(
@@ -3,7 +3,7 @@ import classNames from "@grucloud/bau-css/classNames.js";
3
3
 
4
4
  export default function (context, options = {}) {
5
5
  const { bau, css } = context;
6
- const { div, span, label, input } = bau.tags;
6
+ const { div, label, input } = bau.tags;
7
7
 
8
8
  const style = {
9
9
  base: css`
@@ -16,12 +16,6 @@ export default function (context, options = {}) {
16
16
  position: absolute;
17
17
  z-index: -1;
18
18
  }
19
- & .filename-display {
20
- display: inline-block;
21
- white-space: nowrap;
22
- overflow: hidden;
23
- text-overflow: ellipsis;
24
- }
25
19
  & label {
26
20
  padding: 1rem;
27
21
  border-radius: var(--global-radius);
@@ -51,7 +45,7 @@ export default function (context, options = {}) {
51
45
  return function FileInput(props, ...children) {
52
46
  const {
53
47
  size = options.size ?? "md",
54
- variant = options.variant ?? "plain",
48
+ variant = options.variant ?? "outline",
55
49
  color = options.color ?? "neutral",
56
50
  Component,
57
51
  disabled,
@@ -73,8 +67,7 @@ export default function (context, options = {}) {
73
67
  },
74
68
  Component({ disabled }),
75
69
  input({ type: "file", disabled, ...otherProps })
76
- ),
77
- span({ class: "filename-display" })
70
+ )
78
71
  );
79
72
  };
80
73
  }
package/form/form.js CHANGED
@@ -12,6 +12,7 @@ export default function (context, options = {}) {
12
12
  gap: 1rem;
13
13
  padding: 1rem;
14
14
  min-width: 350px;
15
+
15
16
  & > header {
16
17
  text-align: center;
17
18
  & h1 {
@@ -20,11 +21,12 @@ export default function (context, options = {}) {
20
21
  }
21
22
  }
22
23
  & section {
23
- display: flex;
24
+ display: inline-flex;
24
25
  flex-direction: column;
25
26
  gap: 1rem;
26
27
  }
27
- & label {
28
+ & label,
29
+ legend {
28
30
  display: inline-flex;
29
31
  flex-direction: column;
30
32
  gap: 0.3rem;
@@ -32,6 +34,9 @@ export default function (context, options = {}) {
32
34
  font-size: smaller;
33
35
  color: var(--color-content-secondary);
34
36
  }
37
+ & fieldset {
38
+ border-radius: var(--global-radius);
39
+ }
35
40
  & > footer {
36
41
  display: flex;
37
42
  gap: 1rem;
@@ -27,7 +27,7 @@ const variantToCss = () =>
27
27
  ([color]) =>
28
28
  `
29
29
  .outline.${color} {
30
- border: 2px solid ${darkVar(color)};
30
+ border: 1px solid ${darkVar(color)};
31
31
  color: var(--font-color-base)
32
32
  }
33
33
  .soft.${color} {
@@ -111,7 +111,7 @@ export default function globalStyle(
111
111
  --color-content-secondary: hsl(0, 0%, 30%);
112
112
  --background-color: var(--color-white);
113
113
  --global-border-width: 1px;
114
- --global-radius: 0.4rem;
114
+ --global-radius: 0.2rem;
115
115
  --font-color-base: var(--color-content);
116
116
  --font-color-disabled: var(--color-emphasis-600);
117
117
  --font-color-inverse: var(--color-content-inverse);
package/list/list.js CHANGED
@@ -25,6 +25,7 @@ export default function (context, options = {}) {
25
25
  background-color: inherit;
26
26
  transition: all var(--transition-slow) ease-out;
27
27
  display: flex;
28
+ align-items: center;
28
29
  &:hover {
29
30
  filter: brightness(var(--brightness-hover));
30
31
  }
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.43.4",
4
+ "version": "0.45.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.43.0",
24
- "@grucloud/bau-css": "^0.43.0"
23
+ "@grucloud/bau": "^0.45.0",
24
+ "@grucloud/bau-css": "^0.45.0"
25
25
  },
26
26
  "devDependencies": {
27
27
  "typedoc": "0.24.8"
28
28
  },
29
- "gitHead": "6ae28c28ef4f8b98f221f639e939fa99ce3c71b1"
29
+ "gitHead": "5aaf13d1cf7512eb445b934ec77f97d2724aa8b7"
30
30
  }
@@ -47,7 +47,7 @@ export default function (context, options) {
47
47
  } else {
48
48
  dialogEl.style.top =
49
49
  Math.max(0, rectAnchor.top - rectDialog.height) + "px";
50
- if (rectDialog.height > rectAnchor.top) {
50
+ if (dialogEl.scrollHeight > rectAnchor.top) {
51
51
  dialogEl.style.height = rectAnchor.top + "px";
52
52
  }
53
53
  }
package/select/select.js CHANGED
@@ -30,6 +30,7 @@ export default function (context, componentOptions = {}) {
30
30
  & select {
31
31
  width: 0;
32
32
  height: 0;
33
+ opacity: 0;
33
34
  }
34
35
  & button {
35
36
  &::after {
@@ -55,7 +56,7 @@ export default function (context, componentOptions = {}) {
55
56
  ...children
56
57
  ] = toPropsAndChildren(args);
57
58
 
58
- const inputState = bau.state("");
59
+ const inputState = bau.state(props.value);
59
60
  const openState = bau.state(false);
60
61
  const itemIndexActive = bau.state(0);
61
62
 
@@ -75,11 +76,7 @@ export default function (context, componentOptions = {}) {
75
76
  };
76
77
 
77
78
  const onclickButton = (event) => {
78
- if (!openState.val) {
79
- dialogOpen();
80
- } else {
81
- dialogClose();
82
- }
79
+ popoverEl.open ? dialogClose() : dialogOpen();
83
80
  event.preventDefault();
84
81
  };
85
82
 
@@ -115,7 +112,7 @@ export default function (context, componentOptions = {}) {
115
112
  }
116
113
  break;
117
114
  case "Enter":
118
- if (openState.val) {
115
+ if (popoverEl.open) {
119
116
  inputState.val = getOptionLabel(options[itemIndexActive.val]);
120
117
  dialogClose();
121
118
  } else {
@@ -167,6 +164,7 @@ export default function (context, componentOptions = {}) {
167
164
  option({ value: "" }, "--Select Category--"),
168
165
  options.map((opt) => option(getOptionLabel(opt)))
169
166
  );
167
+ selectEl.value = props.value;
170
168
 
171
169
  return div(
172
170
  {
@@ -0,0 +1,13 @@
1
+ declare module "@grucloud/bau-ui/selectNative" {
2
+ type DefaultDesignProps = import("../constants").DefaultDesignProps;
3
+ type ComponentOption = import("../bau-ui").ComponentOption;
4
+
5
+ export type SelectNativeProps = {} & DefaultDesignProps;
6
+
7
+ type Component = import("../bau-ui").Component<
8
+ SelectNativeProps,
9
+ HTMLSelectElement
10
+ >;
11
+
12
+ export default function (context: any, option?: ComponentOption): Component;
13
+ }
@@ -0,0 +1 @@
1
+ export { default } from "./selectNative";
@@ -0,0 +1,47 @@
1
+ import classNames from "@grucloud/bau-css/classNames.js";
2
+ import { toPropsAndChildren } from "@grucloud/bau/bau.js";
3
+
4
+ export default function (context, componentOptions = {}) {
5
+ const { bau, css } = context;
6
+ const { select } = bau.tags;
7
+
8
+ const className = css`
9
+ border-radius: var(--global-radius);
10
+ &.sm {
11
+ }
12
+ &.md {
13
+ padding: 0.5rem;
14
+ }
15
+ &.lg {
16
+ padding: 0.7rem;
17
+ }
18
+ `;
19
+
20
+ return function SelectNative(...args) {
21
+ let [
22
+ {
23
+ size = componentOptions.size ?? "md",
24
+ variant = componentOptions.variant ?? "outline",
25
+ color = componentOptions.color ?? "neutral",
26
+ ...props
27
+ },
28
+ ...children
29
+ ] = toPropsAndChildren(args);
30
+
31
+ return select(
32
+ {
33
+ ...props,
34
+ class: classNames(
35
+ "select-native",
36
+ color,
37
+ size,
38
+ variant,
39
+ className,
40
+ componentOptions?.class,
41
+ props?.class
42
+ ),
43
+ },
44
+ children
45
+ );
46
+ };
47
+ }
@@ -105,6 +105,7 @@ export default function (context, options = {}) {
105
105
  );
106
106
  return li(
107
107
  Collapsible({
108
+ size,
108
109
  Header,
109
110
  Content: children && depth < maxDepth && Content,
110
111
  })