@abgov/react-components 7.2.0-dev.5 → 7.2.0
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 +1 -0
- package/index.js +57 -12
- package/index.js.map +1 -1
- package/index.mjs +59 -14
- package/index.mjs.map +1 -1
- package/lib/theme/theme-context.d.ts +14 -0
- package/package.json +1 -1
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
|
@@ -4316,30 +4316,28 @@ function GoabWorkSideMenu({
|
|
|
4316
4316
|
}) {
|
|
4317
4317
|
const el = react.useRef(null);
|
|
4318
4318
|
react.useEffect(() => {
|
|
4319
|
-
|
|
4320
|
-
if (!
|
|
4319
|
+
const node = el.current;
|
|
4320
|
+
if (!node || !onToggle) {
|
|
4321
4321
|
return;
|
|
4322
4322
|
}
|
|
4323
|
-
|
|
4323
|
+
node.addEventListener("_toggle", onToggle);
|
|
4324
4324
|
return () => {
|
|
4325
|
-
|
|
4326
|
-
(_a2 = el.current) == null ? void 0 : _a2.removeEventListener("_toggle", onToggle);
|
|
4325
|
+
node.removeEventListener("_toggle", onToggle);
|
|
4327
4326
|
};
|
|
4328
|
-
}, [
|
|
4327
|
+
}, [onToggle]);
|
|
4329
4328
|
react.useEffect(() => {
|
|
4330
|
-
|
|
4331
|
-
if (!
|
|
4329
|
+
const node = el.current;
|
|
4330
|
+
if (!node || !onNavigate) {
|
|
4332
4331
|
return;
|
|
4333
4332
|
}
|
|
4334
4333
|
const handler = (e) => {
|
|
4335
4334
|
onNavigate(e.detail.url);
|
|
4336
4335
|
};
|
|
4337
|
-
|
|
4336
|
+
node.addEventListener("_navigate", handler);
|
|
4338
4337
|
return () => {
|
|
4339
|
-
|
|
4340
|
-
(_a2 = el.current) == null ? void 0 : _a2.removeEventListener("_navigate", handler);
|
|
4338
|
+
node.removeEventListener("_navigate", handler);
|
|
4341
4339
|
};
|
|
4342
|
-
}, [
|
|
4340
|
+
}, [onNavigate]);
|
|
4343
4341
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4344
4342
|
"goa-work-side-menu",
|
|
4345
4343
|
{
|
|
@@ -4462,6 +4460,51 @@ function GoabWorkSideNotificationPanel({
|
|
|
4462
4460
|
}
|
|
4463
4461
|
);
|
|
4464
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
|
+
}
|
|
4465
4508
|
exports.GoALinkButton = GoALinkButton;
|
|
4466
4509
|
exports.GoabAccordion = GoabAccordion;
|
|
4467
4510
|
exports.GoabAppFooter = GoabAppFooter;
|
|
@@ -4550,6 +4593,7 @@ exports.GoabTemporaryNotificationCtrl = GoabTemporaryNotificationCtrl;
|
|
|
4550
4593
|
exports.GoabText = GoabText;
|
|
4551
4594
|
exports.GoabTextArea = GoabTextArea;
|
|
4552
4595
|
exports.GoabTextarea = GoabTextArea;
|
|
4596
|
+
exports.GoabThemeProvider = GoabThemeProvider;
|
|
4553
4597
|
exports.GoabThreeColumnLayout = GoabThreeColumnLayout;
|
|
4554
4598
|
exports.GoabTooltip = GoabTooltip;
|
|
4555
4599
|
exports.GoabTwoColumnLayout = GoabTwoColumnLayout;
|
|
@@ -4559,4 +4603,5 @@ exports.GoabWorkSideMenuItem = GoabWorkSideMenuItem;
|
|
|
4559
4603
|
exports.GoabWorkSideNotificationItem = GoabWorkSideNotificationItem;
|
|
4560
4604
|
exports.GoabWorkSideNotificationPanel = GoabWorkSideNotificationPanel;
|
|
4561
4605
|
exports.usePublicFormController = usePublicFormController;
|
|
4606
|
+
exports.useTheme = useTheme;
|
|
4562
4607
|
//# sourceMappingURL=index.js.map
|