@abgov/react-components 7.2.0-dev.5 → 7.2.0-dev.6

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) {
@@ -4314,30 +4314,28 @@ function GoabWorkSideMenu({
4314
4314
  }) {
4315
4315
  const el = useRef(null);
4316
4316
  useEffect(() => {
4317
- var _a;
4318
- if (!(el == null ? void 0 : el.current) || !onToggle) {
4317
+ const node = el.current;
4318
+ if (!node || !onToggle) {
4319
4319
  return;
4320
4320
  }
4321
- (_a = el.current) == null ? void 0 : _a.addEventListener("_toggle", onToggle);
4321
+ node.addEventListener("_toggle", onToggle);
4322
4322
  return () => {
4323
- var _a2;
4324
- (_a2 = el.current) == null ? void 0 : _a2.removeEventListener("_toggle", onToggle);
4323
+ node.removeEventListener("_toggle", onToggle);
4325
4324
  };
4326
- }, [el, onToggle]);
4325
+ }, [onToggle]);
4327
4326
  useEffect(() => {
4328
- var _a;
4329
- if (!(el == null ? void 0 : el.current) || !onNavigate) {
4327
+ const node = el.current;
4328
+ if (!node || !onNavigate) {
4330
4329
  return;
4331
4330
  }
4332
4331
  const handler = (e) => {
4333
4332
  onNavigate(e.detail.url);
4334
4333
  };
4335
- (_a = el.current) == null ? void 0 : _a.addEventListener("_navigate", handler);
4334
+ node.addEventListener("_navigate", handler);
4336
4335
  return () => {
4337
- var _a2;
4338
- (_a2 = el.current) == null ? void 0 : _a2.removeEventListener("_navigate", handler);
4336
+ node.removeEventListener("_navigate", handler);
4339
4337
  };
4340
- }, [el, onNavigate]);
4338
+ }, [onNavigate]);
4341
4339
  return /* @__PURE__ */ jsxs(
4342
4340
  "goa-work-side-menu",
4343
4341
  {
@@ -4460,6 +4458,51 @@ function GoabWorkSideNotificationPanel({
4460
4458
  }
4461
4459
  );
4462
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
+ }
4463
4506
  export {
4464
4507
  GoALinkButton,
4465
4508
  GoabAccordion,
@@ -4549,6 +4592,7 @@ export {
4549
4592
  GoabText,
4550
4593
  GoabTextArea,
4551
4594
  GoabTextArea as GoabTextarea,
4595
+ GoabThemeProvider,
4552
4596
  GoabThreeColumnLayout,
4553
4597
  GoabTooltip,
4554
4598
  GoabTwoColumnLayout,
@@ -4557,6 +4601,7 @@ export {
4557
4601
  GoabWorkSideMenuItem,
4558
4602
  GoabWorkSideNotificationItem,
4559
4603
  GoabWorkSideNotificationPanel,
4560
- usePublicFormController
4604
+ usePublicFormController,
4605
+ useTheme
4561
4606
  };
4562
4607
  //# sourceMappingURL=index.mjs.map