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