@abgov/react-components 7.3.0 → 7.5.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,22 +151,30 @@ 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,
144
174
  onClick,
145
175
  actionArgs,
146
176
  actionArg,
177
+ ariaLabel,
147
178
  children,
148
179
  ...rest
149
180
  }) {
@@ -172,6 +203,7 @@ function GoabButton({
172
203
  disabled: disabled ? "true" : void 0,
173
204
  "action-arg": actionArg,
174
205
  "action-args": JSON.stringify(actionArgs),
206
+ arialabel: ariaLabel || void 0,
175
207
  ..._props,
176
208
  version: "2",
177
209
  children
@@ -246,6 +278,8 @@ function GoabCheckbox({
246
278
  description,
247
279
  reveal,
248
280
  onChange,
281
+ onFocus,
282
+ onBlur,
249
283
  name,
250
284
  children,
251
285
  size = "default",
@@ -262,11 +296,23 @@ function GoabCheckbox({
262
296
  const detail = e.detail;
263
297
  onChange == null ? void 0 : onChange({ ...detail, event: e });
264
298
  };
299
+ const focusListener = (e) => {
300
+ const detail = e.detail;
301
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
302
+ };
303
+ const blurListener = (e) => {
304
+ const detail = e.detail;
305
+ onBlur == null ? void 0 : onBlur({ ...detail, event: e });
306
+ };
265
307
  current.addEventListener("_change", listener);
308
+ current.addEventListener("_focus", focusListener);
309
+ current.addEventListener("_blur", blurListener);
266
310
  return () => {
267
311
  current.removeEventListener("_change", listener);
312
+ current.removeEventListener("_focus", focusListener);
313
+ current.removeEventListener("_blur", blurListener);
268
314
  };
269
- }, [name, onChange]);
315
+ }, [name, onChange, onFocus, onBlur]);
270
316
  return /* @__PURE__ */ jsxRuntime.jsxs(
271
317
  "goa-checkbox",
272
318
  {
@@ -298,6 +344,8 @@ function GoabCheckboxList({
298
344
  size = "default",
299
345
  children,
300
346
  onChange,
347
+ onFocus,
348
+ onBlur,
301
349
  mt,
302
350
  mr,
303
351
  mb,
@@ -311,11 +359,23 @@ function GoabCheckboxList({
311
359
  const detail = e.detail;
312
360
  onChange == null ? void 0 : onChange({ ...detail, event: e });
313
361
  };
362
+ const focusListener = (e) => {
363
+ const detail = e.detail;
364
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
365
+ };
366
+ const blurListener = (e) => {
367
+ const detail = e.detail;
368
+ onBlur == null ? void 0 : onBlur({ ...detail, event: e });
369
+ };
314
370
  current.addEventListener("_change", listener);
371
+ current.addEventListener("_focus", focusListener);
372
+ current.addEventListener("_blur", blurListener);
315
373
  return () => {
316
374
  current.removeEventListener("_change", listener);
375
+ current.removeEventListener("_focus", focusListener);
376
+ current.removeEventListener("_blur", blurListener);
317
377
  };
318
- }, [onChange]);
378
+ }, [onChange, onFocus, onBlur]);
319
379
  return /* @__PURE__ */ jsxRuntime.jsx(
320
380
  "goa-checkbox-list",
321
381
  {
@@ -2614,6 +2674,8 @@ function GoabDatePicker({
2614
2674
  disabled,
2615
2675
  relative,
2616
2676
  onChange,
2677
+ onFocus,
2678
+ onBlur,
2617
2679
  ...rest
2618
2680
  }) {
2619
2681
  const ref = react.useRef(null);
@@ -2634,15 +2696,27 @@ function GoabDatePicker({
2634
2696
  const detail = e.detail;
2635
2697
  onChange == null ? void 0 : onChange({ ...detail, event: e });
2636
2698
  };
2699
+ const handleFocus = (e) => {
2700
+ const detail = e.detail;
2701
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
2702
+ };
2703
+ const handleBlur = (e) => {
2704
+ const detail = e.detail;
2705
+ onBlur == null ? void 0 : onBlur({ ...detail, event: e });
2706
+ };
2637
2707
  if (onChange) {
2638
2708
  current.addEventListener("_change", handleChange);
2639
2709
  }
2710
+ current.addEventListener("_focus", handleFocus);
2711
+ current.addEventListener("_blur", handleBlur);
2640
2712
  return () => {
2641
2713
  if (onChange) {
2642
2714
  current.removeEventListener("_change", handleChange);
2643
2715
  }
2716
+ current.removeEventListener("_focus", handleFocus);
2717
+ current.removeEventListener("_blur", handleBlur);
2644
2718
  };
2645
- }, [onChange]);
2719
+ }, [onChange, onFocus, onBlur]);
2646
2720
  const formatValue = (val) => {
2647
2721
  if (!val) return "";
2648
2722
  if (val instanceof Date) {
@@ -2738,6 +2812,8 @@ function stringify(value) {
2738
2812
  function GoabDropdown({
2739
2813
  value,
2740
2814
  onChange,
2815
+ onFocus,
2816
+ onBlur,
2741
2817
  disabled,
2742
2818
  error,
2743
2819
  filterable,
@@ -2759,15 +2835,27 @@ function GoabDropdown({
2759
2835
  const detail = e.detail;
2760
2836
  onChange == null ? void 0 : onChange({ ...detail, event: e });
2761
2837
  };
2838
+ const focusListener = (e) => {
2839
+ const detail = e.detail;
2840
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
2841
+ };
2842
+ const blurListener = (e) => {
2843
+ const detail = e.detail;
2844
+ onBlur == null ? void 0 : onBlur({ ...detail, event: e });
2845
+ };
2762
2846
  if (onChange) {
2763
2847
  current.addEventListener("_change", handler);
2764
2848
  }
2849
+ current.addEventListener("_focus", focusListener);
2850
+ current.addEventListener("_blur", blurListener);
2765
2851
  return () => {
2766
2852
  if (onChange) {
2767
2853
  current.removeEventListener("_change", handler);
2768
2854
  }
2855
+ current.removeEventListener("_focus", focusListener);
2856
+ current.removeEventListener("_blur", blurListener);
2769
2857
  };
2770
- }, [el, onChange]);
2858
+ }, [el, onChange, onFocus, onBlur]);
2771
2859
  return /* @__PURE__ */ jsxRuntime.jsx(
2772
2860
  "goa-dropdown",
2773
2861
  {
@@ -2796,7 +2884,8 @@ function GoabDropdownItem({
2796
2884
  label,
2797
2885
  filter,
2798
2886
  name,
2799
- mountType = "append"
2887
+ mountType = "append",
2888
+ children
2800
2889
  }) {
2801
2890
  return /* @__PURE__ */ jsxRuntime.jsx(
2802
2891
  "goa-dropdown-item",
@@ -2805,7 +2894,71 @@ function GoabDropdownItem({
2805
2894
  label,
2806
2895
  filter,
2807
2896
  name,
2808
- mount: mountType
2897
+ mount: mountType,
2898
+ children
2899
+ }
2900
+ );
2901
+ }
2902
+ function GoabDropdownMultiselect({
2903
+ name,
2904
+ value = [],
2905
+ placeholder,
2906
+ disabled,
2907
+ error,
2908
+ filterable,
2909
+ leadingIcon,
2910
+ showSelectAll,
2911
+ testId,
2912
+ ariaLabel,
2913
+ ariaLabelledBy,
2914
+ maxHeight,
2915
+ width,
2916
+ size = "default",
2917
+ labelFormat,
2918
+ children,
2919
+ onChange,
2920
+ mt,
2921
+ mr,
2922
+ mb,
2923
+ ml
2924
+ }) {
2925
+ const el = react.useRef(null);
2926
+ react.useEffect(() => {
2927
+ if (!el.current) return;
2928
+ const current = el.current;
2929
+ const listener = (e) => {
2930
+ const detail = e.detail;
2931
+ onChange == null ? void 0 : onChange({ ...detail, event: e });
2932
+ };
2933
+ current.addEventListener("_change", listener);
2934
+ return () => {
2935
+ current.removeEventListener("_change", listener);
2936
+ };
2937
+ }, [onChange]);
2938
+ return /* @__PURE__ */ jsxRuntime.jsx(
2939
+ "goa-dropdown-multiselect",
2940
+ {
2941
+ ref: el,
2942
+ name,
2943
+ value,
2944
+ placeholder,
2945
+ disabled: disabled ? "true" : void 0,
2946
+ error: error ? "true" : void 0,
2947
+ filterable: filterable ? "true" : void 0,
2948
+ "leading-icon": leadingIcon,
2949
+ testid: testId,
2950
+ "aria-label": ariaLabel,
2951
+ "aria-labelledby": ariaLabelledBy,
2952
+ "max-height": maxHeight,
2953
+ width,
2954
+ size,
2955
+ "label-format": labelFormat ? labelFormat : void 0,
2956
+ "show-select-all": showSelectAll ? "true" : void 0,
2957
+ mt,
2958
+ mr,
2959
+ mb,
2960
+ ml,
2961
+ children
2809
2962
  }
2810
2963
  );
2811
2964
  }
@@ -3170,6 +3323,7 @@ function GoabHeroBannerActions({
3170
3323
  }
3171
3324
  function GoabIconButton({
3172
3325
  variant = "color",
3326
+ type = "default",
3173
3327
  size = "medium",
3174
3328
  theme = "outline",
3175
3329
  disabled,
@@ -3180,7 +3334,7 @@ function GoabIconButton({
3180
3334
  ...rest
3181
3335
  }) {
3182
3336
  const ref = react.useRef(null);
3183
- const _props = transformProps({ variant, size, theme, ...rest }, lowercase);
3337
+ const _props = transformProps({ variant, type, size, theme, ...rest }, lowercase);
3184
3338
  react.useEffect(() => {
3185
3339
  if (!ref.current) {
3186
3340
  return;
@@ -3209,12 +3363,13 @@ function GoabIconButton({
3209
3363
  }
3210
3364
  );
3211
3365
  }
3212
- function GoabIcon({ inverted, ...rest }) {
3366
+ function GoabIcon({ inverted, ariaHidden, ...rest }) {
3213
3367
  const _props = transformProps(rest, lowercase);
3214
3368
  return /* @__PURE__ */ jsxRuntime.jsx(
3215
3369
  "goa-icon",
3216
3370
  {
3217
3371
  inverted: typeof inverted === "boolean" ? inverted ? "true" : void 0 : inverted,
3372
+ ariahidden: ariaHidden ? "true" : void 0,
3218
3373
  ..._props
3219
3374
  }
3220
3375
  );
@@ -3836,6 +3991,8 @@ function GoabRadioGroup({
3836
3991
  disabled,
3837
3992
  error,
3838
3993
  onChange,
3994
+ onFocus,
3995
+ onBlur,
3839
3996
  name,
3840
3997
  children,
3841
3998
  size = "default",
@@ -3849,16 +4006,28 @@ function GoabRadioGroup({
3849
4006
  const detail = e.detail;
3850
4007
  onChange == null ? void 0 : onChange({ ...detail, event: e });
3851
4008
  };
4009
+ const focusListener = (e) => {
4010
+ const detail = e.detail;
4011
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
4012
+ };
4013
+ const blurListener = (e) => {
4014
+ const detail = e.detail;
4015
+ onBlur == null ? void 0 : onBlur({ ...detail, event: e });
4016
+ };
3852
4017
  const currentEl = el.current;
3853
4018
  if (onChange) {
3854
4019
  currentEl.addEventListener("_change", listener);
3855
4020
  }
4021
+ currentEl.addEventListener("_focus", focusListener);
4022
+ currentEl.addEventListener("_blur", blurListener);
3856
4023
  return () => {
3857
4024
  if (onChange) {
3858
4025
  currentEl.removeEventListener("_change", listener);
3859
4026
  }
4027
+ currentEl.removeEventListener("_focus", focusListener);
4028
+ currentEl.removeEventListener("_blur", blurListener);
3860
4029
  };
3861
- }, [name, onChange]);
4030
+ }, [name, onChange, onFocus, onBlur]);
3862
4031
  return /* @__PURE__ */ jsxRuntime.jsx(
3863
4032
  "goa-radio-group",
3864
4033
  {
@@ -3971,14 +4140,25 @@ function GoabScrollPanel({
3971
4140
  footer,
3972
4141
  height,
3973
4142
  testId,
4143
+ direction = "vertical",
3974
4144
  ...rest
3975
4145
  }) {
3976
4146
  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
- ] });
4147
+ return /* @__PURE__ */ jsxRuntime.jsxs(
4148
+ "goa-scroll-panel",
4149
+ {
4150
+ height,
4151
+ testid: testId,
4152
+ direction,
4153
+ style: hostStyle,
4154
+ ...rest,
4155
+ children: [
4156
+ header && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "header", children: header }),
4157
+ children,
4158
+ footer && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "footer", children: footer })
4159
+ ]
4160
+ }
4161
+ );
3982
4162
  }
3983
4163
  function GoabTable({ onSort, onMultiSort, sortMode, ...props }) {
3984
4164
  const ref = react.useRef(null);
@@ -4122,6 +4302,7 @@ function GoabTextArea({
4122
4302
  error,
4123
4303
  onChange,
4124
4304
  onKeyPress,
4305
+ onFocus,
4125
4306
  onBlur,
4126
4307
  ...rest
4127
4308
  }) {
@@ -4140,19 +4321,25 @@ function GoabTextArea({
4140
4321
  const detail = e.detail;
4141
4322
  onKeyPress == null ? void 0 : onKeyPress({ ...detail, event: e });
4142
4323
  };
4324
+ const focusListener = (e) => {
4325
+ const detail = e.detail;
4326
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
4327
+ };
4143
4328
  const blurListener = (e) => {
4144
4329
  const detail = e.detail;
4145
4330
  onBlur == null ? void 0 : onBlur({ ...detail, event: e });
4146
4331
  };
4147
4332
  current.addEventListener("_change", changeListener);
4148
4333
  current.addEventListener("_keyPress", keypressListener);
4334
+ current.addEventListener("_focus", focusListener);
4149
4335
  current.addEventListener("_blur", blurListener);
4150
4336
  return () => {
4151
4337
  current.removeEventListener("_change", changeListener);
4152
4338
  current.removeEventListener("_keyPress", keypressListener);
4339
+ current.removeEventListener("_focus", focusListener);
4153
4340
  current.removeEventListener("_blur", blurListener);
4154
4341
  };
4155
- }, [el, onChange, onKeyPress, onBlur]);
4342
+ }, [el, onChange, onKeyPress, onFocus, onBlur]);
4156
4343
  return /* @__PURE__ */ jsxRuntime.jsx(
4157
4344
  "goa-textarea",
4158
4345
  {
@@ -4211,6 +4398,7 @@ function GoabTwoColumnLayout(props) {
4211
4398
  );
4212
4399
  }
4213
4400
  const GoabFilterChip = ({
4401
+ content,
4214
4402
  iconTheme = "outline",
4215
4403
  error,
4216
4404
  onClick,
@@ -4231,9 +4419,11 @@ const GoabFilterChip = ({
4231
4419
  "goa-filter-chip",
4232
4420
  {
4233
4421
  ref: el,
4422
+ content: typeof content === "string" ? content : void 0,
4234
4423
  error: error ? "true" : void 0,
4235
4424
  version: "2",
4236
- ..._props
4425
+ ..._props,
4426
+ children: typeof content !== "string" && content != null && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "content", children: content })
4237
4427
  }
4238
4428
  );
4239
4429
  };
@@ -4592,6 +4782,7 @@ exports.GoabDivider = GoabDivider;
4592
4782
  exports.GoabDrawer = GoabDrawer;
4593
4783
  exports.GoabDropdown = GoabDropdown;
4594
4784
  exports.GoabDropdownItem = GoabDropdownItem;
4785
+ exports.GoabDropdownMultiselect = GoabDropdownMultiselect;
4595
4786
  exports.GoabDropdownOption = GoabDropdownOption;
4596
4787
  exports.GoabFieldset = GoabFieldset;
4597
4788
  exports.GoabFileUploadCard = GoabFileUploadCard;