@canonical/summon-application 0.44.0 → 0.47.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/README.md +57 -11
- package/dist/esm/application/react/index.js +165 -11
- package/dist/esm/application/react/index.js.map +1 -1
- package/dist/esm/application/react/templates/README.md.ejs +33 -1
- package/dist/esm/application/react/templates/package.json.ejs +25 -18
- package/dist/esm/application/react/templates/src/client/entry.tsx.ejs +10 -16
- package/dist/esm/application/react/templates/src/domains/catalog/CatalogPage.tsx.ejs +5 -5
- package/dist/esm/application/react/templates/src/domains/dashboard/DashboardBreadcrumbs.tsx.ejs +35 -0
- package/dist/esm/application/react/templates/src/domains/dashboard/DashboardLayout.tsx.ejs +39 -0
- package/dist/esm/application/react/templates/src/domains/dashboard/InstancesPage.test.tsx.ejs +144 -0
- package/dist/esm/application/react/templates/src/domains/dashboard/InstancesPage.tsx.ejs +281 -0
- package/dist/esm/application/react/templates/src/domains/dashboard/OverviewPage.test.tsx.ejs +76 -0
- package/dist/esm/application/react/templates/src/domains/dashboard/OverviewPage.tsx.ejs +224 -0
- package/dist/esm/application/react/templates/src/domains/dashboard/SettingsPage.test.tsx.ejs +64 -0
- package/dist/esm/application/react/templates/src/domains/dashboard/SettingsPage.tsx.ejs +142 -0
- package/dist/esm/application/react/templates/src/domains/dashboard/constants.ts.ejs +229 -0
- package/dist/esm/application/react/templates/src/domains/dashboard/hooks/index.ts +2 -0
- package/dist/esm/application/react/templates/src/domains/dashboard/hooks/types.ts +13 -0
- package/dist/esm/application/react/templates/src/domains/dashboard/hooks/useDashboardNavigation.ts.ejs +94 -0
- package/dist/esm/application/react/templates/src/domains/dashboard/projectBreadcrumbs.test.ts +78 -0
- package/dist/esm/application/react/templates/src/domains/dashboard/projectBreadcrumbs.ts +48 -0
- package/dist/esm/application/react/templates/src/domains/dashboard/routes.ts +21 -0
- package/dist/esm/application/react/templates/src/domains/dashboard/selectRelativeTime.test.ts +19 -0
- package/dist/esm/application/react/templates/src/domains/dashboard/selectRelativeTime.ts +24 -0
- package/dist/esm/application/react/templates/src/domains/dashboard/styles.css +98 -0
- package/dist/esm/application/react/templates/src/domains/dashboard/types.ts.ejs +61 -0
- package/dist/esm/application/react/templates/src/domains/marketing/HomePage.tsx.ejs +14 -9
- package/dist/esm/application/react/templates/src/i18n/ar.ts.ejs +173 -0
- package/dist/esm/application/react/templates/src/i18n/en.ts.ejs +172 -0
- package/dist/esm/application/react/templates/src/i18n/fr.ts.ejs +170 -0
- package/dist/esm/application/react/templates/src/lib/ApplicationShell/ApplicationShell.stories.tsx +91 -0
- package/dist/esm/application/react/templates/src/lib/ApplicationShell/ApplicationShell.test.tsx.ejs +139 -0
- package/dist/esm/application/react/templates/src/lib/ApplicationShell/ApplicationShell.tsx.ejs +78 -0
- package/dist/esm/application/react/templates/src/lib/ApplicationShell/index.ts +2 -0
- package/dist/esm/application/react/templates/src/lib/ApplicationShell/styles.css +43 -0
- package/dist/esm/application/react/templates/src/lib/ApplicationShell/types.ts +20 -0
- package/dist/esm/application/react/templates/src/lib/CanonicalLogo/CanonicalLogo.tsx.ejs +51 -0
- package/dist/esm/application/react/templates/src/lib/CanonicalLogo/index.ts +2 -0
- package/dist/esm/application/react/templates/src/lib/CanonicalLogo/styles.css +31 -0
- package/dist/esm/application/react/templates/src/lib/CanonicalLogo/types.ts +11 -0
- package/dist/esm/application/react/templates/src/lib/CodeMessage/CodeMessage.test.tsx +33 -0
- package/dist/esm/application/react/templates/src/lib/CodeMessage/CodeMessage.tsx +33 -0
- package/dist/esm/application/react/templates/src/lib/CodeMessage/index.ts +2 -0
- package/dist/esm/application/react/templates/src/lib/CodeMessage/types.ts +16 -0
- package/dist/esm/application/react/templates/src/lib/LazyComponent/{LazyComponent.tsx → LazyComponent.tsx.ejs} +26 -0
- package/dist/esm/application/react/templates/src/lib/LoadingMessage/LoadingMessage.test.tsx.ejs +20 -0
- package/dist/esm/application/react/templates/src/lib/LoadingMessage/LoadingMessage.tsx.ejs +21 -0
- package/dist/esm/application/react/templates/src/lib/LoadingMessage/index.ts +1 -0
- package/dist/esm/application/react/templates/src/lib/LocaleSelector/{LocaleSelector.tsx → LocaleSelector.tsx.ejs} +23 -0
- package/dist/esm/application/react/templates/src/lib/Navigation/Navigation.test.tsx.ejs +87 -0
- package/dist/esm/application/react/templates/src/lib/Navigation/Navigation.tsx.ejs +3 -0
- package/dist/esm/application/react/templates/src/lib/RouterLink/RouterLink.test.tsx +98 -0
- package/dist/esm/application/react/templates/src/lib/RouterLink/RouterLink.tsx +65 -0
- package/dist/esm/application/react/templates/src/lib/RouterLink/index.ts +1 -0
- package/dist/esm/application/react/templates/src/lib/ThemeSelector/ThemeSelector.tsx.ejs +29 -14
- package/dist/esm/application/react/templates/src/lib/TopBar/TopBar.stories.tsx.ejs +29 -0
- package/dist/esm/application/react/templates/src/lib/TopBar/TopBar.test.tsx.ejs +113 -0
- package/dist/esm/application/react/templates/src/lib/TopBar/TopBar.tsx.ejs +45 -0
- package/dist/esm/application/react/templates/src/lib/TopBar/index.ts +2 -0
- package/dist/esm/application/react/templates/src/lib/TopBar/styles.css +49 -0
- package/dist/esm/application/react/templates/src/lib/TopBar/types.ts +8 -0
- package/dist/esm/application/react/templates/src/lib/index.ts.ejs +10 -0
- package/dist/esm/application/react/templates/src/routes.tsx.ejs +70 -20
- package/dist/esm/application/react/templates/src/server/entry.tsx.ejs +6 -7
- package/dist/esm/application/react/templates/src/sitemap/getSitemapItems.ts.ejs +5 -0
- package/dist/esm/application/react/templates/src/styles/app.css +24 -11
- package/dist/esm/application/react/templates/src/testing/browserStubs.ts +57 -0
- package/dist/esm/application/react/templates/src/testing/fixtures.ts.ejs +29 -0
- package/dist/esm/application/react/templates/src/testing/renderWithProviders.tsx.ejs +64 -0
- package/dist/esm/application/react/templates/test/e2e/servers.e2e.ts.ejs +37 -1
- package/dist/esm/application/react/templates/vite-plugin-ds-icons.ts +23 -4
- package/dist/esm/application/react/templates/vitest.config.ts +4 -0
- package/dist/esm/application/react/textHelpers.js +9 -0
- package/dist/esm/application/react/textHelpers.js.map +1 -0
- package/dist/esm/shared/versions.js +35 -21
- package/dist/esm/shared/versions.js.map +1 -1
- package/dist/types/application/react/index.d.ts +1 -0
- package/dist/types/application/react/index.d.ts.map +1 -1
- package/dist/types/application/react/textHelpers.d.ts +18 -0
- package/dist/types/application/react/textHelpers.d.ts.map +1 -0
- package/dist/types/shared/versions.d.ts +41 -4
- package/dist/types/shared/versions.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/esm/application/react/templates/src/i18n/ar.ts +0 -73
- package/dist/esm/application/react/templates/src/i18n/en.ts +0 -72
- package/dist/esm/application/react/templates/src/i18n/fr.ts +0 -69
package/dist/esm/application/react/templates/src/lib/ApplicationShell/ApplicationShell.test.tsx.ejs
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { FooterRoot, NavRoot } from "@canonical/react-ds-app";
|
|
2
|
+
import { screen, within } from "@testing-library/react";
|
|
3
|
+
import { beforeAll, describe, expect, it } from "vitest";
|
|
4
|
+
import {
|
|
5
|
+
installMatchMedia,
|
|
6
|
+
installResizeObserver,
|
|
7
|
+
} from "../../testing/browserStubs.js";
|
|
8
|
+
import renderWithProviders from "../../testing/renderWithProviders.js";
|
|
9
|
+
import ApplicationShell from "./ApplicationShell.js";
|
|
10
|
+
|
|
11
|
+
const APP_NAME = "<%= name %>";
|
|
12
|
+
|
|
13
|
+
const root: NavRoot = {
|
|
14
|
+
key: "root",
|
|
15
|
+
items: [
|
|
16
|
+
{
|
|
17
|
+
key: "pages",
|
|
18
|
+
items: [
|
|
19
|
+
{ url: "/dashboard", label: "Overview" },
|
|
20
|
+
{ url: "/dashboard/instances", label: "Instances" },
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
key: "later",
|
|
25
|
+
label: "Later",
|
|
26
|
+
items: [{ key: "networks", label: "Networks", disabled: true }],
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const footerRoot: FooterRoot = {
|
|
32
|
+
key: "footer",
|
|
33
|
+
items: [{ url: "/guides/router-core", label: "Router guide" }],
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
beforeAll(() => {
|
|
37
|
+
installMatchMedia();
|
|
38
|
+
installResizeObserver();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
function renderShell(path = "/dashboard/instances") {
|
|
42
|
+
return renderWithProviders(
|
|
43
|
+
<ApplicationShell footerRoot={footerRoot} label="Dashboard" root={root}>
|
|
44
|
+
<h1>Page</h1>
|
|
45
|
+
</ApplicationShell>,
|
|
46
|
+
path,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe("ApplicationShell", () => {
|
|
51
|
+
it("renders the page in the main landmark the skip link targets", () => {
|
|
52
|
+
renderShell();
|
|
53
|
+
|
|
54
|
+
const main = screen.getByRole("main");
|
|
55
|
+
|
|
56
|
+
expect(main).toHaveAttribute("id", "main-content");
|
|
57
|
+
expect(within(main).getByRole("heading", { name: "Page" })).toBeVisible();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("names the side navigation landmark and shows the app's name", () => {
|
|
61
|
+
renderShell();
|
|
62
|
+
|
|
63
|
+
expect(
|
|
64
|
+
screen.getByRole("navigation", { name: "Dashboard" }),
|
|
65
|
+
).toBeInTheDocument();
|
|
66
|
+
expect(screen.getByText(APP_NAME)).toBeInTheDocument();
|
|
67
|
+
expect(
|
|
68
|
+
screen.getByRole("link", { name: "Dashboard overview" }),
|
|
69
|
+
).toHaveAttribute("href", "/dashboard");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("marks the item for the current URL as the current page", () => {
|
|
73
|
+
renderShell("/dashboard/instances");
|
|
74
|
+
|
|
75
|
+
const navigation = screen.getByRole("navigation", { name: "Dashboard" });
|
|
76
|
+
|
|
77
|
+
expect(
|
|
78
|
+
within(navigation).getByRole("link", { name: "Instances" }),
|
|
79
|
+
).toHaveAttribute("aria-current", "page");
|
|
80
|
+
expect(
|
|
81
|
+
within(navigation).getByRole("link", { name: "Overview" }),
|
|
82
|
+
).not.toHaveAttribute("aria-current");
|
|
83
|
+
});
|
|
84
|
+
<% if (intl) { -%>
|
|
85
|
+
|
|
86
|
+
it("translates the side navigation's built-in text", () => {
|
|
87
|
+
renderWithProviders(
|
|
88
|
+
<ApplicationShell label="Tableau de bord" root={root}>
|
|
89
|
+
<p>Page</p>
|
|
90
|
+
</ApplicationShell>,
|
|
91
|
+
"/dashboard",
|
|
92
|
+
"fr",
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
expect(
|
|
96
|
+
screen.getByRole("link", { name: "Aller au contenu principal" }),
|
|
97
|
+
).toBeInTheDocument();
|
|
98
|
+
expect(
|
|
99
|
+
screen.getByRole("button", { name: "Réduire la navigation" }),
|
|
100
|
+
).toHaveTextContent("Fermer le menu");
|
|
101
|
+
});
|
|
102
|
+
<% } -%>
|
|
103
|
+
|
|
104
|
+
it("renders a disabled item without a link", () => {
|
|
105
|
+
renderShell();
|
|
106
|
+
|
|
107
|
+
expect(screen.getByText("Networks").closest("a")).toBeNull();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("renders the footer rows", () => {
|
|
111
|
+
renderShell();
|
|
112
|
+
|
|
113
|
+
expect(screen.getByRole("link", { name: "Router guide" })).toHaveAttribute(
|
|
114
|
+
"href",
|
|
115
|
+
"/guides/router-core",
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("merges a consumer class with its own and spreads native props", () => {
|
|
120
|
+
const { container } = renderWithProviders(
|
|
121
|
+
<ApplicationShell
|
|
122
|
+
className="custom"
|
|
123
|
+
data-testid="shell"
|
|
124
|
+
label="Dashboard"
|
|
125
|
+
root={root}
|
|
126
|
+
>
|
|
127
|
+
<p>Page</p>
|
|
128
|
+
</ApplicationShell>,
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
expect(screen.getByTestId("shell")).toHaveClass(
|
|
132
|
+
"ds",
|
|
133
|
+
"application-shell",
|
|
134
|
+
"surface",
|
|
135
|
+
"custom",
|
|
136
|
+
);
|
|
137
|
+
expect(container.firstElementChild).toBe(screen.getByTestId("shell"));
|
|
138
|
+
});
|
|
139
|
+
});
|
package/dist/esm/application/react/templates/src/lib/ApplicationShell/ApplicationShell.tsx.ejs
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<% if (intl) { -%>
|
|
2
|
+
import { useTranslation } from "@canonical/i18n-react";
|
|
3
|
+
<% } -%>
|
|
4
|
+
import { ApplicationLayout, SideNavigation } from "@canonical/react-ds-app";
|
|
5
|
+
import { useRoute } from "@canonical/router-react";
|
|
6
|
+
import type { ReactElement } from "react";
|
|
7
|
+
import CanonicalLogo from "../CanonicalLogo/index.js";
|
|
8
|
+
import RouterLink from "../RouterLink/index.js";
|
|
9
|
+
import type { ApplicationShellProps } from "./types.js";
|
|
10
|
+
import "./styles.css";
|
|
11
|
+
|
|
12
|
+
const componentCssClassName = "ds application-shell";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* An application's frame: the design system's `ApplicationLayout`, with its
|
|
16
|
+
* `SideNavigation` in the navigation slot and the page in `<main>`.
|
|
17
|
+
*
|
|
18
|
+
* The side navigation follows the router: the current pathname marks the
|
|
19
|
+
* active item, and `RouterLink` turns its links into client-side navigation.
|
|
20
|
+
* `<main id="main-content">` is the side navigation's skip-link target.
|
|
21
|
+
*
|
|
22
|
+
* The shell is a `.surface`: the design system's components read their
|
|
23
|
+
* colours from the surface channels it sets, and the side panels and modals
|
|
24
|
+
* opened inside it paint from them.
|
|
25
|
+
*
|
|
26
|
+
* `import { ApplicationShell } from "#lib/index.js";`
|
|
27
|
+
*/
|
|
28
|
+
export default function ApplicationShell({
|
|
29
|
+
root,
|
|
30
|
+
footerRoot,
|
|
31
|
+
label,
|
|
32
|
+
children,
|
|
33
|
+
className,
|
|
34
|
+
...props
|
|
35
|
+
}: ApplicationShellProps): ReactElement {
|
|
36
|
+
<% if (intl) { -%>
|
|
37
|
+
const { t } = useTranslation();
|
|
38
|
+
<% } -%>
|
|
39
|
+
const { pathname } = useRoute();
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<div
|
|
43
|
+
{...props}
|
|
44
|
+
className={[componentCssClassName, "surface", className]
|
|
45
|
+
.filter(Boolean)
|
|
46
|
+
.join(" ")}
|
|
47
|
+
>
|
|
48
|
+
<ApplicationLayout
|
|
49
|
+
navigation={
|
|
50
|
+
<SideNavigation
|
|
51
|
+
aria-label={label}
|
|
52
|
+
applicationName=<%- attr("app.name", name) %>
|
|
53
|
+
brand={<CanonicalLogo />}
|
|
54
|
+
currentUrl={pathname}
|
|
55
|
+
footerRoot={footerRoot}
|
|
56
|
+
LinkComponent={RouterLink}
|
|
57
|
+
<% if (intl) { -%>
|
|
58
|
+
messages={{
|
|
59
|
+
skipToContent: () => t("shell.skipToContent"),
|
|
60
|
+
collapseNavigation: () => t("shell.collapseNavigation"),
|
|
61
|
+
expandNavigation: () => t("shell.expandNavigation"),
|
|
62
|
+
collapse: () => t("shell.collapse"),
|
|
63
|
+
expand: () => t("shell.expand"),
|
|
64
|
+
openMenu: () => t("shell.openMenu"),
|
|
65
|
+
closeMenu: () => t("shell.closeMenu"),
|
|
66
|
+
}}
|
|
67
|
+
<% } -%>
|
|
68
|
+
root={root}
|
|
69
|
+
/>
|
|
70
|
+
}
|
|
71
|
+
>
|
|
72
|
+
<main className="main" id="main-content">
|
|
73
|
+
{children}
|
|
74
|
+
</main>
|
|
75
|
+
</ApplicationLayout>
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
@layer app {
|
|
2
|
+
/* The shell fills the area its parent gives it. The application layout
|
|
3
|
+
inside is block-size: 100%, so the side navigation spans that height and
|
|
4
|
+
the page scrolls inside <main> rather than the document. */
|
|
5
|
+
.ds.application-shell {
|
|
6
|
+
min-block-size: 0;
|
|
7
|
+
|
|
8
|
+
& .main {
|
|
9
|
+
box-sizing: border-box;
|
|
10
|
+
block-size: 100%;
|
|
11
|
+
overflow: auto;
|
|
12
|
+
padding-block: var(--container-gap-loose);
|
|
13
|
+
padding-inline-end: var(--grid-margin);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/* A side panel opened in the shell is fixed to the viewport and spans its
|
|
17
|
+
full height by default. When the shell sits under other chrome, such
|
|
18
|
+
as a top bar, the page sets --application-shell-overlay-inset-block-start
|
|
19
|
+
so the panel starts below it and that chrome stays usable. */
|
|
20
|
+
& .ds.side-panel {
|
|
21
|
+
inset-block-start: var(--application-shell-overlay-inset-block-start, 0);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* Below the side navigation's small breakpoint (620px) the navigation
|
|
25
|
+
stops being a rail and becomes a bar that opens a full-screen menu,
|
|
26
|
+
so the layout stacks it above the page instead of beside it. */
|
|
27
|
+
@media (width < 620px) {
|
|
28
|
+
& > .ds.application-layout {
|
|
29
|
+
grid-template-columns: 1fr;
|
|
30
|
+
grid-template-rows: auto 1fr;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
& .main {
|
|
34
|
+
padding-inline-start: var(--grid-margin);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* On a phone the panel takes the whole screen. */
|
|
38
|
+
& .ds.side-panel {
|
|
39
|
+
inset-block-start: 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { FooterRoot, NavRoot } from "@canonical/react-ds-app";
|
|
2
|
+
import type { ComponentProps, ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
type OwnProps = {
|
|
5
|
+
/** The side navigation's tree: groups of items, each item with a `url`. */
|
|
6
|
+
readonly root: NavRoot;
|
|
7
|
+
/** The side navigation's footer rows. Omit it to hide the footer. */
|
|
8
|
+
readonly footerRoot?: FooterRoot;
|
|
9
|
+
/** The accessible name of the side navigation's landmark. */
|
|
10
|
+
readonly label: string;
|
|
11
|
+
/** The page, rendered in the shell's `<main>`. */
|
|
12
|
+
readonly children: ReactNode;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Props for `ApplicationShell`: the side navigation's data and the page, plus
|
|
17
|
+
* the native props of the root `<div>`, which reach the element unchanged.
|
|
18
|
+
*/
|
|
19
|
+
export type ApplicationShellProps = OwnProps &
|
|
20
|
+
Omit<ComponentProps<"div">, keyof OwnProps>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<% if (intl) { -%>
|
|
2
|
+
import { useTranslation } from "@canonical/i18n-react";
|
|
3
|
+
<% } -%>
|
|
4
|
+
import { Link } from "@canonical/router-react";
|
|
5
|
+
import type { ReactElement } from "react";
|
|
6
|
+
import type { CanonicalLogoProps } from "./types.js";
|
|
7
|
+
import "./styles.css";
|
|
8
|
+
|
|
9
|
+
const componentCssClassName = "ds canonical-logo";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The brand of the dashboard's side navigation: the brand-orange rectangle
|
|
13
|
+
* with the circle-of-friends mark, linking to the dashboard's overview.
|
|
14
|
+
*
|
|
15
|
+
* It mirrors the `CanonicalLogo` story helper of `@canonical/react-ds-app`,
|
|
16
|
+
* which the package does not export. The mark is inline SVG rather than an
|
|
17
|
+
* image URL, so it renders on the server and needs no asset route.
|
|
18
|
+
*
|
|
19
|
+
* `import { CanonicalLogo } from "#lib/index.js";`
|
|
20
|
+
*/
|
|
21
|
+
export default function CanonicalLogo({
|
|
22
|
+
className,
|
|
23
|
+
...props
|
|
24
|
+
}: CanonicalLogoProps): ReactElement {
|
|
25
|
+
<% if (intl) { -%>
|
|
26
|
+
const { t } = useTranslation();
|
|
27
|
+
|
|
28
|
+
<% } -%>
|
|
29
|
+
return (
|
|
30
|
+
<Link
|
|
31
|
+
{...props}
|
|
32
|
+
aria-label=<%- attr("dashboard.nav.home", "Dashboard overview") %>
|
|
33
|
+
className={[componentCssClassName, className].filter(Boolean).join(" ")}
|
|
34
|
+
to="dashboard"
|
|
35
|
+
>
|
|
36
|
+
<svg
|
|
37
|
+
aria-hidden="true"
|
|
38
|
+
className="mark"
|
|
39
|
+
focusable="false"
|
|
40
|
+
viewBox="0 0 60.45 57.87"
|
|
41
|
+
>
|
|
42
|
+
<circle cx="9.66" cy="27.41" r="8.12" />
|
|
43
|
+
<circle cx="43.48" cy="9.61" r="8.12" />
|
|
44
|
+
<path d="M7.34,38.71A26.67,26.67,0,0,0,32.58,55.55a11.47,11.47,0,0,1-2.49-7Q29,48.4,28,48.19A19.62,19.62,0,0,1,14.55,37.83,11.49,11.49,0,0,1,7.34,38.71Z" />
|
|
45
|
+
<circle cx="41.65" cy="48.35" r="8.12" />
|
|
46
|
+
<path d="M48.9,39.31a11.58,11.58,0,0,1,4,6.25,26.64,26.64,0,0,0,1.36-31.63,11.47,11.47,0,0,1-4.7,5.54A19.73,19.73,0,0,1,48.9,39.31Z" />
|
|
47
|
+
<path d="M9.68,15.85a11.44,11.44,0,0,1,2.4.25,11.72,11.72,0,0,1,3.77,1.54,19.73,19.73,0,0,1,16-8.56,12.15,12.15,0,0,1,.22-1.9h0a11.75,11.75,0,0,1,2.34-4.89A26.9,26.9,0,0,0,8.82,15.88C9.11,15.86,9.39,15.85,9.68,15.85Z" />
|
|
48
|
+
</svg>
|
|
49
|
+
</Link>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* The side navigation's brand slot: a brand-orange rectangle sized by the side
|
|
2
|
+
* navigation's logo tokens, with the circle-of-friends mark on the baseline
|
|
3
|
+
* grid. The rectangle overshoots a grid line by `--logo-overflow` and cancels
|
|
4
|
+
* it with its bottom margin, so the header stays a whole number of baseline
|
|
5
|
+
* units tall. */
|
|
6
|
+
|
|
7
|
+
@layer app {
|
|
8
|
+
.ds.canonical-logo {
|
|
9
|
+
--mark-size: 4; /* the mark's side, in baseline units */
|
|
10
|
+
--mark-margin-top: 5; /* the gap above the mark, in baseline units */
|
|
11
|
+
--logo-overflow: 0.25rem;
|
|
12
|
+
|
|
13
|
+
display: flex;
|
|
14
|
+
align-items: flex-start;
|
|
15
|
+
justify-content: center;
|
|
16
|
+
block-size: var(--sidenav-logo-block-size);
|
|
17
|
+
inline-size: var(--sidenav-logo-inline-size);
|
|
18
|
+
margin-block-end: calc(var(--space-baseline) - var(--logo-overflow));
|
|
19
|
+
background: var(--color-background-logo);
|
|
20
|
+
|
|
21
|
+
& > .mark {
|
|
22
|
+
display: block;
|
|
23
|
+
inline-size: calc(var(--space-baseline) * var(--mark-size));
|
|
24
|
+
block-size: calc(var(--space-baseline) * var(--mark-size));
|
|
25
|
+
margin-block-start: calc(var(--space-baseline) * var(--mark-margin-top));
|
|
26
|
+
/* The mark is part of the brand asset: white on the brand rectangle in
|
|
27
|
+
every theme, so it is not a themable value. */
|
|
28
|
+
fill: white;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ComponentProps } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Props for `CanonicalLogo`. The logo owns its link target, its accessible
|
|
5
|
+
* name and its mark, so it takes only the native props of its root `<a>`,
|
|
6
|
+
* which reach the element unchanged.
|
|
7
|
+
*/
|
|
8
|
+
export type CanonicalLogoProps = Omit<
|
|
9
|
+
ComponentProps<"a">,
|
|
10
|
+
"aria-label" | "children" | "href"
|
|
11
|
+
>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import CodeMessage from "./CodeMessage.js";
|
|
4
|
+
|
|
5
|
+
describe("CodeMessage", () => {
|
|
6
|
+
it("renders backticked names as inline code within the paragraph", () => {
|
|
7
|
+
const { container } = render(
|
|
8
|
+
<CodeMessage message="`LazyComponent` lit une donnée avec `use()`." />,
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
const codes = [...container.querySelectorAll("code")].map(
|
|
12
|
+
(code) => code.textContent,
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
expect(codes).toEqual(["LazyComponent", "use()"]);
|
|
16
|
+
expect(container.querySelector("p")).toHaveTextContent(
|
|
17
|
+
"LazyComponent lit une donnée avec use().",
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("renders a message without backticks as plain text", () => {
|
|
22
|
+
const { container } = render(<CodeMessage message="Plain text." />);
|
|
23
|
+
|
|
24
|
+
expect(container.querySelector("code")).toBeNull();
|
|
25
|
+
expect(screen.getByText("Plain text.")).toBeInTheDocument();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("spreads native props onto the paragraph", () => {
|
|
29
|
+
render(<CodeMessage data-testid="message" message="Text" />);
|
|
30
|
+
|
|
31
|
+
expect(screen.getByTestId("message").tagName).toBe("P");
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { InlineCode } from "@canonical/react-ds-global";
|
|
2
|
+
import type { ReactElement } from "react";
|
|
3
|
+
import type { CodeMessageProps } from "./types.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A paragraph that names code. The message marks code names with backticks,
|
|
7
|
+
* as Markdown does, and each one renders as the design system's `InlineCode`,
|
|
8
|
+
* so a translator writes a natural sentence and the names stay exactly as
|
|
9
|
+
* they are in the source.
|
|
10
|
+
*
|
|
11
|
+
* `import { CodeMessage } from "#lib/index.js";`
|
|
12
|
+
*/
|
|
13
|
+
export default function CodeMessage({
|
|
14
|
+
message,
|
|
15
|
+
...props
|
|
16
|
+
}: CodeMessageProps): ReactElement {
|
|
17
|
+
// Splitting on backticks leaves prose at even positions and code at odd
|
|
18
|
+
// ones. The parts of one message never reorder, so a part's position and
|
|
19
|
+
// text identify it.
|
|
20
|
+
const parts = message.split("`").map((text, position) => ({
|
|
21
|
+
key: `${position}:${text}`,
|
|
22
|
+
code: position % 2 === 1,
|
|
23
|
+
text,
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<p {...props}>
|
|
28
|
+
{parts.map(({ key, code, text }) =>
|
|
29
|
+
code ? <InlineCode key={key}>{text}</InlineCode> : text,
|
|
30
|
+
)}
|
|
31
|
+
</p>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ComponentProps } from "react";
|
|
2
|
+
|
|
3
|
+
type OwnProps = {
|
|
4
|
+
/**
|
|
5
|
+
* A translated message, with code names between backticks, e.g.
|
|
6
|
+
* "`LazyComponent` reads a delayed fetch with `use()`".
|
|
7
|
+
*/
|
|
8
|
+
readonly message: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Props for `CodeMessage`: the message, plus the native props of the root
|
|
13
|
+
* `<p>`, which reach the element unchanged.
|
|
14
|
+
*/
|
|
15
|
+
export type CodeMessageProps = OwnProps &
|
|
16
|
+
Omit<ComponentProps<"p">, keyof OwnProps | "children">;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
<% if (intl) { -%>
|
|
2
|
+
import { useTranslation } from "@canonical/i18n-react";
|
|
3
|
+
<% } -%>
|
|
1
4
|
import { type ReactElement, use } from "react";
|
|
5
|
+
<% if (intl) { -%>
|
|
6
|
+
import type { MessageKey } from "#i18n/en.js";
|
|
7
|
+
<% } -%>
|
|
2
8
|
|
|
3
9
|
/**
|
|
4
10
|
* Demonstrates streaming SSR with Suspense.
|
|
@@ -14,19 +20,39 @@ import { type ReactElement, use } from "react";
|
|
|
14
20
|
* Replace `createDelayedData` with a real data source in your own routes.
|
|
15
21
|
*/
|
|
16
22
|
|
|
23
|
+
<% if (intl) { -%>
|
|
24
|
+
/**
|
|
25
|
+
* Synthetic data source — resolves after `delayMs` to simulate a slow fetch.
|
|
26
|
+
* It resolves to a catalog key, so the streamed text renders in the active
|
|
27
|
+
* locale.
|
|
28
|
+
*/
|
|
29
|
+
function createDelayedData(delayMs = 1000): Promise<MessageKey> {
|
|
30
|
+
return new Promise((resolve) => {
|
|
31
|
+
setTimeout(() => resolve("home.streamed"), delayMs);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
<% } else { -%>
|
|
17
35
|
/** Synthetic data source — resolves after `delayMs` to simulate a slow fetch. */
|
|
18
36
|
function createDelayedData(delayMs = 1000): Promise<string> {
|
|
19
37
|
return new Promise((resolve) => {
|
|
20
38
|
setTimeout(() => resolve("Streamed in after a delay"), delayMs);
|
|
21
39
|
});
|
|
22
40
|
}
|
|
41
|
+
<% } -%>
|
|
23
42
|
|
|
24
43
|
// Created once at module load so re-renders reuse the same promise rather
|
|
25
44
|
// than restarting the "fetch" (and re-suspending) on every render.
|
|
26
45
|
const dataPromise = createDelayedData();
|
|
27
46
|
|
|
28
47
|
export default function LazyComponent(): ReactElement {
|
|
48
|
+
<% if (intl) { -%>
|
|
49
|
+
const { t } = useTranslation();
|
|
50
|
+
const messageKey = use(dataPromise);
|
|
51
|
+
|
|
52
|
+
return <p>{t(messageKey)}</p>;
|
|
53
|
+
<% } else { -%>
|
|
29
54
|
const message = use(dataPromise);
|
|
30
55
|
|
|
31
56
|
return <p>{message}</p>;
|
|
57
|
+
<% } -%>
|
|
32
58
|
}
|
package/dist/esm/application/react/templates/src/lib/LoadingMessage/LoadingMessage.test.tsx.ejs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import renderWithProviders from "../../testing/renderWithProviders.js";
|
|
4
|
+
import LoadingMessage from "./LoadingMessage.js";
|
|
5
|
+
|
|
6
|
+
describe("LoadingMessage", () => {
|
|
7
|
+
<% if (intl) { -%>
|
|
8
|
+
it("renders the loading text in the active locale", () => {
|
|
9
|
+
renderWithProviders(<LoadingMessage />, "/", "fr");
|
|
10
|
+
|
|
11
|
+
expect(screen.getByText("Chargement…")).toBeInTheDocument();
|
|
12
|
+
});
|
|
13
|
+
<% } else { -%>
|
|
14
|
+
it("renders the loading text", () => {
|
|
15
|
+
renderWithProviders(<LoadingMessage />);
|
|
16
|
+
|
|
17
|
+
expect(screen.getByText("Loading…")).toBeInTheDocument();
|
|
18
|
+
});
|
|
19
|
+
<% } -%>
|
|
20
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<% if (intl) { -%>
|
|
2
|
+
import { useTranslation } from "@canonical/i18n-react";
|
|
3
|
+
<% } -%>
|
|
4
|
+
import type { ReactElement } from "react";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The route fallback both entries render while a page suspends<% if (intl) { %>, in the active
|
|
8
|
+
* locale<% } %>. The server and the client render the same one, so the streamed
|
|
9
|
+
* shell hydrates without a mismatch.
|
|
10
|
+
*
|
|
11
|
+
* `import { LoadingMessage } from "#lib/index.js";`
|
|
12
|
+
*/
|
|
13
|
+
export default function LoadingMessage(): ReactElement {
|
|
14
|
+
<% if (intl) { -%>
|
|
15
|
+
const { t } = useTranslation();
|
|
16
|
+
|
|
17
|
+
return <p>{t("app.loading")}</p>;
|
|
18
|
+
<% } else { -%>
|
|
19
|
+
return <p>Loading…</p>;
|
|
20
|
+
<% } -%>
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./LoadingMessage.js";
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { useLocale, useTranslation } from "@canonical/i18n-react";
|
|
2
|
+
<% if (forms) { -%>
|
|
3
|
+
import { SelectInput } from "@canonical/react-ds-global-form";
|
|
4
|
+
<% } -%>
|
|
2
5
|
import type { ChangeEvent, ReactElement } from "react";
|
|
3
6
|
|
|
4
7
|
/**
|
|
@@ -16,9 +19,16 @@ function endonymOf(tag: string): string {
|
|
|
16
19
|
* to the `locale` cookie (so the server renders the matching `<html lang>` on
|
|
17
20
|
* the next request), and flips `<html dir>` for right-to-left locales.
|
|
18
21
|
*
|
|
22
|
+
<% if (forms) { -%>
|
|
23
|
+
* Each option carries a `lang` attribute so assistive technology pronounces
|
|
24
|
+
* the endonym in its own language. Built on the form package's standalone
|
|
25
|
+
* `SelectInput`, so it wears the design system's input chrome; the picker
|
|
26
|
+
* itself stays app-local, as the design-system tier ships no locale switcher.
|
|
27
|
+
<% } else { -%>
|
|
19
28
|
* Each `<option>` carries a `lang` attribute so assistive technology
|
|
20
29
|
* pronounces the endonym in its own language. Deliberately app-local: the
|
|
21
30
|
* design-system tier ships no visual locale switcher.
|
|
31
|
+
<% } -%>
|
|
22
32
|
*/
|
|
23
33
|
export default function LocaleSelector(): ReactElement {
|
|
24
34
|
const { locale, locales, setLocale } = useLocale();
|
|
@@ -29,6 +39,18 @@ export default function LocaleSelector(): ReactElement {
|
|
|
29
39
|
}
|
|
30
40
|
|
|
31
41
|
return (
|
|
42
|
+
<% if (forms) { -%>
|
|
43
|
+
<SelectInput
|
|
44
|
+
aria-label={t("locale.label")}
|
|
45
|
+
onChange={handleChange}
|
|
46
|
+
options={locales.map((tag) => ({
|
|
47
|
+
value: tag,
|
|
48
|
+
label: endonymOf(tag),
|
|
49
|
+
lang: tag,
|
|
50
|
+
}))}
|
|
51
|
+
value={locale}
|
|
52
|
+
/>
|
|
53
|
+
<% } else { -%>
|
|
32
54
|
<select
|
|
33
55
|
aria-label={t("locale.label")}
|
|
34
56
|
onChange={handleChange}
|
|
@@ -40,5 +62,6 @@ export default function LocaleSelector(): ReactElement {
|
|
|
40
62
|
</option>
|
|
41
63
|
))}
|
|
42
64
|
</select>
|
|
65
|
+
<% } -%>
|
|
43
66
|
);
|
|
44
67
|
}
|