@abgov/react-components 7.3.0 → 7.4.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/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # React UI Components
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@abgov/react-components?color=%230081a2&label=react-components&style=flat-square)](https://www.npmjs.com/package/@abgov/react-components)
4
+
5
+ React wrappers for the Government of Alberta Design System web components.
6
+
7
+ Supported React versions: 17, 18, and 19.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm i @abgov/react-components @abgov/web-components @abgov/ui-components-common @abgov/design-tokens
13
+ ```
14
+
15
+ ## Register the web components
16
+
17
+ Import the underlying web components once in your application entry point, such as
18
+ `src/main.tsx`:
19
+
20
+ ```typescript
21
+ import "@abgov/web-components";
22
+ ```
23
+
24
+ ## Add styles
25
+
26
+ Import the component styles and design tokens in your main stylesheet, such as
27
+ `src/index.css`:
28
+
29
+ ```css
30
+ @import "@abgov/web-components/index.css";
31
+ @import "@abgov/design-tokens/dist/tokens.css";
32
+ ```
33
+
34
+ ## Add icons
35
+
36
+ Add Ionicons to the `<head>` of `index.html`:
37
+
38
+ ```html
39
+ <script
40
+ type="module"
41
+ src="https://cdn.jsdelivr.net/npm/ionicons@latest/dist/ionicons/ionicons.esm.js"
42
+ ></script>
43
+ <script
44
+ nomodule
45
+ src="https://cdn.jsdelivr.net/npm/ionicons@latest/dist/ionicons/ionicons.js"
46
+ ></script>
47
+ ```
48
+
49
+ ## Use a component
50
+
51
+ ```tsx
52
+ import { GoabButton } from "@abgov/react-components";
53
+
54
+ export function App() {
55
+ return <GoabButton type="primary">Continue</GoabButton>;
56
+ }
57
+ ```
58
+
59
+ See the [developer setup guide](https://design.alberta.ca/get-started/developers/setup/) and
60
+ [Government of Alberta Design System](https://design.alberta.ca) for more information.
package/index.d.ts CHANGED
@@ -19,6 +19,7 @@ export * from './lib/divider/divider';
19
19
  export * from './lib/drawer/drawer';
20
20
  export * from './lib/dropdown/dropdown';
21
21
  export * from './lib/dropdown/dropdown-item';
22
+ export * from './lib/dropdown-multiselect/dropdown-multiselect';
22
23
  export * from './lib/file-upload-card/file-upload-card';
23
24
  export * from './lib/file-upload-input/file-upload-input';
24
25
  export * from './lib/footer/footer';
package/index.js CHANGED
@@ -65,10 +65,26 @@ function GoabAccordion({
65
65
  }
66
66
  );
67
67
  }
68
+ function renderSlottedItems(children, slot) {
69
+ return react.Children.map(children, (child) => {
70
+ if (!react.isValidElement(child)) {
71
+ return child;
72
+ }
73
+ if (child.type === react.Fragment) {
74
+ const fragment = child;
75
+ return renderSlottedItems(fragment.props.children, slot);
76
+ }
77
+ return react.cloneElement(child, { slot });
78
+ });
79
+ }
68
80
  function GoabAppHeader({
69
81
  onMenuClick,
70
82
  children,
71
83
  secondaryText,
84
+ banner,
85
+ phase,
86
+ navigation,
87
+ utilities,
72
88
  ...rest
73
89
  }) {
74
90
  const el = react.useRef(null);
@@ -89,7 +105,7 @@ function GoabAppHeader({
89
105
  current.removeEventListener("_menuClick", listener);
90
106
  };
91
107
  }, [el, onMenuClick]);
92
- return /* @__PURE__ */ jsxRuntime.jsx(
108
+ return /* @__PURE__ */ jsxRuntime.jsxs(
93
109
  "goa-app-header",
94
110
  {
95
111
  ref: el,
@@ -97,7 +113,13 @@ function GoabAppHeader({
97
113
  secondarytext: secondaryText,
98
114
  ..._props,
99
115
  version: "2",
100
- children
116
+ children: [
117
+ children,
118
+ banner && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "banner", children: banner }),
119
+ phase && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "phase", children: phase }),
120
+ navigation && renderSlottedItems(navigation, "navigation"),
121
+ utilities && renderSlottedItems(utilities, "utilities")
122
+ ]
101
123
  }
102
124
  );
103
125
  }
@@ -116,6 +138,7 @@ function getIconValue(icon, iconType) {
116
138
  return iconType ? "true" : "false";
117
139
  }
118
140
  function GoabBadge({
141
+ content,
119
142
  icon,
120
143
  iconType,
121
144
  size = "medium",
@@ -128,16 +151,23 @@ function GoabBadge({
128
151
  {
129
152
  icon: getIconValue(icon, iconType),
130
153
  icontype: iconType,
154
+ content: typeof content === "string" ? content : void 0,
131
155
  ..._props,
132
156
  version: "2",
133
157
  size,
134
- emphasis
158
+ emphasis,
159
+ children: typeof content !== "string" && content != null && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "content", children: content })
135
160
  }
136
161
  );
137
162
  }
138
- function GoabBlock({ testId, children, ...rest }) {
163
+ function GoabBlock({
164
+ testId,
165
+ stretch,
166
+ children,
167
+ ...rest
168
+ }) {
139
169
  const _props = transformProps({ testid: testId, ...rest }, kebab);
140
- return /* @__PURE__ */ jsxRuntime.jsx("goa-block", { ..._props, children });
170
+ return /* @__PURE__ */ jsxRuntime.jsx("goa-block", { ..._props, stretch: stretch ? "true" : void 0, children });
141
171
  }
142
172
  function GoabButton({
143
173
  disabled,
@@ -246,6 +276,8 @@ function GoabCheckbox({
246
276
  description,
247
277
  reveal,
248
278
  onChange,
279
+ onFocus,
280
+ onBlur,
249
281
  name,
250
282
  children,
251
283
  size = "default",
@@ -262,11 +294,23 @@ function GoabCheckbox({
262
294
  const detail = e.detail;
263
295
  onChange == null ? void 0 : onChange({ ...detail, event: e });
264
296
  };
297
+ const focusListener = (e) => {
298
+ const detail = e.detail;
299
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
300
+ };
301
+ const blurListener = (e) => {
302
+ const detail = e.detail;
303
+ onBlur == null ? void 0 : onBlur({ ...detail, event: e });
304
+ };
265
305
  current.addEventListener("_change", listener);
306
+ current.addEventListener("_focus", focusListener);
307
+ current.addEventListener("_blur", blurListener);
266
308
  return () => {
267
309
  current.removeEventListener("_change", listener);
310
+ current.removeEventListener("_focus", focusListener);
311
+ current.removeEventListener("_blur", blurListener);
268
312
  };
269
- }, [name, onChange]);
313
+ }, [name, onChange, onFocus, onBlur]);
270
314
  return /* @__PURE__ */ jsxRuntime.jsxs(
271
315
  "goa-checkbox",
272
316
  {
@@ -298,6 +342,8 @@ function GoabCheckboxList({
298
342
  size = "default",
299
343
  children,
300
344
  onChange,
345
+ onFocus,
346
+ onBlur,
301
347
  mt,
302
348
  mr,
303
349
  mb,
@@ -311,11 +357,23 @@ function GoabCheckboxList({
311
357
  const detail = e.detail;
312
358
  onChange == null ? void 0 : onChange({ ...detail, event: e });
313
359
  };
360
+ const focusListener = (e) => {
361
+ const detail = e.detail;
362
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
363
+ };
364
+ const blurListener = (e) => {
365
+ const detail = e.detail;
366
+ onBlur == null ? void 0 : onBlur({ ...detail, event: e });
367
+ };
314
368
  current.addEventListener("_change", listener);
369
+ current.addEventListener("_focus", focusListener);
370
+ current.addEventListener("_blur", blurListener);
315
371
  return () => {
316
372
  current.removeEventListener("_change", listener);
373
+ current.removeEventListener("_focus", focusListener);
374
+ current.removeEventListener("_blur", blurListener);
317
375
  };
318
- }, [onChange]);
376
+ }, [onChange, onFocus, onBlur]);
319
377
  return /* @__PURE__ */ jsxRuntime.jsx(
320
378
  "goa-checkbox-list",
321
379
  {
@@ -2614,6 +2672,8 @@ function GoabDatePicker({
2614
2672
  disabled,
2615
2673
  relative,
2616
2674
  onChange,
2675
+ onFocus,
2676
+ onBlur,
2617
2677
  ...rest
2618
2678
  }) {
2619
2679
  const ref = react.useRef(null);
@@ -2634,15 +2694,27 @@ function GoabDatePicker({
2634
2694
  const detail = e.detail;
2635
2695
  onChange == null ? void 0 : onChange({ ...detail, event: e });
2636
2696
  };
2697
+ const handleFocus = (e) => {
2698
+ const detail = e.detail;
2699
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
2700
+ };
2701
+ const handleBlur = (e) => {
2702
+ const detail = e.detail;
2703
+ onBlur == null ? void 0 : onBlur({ ...detail, event: e });
2704
+ };
2637
2705
  if (onChange) {
2638
2706
  current.addEventListener("_change", handleChange);
2639
2707
  }
2708
+ current.addEventListener("_focus", handleFocus);
2709
+ current.addEventListener("_blur", handleBlur);
2640
2710
  return () => {
2641
2711
  if (onChange) {
2642
2712
  current.removeEventListener("_change", handleChange);
2643
2713
  }
2714
+ current.removeEventListener("_focus", handleFocus);
2715
+ current.removeEventListener("_blur", handleBlur);
2644
2716
  };
2645
- }, [onChange]);
2717
+ }, [onChange, onFocus, onBlur]);
2646
2718
  const formatValue = (val) => {
2647
2719
  if (!val) return "";
2648
2720
  if (val instanceof Date) {
@@ -2738,6 +2810,8 @@ function stringify(value) {
2738
2810
  function GoabDropdown({
2739
2811
  value,
2740
2812
  onChange,
2813
+ onFocus,
2814
+ onBlur,
2741
2815
  disabled,
2742
2816
  error,
2743
2817
  filterable,
@@ -2759,15 +2833,27 @@ function GoabDropdown({
2759
2833
  const detail = e.detail;
2760
2834
  onChange == null ? void 0 : onChange({ ...detail, event: e });
2761
2835
  };
2836
+ const focusListener = (e) => {
2837
+ const detail = e.detail;
2838
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
2839
+ };
2840
+ const blurListener = (e) => {
2841
+ const detail = e.detail;
2842
+ onBlur == null ? void 0 : onBlur({ ...detail, event: e });
2843
+ };
2762
2844
  if (onChange) {
2763
2845
  current.addEventListener("_change", handler);
2764
2846
  }
2847
+ current.addEventListener("_focus", focusListener);
2848
+ current.addEventListener("_blur", blurListener);
2765
2849
  return () => {
2766
2850
  if (onChange) {
2767
2851
  current.removeEventListener("_change", handler);
2768
2852
  }
2853
+ current.removeEventListener("_focus", focusListener);
2854
+ current.removeEventListener("_blur", blurListener);
2769
2855
  };
2770
- }, [el, onChange]);
2856
+ }, [el, onChange, onFocus, onBlur]);
2771
2857
  return /* @__PURE__ */ jsxRuntime.jsx(
2772
2858
  "goa-dropdown",
2773
2859
  {
@@ -2796,7 +2882,8 @@ function GoabDropdownItem({
2796
2882
  label,
2797
2883
  filter,
2798
2884
  name,
2799
- mountType = "append"
2885
+ mountType = "append",
2886
+ children
2800
2887
  }) {
2801
2888
  return /* @__PURE__ */ jsxRuntime.jsx(
2802
2889
  "goa-dropdown-item",
@@ -2805,7 +2892,71 @@ function GoabDropdownItem({
2805
2892
  label,
2806
2893
  filter,
2807
2894
  name,
2808
- mount: mountType
2895
+ mount: mountType,
2896
+ children
2897
+ }
2898
+ );
2899
+ }
2900
+ function GoabDropdownMultiselect({
2901
+ name,
2902
+ value = [],
2903
+ placeholder,
2904
+ disabled,
2905
+ error,
2906
+ filterable,
2907
+ leadingIcon,
2908
+ showSelectAll,
2909
+ testId,
2910
+ ariaLabel,
2911
+ ariaLabelledBy,
2912
+ maxHeight,
2913
+ width,
2914
+ size = "default",
2915
+ labelFormat,
2916
+ children,
2917
+ onChange,
2918
+ mt,
2919
+ mr,
2920
+ mb,
2921
+ ml
2922
+ }) {
2923
+ const el = react.useRef(null);
2924
+ react.useEffect(() => {
2925
+ if (!el.current) return;
2926
+ const current = el.current;
2927
+ const listener = (e) => {
2928
+ const detail = e.detail;
2929
+ onChange == null ? void 0 : onChange({ ...detail, event: e });
2930
+ };
2931
+ current.addEventListener("_change", listener);
2932
+ return () => {
2933
+ current.removeEventListener("_change", listener);
2934
+ };
2935
+ }, [onChange]);
2936
+ return /* @__PURE__ */ jsxRuntime.jsx(
2937
+ "goa-dropdown-multiselect",
2938
+ {
2939
+ ref: el,
2940
+ name,
2941
+ value,
2942
+ placeholder,
2943
+ disabled: disabled ? "true" : void 0,
2944
+ error: error ? "true" : void 0,
2945
+ filterable: filterable ? "true" : void 0,
2946
+ "leading-icon": leadingIcon,
2947
+ testid: testId,
2948
+ "aria-label": ariaLabel,
2949
+ "aria-labelledby": ariaLabelledBy,
2950
+ "max-height": maxHeight,
2951
+ width,
2952
+ size,
2953
+ "label-format": labelFormat ? labelFormat : void 0,
2954
+ "show-select-all": showSelectAll ? "true" : void 0,
2955
+ mt,
2956
+ mr,
2957
+ mb,
2958
+ ml,
2959
+ children
2809
2960
  }
2810
2961
  );
2811
2962
  }
@@ -3170,6 +3321,7 @@ function GoabHeroBannerActions({
3170
3321
  }
3171
3322
  function GoabIconButton({
3172
3323
  variant = "color",
3324
+ type = "default",
3173
3325
  size = "medium",
3174
3326
  theme = "outline",
3175
3327
  disabled,
@@ -3180,7 +3332,7 @@ function GoabIconButton({
3180
3332
  ...rest
3181
3333
  }) {
3182
3334
  const ref = react.useRef(null);
3183
- const _props = transformProps({ variant, size, theme, ...rest }, lowercase);
3335
+ const _props = transformProps({ variant, type, size, theme, ...rest }, lowercase);
3184
3336
  react.useEffect(() => {
3185
3337
  if (!ref.current) {
3186
3338
  return;
@@ -3836,6 +3988,8 @@ function GoabRadioGroup({
3836
3988
  disabled,
3837
3989
  error,
3838
3990
  onChange,
3991
+ onFocus,
3992
+ onBlur,
3839
3993
  name,
3840
3994
  children,
3841
3995
  size = "default",
@@ -3849,16 +4003,28 @@ function GoabRadioGroup({
3849
4003
  const detail = e.detail;
3850
4004
  onChange == null ? void 0 : onChange({ ...detail, event: e });
3851
4005
  };
4006
+ const focusListener = (e) => {
4007
+ const detail = e.detail;
4008
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
4009
+ };
4010
+ const blurListener = (e) => {
4011
+ const detail = e.detail;
4012
+ onBlur == null ? void 0 : onBlur({ ...detail, event: e });
4013
+ };
3852
4014
  const currentEl = el.current;
3853
4015
  if (onChange) {
3854
4016
  currentEl.addEventListener("_change", listener);
3855
4017
  }
4018
+ currentEl.addEventListener("_focus", focusListener);
4019
+ currentEl.addEventListener("_blur", blurListener);
3856
4020
  return () => {
3857
4021
  if (onChange) {
3858
4022
  currentEl.removeEventListener("_change", listener);
3859
4023
  }
4024
+ currentEl.removeEventListener("_focus", focusListener);
4025
+ currentEl.removeEventListener("_blur", blurListener);
3860
4026
  };
3861
- }, [name, onChange]);
4027
+ }, [name, onChange, onFocus, onBlur]);
3862
4028
  return /* @__PURE__ */ jsxRuntime.jsx(
3863
4029
  "goa-radio-group",
3864
4030
  {
@@ -3971,14 +4137,25 @@ function GoabScrollPanel({
3971
4137
  footer,
3972
4138
  height,
3973
4139
  testId,
4140
+ direction = "vertical",
3974
4141
  ...rest
3975
4142
  }) {
3976
4143
  const hostStyle = height ? { height } : void 0;
3977
- return /* @__PURE__ */ jsxRuntime.jsxs("goa-scroll-panel", { height, testid: testId, style: hostStyle, ...rest, children: [
3978
- header && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "header", children: header }),
3979
- children,
3980
- footer && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "footer", children: footer })
3981
- ] });
4144
+ return /* @__PURE__ */ jsxRuntime.jsxs(
4145
+ "goa-scroll-panel",
4146
+ {
4147
+ height,
4148
+ testid: testId,
4149
+ direction,
4150
+ style: hostStyle,
4151
+ ...rest,
4152
+ children: [
4153
+ header && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "header", children: header }),
4154
+ children,
4155
+ footer && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "footer", children: footer })
4156
+ ]
4157
+ }
4158
+ );
3982
4159
  }
3983
4160
  function GoabTable({ onSort, onMultiSort, sortMode, ...props }) {
3984
4161
  const ref = react.useRef(null);
@@ -4122,6 +4299,7 @@ function GoabTextArea({
4122
4299
  error,
4123
4300
  onChange,
4124
4301
  onKeyPress,
4302
+ onFocus,
4125
4303
  onBlur,
4126
4304
  ...rest
4127
4305
  }) {
@@ -4140,19 +4318,25 @@ function GoabTextArea({
4140
4318
  const detail = e.detail;
4141
4319
  onKeyPress == null ? void 0 : onKeyPress({ ...detail, event: e });
4142
4320
  };
4321
+ const focusListener = (e) => {
4322
+ const detail = e.detail;
4323
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
4324
+ };
4143
4325
  const blurListener = (e) => {
4144
4326
  const detail = e.detail;
4145
4327
  onBlur == null ? void 0 : onBlur({ ...detail, event: e });
4146
4328
  };
4147
4329
  current.addEventListener("_change", changeListener);
4148
4330
  current.addEventListener("_keyPress", keypressListener);
4331
+ current.addEventListener("_focus", focusListener);
4149
4332
  current.addEventListener("_blur", blurListener);
4150
4333
  return () => {
4151
4334
  current.removeEventListener("_change", changeListener);
4152
4335
  current.removeEventListener("_keyPress", keypressListener);
4336
+ current.removeEventListener("_focus", focusListener);
4153
4337
  current.removeEventListener("_blur", blurListener);
4154
4338
  };
4155
- }, [el, onChange, onKeyPress, onBlur]);
4339
+ }, [el, onChange, onKeyPress, onFocus, onBlur]);
4156
4340
  return /* @__PURE__ */ jsxRuntime.jsx(
4157
4341
  "goa-textarea",
4158
4342
  {
@@ -4211,6 +4395,7 @@ function GoabTwoColumnLayout(props) {
4211
4395
  );
4212
4396
  }
4213
4397
  const GoabFilterChip = ({
4398
+ content,
4214
4399
  iconTheme = "outline",
4215
4400
  error,
4216
4401
  onClick,
@@ -4231,9 +4416,11 @@ const GoabFilterChip = ({
4231
4416
  "goa-filter-chip",
4232
4417
  {
4233
4418
  ref: el,
4419
+ content: typeof content === "string" ? content : void 0,
4234
4420
  error: error ? "true" : void 0,
4235
4421
  version: "2",
4236
- ..._props
4422
+ ..._props,
4423
+ children: typeof content !== "string" && content != null && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "content", children: content })
4237
4424
  }
4238
4425
  );
4239
4426
  };
@@ -4592,6 +4779,7 @@ exports.GoabDivider = GoabDivider;
4592
4779
  exports.GoabDrawer = GoabDrawer;
4593
4780
  exports.GoabDropdown = GoabDropdown;
4594
4781
  exports.GoabDropdownItem = GoabDropdownItem;
4782
+ exports.GoabDropdownMultiselect = GoabDropdownMultiselect;
4595
4783
  exports.GoabDropdownOption = GoabDropdownOption;
4596
4784
  exports.GoabFieldset = GoabFieldset;
4597
4785
  exports.GoabFileUploadCard = GoabFileUploadCard;