@abgov/react-components 7.2.0-dev.1 → 7.2.0-dev.11

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,
@@ -2676,14 +2688,19 @@ function GoabDrawer({
2676
2688
  }) {
2677
2689
  const el = useRef(null);
2678
2690
  useEffect(() => {
2679
- var _a;
2680
2691
  if (!(el == null ? void 0 : el.current) || !onClose) {
2681
2692
  return;
2682
2693
  }
2683
- (_a = el.current) == null ? void 0 : _a.addEventListener("_close", onClose);
2694
+ const current = el.current;
2695
+ const listener = (e) => {
2696
+ if (e.target !== current) {
2697
+ return;
2698
+ }
2699
+ onClose();
2700
+ };
2701
+ current.addEventListener("_close", listener);
2684
2702
  return () => {
2685
- var _a2;
2686
- (_a2 = el.current) == null ? void 0 : _a2.removeEventListener("_close", onClose);
2703
+ current.removeEventListener("_close", listener);
2687
2704
  };
2688
2705
  }, [el, onClose]);
2689
2706
  return /* @__PURE__ */ jsxs(
@@ -3578,7 +3595,10 @@ function GoabModal({
3578
3595
  return;
3579
3596
  }
3580
3597
  const current = el.current;
3581
- const listener = () => {
3598
+ const listener = (e) => {
3599
+ if (e.target !== current) {
3600
+ return;
3601
+ }
3582
3602
  onClose == null ? void 0 : onClose();
3583
3603
  };
3584
3604
  current.addEventListener("_close", listener);
@@ -3729,14 +3749,19 @@ function GoabPushDrawer({
3729
3749
  }) {
3730
3750
  const el = useRef(null);
3731
3751
  useEffect(() => {
3732
- var _a;
3733
3752
  if (!(el == null ? void 0 : el.current) || !onClose) {
3734
3753
  return;
3735
3754
  }
3736
- (_a = el.current) == null ? void 0 : _a.addEventListener("_close", onClose);
3755
+ const current = el.current;
3756
+ const listener = (e) => {
3757
+ if (e.target !== current) {
3758
+ return;
3759
+ }
3760
+ onClose();
3761
+ };
3762
+ current.addEventListener("_close", listener);
3737
3763
  return () => {
3738
- var _a2;
3739
- (_a2 = el.current) == null ? void 0 : _a2.removeEventListener("_close", onClose);
3764
+ current.removeEventListener("_close", listener);
3740
3765
  };
3741
3766
  }, [el, onClose]);
3742
3767
  return /* @__PURE__ */ jsxs(
@@ -3988,6 +4013,7 @@ function GoabTableSortHeader({
3988
4013
  name,
3989
4014
  direction,
3990
4015
  "sort-order": sortOrder,
4016
+ version: "2",
3991
4017
  ...rest,
3992
4018
  children
3993
4019
  }
@@ -4288,30 +4314,28 @@ function GoabWorkSideMenu({
4288
4314
  }) {
4289
4315
  const el = useRef(null);
4290
4316
  useEffect(() => {
4291
- var _a;
4292
- if (!(el == null ? void 0 : el.current) || !onToggle) {
4317
+ const node = el.current;
4318
+ if (!node || !onToggle) {
4293
4319
  return;
4294
4320
  }
4295
- (_a = el.current) == null ? void 0 : _a.addEventListener("_toggle", onToggle);
4321
+ node.addEventListener("_toggle", onToggle);
4296
4322
  return () => {
4297
- var _a2;
4298
- (_a2 = el.current) == null ? void 0 : _a2.removeEventListener("_toggle", onToggle);
4323
+ node.removeEventListener("_toggle", onToggle);
4299
4324
  };
4300
- }, [el, onToggle]);
4325
+ }, [onToggle]);
4301
4326
  useEffect(() => {
4302
- var _a;
4303
- if (!(el == null ? void 0 : el.current) || !onNavigate) {
4327
+ const node = el.current;
4328
+ if (!node || !onNavigate) {
4304
4329
  return;
4305
4330
  }
4306
4331
  const handler = (e) => {
4307
4332
  onNavigate(e.detail.url);
4308
4333
  };
4309
- (_a = el.current) == null ? void 0 : _a.addEventListener("_navigate", handler);
4334
+ node.addEventListener("_navigate", handler);
4310
4335
  return () => {
4311
- var _a2;
4312
- (_a2 = el.current) == null ? void 0 : _a2.removeEventListener("_navigate", handler);
4336
+ node.removeEventListener("_navigate", handler);
4313
4337
  };
4314
- }, [el, onNavigate]);
4338
+ }, [onNavigate]);
4315
4339
  return /* @__PURE__ */ jsxs(
4316
4340
  "goa-work-side-menu",
4317
4341
  {
@@ -4356,6 +4380,7 @@ function GoabWorkSideMenuItem(props) {
4356
4380
  type: props.type,
4357
4381
  children: [
4358
4382
  props.popoverContent && /* @__PURE__ */ jsx("div", { slot: "popoverContent", children: props.popoverContent }),
4383
+ props.trailingContent && /* @__PURE__ */ jsx("div", { slot: "trailingContent", children: props.trailingContent }),
4359
4384
  props.children
4360
4385
  ]
4361
4386
  }
@@ -4433,6 +4458,51 @@ function GoabWorkSideNotificationPanel({
4433
4458
  }
4434
4459
  );
4435
4460
  }
4461
+ const STORAGE_KEY = "goab-theme";
4462
+ const ATTRIBUTE = "data-theme";
4463
+ const GoabThemeContext = createContext(null);
4464
+ function readInitialMode(defaultMode) {
4465
+ if (typeof window === "undefined") return defaultMode;
4466
+ try {
4467
+ const stored = window.localStorage.getItem(STORAGE_KEY);
4468
+ if (stored === "light" || stored === "dark") return stored;
4469
+ } catch {
4470
+ }
4471
+ const fromAttribute = document.documentElement.getAttribute(ATTRIBUTE);
4472
+ if (fromAttribute === "light" || fromAttribute === "dark") return fromAttribute;
4473
+ if (window.matchMedia("(prefers-color-scheme: dark)").matches) return "dark";
4474
+ return defaultMode;
4475
+ }
4476
+ function GoabThemeProvider({
4477
+ children,
4478
+ defaultMode = "light"
4479
+ }) {
4480
+ const [mode, setModeState] = useState(
4481
+ () => readInitialMode(defaultMode)
4482
+ );
4483
+ useEffect(() => {
4484
+ if (typeof document === "undefined") return;
4485
+ document.documentElement.setAttribute(ATTRIBUTE, mode);
4486
+ try {
4487
+ window.localStorage.setItem(STORAGE_KEY, mode);
4488
+ } catch {
4489
+ }
4490
+ }, [mode]);
4491
+ const setMode = useCallback((next) => {
4492
+ setModeState(next);
4493
+ }, []);
4494
+ const toggle = useCallback(() => {
4495
+ setModeState((prev) => prev === "light" ? "dark" : "light");
4496
+ }, []);
4497
+ return /* @__PURE__ */ jsx(GoabThemeContext.Provider, { value: { mode, setMode, toggle }, children });
4498
+ }
4499
+ function useTheme() {
4500
+ const ctx = useContext(GoabThemeContext);
4501
+ if (!ctx) {
4502
+ throw new Error("useTheme must be used within a GoabThemeProvider");
4503
+ }
4504
+ return ctx;
4505
+ }
4436
4506
  export {
4437
4507
  GoALinkButton,
4438
4508
  GoabAccordion,
@@ -4522,6 +4592,7 @@ export {
4522
4592
  GoabText,
4523
4593
  GoabTextArea,
4524
4594
  GoabTextArea as GoabTextarea,
4595
+ GoabThemeProvider,
4525
4596
  GoabThreeColumnLayout,
4526
4597
  GoabTooltip,
4527
4598
  GoabTwoColumnLayout,
@@ -4530,6 +4601,7 @@ export {
4530
4601
  GoabWorkSideMenuItem,
4531
4602
  GoabWorkSideNotificationItem,
4532
4603
  GoabWorkSideNotificationPanel,
4533
- usePublicFormController
4604
+ usePublicFormController,
4605
+ useTheme
4534
4606
  };
4535
4607
  //# sourceMappingURL=index.mjs.map