@abgov/react-components 7.2.0-dev.2 → 7.2.0-dev.21

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/index.mjs CHANGED
@@ -9,7 +9,7 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
9
9
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
10
10
  var _PublicFormController_instances, updateObjectListState_fn, dispatchError_fn;
11
11
  import { jsxs, jsx } from "react/jsx-runtime";
12
- import { useRef, useEffect, useLayoutEffect, useState, useCallback } from "react";
12
+ import { useRef, useEffect, Children, isValidElement, Fragment, cloneElement, useLayoutEffect, useState, useCallback, createContext, useContext } from "react";
13
13
  const lowercase = (input) => input.toLowerCase();
14
14
  const kebab = (input) => input.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
15
15
  function transformProps(props, transform = lowercase) {
@@ -28,6 +28,8 @@ function GoabAccordion({
28
28
  open,
29
29
  onChange,
30
30
  headingContent,
31
+ headingType,
32
+ actions,
31
33
  children,
32
34
  ...rest
33
35
  }) {
@@ -46,15 +48,41 @@ function GoabAccordion({
46
48
  };
47
49
  }
48
50
  }, [onChange]);
49
- return /* @__PURE__ */ jsxs("goa-accordion", { ref, open: open ? "true" : void 0, ..._props, children: [
50
- headingContent && /* @__PURE__ */ jsx("div", { slot: "headingcontent", children: headingContent }),
51
- children
52
- ] });
51
+ return /* @__PURE__ */ jsxs(
52
+ "goa-accordion",
53
+ {
54
+ ref,
55
+ open: open ? "true" : void 0,
56
+ "heading-type": headingType,
57
+ ..._props,
58
+ children: [
59
+ headingContent && /* @__PURE__ */ jsx("div", { slot: "headingcontent", children: headingContent }),
60
+ actions && /* @__PURE__ */ jsx("div", { slot: "actions", children: actions }),
61
+ children
62
+ ]
63
+ }
64
+ );
65
+ }
66
+ function renderSlottedItems(children, slot) {
67
+ return Children.map(children, (child) => {
68
+ if (!isValidElement(child)) {
69
+ return child;
70
+ }
71
+ if (child.type === Fragment) {
72
+ const fragment = child;
73
+ return renderSlottedItems(fragment.props.children, slot);
74
+ }
75
+ return cloneElement(child, { slot });
76
+ });
53
77
  }
54
78
  function GoabAppHeader({
55
79
  onMenuClick,
56
80
  children,
57
81
  secondaryText,
82
+ banner,
83
+ phase,
84
+ navigation,
85
+ utilities,
58
86
  ...rest
59
87
  }) {
60
88
  const el = useRef(null);
@@ -75,7 +103,7 @@ function GoabAppHeader({
75
103
  current.removeEventListener("_menuClick", listener);
76
104
  };
77
105
  }, [el, onMenuClick]);
