@olenbetong/synergi-react 2.7.1 → 2.9.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/dist/styles/styles.css.map +1 -1
- package/es/{components → chrome}/AppMenu/AppMenu.css +648 -648
- package/es/{components → chrome}/AppMenu/index.d.ts +1 -1
- package/es/components/ImageEditor/ImageEditor.d.ts +12 -0
- package/es/components/ImageEditor/ImageEditor.js +27 -6
- package/es/components/ImageEditor/index.d.ts +2 -0
- package/es/components/ImageEditor/index.js +2 -0
- package/es/components/ImageEditor/plugins/zoomPlugin/ZoomControls.js +1 -1
- package/es/components/ImageEditor/useImageHistory.d.ts +6 -1
- package/es/components/ImageEditor/useImageHistory.js +21 -23
- package/es/components/PageBanner/index.d.ts +1 -1
- package/es/elements/ElementDamage/DamageFormButtons.d.ts +2 -3
- package/es/elements/ElementDamage/DamageFormButtons.js +1 -1
- package/es/elements/ElementDamage/TransportElementSelect.d.ts +1 -2
- package/es/elements/index.d.ts +5 -0
- package/es/elements/index.js +5 -0
- package/es/index.d.ts +2 -2
- package/es/index.js +2 -2
- package/package.json +4 -4
- package/src/{components → chrome}/AppMenu/AppMenu.css +648 -648
- package/src/{components → chrome}/AppMenu/AppMenu.tsx +285 -285
- package/src/{components → chrome}/AppMenu/AppMenuFavoriteButton.tsx +47 -47
- package/src/{components → chrome}/AppMenu/AppMenuHeader.tsx +79 -79
- package/src/{components → chrome}/AppMenu/AppMenuList.tsx +89 -89
- package/src/{components → chrome}/AppMenu/AppMenuRail.tsx +117 -117
- package/src/{components → chrome}/AppMenu/icons.tsx +76 -76
- package/src/{components → chrome}/AppMenu/index.ts +17 -17
- package/src/{components → chrome}/AppMenu/menuEntries.ts +128 -128
- package/src/{components → chrome}/AppMenu/types.ts +45 -45
- package/src/{components → chrome}/AppMenu/useFavorites.ts +40 -40
- package/src/{components → chrome}/AppMenu/useRovingTabIndex.ts +130 -130
- package/src/{components → chrome}/AppShell/index.tsx +287 -287
- package/src/colorScheme.ts +81 -81
- package/src/components/ImageEditor/ImageEditor.tsx +41 -6
- package/src/components/ImageEditor/index.ts +2 -0
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +7 -8
- package/src/components/ImageEditor/useImageHistory.ts +27 -19
- package/src/components/LinkedCardList/index.scss +95 -93
- package/src/components/PageBanner/index.tsx +5 -4
- package/src/components/ProgressBar/index.scss +96 -94
- package/src/elements/ElementDamage/DamageFormButtons.tsx +2 -2
- package/src/elements/ElementDamage/TransportElementSelect.tsx +1 -1
- package/src/elements/index.ts +5 -0
- package/src/index.ts +70 -61
- /package/es/{components → chrome}/AppMenu/AppMenu.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenu.js +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuColorScheme.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuColorScheme.js +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuFavoriteButton.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuFavoriteButton.js +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuHeader.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuHeader.js +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuList.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuList.js +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuRail.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuRail.js +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuToggle.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuToggle.js +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuUserMenu.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuUserMenu.js +0 -0
- /package/es/{components → chrome}/AppMenu/developerCategories.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/developerCategories.js +0 -0
- /package/es/{components → chrome}/AppMenu/icons.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/icons.js +0 -0
- /package/es/{components → chrome}/AppMenu/index.js +0 -0
- /package/es/{components → chrome}/AppMenu/menuEntries.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/menuEntries.js +0 -0
- /package/es/{components → chrome}/AppMenu/types.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/types.js +0 -0
- /package/es/{components → chrome}/AppMenu/useFavorites.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/useFavorites.js +0 -0
- /package/es/{components → chrome}/AppMenu/useRovingTabIndex.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/useRovingTabIndex.js +0 -0
- /package/es/{components → chrome}/AppMenu/useServiceWorkerUpdate.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/useServiceWorkerUpdate.js +0 -0
- /package/es/{components → chrome}/AppShell/index.d.ts +0 -0
- /package/es/{components → chrome}/AppShell/index.js +0 -0
- /package/src/{components → chrome}/AppMenu/AppMenuColorScheme.tsx +0 -0
- /package/src/{components → chrome}/AppMenu/AppMenuToggle.tsx +0 -0
- /package/src/{components → chrome}/AppMenu/AppMenuUserMenu.tsx +0 -0
- /package/src/{components → chrome}/AppMenu/developerCategories.ts +0 -0
- /package/src/{components → chrome}/AppMenu/useServiceWorkerUpdate.ts +0 -0
|
@@ -1,79 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -1,89 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -1,117 +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
|
-
}
|
|
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
|
+
}
|