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

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, 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,10 +48,20 @@ 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
+ );
53
65
  }
54
66
  function GoabAppHeader({
55
67
  onMenuClick,
@@ -121,9 +133,14 @@ function GoabBadge({
121
133
  }
122
134
  );
123
135
  }
124
- function GoabBlock({ testId, children, ...rest }) {
136
+ function GoabBlock({
137
+ testId,
138
+ stretch,
139
+ children,
140
+ ...rest
141
+ }) {
125
142
  const _props = transformProps({ testid: testId, ...rest }, kebab);
126
- return /* @__PURE__ */ jsx("goa-block", { ..._props, children });
143
+ return /* @__PURE__ */ jsx("goa-block", { ..._props, stretch: stretch ? "true" : void 0, children });
127
144
  }
128
145
  function GoabButton({
129
146
  disabled,
@@ -232,6 +249,8 @@ function GoabCheckbox({
232
249
  description,
233
250
  reveal,
234
251
  onChange,
252
+ onFocus,
253
+ onBlur,
235
254
  name,
236
255
  children,
237
256
  size = "default",
@@ -248,11 +267,23 @@ function GoabCheckbox({
248
267
  const detail = e.detail;
249
268
  onChange == null ? void 0 : onChange({ ...detail, event: e });
250
269
  };
270
+ const focusListener = (e) => {
271
+ const detail = e.detail;
272
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
273
+ };
274
+ const blurListener = (e) => {
275
+ const detail = e.detail;
276
+ onBlur == null ? void 0 : onBlur({ ...detail, event: e });
277
+ };
251
278
  current.addEventListener("_change", listener);
279
+ current.addEventListener("_focus", focusListener);
280
+ current.addEventListener("_blur", blurListener);
252
281
  return () => {
253
282
  current.removeEventListener("_change", listener);
283
+ current.removeEventListener("_focus", focusListener);
284
+ current.removeEventListener("_blur", blurListener);
254
285
  };
255
- }, [name, onChange]);
286
+ }, [name, onChange, onFocus, onBlur]);
256
287
  return /* @__PURE__ */ jsxs(
257
288
  "goa-checkbox",
258
289
  {
@@ -284,6 +315,8 @@ function GoabCheckboxList({
284
315
  size = "default",
285
316
  children,
286
317
  onChange,
318
+ onFocus,
319
+ onBlur,
287
320
  mt,
288
321
  mr,
289
322
  mb,
@@ -297,11 +330,23 @@ function GoabCheckboxList({
297
330
  const detail = e.detail;
298
331
  onChange == null ? void 0 : onChange({ ...detail, event: e });
299
332
  };
333
+ const focusListener = (e) => {
334
+ const detail = e.detail;
335
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
336
+ };
337
+ const blurListener = (e) => {
338
+ const detail = e.detail;
339
+ onBlur == null ? void 0 : onBlur({ ...detail, event: e });
340
+ };
300
341
  current.addEventListener("_change", listener);
342
+ current.addEventListener("_focus", focusListener);
343
+ current.addEventListener("_blur", blurListener);
301
344
  return () => {
302
345
  current.removeEventListener("_change", listener);
346
+ current.removeEventListener("_focus", focusListener);
347
+ current.removeEventListener("_blur", blurListener);
303
348
  };
304
- }, [onChange]);
349
+ }, [onChange, onFocus, onBlur]);
305
350
  return /* @__PURE__ */ jsx(
306
351
  "goa-checkbox-list",
307
352
  {
@@ -398,6 +443,9 @@ function GoabDataGrid({
398
443
  }
399
444
  );
400
445
  }
446
+ const GoabWorkspaceLayoutScrollState = {
447
+ NO_SCROLL: "no-scroll"
448
+ };
401
449
  function dispatch(el, eventName, detail, opts) {
402
450
  if (!el) {
403
451
  console.error("dispatch element is null");
@@ -2597,6 +2645,8 @@ function GoabDatePicker({
2597
2645
  disabled,
2598
2646
  relative,
2599
2647
  onChange,
2648
+ onFocus,
2649
+ onBlur,
2600
2650
  ...rest
2601
2651
  }) {
2602
2652
  const ref = useRef(null);
@@ -2617,15 +2667,27 @@ function GoabDatePicker({
2617
2667
  const detail = e.detail;
2618
2668
  onChange == null ? void 0 : onChange({ ...detail, event: e });
2619
2669
  };
2670
+ const handleFocus = (e) => {
2671
+ const detail = e.detail;
2672
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
2673
+ };
2674
+ const handleBlur = (e) => {
2675
+ const detail = e.detail;
2676
+ onBlur == null ? void 0 : onBlur({ ...detail, event: e });
2677
+ };
2620
2678
  if (onChange) {
2621
2679
  current.addEventListener("_change", handleChange);
2622
2680
  }
2681
+ current.addEventListener("_focus", handleFocus);
2682
+ current.addEventListener("_blur", handleBlur);
2623
2683
  return () => {
2624
2684
  if (onChange) {
2625
2685
  current.removeEventListener("_change", handleChange);
2626
2686
  }
2687
+ current.removeEventListener("_focus", handleFocus);
2688
+ current.removeEventListener("_blur", handleBlur);
2627
2689
  };
2628
- }, [onChange]);
2690
+ }, [onChange, onFocus, onBlur]);
2629
2691
  const formatValue = (val) => {
2630
2692
  if (!val) return "";
2631
2693
  if (val instanceof Date) {
@@ -2721,6 +2783,8 @@ function stringify(value) {
2721
2783
  function GoabDropdown({
2722
2784
  value,
2723
2785
  onChange,
2786
+ onFocus,
2787
+ onBlur,
2724
2788
  disabled,
2725
2789
  error,
2726
2790
  filterable,
@@ -2742,15 +2806,27 @@ function GoabDropdown({
2742
2806
  const detail = e.detail;
2743
2807
  onChange == null ? void 0 : onChange({ ...detail, event: e });
2744
2808
  };
2809
+ const focusListener = (e) => {
2810
+ const detail = e.detail;
2811
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
2812
+ };
2813
+ const blurListener = (e) => {
2814
+ const detail = e.detail;
2815
+ onBlur == null ? void 0 : onBlur({ ...detail, event: e });
2816
+ };
2745
2817
  if (onChange) {
2746
2818
  current.addEventListener("_change", handler);
2747
2819
  }
2820
+ current.addEventListener("_focus", focusListener);
2821
+ current.addEventListener("_blur", blurListener);
2748
2822
  return () => {
2749
2823
  if (onChange) {
2750
2824
  current.removeEventListener("_change", handler);
2751
2825
  }
2826
+ current.removeEventListener("_focus", focusListener);
2827
+ current.removeEventListener("_blur", blurListener);
2752
2828
  };
2753
- }, [el, onChange]);
2829
+ }, [el, onChange, onFocus, onBlur]);
2754
2830
  return /* @__PURE__ */ jsx(
2755
2831
  "goa-dropdown",
2756
2832
  {
@@ -3819,6 +3895,8 @@ function GoabRadioGroup({
3819
3895
  disabled,
3820
3896
  error,
3821
3897
  onChange,
3898
+ onFocus,
3899
+ onBlur,
3822
3900
  name,
3823
3901
  children,
3824
3902
  size = "default",
@@ -3832,16 +3910,28 @@ function GoabRadioGroup({
3832
3910
  const detail = e.detail;
3833
3911
  onChange == null ? void 0 : onChange({ ...detail, event: e });
3834
3912
  };
3913
+ const focusListener = (e) => {
3914
+ const detail = e.detail;
3915
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
3916
+ };
3917
+ const blurListener = (e) => {
3918
+ const detail = e.detail;
3919
+ onBlur == null ? void 0 : onBlur({ ...detail, event: e });
3920
+ };
3835
3921
  const currentEl = el.current;
3836
3922
  if (onChange) {
3837
3923
  currentEl.addEventListener("_change", listener);
3838
3924
  }
3925
+ currentEl.addEventListener("_focus", focusListener);
3926
+ currentEl.addEventListener("_blur", blurListener);
3839
3927
  return () => {
3840
3928
  if (onChange) {
3841
3929
  currentEl.removeEventListener("_change", listener);
3842
3930
  }
3931
+ currentEl.removeEventListener("_focus", focusListener);
3932
+ currentEl.removeEventListener("_blur", blurListener);
3843
3933
  };
3844
- }, [name, onChange]);
3934
+ }, [name, onChange, onFocus, onBlur]);
3845
3935
  return /* @__PURE__ */ jsx(
3846
3936
  "goa-radio-group",
3847
3937
  {
@@ -3948,6 +4038,21 @@ function GoabSpinner({
3948
4038
  }
3949
4039
  );
3950
4040
  }
4041
+ function GoabScrollPanel({
4042
+ header,
4043
+ children,
4044
+ footer,
4045
+ height,
4046
+ testId,
4047
+ ...rest
4048
+ }) {
4049
+ const hostStyle = height ? { height } : void 0;
4050
+ return /* @__PURE__ */ jsxs("goa-scroll-panel", { height, testid: testId, style: hostStyle, ...rest, children: [
4051
+ header && /* @__PURE__ */ jsx("div", { slot: "header", children: header }),
4052
+ children,
4053
+ footer && /* @__PURE__ */ jsx("div", { slot: "footer", children: footer })
4054
+ ] });
4055
+ }
3951
4056
  function GoabTable({ onSort, onMultiSort, sortMode, ...props }) {
3952
4057
  const ref = useRef(null);
3953
4058
  useEffect(() => {
@@ -4001,6 +4106,7 @@ function GoabTableSortHeader({
4001
4106
  name,
4002
4107
  direction,
4003
4108
  "sort-order": sortOrder,
4109
+ version: "2",
4004
4110
  ...rest,
4005
4111
  children
4006
4112
  }
@@ -4089,6 +4195,7 @@ function GoabTextArea({
4089
4195
  error,
4090
4196
  onChange,
4091
4197
  onKeyPress,
4198
+ onFocus,
4092
4199
  onBlur,
4093
4200
  ...rest
4094
4201
  }) {
@@ -4107,19 +4214,25 @@ function GoabTextArea({
4107
4214
  const detail = e.detail;
4108
4215
  onKeyPress == null ? void 0 : onKeyPress({ ...detail, event: e });
4109
4216
  };
4217
+ const focusListener = (e) => {
4218
+ const detail = e.detail;
4219
+ onFocus == null ? void 0 : onFocus({ ...detail, event: e });
4220
+ };
4110
4221
  const blurListener = (e) => {
4111
4222
  const detail = e.detail;
4112
4223
  onBlur == null ? void 0 : onBlur({ ...detail, event: e });
4113
4224
  };
4114
4225
  current.addEventListener("_change", changeListener);
4115
4226
  current.addEventListener("_keyPress", keypressListener);
4227
+ current.addEventListener("_focus", focusListener);
4116
4228
  current.addEventListener("_blur", blurListener);
4117
4229
  return () => {
4118
4230
  current.removeEventListener("_change", changeListener);
4119
4231
  current.removeEventListener("_keyPress", keypressListener);
4232
+ current.removeEventListener("_focus", focusListener);
4120
4233
  current.removeEventListener("_blur", blurListener);
4121
4234
  };
4122
- }, [el, onChange, onKeyPress, onBlur]);
4235
+ }, [el, onChange, onKeyPress, onFocus, onBlur]);
4123
4236
  return /* @__PURE__ */ jsx(
4124
4237
  "goa-textarea",
4125
4238
  {
@@ -4301,30 +4414,28 @@ function GoabWorkSideMenu({
4301
4414
  }) {
4302
4415
  const el = useRef(null);
4303
4416
  useEffect(() => {
4304
- var _a;
4305
- if (!(el == null ? void 0 : el.current) || !onToggle) {
4417
+ const node = el.current;
4418
+ if (!node || !onToggle) {
4306
4419
  return;
4307
4420
  }
4308
- (_a = el.current) == null ? void 0 : _a.addEventListener("_toggle", onToggle);
4421
+ node.addEventListener("_toggle", onToggle);
4309
4422
  return () => {
4310
- var _a2;
4311
- (_a2 = el.current) == null ? void 0 : _a2.removeEventListener("_toggle", onToggle);
4423
+ node.removeEventListener("_toggle", onToggle);
4312
4424
  };
4313
- }, [el, onToggle]);
4425
+ }, [onToggle]);
4314
4426
  useEffect(() => {
4315
- var _a;
4316
- if (!(el == null ? void 0 : el.current) || !onNavigate) {
4427
+ const node = el.current;
4428
+ if (!node || !onNavigate) {
4317
4429
  return;
4318
4430
  }
4319
4431
  const handler = (e) => {
4320
4432
  onNavigate(e.detail.url);
4321
4433
  };
4322
- (_a = el.current) == null ? void 0 : _a.addEventListener("_navigate", handler);
4434
+ node.addEventListener("_navigate", handler);
4323
4435
  return () => {
4324
- var _a2;
4325
- (_a2 = el.current) == null ? void 0 : _a2.removeEventListener("_navigate", handler);
4436
+ node.removeEventListener("_navigate", handler);
4326
4437
  };
4327
- }, [el, onNavigate]);
4438
+ }, [onNavigate]);
4328
4439
  return /* @__PURE__ */ jsxs(
4329
4440
  "goa-work-side-menu",
4330
4441
  {
@@ -4369,6 +4480,7 @@ function GoabWorkSideMenuItem(props) {
4369
4480
  type: props.type,
4370
4481
  children: [
4371
4482
  props.popoverContent && /* @__PURE__ */ jsx("div", { slot: "popoverContent", children: props.popoverContent }),
4483
+ props.trailingContent && /* @__PURE__ */ jsx("div", { slot: "trailingContent", children: props.trailingContent }),
4372
4484
  props.children
4373
4485
  ]
4374
4486
  }
@@ -4446,6 +4558,95 @@ function GoabWorkSideNotificationPanel({
4446
4558
  }
4447
4559
  );
4448
4560
  }
4561
+ const STORAGE_KEY = "goab-theme";
4562
+ const ATTRIBUTE = "data-theme";
4563
+ const GoabThemeContext = createContext(null);
4564
+ function readInitialMode(defaultMode) {
4565
+ if (typeof window === "undefined") return defaultMode;
4566
+ try {
4567
+ const stored = window.localStorage.getItem(STORAGE_KEY);
4568
+ if (stored === "light" || stored === "dark") return stored;
4569
+ } catch {
4570
+ }
4571
+ const fromAttribute = document.documentElement.getAttribute(ATTRIBUTE);
4572
+ if (fromAttribute === "light" || fromAttribute === "dark") return fromAttribute;
4573
+ if (window.matchMedia("(prefers-color-scheme: dark)").matches) return "dark";
4574
+ return defaultMode;
4575
+ }
4576
+ function GoabThemeProvider({
4577
+ children,
4578
+ defaultMode = "light"
4579
+ }) {
4580
+ const [mode, setModeState] = useState(
4581
+ () => readInitialMode(defaultMode)
4582
+ );
4583
+ useEffect(() => {
4584
+ if (typeof document === "undefined") return;
4585
+ document.documentElement.setAttribute(ATTRIBUTE, mode);
4586
+ try {
4587
+ window.localStorage.setItem(STORAGE_KEY, mode);
4588
+ } catch {
4589
+ }
4590
+ }, [mode]);
4591
+ const setMode = useCallback((next) => {
4592
+ setModeState(next);
4593
+ }, []);
4594
+ const toggle = useCallback(() => {
4595
+ setModeState((prev) => prev === "light" ? "dark" : "light");
4596
+ }, []);
4597
+ return /* @__PURE__ */ jsx(GoabThemeContext.Provider, { value: { mode, setMode, toggle }, children });
4598
+ }
4599
+ function useTheme() {
4600
+ const ctx = useContext(GoabThemeContext);
4601
+ if (!ctx) {
4602
+ throw new Error("useTheme must be used within a GoabThemeProvider");
4603
+ }
4604
+ return ctx;
4605
+ }
4606
+ const GoabWorkspaceLayoutScrollStateDefault = {
4607
+ scrollPosition: GoabWorkspaceLayoutScrollState.NO_SCROLL,
4608
+ isScrollable: false
4609
+ };
4610
+ const GoabWorkspaceLayoutScrollStateContext = createContext(
4611
+ GoabWorkspaceLayoutScrollStateDefault
4612
+ );
4613
+ function useGoabWorkspaceLayoutScrollState() {
4614
+ return useContext(GoabWorkspaceLayoutScrollStateContext);
4615
+ }
4616
+ function GoabWorkspaceLayout({
4617
+ sideMenu,
4618
+ pageHeader,
4619
+ pageFooter,
4620
+ pushDrawer,
4621
+ children,
4622
+ testId,
4623
+ onScrollStateChange,
4624
+ ...rest
4625
+ }) {
4626
+ const ref = useRef(null);
4627
+ const [scrollState, setScrollState] = useState(GoabWorkspaceLayoutScrollStateDefault);
4628
+ useEffect(() => {
4629
+ const el = ref.current;
4630
+ if (!el) return;
4631
+ const listener = (e) => {
4632
+ const detail = e.detail;
4633
+ setScrollState({
4634
+ scrollPosition: detail.state,
4635
+ isScrollable: detail.isScrollable
4636
+ });
4637
+ onScrollStateChange == null ? void 0 : onScrollStateChange({ ...detail, event: e });
4638
+ };
4639
+ el.addEventListener("_scrollStateChange", listener);
4640
+ return () => el.removeEventListener("_scrollStateChange", listener);
4641
+ }, [onScrollStateChange]);
4642
+ return /* @__PURE__ */ jsx(GoabWorkspaceLayoutScrollStateContext.Provider, { value: scrollState, children: /* @__PURE__ */ jsxs("goa-workspace-layout", { ref, testid: testId, ...rest, children: [
4643
+ sideMenu && /* @__PURE__ */ jsx("div", { slot: "side-menu", children: sideMenu }),
4644
+ pageHeader && /* @__PURE__ */ jsx("div", { slot: "page-header", children: pageHeader }),
4645
+ children,
4646
+ pageFooter && /* @__PURE__ */ jsx("div", { slot: "page-footer", children: pageFooter }),
4647
+ pushDrawer && /* @__PURE__ */ jsx("div", { slot: "push-drawer", children: pushDrawer })
4648
+ ] }) });
4649
+ }
4449
4650
  export {
4450
4651
  GoALinkButton,
4451
4652
  GoabAccordion,
@@ -4521,6 +4722,7 @@ export {
4521
4722
  GoabPushDrawer,
4522
4723
  GoabRadioGroup,
4523
4724
  GoabRadioItem,
4725
+ GoabScrollPanel,
4524
4726
  GoabSideMenu,
4525
4727
  GoabSideMenuGroup,
4526
4728
  GoabSideMenuHeading,
@@ -4535,6 +4737,7 @@ export {
4535
4737
  GoabText,
4536
4738
  GoabTextArea,
4537
4739
  GoabTextArea as GoabTextarea,
4740
+ GoabThemeProvider,
4538
4741
  GoabThreeColumnLayout,
4539
4742
  GoabTooltip,
4540
4743
  GoabTwoColumnLayout,
@@ -4543,6 +4746,9 @@ export {
4543
4746
  GoabWorkSideMenuItem,
4544
4747
  GoabWorkSideNotificationItem,
4545
4748
  GoabWorkSideNotificationPanel,
4546
- usePublicFormController
4749
+ GoabWorkspaceLayout,
4750
+ useGoabWorkspaceLayoutScrollState,
4751
+ usePublicFormController,
4752
+ useTheme
4547
4753
  };
4548
4754
  //# sourceMappingURL=index.mjs.map