@olenbetong/synergi-react 2.6.0 → 2.7.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/es/components/AppMenu/AppMenu.css +0 -25
- package/es/components/AppMenu/AppMenu.js +1 -2
- package/es/components/AppMenu/index.d.ts +0 -1
- package/es/components/AppMenu/index.js +0 -1
- package/es/index.d.ts +1 -2
- package/es/index.js +1 -2
- package/package.json +3 -3
- package/src/colorScheme.ts +81 -81
- package/src/components/AppMenu/AppMenu.css +648 -546
- package/src/components/AppMenu/AppMenu.tsx +285 -478
- package/src/components/AppMenu/AppMenuColorScheme.tsx +41 -41
- package/src/components/AppMenu/AppMenuFavoriteButton.tsx +47 -0
- package/src/components/AppMenu/AppMenuHeader.tsx +79 -0
- package/src/components/AppMenu/AppMenuList.tsx +89 -0
- package/src/components/AppMenu/AppMenuRail.tsx +117 -0
- package/src/components/AppMenu/icons.tsx +76 -0
- package/src/components/AppMenu/index.ts +17 -12
- package/src/components/AppMenu/menuEntries.ts +128 -0
- package/src/components/AppMenu/types.ts +45 -35
- package/src/components/AppMenu/useFavorites.ts +40 -0
- package/src/components/AppMenu/useRovingTabIndex.ts +130 -118
- package/src/components/AppShell/index.tsx +287 -259
- package/src/components/LinkedCardList/index.scss +93 -93
- package/src/components/ProgressBar/index.scss +94 -94
- package/src/index.ts +61 -61
- package/es/colorScheme.d.ts +0 -17
- package/es/colorScheme.js +0 -54
- package/es/components/AppMenu/AppMenuColorScheme.d.ts +0 -2
- package/es/components/AppMenu/AppMenuColorScheme.js +0 -18
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import { ToggleGroup, Tooltip } from "@digdir/designsystemet-react";
|
|
2
|
-
import { MonitorIcon, MoonIcon, SunIcon } from "@navikt/aksel-icons";
|
|
3
|
-
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
4
|
-
|
|
5
|
-
import { type ColorSchemePreference, useColorSchemePreference } from "../../colorScheme.js";
|
|
6
|
-
|
|
7
|
-
const OPTIONS: Array<{ value: ColorSchemePreference; label: string; Icon: typeof MonitorIcon }> = [
|
|
8
|
-
{ value: "auto", label: "Follow system setting", Icon: MonitorIcon },
|
|
9
|
-
{ value: "light", label: "Light mode", Icon: SunIcon },
|
|
10
|
-
{ value: "dark", label: "Dark mode", Icon: MoonIcon },
|
|
11
|
-
];
|
|
12
|
-
|
|
13
|
-
/** Icon-only color scheme toggle, shown at the bottom of the app menu rail. */
|
|
14
|
-
export function AppMenuColorScheme() {
|
|
15
|
-
let [preference, setPreference] = useColorSchemePreference();
|
|
16
|
-
|
|
17
|
-
return (
|
|
18
|
-
<div className="ob-app-menu__color-scheme">
|
|
19
|
-
<ToggleGroup
|
|
20
|
-
data-size="sm"
|
|
21
|
-
aria-label={getLocalizedString("Theme")}
|
|
22
|
-
value={preference}
|
|
23
|
-
onChange={(value) => setPreference(value as ColorSchemePreference)}
|
|
24
|
-
>
|
|
25
|
-
{OPTIONS.map(({ value, label, Icon }) => {
|
|
26
|
-
let localizedLabel = getLocalizedString(label);
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<Tooltip key={value} content={localizedLabel}>
|
|
30
|
-
<ToggleGroup.Item value={value}>
|
|
31
|
-
<Icon aria-hidden fontSize="1.25rem" />
|
|
32
|
-
{/* The radio takes its accessible name from the label's text content. */}
|
|
33
|
-
<span className="ob-app-menu__color-scheme-label">{localizedLabel}</span>
|
|
34
|
-
</ToggleGroup.Item>
|
|
35
|
-
</Tooltip>
|
|
36
|
-
);
|
|
37
|
-
})}
|
|
38
|
-
</ToggleGroup>
|
|
39
|
-
</div>
|
|
40
|
-
);
|
|
41
|
-
}
|
|
1
|
+
import { ToggleGroup, Tooltip } from "@digdir/designsystemet-react";
|
|
2
|
+
import { MonitorIcon, MoonIcon, SunIcon } from "@navikt/aksel-icons";
|
|
3
|
+
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
4
|
+
|
|
5
|
+
import { type ColorSchemePreference, useColorSchemePreference } from "../../colorScheme.js";
|
|
6
|
+
|
|
7
|
+
const OPTIONS: Array<{ value: ColorSchemePreference; label: string; Icon: typeof MonitorIcon }> = [
|
|
8
|
+
{ value: "auto", label: "Follow system setting", Icon: MonitorIcon },
|
|
9
|
+
{ value: "light", label: "Light mode", Icon: SunIcon },
|
|
10
|
+
{ value: "dark", label: "Dark mode", Icon: MoonIcon },
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
/** Icon-only color scheme toggle, shown at the bottom of the app menu rail. */
|
|
14
|
+
export function AppMenuColorScheme() {
|
|
15
|
+
let [preference, setPreference] = useColorSchemePreference();
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<div className="ob-app-menu__color-scheme">
|
|
19
|
+
<ToggleGroup
|
|
20
|
+
data-size="sm"
|
|
21
|
+
aria-label={getLocalizedString("Theme")}
|
|
22
|
+
value={preference}
|
|
23
|
+
onChange={(value) => setPreference(value as ColorSchemePreference)}
|
|
24
|
+
>
|
|
25
|
+
{OPTIONS.map(({ value, label, Icon }) => {
|
|
26
|
+
let localizedLabel = getLocalizedString(label);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Tooltip key={value} content={localizedLabel}>
|
|
30
|
+
<ToggleGroup.Item value={value}>
|
|
31
|
+
<Icon aria-hidden fontSize="1.25rem" />
|
|
32
|
+
{/* The radio takes its accessible name from the label's text content. */}
|
|
33
|
+
<span className="ob-app-menu__color-scheme-label">{localizedLabel}</span>
|
|
34
|
+
</ToggleGroup.Item>
|
|
35
|
+
</Tooltip>
|
|
36
|
+
);
|
|
37
|
+
})}
|
|
38
|
+
</ToggleGroup>
|
|
39
|
+
</div>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
2
|
+
|
|
3
|
+
import { StarIcon } from "./icons.js";
|
|
4
|
+
|
|
5
|
+
export type AppMenuFavoriteButtonProps = {
|
|
6
|
+
/** Label of the app the toggle belongs to, used for the accessible name. */
|
|
7
|
+
appLabel: string;
|
|
8
|
+
isFavorite: boolean;
|
|
9
|
+
onToggle: () => void;
|
|
10
|
+
/**
|
|
11
|
+
* Shares the tab stop of the app link it belongs to, so Tab reaches it
|
|
12
|
+
* without adding a stop per app to the arrow key navigation. See
|
|
13
|
+
* `useRovingTabIndex().getSecondaryProps`.
|
|
14
|
+
*/
|
|
15
|
+
tabIndex: number;
|
|
16
|
+
onFocus: () => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Star toggle rendered next to an app link. It is only visible while the entry
|
|
21
|
+
* is hovered or focused, unless the app already is a favorite.
|
|
22
|
+
*/
|
|
23
|
+
export function AppMenuFavoriteButton({
|
|
24
|
+
appLabel,
|
|
25
|
+
isFavorite,
|
|
26
|
+
onToggle,
|
|
27
|
+
tabIndex,
|
|
28
|
+
onFocus,
|
|
29
|
+
}: AppMenuFavoriteButtonProps) {
|
|
30
|
+
let label = isFavorite ? getLocalizedString("Remove from favorites") : getLocalizedString("Add to favorites");
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<button
|
|
34
|
+
type="button"
|
|
35
|
+
className="ob-app-menu__favorite"
|
|
36
|
+
aria-pressed={isFavorite}
|
|
37
|
+
aria-label={`${label}: ${appLabel}`}
|
|
38
|
+
title={label}
|
|
39
|
+
data-favorite={isFavorite ? "true" : undefined}
|
|
40
|
+
tabIndex={tabIndex}
|
|
41
|
+
onFocus={onFocus}
|
|
42
|
+
onClick={onToggle}
|
|
43
|
+
>
|
|
44
|
+
<StarIcon filled={isFavorite} />
|
|
45
|
+
</button>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
2
|
+
import type { DataObject } from "@olenbetong/appframe-data";
|
|
3
|
+
|
|
4
|
+
import { AppMenuUserMenu, type AppMenuUser } from "./AppMenuUserMenu.js";
|
|
5
|
+
import { CloseIcon, HomeIcon, ReloadIcon } from "./icons.js";
|
|
6
|
+
import type { AppMenuLink } from "./types.js";
|
|
7
|
+
|
|
8
|
+
export type AppMenuHeaderProps = {
|
|
9
|
+
/** Link shown at the start of the header, e.g. the portal/front page. */
|
|
10
|
+
homeLink?: AppMenuLink;
|
|
11
|
+
/** Which pane is shown on narrow viewports. */
|
|
12
|
+
mobilePane: "apps" | "groups";
|
|
13
|
+
onToggleMobilePane: () => void;
|
|
14
|
+
hasUpdate: boolean;
|
|
15
|
+
onInstallUpdate?: () => void;
|
|
16
|
+
userDataObject?: DataObject<AppMenuUser>;
|
|
17
|
+
userMenuItems?: AppMenuLink[];
|
|
18
|
+
userSubtitle?: string;
|
|
19
|
+
onClose: () => void;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Header of the app menu's content pane, holding the navigation shortcuts on
|
|
24
|
+
* the start side and the user/update/close controls on the end side.
|
|
25
|
+
*
|
|
26
|
+
* It is rendered after the app list so it comes last in the tab order, and is
|
|
27
|
+
* moved back to the top visually with `order: -1`.
|
|
28
|
+
*/
|
|
29
|
+
export function AppMenuHeader({
|
|
30
|
+
homeLink,
|
|
31
|
+
mobilePane,
|
|
32
|
+
onToggleMobilePane,
|
|
33
|
+
hasUpdate,
|
|
34
|
+
onInstallUpdate,
|
|
35
|
+
userDataObject,
|
|
36
|
+
userMenuItems,
|
|
37
|
+
userSubtitle,
|
|
38
|
+
onClose,
|
|
39
|
+
}: AppMenuHeaderProps) {
|
|
40
|
+
return (
|
|
41
|
+
<div className="ob-app-menu__content-header">
|
|
42
|
+
<div className="ob-app-menu__header-start">
|
|
43
|
+
{homeLink && (
|
|
44
|
+
<a
|
|
45
|
+
className="ob-app-menu__home"
|
|
46
|
+
href={homeLink.href}
|
|
47
|
+
target={homeLink.target}
|
|
48
|
+
rel={homeLink.rel}
|
|
49
|
+
onClick={() => {
|
|
50
|
+
homeLink.onClick?.();
|
|
51
|
+
if (!homeLink.keepOpen) onClose();
|
|
52
|
+
}}
|
|
53
|
+
>
|
|
54
|
+
<HomeIcon />
|
|
55
|
+
<span className="ob-app-menu__home-label">{homeLink.label}</span>
|
|
56
|
+
</a>
|
|
57
|
+
)}
|
|
58
|
+
<button type="button" className="ob-app-menu__pane-toggle" onClick={onToggleMobilePane}>
|
|
59
|
+
{mobilePane === "apps" ? getLocalizedString("Categories") : getLocalizedString("Applications")}
|
|
60
|
+
</button>
|
|
61
|
+
</div>
|
|
62
|
+
{hasUpdate && (
|
|
63
|
+
<button
|
|
64
|
+
type="button"
|
|
65
|
+
className="ob-app-menu__update"
|
|
66
|
+
aria-label={getLocalizedString("Install update and reload")}
|
|
67
|
+
onClick={onInstallUpdate}
|
|
68
|
+
>
|
|
69
|
+
<ReloadIcon />
|
|
70
|
+
<span className="ob-app-menu__update-label">{getLocalizedString("Install update and reload")}</span>
|
|
71
|
+
</button>
|
|
72
|
+
)}
|
|
73
|
+
{userDataObject && <AppMenuUserMenu dataObject={userDataObject} items={userMenuItems} subtitle={userSubtitle} />}
|
|
74
|
+
<button type="button" className="ob-app-menu__close" aria-label={getLocalizedString("Close")} onClick={onClose}>
|
|
75
|
+
<CloseIcon />
|
|
76
|
+
</button>
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { AppMenuFavoriteButton } from "./AppMenuFavoriteButton.js";
|
|
2
|
+
import type { AppMenuLink, AppMenuLinkGroup } from "./types.js";
|
|
3
|
+
import { useRovingTabIndex } from "./useRovingTabIndex.js";
|
|
4
|
+
|
|
5
|
+
export type AppMenuListProps = {
|
|
6
|
+
groups: AppMenuLinkGroup[];
|
|
7
|
+
/** Total number of links across all groups; the roving tab index size. */
|
|
8
|
+
itemCount: number;
|
|
9
|
+
/** Called when an entry that doesn't opt out with `keepOpen` is activated. */
|
|
10
|
+
onClose: () => void;
|
|
11
|
+
/** Without a handler no favorite toggles are rendered. */
|
|
12
|
+
onToggleFavorite?: (id: string, favorite: boolean) => void;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The app menu's right hand pane: the selected category's links, laid out as
|
|
17
|
+
* titled groups of wrapping columns.
|
|
18
|
+
*
|
|
19
|
+
* The whole list is a single tab stop; the arrow keys move focus between the
|
|
20
|
+
* links, following the visual grid.
|
|
21
|
+
*/
|
|
22
|
+
export function AppMenuList({ groups, itemCount, onClose, onToggleFavorite }: AppMenuListProps) {
|
|
23
|
+
let roving = useRovingTabIndex(itemCount, { columns: true });
|
|
24
|
+
|
|
25
|
+
// Links are numbered across all groups, since they share one roving index.
|
|
26
|
+
let itemIndex = -1;
|
|
27
|
+
|
|
28
|
+
function renderItem(item: AppMenuLink, index: number) {
|
|
29
|
+
let props = {
|
|
30
|
+
className: "ob-app-menu__link",
|
|
31
|
+
...item.attributes,
|
|
32
|
+
...roving.getItemProps(index),
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function activate() {
|
|
36
|
+
item.onClick?.();
|
|
37
|
+
if (!item.keepOpen) onClose();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let link = item.href ? (
|
|
41
|
+
<a {...props} href={item.href} target={item.target} rel={item.rel} onClick={activate}>
|
|
42
|
+
{item.label}
|
|
43
|
+
</a>
|
|
44
|
+
) : (
|
|
45
|
+
<button {...props} type="button" onClick={activate}>
|
|
46
|
+
{item.label}
|
|
47
|
+
</button>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
// Only app entries carry an id and a favorite state; the fixed category
|
|
51
|
+
// links (e.g. the developer tools) can't be favorited.
|
|
52
|
+
if (!onToggleFavorite || item.id === undefined || typeof item.isFavorite !== "boolean") return link;
|
|
53
|
+
|
|
54
|
+
let id = item.id;
|
|
55
|
+
let isFavorite = item.isFavorite;
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<>
|
|
59
|
+
{link}
|
|
60
|
+
<AppMenuFavoriteButton
|
|
61
|
+
appLabel={item.label}
|
|
62
|
+
isFavorite={isFavorite}
|
|
63
|
+
onToggle={() => onToggleFavorite(id, !isFavorite)}
|
|
64
|
+
{...roving.getSecondaryProps(index)}
|
|
65
|
+
/>
|
|
66
|
+
</>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<div className="ob-app-menu__columns" onKeyDown={roving.onKeyDown}>
|
|
72
|
+
{groups.map((group, groupIdx) => (
|
|
73
|
+
<section key={group.title ?? groupIdx} className="ob-app-menu__group">
|
|
74
|
+
{group.title && <h2 className="ob-app-menu__group-title">{group.title}</h2>}
|
|
75
|
+
<ul className="ob-app-menu__list">
|
|
76
|
+
{group.items.map((item) => {
|
|
77
|
+
itemIndex += 1;
|
|
78
|
+
return (
|
|
79
|
+
<li key={item.href ?? item.label} className="ob-app-menu__item">
|
|
80
|
+
{renderItem(item, itemIndex)}
|
|
81
|
+
</li>
|
|
82
|
+
);
|
|
83
|
+
})}
|
|
84
|
+
</ul>
|
|
85
|
+
</section>
|
|
86
|
+
))}
|
|
87
|
+
</div>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
2
|
+
import { Fragment, type RefObject } from "react";
|
|
3
|
+
|
|
4
|
+
import { AppMenuColorScheme } from "./AppMenuColorScheme.js";
|
|
5
|
+
import { countItems, groupLabel, type Selection, toRailSections } from "./menuEntries.js";
|
|
6
|
+
import type { AppMenuCategory } from "./types.js";
|
|
7
|
+
import { useRovingTabIndex } from "./useRovingTabIndex.js";
|
|
8
|
+
|
|
9
|
+
export type AppMenuRailProps = {
|
|
10
|
+
searchRef: RefObject<HTMLInputElement | null>;
|
|
11
|
+
search: string;
|
|
12
|
+
onSearchChange: (value: string) => void;
|
|
13
|
+
/** App groups, in the order they are listed. */
|
|
14
|
+
groups: { key: string; count: number }[];
|
|
15
|
+
/** Number of apps matching the search, shown next to "All applications". */
|
|
16
|
+
appCount: number;
|
|
17
|
+
/** Extra link categories, listed after the app groups. */
|
|
18
|
+
categories: AppMenuCategory[];
|
|
19
|
+
selection: Selection;
|
|
20
|
+
onSelect: (selection: Selection) => void;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The app menu's left rail: the local search field, the app groups and any
|
|
25
|
+
* extra link categories.
|
|
26
|
+
*
|
|
27
|
+
* The rail is a single tab stop; the arrow keys move focus between the buttons.
|
|
28
|
+
*/
|
|
29
|
+
export function AppMenuRail({
|
|
30
|
+
searchRef,
|
|
31
|
+
search,
|
|
32
|
+
onSearchChange,
|
|
33
|
+
groups,
|
|
34
|
+
appCount,
|
|
35
|
+
categories,
|
|
36
|
+
selection,
|
|
37
|
+
onSelect,
|
|
38
|
+
}: AppMenuRailProps) {
|
|
39
|
+
// "All applications", then the app groups, then the categories.
|
|
40
|
+
let roving = useRovingTabIndex(groups.length + 1 + categories.length);
|
|
41
|
+
let railSections = toRailSections(categories);
|
|
42
|
+
let categoryIndex = groups.length;
|
|
43
|
+
|
|
44
|
+
function isSelected(next: NonNullable<Selection>) {
|
|
45
|
+
if (selection === null) return false;
|
|
46
|
+
if (next.type === "group") return selection.type === "group" && selection.key === next.key;
|
|
47
|
+
return selection.type === "category" && selection.id === next.id;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div className="ob-app-menu__rail">
|
|
52
|
+
<div className="ds-search ob-app-menu__search" data-size="sm">
|
|
53
|
+
<input
|
|
54
|
+
ref={searchRef}
|
|
55
|
+
className="ds-input"
|
|
56
|
+
type="search"
|
|
57
|
+
value={search}
|
|
58
|
+
onChange={(event) => onSearchChange(event.target.value)}
|
|
59
|
+
placeholder={getLocalizedString("Search applications")}
|
|
60
|
+
aria-label={getLocalizedString("Search applications")}
|
|
61
|
+
autoComplete="off"
|
|
62
|
+
/>
|
|
63
|
+
</div>
|
|
64
|
+
|
|
65
|
+
<nav className="ob-app-menu__groups" aria-label={getLocalizedString("Categories")} onKeyDown={roving.onKeyDown}>
|
|
66
|
+
<button
|
|
67
|
+
type="button"
|
|
68
|
+
className="ob-app-menu__group-button"
|
|
69
|
+
aria-current={selection === null ? "true" : undefined}
|
|
70
|
+
onClick={() => onSelect(null)}
|
|
71
|
+
{...roving.getItemProps(0)}
|
|
72
|
+
>
|
|
73
|
+
<span>{getLocalizedString("All applications")}</span>
|
|
74
|
+
<span className="ob-app-menu__count">{appCount}</span>
|
|
75
|
+
</button>
|
|
76
|
+
{groups.map(({ key, count }, index) => (
|
|
77
|
+
<button
|
|
78
|
+
key={key}
|
|
79
|
+
type="button"
|
|
80
|
+
className="ob-app-menu__group-button"
|
|
81
|
+
aria-current={isSelected({ type: "group", key }) ? "true" : undefined}
|
|
82
|
+
onClick={() => onSelect({ type: "group", key })}
|
|
83
|
+
{...roving.getItemProps(index + 1)}
|
|
84
|
+
>
|
|
85
|
+
<span>{groupLabel(key)}</span>
|
|
86
|
+
<span className="ob-app-menu__count">{count}</span>
|
|
87
|
+
</button>
|
|
88
|
+
))}
|
|
89
|
+
|
|
90
|
+
{railSections.map(([section, sectionCategories]) => (
|
|
91
|
+
<Fragment key={section || "\u0000default"}>
|
|
92
|
+
{section && <h2 className="ob-app-menu__rail-heading">{section}</h2>}
|
|
93
|
+
{sectionCategories.map((category) => {
|
|
94
|
+
categoryIndex += 1;
|
|
95
|
+
let railIndex = categoryIndex;
|
|
96
|
+
return (
|
|
97
|
+
<button
|
|
98
|
+
key={category.id}
|
|
99
|
+
type="button"
|
|
100
|
+
className="ob-app-menu__group-button"
|
|
101
|
+
aria-current={isSelected({ type: "category", id: category.id }) ? "true" : undefined}
|
|
102
|
+
onClick={() => onSelect({ type: "category", id: category.id })}
|
|
103
|
+
{...roving.getItemProps(railIndex)}
|
|
104
|
+
>
|
|
105
|
+
<span>{category.label}</span>
|
|
106
|
+
<span className="ob-app-menu__count">{countItems(category)}</span>
|
|
107
|
+
</button>
|
|
108
|
+
);
|
|
109
|
+
})}
|
|
110
|
+
</Fragment>
|
|
111
|
+
))}
|
|
112
|
+
</nav>
|
|
113
|
+
|
|
114
|
+
<AppMenuColorScheme />
|
|
115
|
+
</div>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline icons used by the app menu. They are kept here instead of using an
|
|
3
|
+
* icon package so the menu has no runtime dependencies beyond React — it is
|
|
4
|
+
* rendered on every page in the portal.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
type IconProps = {
|
|
8
|
+
size?: number;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function StarIcon({ filled = false, size = 16 }: IconProps & { filled?: boolean }) {
|
|
12
|
+
return (
|
|
13
|
+
<svg
|
|
14
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
15
|
+
viewBox="0 0 24 24"
|
|
16
|
+
fill={filled ? "currentColor" : "none"}
|
|
17
|
+
stroke="currentColor"
|
|
18
|
+
strokeWidth="1.5"
|
|
19
|
+
strokeLinejoin="round"
|
|
20
|
+
aria-hidden="true"
|
|
21
|
+
focusable="false"
|
|
22
|
+
width={size}
|
|
23
|
+
height={size}
|
|
24
|
+
>
|
|
25
|
+
<path d="M12 3.25l2.72 5.51 6.08.89-4.4 4.29 1.04 6.06L12 17.14l-5.44 2.86 1.04-6.06-4.4-4.29 6.08-.89z" />
|
|
26
|
+
</svg>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function HomeIcon({ size = 18 }: IconProps) {
|
|
31
|
+
return (
|
|
32
|
+
<svg
|
|
33
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
34
|
+
viewBox="0 0 24 24"
|
|
35
|
+
fill="currentColor"
|
|
36
|
+
aria-hidden="true"
|
|
37
|
+
focusable="false"
|
|
38
|
+
width={size}
|
|
39
|
+
height={size}
|
|
40
|
+
>
|
|
41
|
+
<path d="M11.36 3.2a1 1 0 0 1 1.28 0l7.5 6.25a.75.75 0 0 1-.96 1.15L19 10.4V19a2 2 0 0 1-2 2h-2.75a.75.75 0 0 1-.75-.75V15.5h-3v4.75a.75.75 0 0 1-.75.75H7a2 2 0 0 1-2-2v-8.6l-.18.2a.75.75 0 1 1-.96-1.15zM6.5 9.15V19a.5.5 0 0 0 .5.5h2v-4.75a.75.75 0 0 1 .75-.75h4.5a.75.75 0 0 1 .75.75v4.75h2a.5.5 0 0 0 .5-.5V9.15L12 4.73z" />
|
|
42
|
+
</svg>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function ReloadIcon({ size = 18 }: IconProps) {
|
|
47
|
+
return (
|
|
48
|
+
<svg
|
|
49
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
50
|
+
viewBox="0 0 24 24"
|
|
51
|
+
fill="currentColor"
|
|
52
|
+
aria-hidden="true"
|
|
53
|
+
focusable="false"
|
|
54
|
+
width={size}
|
|
55
|
+
height={size}
|
|
56
|
+
>
|
|
57
|
+
<path d="M12 4a8 8 0 0 1 7.5 5.2.75.75 0 1 1-1.4.5A6.5 6.5 0 0 0 6.2 9.25H8.5a.75.75 0 0 1 0 1.5H4.75A.75.75 0 0 1 4 10V6.25a.75.75 0 0 1 1.5 0v1.86A8 8 0 0 1 12 4m-7.6 9.55a.75.75 0 0 1 .95.45A6.5 6.5 0 0 0 17.8 14.75H15.5a.75.75 0 0 1 0-1.5h3.75a.75.75 0 0 1 .75.75V17.75a.75.75 0 0 1-1.5 0v-1.86A8 8 0 0 1 4.5 14.5a.75.75 0 0 1 .45-.95z" />
|
|
58
|
+
</svg>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function CloseIcon({ size = 20 }: IconProps) {
|
|
63
|
+
return (
|
|
64
|
+
<svg
|
|
65
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
66
|
+
viewBox="0 0 24 24"
|
|
67
|
+
fill="currentColor"
|
|
68
|
+
aria-hidden="true"
|
|
69
|
+
focusable="false"
|
|
70
|
+
width={size}
|
|
71
|
+
height={size}
|
|
72
|
+
>
|
|
73
|
+
<path d="M6.53 5.47a.75.75 0 0 0-1.06 1.06L10.94 12l-5.47 5.47a.75.75 0 1 0 1.06 1.06L12 13.06l5.47 5.47a.75.75 0 1 0 1.06-1.06L13.06 12l5.47-5.47a.75.75 0 0 0-1.06-1.06L12 10.94z" />
|
|
74
|
+
</svg>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
export { AppMenu, type
|
|
2
|
-
export { AppMenuColorScheme } from "./AppMenuColorScheme.js";
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
export { AppMenu, type AppMenuProps } from "./AppMenu.js";
|
|
2
|
+
export { AppMenuColorScheme } from "./AppMenuColorScheme.js";
|
|
3
|
+
export { AppMenuFavoriteButton, type AppMenuFavoriteButtonProps } from "./AppMenuFavoriteButton.js";
|
|
4
|
+
export { AppMenuHeader, type AppMenuHeaderProps } from "./AppMenuHeader.js";
|
|
5
|
+
export { AppMenuList, type AppMenuListProps } from "./AppMenuList.js";
|
|
6
|
+
export { AppMenuRail, type AppMenuRailProps } from "./AppMenuRail.js";
|
|
7
|
+
export { AppMenuToggle, type AppMenuToggleProps } from "./AppMenuToggle.js";
|
|
8
|
+
export {
|
|
9
|
+
AppMenuUserMenu,
|
|
10
|
+
type AppMenuUser,
|
|
11
|
+
type AppMenuUserMenuProps,
|
|
12
|
+
defaultUserMenuItems,
|
|
13
|
+
} from "./AppMenuUserMenu.js";
|
|
14
|
+
export { createDeveloperCategories, type DeveloperCategoryOptions } from "./developerCategories.js";
|
|
15
|
+
export type { AppMenuArticle } from "./menuEntries.js";
|
|
16
|
+
export type { AppMenuCategory, AppMenuLink, AppMenuLinkGroup } from "./types.js";
|
|
17
|
+
export { useServiceWorkerUpdate } from "./useServiceWorkerUpdate.js";
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
2
|
+
|
|
3
|
+
import type { AppMenuCategory } from "./types.js";
|
|
4
|
+
|
|
5
|
+
/** A single row from the articles data object backing the app list. */
|
|
6
|
+
export type AppMenuArticle = {
|
|
7
|
+
ArticleId: string;
|
|
8
|
+
Title: string | null;
|
|
9
|
+
MenuGroup: string | null;
|
|
10
|
+
Path: string | null;
|
|
11
|
+
IsFavorite?: boolean | null;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/** Sentinel group key for apps that have no MenuGroup set. */
|
|
15
|
+
export const UNGROUPED = "\u0000ungrouped";
|
|
16
|
+
|
|
17
|
+
/** Sentinel group key for the virtual group holding the user's favorites. */
|
|
18
|
+
export const FAVORITES = "\u0000favorites";
|
|
19
|
+
|
|
20
|
+
/** Strip version suffixes (`my-app.0000012`) from an ArticleId. */
|
|
21
|
+
export function stripVersionSuffix(articleId: string): string {
|
|
22
|
+
return articleId.replace(/\.\d+$/, "");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type AppEntry = {
|
|
26
|
+
id: string;
|
|
27
|
+
title: string;
|
|
28
|
+
group: string;
|
|
29
|
+
href: string;
|
|
30
|
+
isFavorite: boolean;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** The category currently selected in the rail. `null` means "all applications". */
|
|
34
|
+
export type Selection = { type: "group"; key: string } | { type: "category"; id: string } | null;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Normalize the raw article rows into a deduplicated, sorted list of apps.
|
|
38
|
+
*
|
|
39
|
+
* `aviw_WebShared_Articles` contains one row per published article version, so
|
|
40
|
+
* the same app can appear dozens of times. Deduplicating on the version-less
|
|
41
|
+
* ArticleId guarantees a single entry per app even if the data object's where
|
|
42
|
+
* clause is relaxed.
|
|
43
|
+
*/
|
|
44
|
+
export function toAppEntries(articles: readonly AppMenuArticle[]): AppEntry[] {
|
|
45
|
+
let byId = new Map<string, AppEntry>();
|
|
46
|
+
|
|
47
|
+
for (let article of articles) {
|
|
48
|
+
let id = stripVersionSuffix(article.ArticleId);
|
|
49
|
+
if (byId.has(id)) continue;
|
|
50
|
+
|
|
51
|
+
byId.set(id, {
|
|
52
|
+
id,
|
|
53
|
+
title: article.Title?.trim() || id,
|
|
54
|
+
group: article.MenuGroup?.trim() || UNGROUPED,
|
|
55
|
+
href: `/${article.Path?.trim() || id}`,
|
|
56
|
+
isFavorite: article.IsFavorite === true,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return [...byId.values()].sort((a, b) => a.title.localeCompare(b.title));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Group entries by group key. The favorites are a virtual group listed first,
|
|
65
|
+
* and ungrouped apps are always listed last.
|
|
66
|
+
*/
|
|
67
|
+
export function groupEntries(entries: readonly AppEntry[]): [string, AppEntry[]][] {
|
|
68
|
+
let map = new Map<string, AppEntry[]>();
|
|
69
|
+
|
|
70
|
+
for (let entry of entries) {
|
|
71
|
+
let list = map.get(entry.group);
|
|
72
|
+
if (!list) {
|
|
73
|
+
list = [];
|
|
74
|
+
map.set(entry.group, list);
|
|
75
|
+
}
|
|
76
|
+
list.push(entry);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let groups = [...map.entries()].sort(([a], [b]) => {
|
|
80
|
+
if (a === b) return 0;
|
|
81
|
+
if (a === UNGROUPED) return 1;
|
|
82
|
+
if (b === UNGROUPED) return -1;
|
|
83
|
+
return a.localeCompare(b);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
let favorites = entries.filter((entry) => entry.isFavorite);
|
|
87
|
+
|
|
88
|
+
return favorites.length > 0 ? [[FAVORITES, favorites], ...groups] : groups;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Human readable title for a group key, resolving the sentinel keys. */
|
|
92
|
+
export function groupLabel(group: string) {
|
|
93
|
+
if (group === UNGROUPED) return getLocalizedString("Other");
|
|
94
|
+
if (group === FAVORITES) return getLocalizedString("Favorites");
|
|
95
|
+
return group;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Drop entries that don't match the search term, then empty groups. */
|
|
99
|
+
export function filterCategory(category: AppMenuCategory, term: string): AppMenuCategory {
|
|
100
|
+
if (!term) return category;
|
|
101
|
+
|
|
102
|
+
let groups = category.groups
|
|
103
|
+
.map((group) => ({ ...group, items: group.items.filter((item) => item.label.toLowerCase().includes(term)) }))
|
|
104
|
+
.filter((group) => group.items.length > 0);
|
|
105
|
+
|
|
106
|
+
return { ...category, groups };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function countItems(category: AppMenuCategory) {
|
|
110
|
+
return category.groups.reduce((total, group) => total + group.items.length, 0);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Split the categories into their rail sections, preserving the given order. */
|
|
114
|
+
export function toRailSections(categories: readonly AppMenuCategory[]): [string, AppMenuCategory[]][] {
|
|
115
|
+
let sections = new Map<string, AppMenuCategory[]>();
|
|
116
|
+
|
|
117
|
+
for (let category of categories) {
|
|
118
|
+
let key = category.section ?? "";
|
|
119
|
+
let list = sections.get(key);
|
|
120
|
+
if (!list) {
|
|
121
|
+
list = [];
|
|
122
|
+
sections.set(key, list);
|
|
123
|
+
}
|
|
124
|
+
list.push(category);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return [...sections.entries()];
|
|
128
|
+
}
|