@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.d.ts CHANGED
@@ -79,3 +79,4 @@ export * from './lib/work-side-menu-group/work-side-menu-group';
79
79
  export * from './lib/work-side-menu-item/work-side-menu-item';
80
80
  export * from './lib/work-side-notification-item/work-side-notification-item';
81
81
  export * from './lib/work-side-notification-panel/work-side-notification-panel';
82
+ export * from './lib/theme/theme-context';
package/index.js CHANGED
@@ -30,6 +30,8 @@ function GoabAccordion({
30
30
  open,
31
31
  onChange,
32
32
  headingContent,
33
+ headingType,
34
+ actions,
33
35
  children,
34
36
  ...rest
35
37
  }) {
@@ -48,10 +50,20 @@ function GoabAccordion({
48
50
  };
49
51
  }
50
52
  }, [onChange]);
51
- return /* @__PURE__ */ jsxRuntime.jsxs("goa-accordion", { ref, open: open ? "true" : void 0, ..._props, children: [
52
- headingContent && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "headingcontent", children: headingContent }),
53
- children
54
- ] });
53
+ return /* @__PURE__ */ jsxRuntime.jsxs(
54
+ "goa-accordion",
55
+ {
56
+ ref,
57
+ open: open ? "true" : void 0,
58
+ "heading-type": headingType,
59
+ ..._props,
60
+ children: [
61
+ headingContent && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "headingcontent", children: headingContent }),
62
+ actions && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "actions", children: actions }),
63
+ children
64
+ ]
65
+ }
66
+ );
55
67
  }