78
- return /* @__PURE__ */ jsx(
106
+ return /* @__PURE__ */ jsxs(
79
107
  "goa-app-header",
80
108
  {
81
109
  ref: el,
@@ -83,7 +111,13 @@ function GoabAppHeader({
83
111
  secondarytext: secondaryText,
84
112
  ..._props,
85
113
  version: "2",
86
- children
114
+ children: [
115
+ children,
116
+ banner && /* @__PURE__ */ jsx("div", { slot: "banner", children: banner }),
117
+ phase && /* @__PURE__ */ jsx("div", { slot: "phase", children: phase }),
118
+ navigation && renderSlottedItems(navigation, "navigation"),
119
+ utilities && renderSlottedItems(utilities, "utilities")
120
+ ]
87
121
  }
88
122
  );
89
123
  }
@@ -121,9 +155,14 @@ function GoabBadge({
121
155
  }
122
156
  );
123
157
  }
124
- function GoabBlock({ testId, children, ...rest }) {
158
+ function GoabBlock({
159
+ testId,
160
+ stretch,
161
+ children,
162
+ ...rest
163
+ }) {
125
164
  const _props = transformProps({ testid: testId, ...rest }, kebab);
126
- return /* @__PURE__ */ jsx("goa-block", { ..._props, children });
165
+ return /* @__PURE__ */ jsx("goa-block", { ..._props, stretch: stretch ? "true" : void 0, children });
127
166
  }
128
167
  function GoabButton({
129
168
  disabled,
@@ -232,6 +271,8 @@ function GoabCheckbox({
232
271
  description,
233
272
  reveal,
234
273
  onChange,
274
+ onFocus,
275
+ onBlur,
235
276
  name,
236
277
  children,
237
278
  size = "default",
@@ -248,11 +289,23 @@ function GoabCheckbox({
248
289
  const detail = e.detail;
249
290
  onChange == null ? void 0 : onChange({ ...detail, event: e });
250
291
  };
292
+ const focusListener = (e) => {
293
+ const detail = e.detail;
294
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
295
+ };
296
+ const blurListener = (e) => {
297
+ const detail = e.detail;
298
+ onBlur == null ? void 0 : onBlur({ ...detail, event: e });
299
+ };
251
300
  current.addEventListener("_change", listener);
301
+ current.addEventListener("_focus", focusListener);
302
+ current.addEventListener("_blur", blurListener);
252
303
  return () => {
253
304
  current.removeEventListener("_change", listener);
305
+ current.removeEventListener("_focus", focusListener);
306
+ current.removeEventListener("_blur", blurListener);
254
307
  };
255
- }, [name, onChange]);
308
+ }, [name, onChange, onFocus, onBlur]);
256
309
  return /* @__PURE__ */ jsxs(
257
310
  "goa-checkbox",
258
311
  {
@@ -284,6 +337,8 @@ function GoabCheckboxList({
284
337
  size = "default",
285
338
  children,
286
339
  onChange,
340
+ onFocus,
341
+ onBlur,
287
342
  mt,
288
343
  mr,
289
344
  mb,
@@ -297,11 +352,23 @@ function GoabCheckboxList({
297
352
  const detail = e.detail;
298
353
  onChange == null ? void 0 : onChange({ ...detail, event: e });
299
354
  };
355
+ const focusListener = (e) => {
356
+ const detail = e.detail;
357
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
358
+ };
359
+ const blurListener = (e) => {
360
+ const detail = e.detail;
361
+ onBlur == null ? void 0 : onBlur({ ...detail, event: e });
362
+ };
300
363
  current.addEventListener("_change", listener);
364
+ current.addEventListener("_focus", focusListener);
365
+ current.addEventListener("_blur", blurListener);
301
366
  return () => {
302
367
  current.removeEventListener("_change", listener);
368
+ current.removeEventListener("_focus", focusListener);
369
+ current.removeEventListener("_blur", blurListener);
303
370
  };
304
- }, [onChange]);
371
+ }, [onChange, onFocus, onBlur]);
305
372
  return /* @__PURE__ */ jsx(
306
373
  "goa-checkbox-list",
307
374
  {
@@ -398,6 +465,9 @@ function GoabDataGrid({
398
465
  }
399
466
  );
400
467
  }
468
+ const GoabWorkspaceLayoutScrollState = {
469
+ NO_SCROLL: "no-scroll"
470
+ };
401
471
  function dispatch(el, eventName, detail, opts) {
402
472
  if (!el) {
403
473
  console.error("dispatch element is null");
@@ -2597,6 +2667,8 @@ function GoabDatePicker({
2597
2667
  disabled,
2598
2668
  relative,
2599
2669
  onChange,
2670
+ onFocus,
2671
+ onBlur,
2600
2672
  ...rest
2601
2673
  }) {
2602
2674
  const ref = useRef(null);
@@ -2617,15 +2689,27 @@ function GoabDatePicker({
2617
2689
  const detail = e.detail;
2618
2690
  onChange == null ? void 0 : onChange({ ...detail, event: e });
2619
2691
  };
2692
+ const handleFocus = (e) => {
2693
+ const detail = e.detail;
2694
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
2695
+ };
2696
+ const handleBlur = (e) => {
2697
+ const detail = e.detail;
2698
+ onBlur == null ? void 0 : onBlur({ ...detail, event: e });
2699
+ };
2620
2700
  if (onChange) {
2621
2701
  current.addEventListener("_change", handleChange);
2622
2702
  }
2703
+ current.addEventListener("_focus", handleFocus);
2704
+ current.addEventListener("_blur", handleBlur);
2623
2705
  return () => {
2624
2706
  if (onChange) {
2625
2707
  current.removeEventListener("_change", handleChange);
2626
2708
  }
2709
+ current.removeEventListener("_focus", handleFocus);
2710
+ current.removeEventListener("_blur", handleBlur);
2627
2711
  };
2628
- }, [onChange]);
2712
+ }, [onChange, onFocus, onBlur]);
2629
2713
  const formatValue = (val) => {
2630
2714
  if (!val) return "";
2631
2715
  if (val instanceof Date) {
@@ -2721,6 +2805,8 @@ function stringify(value) {
2721
2805
  function GoabDropdown({
2722
2806
  value,
2723
2807
  onChange,
2808
+ onFocus,
2809
+ onBlur,
2724
2810
  disabled,
2725
2811
  error,
2726
2812
  filterable,
@@ -2742,15 +2828,27 @@ function GoabDropdown({
2742
2828
  const detail = e.detail;
2743
2829
  onChange == null ? void 0 : onChange({ ...detail, event: e });
2744
2830
  };
2831
+ const focusListener = (e) => {
2832
+ const detail = e.detail;
2833
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
2834
+ };
2835
+ const blurListener = (e) => {
2836
+ const detail = e.detail;
2837
+ onBlur == null ? void 0 : onBlur({ ...detail, event: e });
2838
+ };
2745
2839
  if (onChange) {
2746
2840
  current.addEventListener("_change", handler);
2747
2841
  }
2842
+ current.addEventListener("_focus", focusListener);
2843
+ current.addEventListener("_blur", blurListener);
2748
2844
  return () => {
2749
2845
  if (onChange) {
2750
2846
  current.removeEventListener("_change", handler);
2751
2847
  }
2848
+ current.removeEventListener("_focus", focusListener);
2849
+ current.removeEventListener("_blur", blurListener);
2752
2850
  };
2753
- }, [el, onChange]);
2851
+ }, [el, onChange, onFocus, onBlur]);
2754
2852
  return /* @__PURE__ */ jsx(
2755
2853
  "goa-dropdown",
2756
2854
  {
@@ -2779,7 +2877,8 @@ function GoabDropdownItem({
2779
2877
  label,
2780
2878
  filter,
2781
2879
  name,
2782
- mountType = "append"
2880
+ mountType = "append",
2881
+ children
2783
2882
  }) {
2784
2883
  return /* @__PURE__ */ jsx(
2785
2884
  "goa-dropdown-item",
@@ -2788,7 +2887,8 @@ function GoabDropdownItem({
2788
2887
  label,
2789
2888
  filter,
2790
2889
  name,
2791
- mount: mountType
2890
+ mount: mountType,
2891
+ children
2792
2892
  }
2793
2893
  );
2794
2894
  }
@@ -3819,6 +3919,8 @@ function GoabRadioGroup({
3819
3919
  disabled,
3820
3920
  error,
3821
3921
  onChange,
3922
+ onFocus,
3923
+ onBlur,
3822
3924
  name,
3823
3925
  children,
3824
3926
  size = "default",
@@ -3832,16 +3934,28 @@ function GoabRadioGroup({
3832
3934
  const detail = e.detail;
3833
3935
  onChange == null ? void 0 : onChange({ ...detail, event: e });
3834
3936
  };
3937
+ const focusListener = (e) => {
3938
+ const detail = e.detail;
3939
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
3940
+ };
3941
+ const blurListener = (e) => {
3942
+ const detail = e.detail;
3943
+ onBlur == null ? void 0 : onBlur({ ...detail, event: e });
3944
+ };
3835
3945
  const currentEl = el.current;
3836
3946
  if (onChange) {
3837
3947
  currentEl.addEventListener("_change", listener);
3838
3948
  }
3949
+ currentEl.addEventListener("_focus", focusListener);
3950
+ currentEl.addEventListener("_blur", blurListener);
3839
3951
  return () => {
3840
3952
  if (onChange) {
3841
3953
  currentEl.removeEventListener("_change", listener);
3842
3954
  }
3955
+ currentEl.removeEventListener("_focus", focusListener);
3956
+ currentEl.removeEventListener("_blur", blurListener);
3843
3957
  };
3844
- }, [name, onChange]);
3958
+ }, [name, onChange, onFocus, onBlur]);
3845
3959
  return /* @__PURE__ */ jsx(
3846
3960
  "goa-radio-group",
3847
3961
  {
@@ -3948,6 +4062,21 @@ function GoabSpinner({
3948
4062
  }
3949
4063
  );
3950
4064
  }
4065
+ function GoabScrollPanel({
4066
+ header,
4067
+ children,
4068
+ footer,
4069
+ height,
4070
+ testId,
4071
+ ...rest
4072
+ }) {
4073
+ const hostStyle = height ? { height } : void 0;
4074
+ return /* @__PURE__ */ jsxs("goa-scroll-panel", { height, testid: testId, style: hostStyle, ...rest, children: [
4075
+ header && /* @__PURE__ */ jsx("div", { slot: "header", children: header }),
4076
+ children,
4077
+ footer && /* @__PURE__ */ jsx("div", { slot: "footer", children: footer })
4078
+ ] });
4079
+ }
3951
4080
  function GoabTable({ onSort, onMultiSort, sortMode, ...props }) {
3952
4081
  const ref = useRef(null);
3953
4082
  useEffect(() => {
@@ -4001,6 +4130,7 @@ function GoabTableSortHeader({
4001
4130
  name,
4002
4131
  direction,
4003
4132
  "sort-order": sortOrder,
4133
+ version: "2",
4004
4134
  ...rest,
4005
4135
  children
4006
4136
  }
@@ -4089,6 +4219,7 @@ function GoabTextArea({
4089
4219
  error,
4090
4220
  onChange,
4091
4221
  onKeyPress,
4222
+ onFocus,
4092
4223
  onBlur,
4093
4224
  ...rest
4094
4225
  }) {
@@ -4107,19 +4238,25 @@ function GoabTextArea({
4107
4238
  const detail = e.detail;
4108
4239
  onKeyPress == null ? void 0 : onKeyPress({ ...detail, event: e });
4109
4240
  };
4241
+ const focusListener = (e) => {
4242
+ const detail = e.detail;
4243
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
4244
+ };
4110
4245
  const blurListener = (e) => {
4111
4246
  const detail = e.detail;
4112
4247
  onBlur == null ? void 0 : onBlur({ ...detail, event: e });
4113
4248
  };
4114
4249
  current.addEventListener("_change", changeListener);
4115
4250
  current.addEventListener("_keyPress", keypressListener);
4251
+ current.addEventListener("_focus", focusListener);
4116
4252
  current.addEventListener("_blur", blurListener);
4117
4253
  return () => {
4118
4254
  current.removeEventListener("_change", changeListener);
4119
4255
  current.removeEventListener("_keyPress", keypressListener);
4256
+ current.removeEventListener("_focus", focusListener);
4120
4257
  current.removeEventListener("_blur", blurListener);
4121
4258
  };
4122
- }, [el, onChange, onKeyPress, onBlur]);
4259
+ }, [el, onChange, onKeyPress, onFocus, onBlur]);
4123
4260
  return /* @__PURE__ */ jsx(
4124
4261
  "goa-textarea",
4125
4262
  {
@@ -4301,30 +4438,28 @@ function GoabWorkSideMenu({
4301
4438
  }) {
4302
4439
  const el = useRef(null);
4303
4440
  useEffect(() => {
4304
- var _a;
4305
- if (!(el == null ? void 0 : el.current) || !onToggle) {
4441
+ const node = el.current;
4442
+ if (!node || !onToggle) {
4306
4443
  return;
4307
4444
  }
4308
- (_a = el.current) == null ? void 0 : _a.addEventListener("_toggle", onToggle);
4445
+ node.addEventListener("_toggle", onToggle);
4309
4446
  return () => {
4310
- var _a2;
4311
- (_a2 = el.current) == null ? void 0 : _a2.removeEventListener("_toggle", onToggle);
4447
+ node.removeEventListener("_toggle", onToggle);
4312
4448
  };
4313
- }, [el, onToggle]);
4449
+ }, [onToggle]);
4314
4450
  useEffect(() => {
4315
- var _a;
4316
- if (!(el == null ? void 0 : el.current) || !onNavigate) {
4451
+ const node = el.current;
4452
+ if (!node || !onNavigate) {
4317
4453
  return;
4318
4454
  }
4319
4455
  const handler = (e) => {
4320
4456
  onNavigate(e.detail.url);
4321
4457
  };
4322
- (_a = el.current) == null ? void 0 : _a.addEventListener("_navigate", handler);
4458
+ node.addEventListener("_navigate", handler);
4323
4459
  return () => {
4324
- var _a2;
4325
- (_a2 = el.current) == null ? void 0 : _a2.removeEventListener("_navigate", handler);
4460
+ node.removeEventListener("_navigate", handler);
4326
4461
  };
4327
- }, [el, onNavigate]);
4462
+ }, [onNavigate]);
4328
4463
  return /* @__PURE__ */ jsxs(
4329
4464
  "goa-work-side-menu",
4330
4465
  {
@@ -4369,6 +4504,7 @@ function GoabWorkSideMenuItem(props) {
4369
4504
  type: props.type,
4370
4505
  children: [
4371
4506
  props.popoverContent && /* @__PURE__ */ jsx("div", { slot: "popoverContent", children: props.popoverContent }),
4507
+ props.trailingContent && /* @__PURE__ */ jsx("div", { slot: "trailingContent", children: props.trailingContent }),
4372
4508
  props.children
4373
4509
  ]
4374
4510
  }
@@ -4446,6 +4582,95 @@ function GoabWorkSideNotificationPanel({
4446
4582
  }
4447
4583
  );
4448
4584
  }
4585
+ const STORAGE_KEY = "goab-theme";
4586
+ const ATTRIBUTE = "data-theme";
4587
+ const GoabThemeContext = createContext(null);
4588
+ function readInitialMode(defaultMode) {
4589
+ if (typeof window === "undefined") return defaultMode;
4590
+ try {
4591
+ const stored = window.localStorage.getItem(STORAGE_KEY);
4592
+ if (stored === "light" || stored === "dark") return stored;
4593
+ } catch {
4594
+ }
4595
+ const fromAttribute = document.documentElement.getAttribute(ATTRIBUTE);
4596
+ if (fromAttribute === "light" || fromAttribute === "dark") return fromAttribute;
4597
+ if (window.matchMedia("(prefers-color-scheme: dark)").matches) return "dark";
4598
+ return defaultMode;
4599
+ }
4600
+ function GoabThemeProvider({
4601
+ children,
4602
+ defaultMode = "light"
4603
+ }) {
4604
+ const [mode, setModeState] = useState(
4605
+ () => readInitialMode(defaultMode)
4606
+ );
4607
+ useEffect(() => {
4608
+ if (typeof document === "undefined") return;
4609
+ document.documentElement.setAttribute(ATTRIBUTE, mode);
4610
+ try {
4611
+ window.localStorage.setItem(STORAGE_KEY, mode);
4612
+ } catch {
4613
+ }
4614
+ }, [mode]);
4615
+ const setMode = useCallback((next) => {
4616
+ setModeState(next);
4617
+ }, []);
4618
+ const toggle = useCallback(() => {
4619
+ setModeState((prev) => prev === "light" ? "dark" : "light");
4620
+ }, []);
4621
+ return /* @__PURE__ */ jsx(GoabThemeContext.Provider, { value: { mode, setMode, toggle }, children });
4622
+ }
4623
+ function useTheme() {
4624
+ const ctx = useContext(GoabThemeContext);
4625
+ if (!ctx) {
4626
+ throw new Error("useTheme must be used within a GoabThemeProvider");
4627
+ }
4628
+ return ctx;
4629
+ }
4630
+ const GoabWorkspaceLayoutScrollStateDefault = {
4631
+ scrollPosition: GoabWorkspaceLayoutScrollState.NO_SCROLL,
4632
+ isScrollable: false
4633
+ };
4634
+ const GoabWorkspaceLayoutScrollStateContext = createContext(
4635
+ GoabWorkspaceLayoutScrollStateDefault
4636
+ );
4637
+ function useGoabWorkspaceLayoutScrollState() {
4638
+ return useContext(GoabWorkspaceLayoutScrollStateContext);
4639
+ }
4640
+ function GoabWorkspaceLayout({
4641
+ sideMenu,
4642
+ pageHeader,
4643
+ pageFooter,
4644
+ pushDrawer,
4645
+ children,
4646
+ testId,
4647
+ onScrollStateChange,
4648
+ ...rest
4649
+ }) {
4650
+ const ref = useRef(null);
4651
+ const [scrollState, setScrollState] = useState(GoabWorkspaceLayoutScrollStateDefault);
4652
+ useEffect(() => {
4653
+ const el = ref.current;
4654
+ if (!el) return;
4655
+ const listener = (e) => {
4656
+ const detail = e.detail;
4657
+ setScrollState({
4658
+ scrollPosition: detail.state,
4659
+ isScrollable: detail.isScrollable
4660
+ });
4661
+ onScrollStateChange == null ? void 0 : onScrollStateChange({ ...detail, event: e });
4662
+ };
4663
+ el.addEventListener("_scrollStateChange", listener);
4664
+ return () => el.removeEventListener("_scrollStateChange", listener);
4665
+ }, [onScrollStateChange]);
4666
+ return /* @__PURE__ */ jsx(GoabWorkspaceLayoutScrollStateContext.Provider, { value: scrollState, children: /* @__PURE__ */ jsxs("goa-workspace-layout", { ref, testid: testId, ...rest, children: [
4667
+ sideMenu && /* @__PURE__ */ jsx("div", { slot: "side-menu", children: sideMenu }),
4668
+ pageHeader && /* @__PURE__ */ jsx("div", { slot: "page-header", children: pageHeader }),
4669
+ children,
4670
+ pageFooter && /* @__PURE__ */ jsx("div", { slot: "page-footer", children: pageFooter }),
4671
+ pushDrawer && /* @__PURE__ */ jsx("div", { slot: "push-drawer", children: pushDrawer })
4672
+ ] }) });
4673
+ }
4449
4674
  export {
4450
4675
  GoALinkButton,
4451
4676
  GoabAccordion,
@@ -4521,6 +4746,7 @@ export {
4521
4746
  GoabPushDrawer,
4522
4747
  GoabRadioGroup,
4523
4748
  GoabRadioItem,
4749
+ GoabScrollPanel,
4524
4750
  GoabSideMenu,
4525
4751
  GoabSideMenuGroup,
4526
4752
  GoabSideMenuHeading,
@@ -4535,6 +4761,7 @@ export {
4535
4761
  GoabText,
4536
4762
  GoabTextArea,
4537
4763
  GoabTextArea as GoabTextarea,
4764
+ GoabThemeProvider,
4538
4765
  GoabThreeColumnLayout,
4539
4766
  GoabTooltip,
4540
4767
  GoabTwoColumnLayout,
@@ -4543,6 +4770,9 @@ export {
4543
4770
  GoabWorkSideMenuItem,
4544
4771
  GoabWorkSideNotificationItem,
4545
4772
  GoabWorkSideNotificationPanel,
4546
- usePublicFormController
4773
+ GoabWorkspaceLayout,
4774
+ useGoabWorkspaceLayoutScrollState,
4775
+ usePublicFormController,
4776
+ useTheme
4547
4777
  };
4548
4778
  //# sourceMappingURL=index.mjs.map