@abgov-uiam/shell 0.0.0-stage → 0.1.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/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +356 -2
- package/dist/index.cjs.js +337 -0
- package/dist/index.esm.js +333 -0
- package/dist/styles/shell.css +124 -0
- package/dist/types/components/AppLayout.d.ts +18 -0
- package/dist/types/components/Footer.d.ts +6 -0
- package/dist/types/components/Header.d.ts +15 -0
- package/dist/types/components/ShellAnchor.d.ts +11 -0
- package/dist/types/components/SideMenu.d.ts +17 -0
- package/dist/types/components/UserDetails.d.ts +14 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/types.d.ts +130 -0
- package/dist/types/utils/paths.d.ts +38 -0
- package/dist/types/utils/useMediaQuery.d.ts +5 -0
- package/package.json +80 -4
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var reactComponents = require('@abgov/react-components');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
const canMatchMedia = () => typeof window !== 'undefined' && typeof window.matchMedia === 'function';
|
|
8
|
+
/**
|
|
9
|
+
* Whether a CSS media query matches, kept in sync with the viewport. Always `false` where
|
|
10
|
+
* `window.matchMedia` doesn't exist (server rendering, jsdom).
|
|
11
|
+
*/
|
|
12
|
+
const useMediaQuery = (query) => {
|
|
13
|
+
const subscribe = react.useCallback((onChange) => {
|
|
14
|
+
if (!canMatchMedia())
|
|
15
|
+
return () => undefined;
|
|
16
|
+
const list = window.matchMedia(query);
|
|
17
|
+
// Safari before 14 only has the deprecated addListener/removeListener.
|
|
18
|
+
if (typeof list.addEventListener === 'function') {
|
|
19
|
+
list.addEventListener('change', onChange);
|
|
20
|
+
return () => list.removeEventListener('change', onChange);
|
|
21
|
+
}
|
|
22
|
+
list.addListener(onChange);
|
|
23
|
+
return () => list.removeListener(onChange);
|
|
24
|
+
}, [query]);
|
|
25
|
+
const getSnapshot = react.useCallback(() => canMatchMedia() && window.matchMedia(query).matches, [query]);
|
|
26
|
+
return react.useSyncExternalStore(subscribe, getSnapshot, () => false);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Path helpers for the side menu. The active-link rules are ported from
|
|
31
|
+
* `packages/shared/src/util/pathUtils.ts` (the shell can't import `@abgov-uiam/shared`), so the shell
|
|
32
|
+
* marks the same link active as the legacy side menu.
|
|
33
|
+
*/
|
|
34
|
+
/** Removes trailing slashes and ensures a leading slash. A loop rather than a regex, so untrusted input can't backtrack. */
|
|
35
|
+
const normalizePath = (path) => {
|
|
36
|
+
if (!path)
|
|
37
|
+
return '/';
|
|
38
|
+
let normalized = path;
|
|
39
|
+
while (normalized.length > 1 && normalized.endsWith('/')) {
|
|
40
|
+
normalized = normalized.slice(0, -1);
|
|
41
|
+
}
|
|
42
|
+
return normalized.startsWith('/') ? normalized : `/${normalized}`;
|
|
43
|
+
};
|
|
44
|
+
/** The normalized pathname of an absolute URL or a path. */
|
|
45
|
+
const getPathFromHref = (href) => {
|
|
46
|
+
if (!href || !href.trim())
|
|
47
|
+
return '/';
|
|
48
|
+
const trimmed = href.trim();
|
|
49
|
+
try {
|
|
50
|
+
return normalizePath(new URL(trimmed, 'http://dummy').pathname);
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return normalizePath(trimmed);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
/** Whether `path` ends with the normalized path `tail`. `tail` starts with `/`, so it can only match whole segments. */
|
|
57
|
+
const endsWithPath = (path, tail) => path.length > tail.length && path.endsWith(tail);
|
|
58
|
+
/**
|
|
59
|
+
* Whether `href` is the current page. Either side may include the app's base path:
|
|
60
|
+
* `/personal` matches `https://host/ui/account/personal`, and `/ui/account/personal` matches `/personal`.
|
|
61
|
+
*/
|
|
62
|
+
const isExactPathMatch = (currentPath, href) => {
|
|
63
|
+
if (!currentPath || !href)
|
|
64
|
+
return false;
|
|
65
|
+
const current = normalizePath(currentPath);
|
|
66
|
+
const target = getPathFromHref(href);
|
|
67
|
+
return current === target || endsWithPath(target, current) || endsWithPath(current, target);
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Whether the current page is `href` or a page below it, such as `/business/ACME/staff/5` for
|
|
71
|
+
* `/business/ACME/staff`. Either side may include the app's base path.
|
|
72
|
+
*/
|
|
73
|
+
const isPathWithin = (currentPath, href) => {
|
|
74
|
+
if (isExactPathMatch(currentPath, href))
|
|
75
|
+
return true;
|
|
76
|
+
if (!currentPath || !href)
|
|
77
|
+
return false;
|
|
78
|
+
const current = normalizePath(currentPath);
|
|
79
|
+
const target = getPathFromHref(href);
|
|
80
|
+
if (target === '/')
|
|
81
|
+
return false;
|
|
82
|
+
// At the start, or after a base path the href doesn't have. `target` starts with `/` and the search adds a
|
|
83
|
+
// trailing `/`, so only whole segments match: `/ui/account/business/ORG11/x` is within `/business/ORG11`, but
|
|
84
|
+
// `/ui/account/business/ORG110/x` and `/ui/xbusiness/ORG11/x` aren't.
|
|
85
|
+
if (current.includes(`${target}/`))
|
|
86
|
+
return true;
|
|
87
|
+
// Drop leading (base path) segments from the href, keeping at least two so a lone segment can't match.
|
|
88
|
+
const segments = target.split('/').filter(Boolean);
|
|
89
|
+
for (let i = 1; i <= segments.length - 2; i++) {
|
|
90
|
+
if (current.startsWith(`/${segments.slice(i).join('/')}/`))
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
};
|
|
95
|
+
/** A path within the current site: starts with a single `/` and has no scheme. */
|
|
96
|
+
const isInternalRoute = (href) => {
|
|
97
|
+
if (!href)
|
|
98
|
+
return false;
|
|
99
|
+
if (/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(href))
|
|
100
|
+
return false;
|
|
101
|
+
if (href.startsWith('//'))
|
|
102
|
+
return false;
|
|
103
|
+
return href.startsWith('/');
|
|
104
|
+
};
|
|
105
|
+
/** A path, or an absolute URL on the current page's origin. Absolute URLs are never same-origin outside a browser. */
|
|
106
|
+
const isSameOrigin = (href) => {
|
|
107
|
+
if (!href)
|
|
108
|
+
return false;
|
|
109
|
+
if (isInternalRoute(href))
|
|
110
|
+
return true;
|
|
111
|
+
if (typeof window === 'undefined')
|
|
112
|
+
return false;
|
|
113
|
+
try {
|
|
114
|
+
return new URL(href).origin === window.location.origin;
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* The href for a full page load. A bare path becomes `origin + path`, so a `<base>` element can't
|
|
122
|
+
* resolve it relative to the current app.
|
|
123
|
+
*/
|
|
124
|
+
const toAbsoluteHref = (href) => {
|
|
125
|
+
if (typeof window === 'undefined' || !isInternalRoute(href))
|
|
126
|
+
return href;
|
|
127
|
+
return `${window.location.origin}${href}`;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Where a router link should go for an href, for `renderLink`. Paths are returned as-is. An absolute URL on
|
|
131
|
+
* the current origin inside `basePath` (the router's basename, such as `/ui/account`) becomes the path below
|
|
132
|
+
* it, keeping its query and hash. Anything else, such as another app on the same origin, is returned
|
|
133
|
+
* unchanged: React Router's `<Link>` loads an absolute URL outside its basename as a full page.
|
|
134
|
+
*
|
|
135
|
+
* @example toRouterPath('https://account.alberta.ca/ui/account/personal?tab=1', '/ui/account') // '/personal?tab=1'
|
|
136
|
+
* @example toRouterPath('https://account.alberta.ca/app/directory/x', '/ui/account') // unchanged
|
|
137
|
+
*/
|
|
138
|
+
const toRouterPath = (href, basePath) => {
|
|
139
|
+
if (isInternalRoute(href) || !isSameOrigin(href))
|
|
140
|
+
return href;
|
|
141
|
+
const url = new URL(href);
|
|
142
|
+
const path = normalizePath(url.pathname);
|
|
143
|
+
const base = basePath ? normalizePath(basePath) : '/';
|
|
144
|
+
const queryAndHash = `${url.search}${url.hash}`;
|
|
145
|
+
if (base === '/')
|
|
146
|
+
return `${path}${queryAndHash}`;
|
|
147
|
+
if (path === base)
|
|
148
|
+
return `/${queryAndHash}`;
|
|
149
|
+
return path.startsWith(`${base}/`) ? `${path.slice(base.length)}${queryAndHash}` : href;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* A link through `renderLink` when it is same-origin and not external (client-side navigation);
|
|
154
|
+
* otherwise a plain `<a>`, which is a full page load.
|
|
155
|
+
*/
|
|
156
|
+
const ShellAnchor = ({ href, external, renderLink, children, ...anchorProps }) => {
|
|
157
|
+
if (!external && renderLink && isSameOrigin(href)) {
|
|
158
|
+
return jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderLink({ href, children, ...anchorProps }) });
|
|
159
|
+
}
|
|
160
|
+
return (jsxRuntime.jsx("a", { href: external ? toAbsoluteHref(href) : href, ...anchorProps, children: children }));
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/** The Alberta.ca Account footer links, as in the account and sign-in apps. Each one is a full page load. */
|
|
164
|
+
const DEFAULT_FOOTER_LINKS = [
|
|
165
|
+
{
|
|
166
|
+
label: 'Available services',
|
|
167
|
+
href: 'https://www.alberta.ca/alberta-ca-account-available-services',
|
|
168
|
+
external: true,
|
|
169
|
+
testId: 'footer-available-services'
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
label: 'Security and privacy',
|
|
173
|
+
href: 'https://www.alberta.ca/about-alberta-ca-account#jumplinks-3',
|
|
174
|
+
external: true,
|
|
175
|
+
testId: 'footer-security-privacy'
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
label: 'About us',
|
|
179
|
+
href: 'https://www.alberta.ca/about-alberta-ca-account',
|
|
180
|
+
external: true,
|
|
181
|
+
testId: 'footer-about-us'
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
label: 'Get help',
|
|
185
|
+
href: 'https://www.alberta.ca/alberta-ca-account',
|
|
186
|
+
external: true,
|
|
187
|
+
testId: 'footer-get-help'
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
label: 'Contact',
|
|
191
|
+
href: 'https://www.alberta.ca/alberta-ca-account-contact',
|
|
192
|
+
external: true,
|
|
193
|
+
testId: 'footer-contact'
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
label: 'Accessibility',
|
|
197
|
+
href: 'https://www.alberta.ca/accessibility',
|
|
198
|
+
external: true,
|
|
199
|
+
testId: 'footer-accessibility'
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
label: 'Terms of use',
|
|
203
|
+
href: 'https://account.alberta.ca/ui/account/terms-of-use',
|
|
204
|
+
external: true,
|
|
205
|
+
testId: 'footer-terms-of-use'
|
|
206
|
+
}
|
|
207
|
+
];
|
|
208
|
+
/** The Design System 2.0 app footer, with the links in its meta section. */
|
|
209
|
+
const Footer = ({ footerLinks = DEFAULT_FOOTER_LINKS, maxContentWidth = '100%', renderLink }) => (jsxRuntime.jsx(reactComponents.GoabAppFooter, { maxContentWidth: maxContentWidth, testId: "uiam-shell-footer", children: jsxRuntime.jsx(reactComponents.GoabAppFooterMetaSection, { children: footerLinks.map((link) => (jsxRuntime.jsx(ShellAnchor, { href: link.href, external: link.external, renderLink: renderLink, "data-testid": link.testId, children: link.label }, `${link.label}:${link.href}`))) }) }));
|
|
210
|
+
|
|
211
|
+
// The data API sends icon names as plain strings.
|
|
212
|
+
const toIcon = (icon) => (icon ? icon : undefined);
|
|
213
|
+
/** The legacy side menu's link test id: "Personal information" → "personalinformationlink". */
|
|
214
|
+
const linkTestId = (heading) => `${heading.replace(/\s+/g, '').toLowerCase()}link`;
|
|
215
|
+
const baseKey = (item) => item.itemKey ?? `${item.type}:${item.heading}:${item.href ?? ''}`;
|
|
216
|
+
/** Whether the current page belongs to the group: at or below its `activePathPrefix`, or one of its links or below one. */
|
|
217
|
+
const containsPath = (group, currentPath) => (!!group.activePathPrefix && isPathWithin(currentPath, group.activePathPrefix)) ||
|
|
218
|
+
(group.items ?? []).some((child) => child.type === 'group' ? containsPath(child, currentPath) : !!child.href && isPathWithin(currentPath, child.href));
|
|
219
|
+
/** Changes whenever the menu's structure does, so the Design System side menu re-reads its links. */
|
|
220
|
+
const structureKey = (items) => items.map((item) => `${baseKey(item)}(${structureKey(item.items ?? [])})`).join('|');
|
|
221
|
+
const MenuLink = ({ item, context }) => {
|
|
222
|
+
if (!item.href)
|
|
223
|
+
return null;
|
|
224
|
+
const current = isExactPathMatch(context.currentPath, item.href);
|
|
225
|
+
const className = [current && 'current', item.isSectionHeader && 'uiam-shell-section-link'].filter(Boolean).join(' ');
|
|
226
|
+
const icon = toIcon(item.icon);
|
|
227
|
+
return (jsxRuntime.jsxs(ShellAnchor, { href: item.href, external: item.external, renderLink: context.renderLink, className: className || undefined, "aria-current": current ? 'page' : undefined, "data-testid": linkTestId(item.heading), onClick: context.onNavigate, children: [icon && jsxRuntime.jsx(reactComponents.GoabIcon, { type: icon }), item.heading] }));
|
|
228
|
+
};
|
|
229
|
+
const HIDDEN = { display: 'none' };
|
|
230
|
+
const MenuGroup = ({ item, context, hidden = false }) => {
|
|
231
|
+
const children = item.items ?? [];
|
|
232
|
+
const nestedGroups = children.filter((child) => child.type === 'group');
|
|
233
|
+
const overflow = nestedGroups.slice(context.nestedGroupLimit);
|
|
234
|
+
const currentPageInOverflow = overflow.some((group) => containsPath(group, context.currentPath));
|
|
235
|
+
// Like the legacy organization list, moving to a page in a hidden group shows them all. "Show less" still
|
|
236
|
+
// collapses the list, until the page changes again.
|
|
237
|
+
const [showAll, setShowAll] = react.useState(currentPageInOverflow);
|
|
238
|
+
const [previousPath, setPreviousPath] = react.useState(context.currentPath);
|
|
239
|
+
if (previousPath !== context.currentPath) {
|
|
240
|
+
setPreviousPath(context.currentPath);
|
|
241
|
+
if (currentPageInOverflow)
|
|
242
|
+
setShowAll(true);
|
|
243
|
+
}
|
|
244
|
+
// The element itself rather than GoabSideMenuGroup, which can't hide a group. The Design System side menu keeps
|
|
245
|
+
// every group that registers with it, and errors on each later page change once one is removed, so a collapsed
|
|
246
|
+
// list hides its extra groups instead of removing them.
|
|
247
|
+
return (jsxRuntime.jsxs("goa-side-menu-group", { heading: item.heading, icon: toIcon(item.icon), testid: item.itemKey ?? item.heading, style: hidden ? HIDDEN : undefined, children: [renderItems(children, context, showAll ? [] : overflow), overflow.length > 0 && (jsxRuntime.jsxs("button", { type: "button", className: "uiam-shell-show-more", "aria-expanded": showAll, "data-testid": "collapsible-entity-list-toggle", onClick: () => setShowAll(!showAll), children: [showAll ? 'Show less' : `Show ${overflow.length} more`, jsxRuntime.jsx(reactComponents.GoabIcon, { type: showAll ? 'chevron-up' : 'chevron-forward', size: "small" })] }))] }));
|
|
248
|
+
};
|
|
249
|
+
const renderItems = (items, context, hiddenGroups = []) => {
|
|
250
|
+
const seen = new Map();
|
|
251
|
+
return items.map((item) => {
|
|
252
|
+
const key = baseKey(item);
|
|
253
|
+
const count = seen.get(key) ?? 0;
|
|
254
|
+
seen.set(key, count + 1);
|
|
255
|
+
const uniqueKey = count ? `${key}#${count}` : key;
|
|
256
|
+
return item.type === 'group' ? (jsxRuntime.jsx(MenuGroup, { item: item, context: context, hidden: hiddenGroups.includes(item) }, uniqueKey)) : (jsxRuntime.jsx(MenuLink, { item: item, context: context }, uniqueKey));
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
* The side menu, from the data API's `UserMenu.left`. Groups are Design System side menu groups, which
|
|
261
|
+
* open and close themselves and open on their own when one of their links is the current page.
|
|
262
|
+
*/
|
|
263
|
+
const SideMenu = ({ menu, currentPath = '/', renderLink, onNavigate, nestedGroupLimit = 10, ariaLabel = 'Side menu', testId = 'uiam-shell-side-menu' }) => {
|
|
264
|
+
const items = menu?.left ?? [];
|
|
265
|
+
if (items.length === 0)
|
|
266
|
+
return null;
|
|
267
|
+
const context = { currentPath, renderLink, onNavigate, nestedGroupLimit };
|
|
268
|
+
return (jsxRuntime.jsx("nav", { "aria-label": ariaLabel, className: "uiam-shell-side-menu", children: jsxRuntime.jsx(reactComponents.GoabSideMenu, { testId: testId, children: renderItems(items, context) }, structureKey(items)) }));
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
/** Who is signed in: name, email and organization, as at the top of the legacy user menu and drawer. */
|
|
272
|
+
const UserDetails = ({ user, top, renderLink, onNavigate, showIcon = false, children }) => {
|
|
273
|
+
const orgName = top?.staffAccountOrgName;
|
|
274
|
+
const orgHref = top?.staffAccountOrgHref;
|
|
275
|
+
return (jsxRuntime.jsxs("div", { className: "uiam-shell-user-details", "data-testid": "uiam-shell-user-details", children: [showIcon && jsxRuntime.jsx(reactComponents.GoabIcon, { type: "person-circle" }), jsxRuntime.jsxs("div", { className: "uiam-shell-user-details-content", children: [jsxRuntime.jsx("p", { className: "uiam-shell-user-name", children: user.name || '\u00a0' }), user.email && jsxRuntime.jsx("p", { className: "uiam-shell-user-email", children: user.email.toLowerCase() }), orgName &&
|
|
276
|
+
(orgHref ? (jsxRuntime.jsx(ShellAnchor, { href: orgHref, renderLink: renderLink, className: "uiam-shell-user-org", "data-testid": "uiam-shell-user-org", onClick: onNavigate, children: orgName })) : (jsxRuntime.jsx("p", { className: "uiam-shell-user-org", "data-testid": "uiam-shell-user-org", children: orgName }))), children] })] }));
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
const MAX_MENU_HEADING_LENGTH = 18;
|
|
280
|
+
/** The user menu button's label, shortened as in the legacy header. */
|
|
281
|
+
const shortenName = (name) => name.length > MAX_MENU_HEADING_LENGTH ? `${name.substring(0, MAX_MENU_HEADING_LENGTH)}...` : name;
|
|
282
|
+
const pendingApprovals = (top) => top?.staffAccountApprovalHref && top.staffAccountApprovalCount > 0
|
|
283
|
+
? { href: top.staffAccountApprovalHref, count: top.staffAccountApprovalCount }
|
|
284
|
+
: undefined;
|
|
285
|
+
const SignOutLink = ({ onSignOut, className, testId }) => (jsxRuntime.jsx("a", { href: "#", className: className, "data-testid": testId, onClick: (event) => {
|
|
286
|
+
event.preventDefault();
|
|
287
|
+
onSignOut();
|
|
288
|
+
}, children: "Sign out" }));
|
|
289
|
+
const renderUserLinks = (links, renderLink, onClick) => links.map((link) => (jsxRuntime.jsx(ShellAnchor, { href: link.href, external: link.external, renderLink: renderLink, "data-testid": link.testId, onClick: onClick, children: link.label }, `${link.label}:${link.href}`)));
|
|
290
|
+
/**
|
|
291
|
+
* The Design System 2.0 app header. Desktop: the pending staff requests notification and the user menu.
|
|
292
|
+
* Mobile: a "Menu" button that opens a drawer with the user details, the side menu and "Sign out".
|
|
293
|
+
*/
|
|
294
|
+
const Header = ({ appName, appUrl, user, menu, currentPath = '/', userLinks = [], renderLink, onSignOut, maxContentWidth = '100%', mobileBreakpoint = 1024 }) => {
|
|
295
|
+
const isMobile = useMediaQuery(`(max-width: ${mobileBreakpoint}px)`);
|
|
296
|
+
// The page the drawer was opened on. Changing page closes it, because it covers the new page, and so does
|
|
297
|
+
// leaving the mobile layout. Both also forget the page, so the drawer never reopens without a Menu click.
|
|
298
|
+
const [drawerPath, setDrawerPath] = react.useState();
|
|
299
|
+
if (drawerPath !== undefined && (!isMobile || drawerPath !== currentPath))
|
|
300
|
+
setDrawerPath(undefined);
|
|
301
|
+
const drawerOpen = isMobile && drawerPath === currentPath;
|
|
302
|
+
const openDrawer = react.useCallback(() => setDrawerPath(currentPath), [currentPath]);
|
|
303
|
+
const closeDrawer = react.useCallback(() => setDrawerPath(undefined), []);
|
|
304
|
+
const top = menu?.top;
|
|
305
|
+
const approvals = pendingApprovals(top);
|
|
306
|
+
const hasDrawer = isMobile && (!!user || (menu?.left?.length ?? 0) > 0);
|
|
307
|
+
// The Design System header only reads its utilities when it first appears on the page: it creates their slot only
|
|
308
|
+
// if there are some, and counts them to decide whether to fold them into its own menu. So it's created afresh
|
|
309
|
+
// whenever they change, such as when the user loads after the page, or the viewport crosses the breakpoint.
|
|
310
|
+
let utilitiesKey = 'none';
|
|
311
|
+
let utilities;
|
|
312
|
+
if (hasDrawer) {
|
|
313
|
+
utilitiesKey = 'menu-button';
|
|
314
|
+
utilities = (jsxRuntime.jsx(reactComponents.GoabButton, { type: "tertiary", size: "compact", leadingIcon: "menu", testId: "uiam-shell-menu-button", onClick: openDrawer, children: "Menu" }));
|
|
315
|
+
}
|
|
316
|
+
else if (user && !isMobile) {
|
|
317
|
+
utilitiesKey = approvals ? 'notification user-menu' : 'user-menu';
|
|
318
|
+
utilities = (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [approvals && (jsxRuntime.jsx("span", { className: "uiam-shell-utility", children: jsxRuntime.jsxs(ShellAnchor, { href: approvals.href, renderLink: renderLink, className: "uiam-shell-notification", "aria-label": `Notifications (${approvals.count} pending requests)`, "data-testid": "uiam-shell-notification", children: [jsxRuntime.jsx(reactComponents.GoabIcon, { type: "notifications" }), jsxRuntime.jsx("span", { className: "uiam-shell-count", children: approvals.count })] }) })), jsxRuntime.jsxs(reactComponents.GoabAppHeaderMenu, { heading: shortenName(user.name || 'Account'), leadingIcon: "person-circle", testId: "uiam-desktop-headermenu", children: [jsxRuntime.jsx(UserDetails, { user: user, top: top, renderLink: renderLink }), renderUserLinks(userLinks, renderLink), onSignOut && (jsxRuntime.jsx(SignOutLink, { onSignOut: onSignOut, className: "uiam-shell-sign-out", testId: "uiam-desktop-signout-link" }))] })] }));
|
|
319
|
+
}
|
|
320
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(reactComponents.GoabAppHeader, { heading: appName, url: appUrl, maxContentWidth: maxContentWidth, testId: "uiam-shell-header", utilities: utilities }, utilitiesKey), hasDrawer && (jsxRuntime.jsxs(reactComponents.GoabDrawer, { position: "bottom", heading: "Menu", open: drawerOpen, onClose: closeDrawer, testId: "uiam-shell-drawer", children: [user && (jsxRuntime.jsx(UserDetails, { user: user, top: top, renderLink: renderLink, onNavigate: closeDrawer, showIcon: true, children: approvals && (jsxRuntime.jsxs(ShellAnchor, { href: approvals.href, renderLink: renderLink, className: "uiam-shell-staff-requests", "data-testid": "uiam-shell-staff-requests", onClick: closeDrawer, children: ["Staff account requests ", jsxRuntime.jsx("span", { className: "uiam-shell-count", children: approvals.count })] })) })), renderUserLinks(userLinks, renderLink, closeDrawer), jsxRuntime.jsx(SideMenu, { menu: menu, currentPath: currentPath, renderLink: renderLink, onNavigate: closeDrawer, testId: "uiam-shell-drawer-side-menu" }), user && onSignOut && (jsxRuntime.jsx(SignOutLink, { onSignOut: onSignOut, className: "uiam-shell-drawer-sign-out", testId: "uiam-mobile-signout-link" }))] }))] }));
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* The Alberta.ca Account page frame on Design System 2.0: the app header, the side menu beside the page (in the
|
|
325
|
+
* header's drawer on narrow viewports), and the app footer, all from the same `ShellProps`.
|
|
326
|
+
*/
|
|
327
|
+
const AppLayout = ({ children, banner, mobileBreakpoint = 1024, ...shell }) => {
|
|
328
|
+
const isMobile = useMediaQuery(`(max-width: ${mobileBreakpoint}px)`);
|
|
329
|
+
const showSideMenu = !isMobile && (shell.menu?.left?.length ?? 0) > 0;
|
|
330
|
+
// The page keeps its place among the children whether or not the side menu column is there, so crossing the
|
|
331
|
+
// breakpoint never remounts it.
|
|
332
|
+
return (jsxRuntime.jsxs(reactComponents.GoabOneColumnLayout, { children: [jsxRuntime.jsxs("section", { slot: "header", className: "uiam-shell-layout-header", children: [banner, jsxRuntime.jsx(Header, { ...shell, mobileBreakpoint: mobileBreakpoint })] }), jsxRuntime.jsxs("div", { className: showSideMenu ? 'uiam-shell-layout uiam-shell-layout--side-menu' : 'uiam-shell-layout', "data-testid": "uiam-shell-layout", children: [showSideMenu && (jsxRuntime.jsx("div", { className: "uiam-shell-layout-side-menu", children: jsxRuntime.jsx(SideMenu, { menu: shell.menu, currentPath: shell.currentPath, renderLink: shell.renderLink }) })), jsxRuntime.jsx("div", { className: "uiam-shell-layout-content", "data-testid": "uiam-shell-content", children: children })] }), jsxRuntime.jsx("section", { slot: "footer", className: "uiam-shell-layout-footer", children: jsxRuntime.jsx(Footer, { footerLinks: shell.footerLinks, maxContentWidth: shell.maxContentWidth, renderLink: shell.renderLink }) })] }));
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
exports.AppLayout = AppLayout;
|
|
336
|
+
exports.DEFAULT_FOOTER_LINKS = DEFAULT_FOOTER_LINKS;
|
|
337
|
+
exports.toRouterPath = toRouterPath;
|