56
68
  function GoabAppHeader({
57
69
  onMenuClick,
@@ -2678,14 +2690,19 @@ function GoabDrawer({
2678
2690
  }) {
2679
2691
  const el = react.useRef(null);
2680
2692
  react.useEffect(() => {
2681
- var _a;
2682
2693
  if (!(el == null ? void 0 : el.current) || !onClose) {
2683
2694
  return;
2684
2695
  }
2685
- (_a = el.current) == null ? void 0 : _a.addEventListener("_close", onClose);
2696
+ const current = el.current;
2697
+ const listener = (e) => {
2698
+ if (e.target !== current) {
2699
+ return;
2700
+ }
2701
+ onClose();
2702
+ };
2703
+ current.addEventListener("_close", listener);
2686
2704
  return () => {
2687
- var _a2;
2688
- (_a2 = el.current) == null ? void 0 : _a2.removeEventListener("_close", onClose);
2705
+ current.removeEventListener("_close", listener);
2689
2706
  };
2690
2707
  }, [el, onClose]);
2691
2708
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -3580,7 +3597,10 @@ function GoabModal({
3580
3597
  return;
3581
3598
  }
3582
3599
  const current = el.current;
3583
- const listener = () => {
3600
+ const listener = (e) => {
3601
+ if (e.target !== current) {
3602
+ return;
3603
+ }
3584
3604
  onClose == null ? void 0 : onClose();
3585
3605
  };
3586
3606
  current.addEventListener("_close", listener);
@@ -3731,14 +3751,19 @@ function GoabPushDrawer({
3731
3751
  }) {
3732
3752
  const el = react.useRef(null);
3733
3753
  react.useEffect(() => {
3734
- var _a;
3735
3754
  if (!(el == null ? void 0 : el.current) || !onClose) {
3736
3755
  return;
3737
3756
  }
3738
- (_a = el.current) == null ? void 0 : _a.addEventListener("_close", onClose);
3757
+ const current = el.current;
3758
+ const listener = (e) => {
3759
+ if (e.target !== current) {
3760
+ return;
3761
+ }
3762
+ onClose();
3763
+ };
3764
+ current.addEventListener("_close", listener);
3739
3765
  return () => {
3740
- var _a2;
3741
- (_a2 = el.current) == null ? void 0 : _a2.removeEventListener("_close", onClose);
3766
+ current.removeEventListener("_close", listener);
3742
3767
  };
3743
3768
  }, [el, onClose]);
3744
3769
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -3990,6 +4015,7 @@ function GoabTableSortHeader({
3990
4015
  name,
3991
4016
  direction,
3992
4017
  "sort-order": sortOrder,
4018
+ version: "2",
3993
4019
  ...rest,
3994
4020
  children
3995
4021
  }
@@ -4290,30 +4316,28 @@ function GoabWorkSideMenu({
4290
4316
  }) {
4291
4317
  const el = react.useRef(null);
4292
4318
  react.useEffect(() => {
4293
- var _a;
4294
- if (!(el == null ? void 0 : el.current) || !onToggle) {
4319
+ const node = el.current;
4320
+ if (!node || !onToggle) {
4295
4321
  return;
4296
4322
  }
4297
- (_a = el.current) == null ? void 0 : _a.addEventListener("_toggle", onToggle);
4323
+ node.addEventListener("_toggle", onToggle);
4298
4324
  return () => {
4299
- var _a2;
4300
- (_a2 = el.current) == null ? void 0 : _a2.removeEventListener("_toggle", onToggle);
4325
+ node.removeEventListener("_toggle", onToggle);
4301
4326
  };
4302
- }, [el, onToggle]);
4327
+ }, [onToggle]);
4303
4328
  react.useEffect(() => {
4304
- var _a;
4305
- if (!(el == null ? void 0 : el.current) || !onNavigate) {
4329
+ const node = el.current;
4330
+ if (!node || !onNavigate) {
4306
4331
  return;
4307
4332
  }
4308
4333
  const handler = (e) => {
4309
4334
  onNavigate(e.detail.url);
4310
4335
  };
4311
- (_a = el.current) == null ? void 0 : _a.addEventListener("_navigate", handler);
4336
+ node.addEventListener("_navigate", handler);
4312
4337
  return () => {
4313
- var _a2;
4314
- (_a2 = el.current) == null ? void 0 : _a2.removeEventListener("_navigate", handler);
4338
+ node.removeEventListener("_navigate", handler);
4315
4339
  };
4316
- }, [el, onNavigate]);
4340
+ }, [onNavigate]);
4317
4341
  return /* @__PURE__ */ jsxRuntime.jsxs(
4318
4342
  "goa-work-side-menu",
4319
4343
  {
@@ -4358,6 +4382,7 @@ function GoabWorkSideMenuItem(props) {
4358
4382
  type: props.type,
4359
4383
  children: [
4360
4384
  props.popoverContent && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "popoverContent", children: props.popoverContent }),
4385
+ props.trailingContent && /* @__PURE__ */ jsxRuntime.jsx("div", { slot: "trailingContent", children: props.trailingContent }),
4361
4386
  props.children
4362
4387
  ]
4363
4388
  }
@@ -4435,6 +4460,51 @@ function GoabWorkSideNotificationPanel({
4435
4460
  }
4436
4461
  );
4437
4462
  }
4463
+ const STORAGE_KEY = "goab-theme";
4464
+ const ATTRIBUTE = "data-theme";
4465
+ const GoabThemeContext = react.createContext(null);
4466
+ function readInitialMode(defaultMode) {
4467
+ if (typeof window === "undefined") return defaultMode;
4468
+ try {
4469
+ const stored = window.localStorage.getItem(STORAGE_KEY);
4470
+ if (stored === "light" || stored === "dark") return stored;
4471
+ } catch {
4472
+ }
4473
+ const fromAttribute = document.documentElement.getAttribute(ATTRIBUTE);
4474
+ if (fromAttribute === "light" || fromAttribute === "dark") return fromAttribute;
4475
+ if (window.matchMedia("(prefers-color-scheme: dark)").matches) return "dark";
4476
+ return defaultMode;
4477
+ }
4478
+ function GoabThemeProvider({
4479
+ children,
4480
+ defaultMode = "light"
4481
+ }) {
4482
+ const [mode, setModeState] = react.useState(
4483
+ () => readInitialMode(defaultMode)
4484
+ );
4485
+ react.useEffect(() => {
4486
+ if (typeof document === "undefined") return;
4487
+ document.documentElement.setAttribute(ATTRIBUTE, mode);
4488
+ try {
4489
+ window.localStorage.setItem(STORAGE_KEY, mode);
4490
+ } catch {
4491
+ }
4492
+ }, [mode]);
4493
+ const setMode = react.useCallback((next) => {
4494
+ setModeState(next);
4495
+ }, []);
4496
+ const toggle = react.useCallback(() => {
4497
+ setModeState((prev) => prev === "light" ? "dark" : "light");
4498
+ }, []);
4499
+ return /* @__PURE__ */ jsxRuntime.jsx(GoabThemeContext.Provider, { value: { mode, setMode, toggle }, children });
4500
+ }
4501
+ function useTheme() {
4502
+ const ctx = react.useContext(GoabThemeContext);
4503
+ if (!ctx) {
4504
+ throw new Error("useTheme must be used within a GoabThemeProvider");
4505
+ }
4506
+ return ctx;
4507
+ }
4438
4508
  exports.GoALinkButton = GoALinkButton;
4439
4509
  exports.GoabAccordion = GoabAccordion;
4440
4510
  exports.GoabAppFooter = GoabAppFooter;
@@ -4523,6 +4593,7 @@ exports.GoabTemporaryNotificationCtrl = GoabTemporaryNotificationCtrl;
4523
4593
  exports.GoabText = GoabText;
4524
4594
  exports.GoabTextArea = GoabTextArea;
4525
4595
  exports.GoabTextarea = GoabTextArea;
4596
+ exports.GoabThemeProvider = GoabThemeProvider;
4526
4597
  exports.GoabThreeColumnLayout = GoabThreeColumnLayout;
4527
4598
  exports.GoabTooltip = GoabTooltip;
4528
4599
  exports.GoabTwoColumnLayout = GoabTwoColumnLayout;
@@ -4532,4 +4603,5 @@ exports.GoabWorkSideMenuItem = GoabWorkSideMenuItem;
4532
4603
  exports.GoabWorkSideNotificationItem = GoabWorkSideNotificationItem;
4533
4604
  exports.GoabWorkSideNotificationPanel = GoabWorkSideNotificationPanel;
4534
4605
  exports.usePublicFormController = usePublicFormController;
4606
+ exports.useTheme = useTheme;
4535
4607
  //# sourceMappingURL=index.js.map