@datalayer/design 1.0.12 → 1.0.13
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/lib/pages/IconsPage.js +47 -7
- package/package.json +3 -2
package/lib/pages/IconsPage.js
CHANGED
|
@@ -4,17 +4,32 @@ import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-run
|
|
|
4
4
|
* Distributed under the terms of the Modified BSD License.
|
|
5
5
|
*/
|
|
6
6
|
/**
|
|
7
|
-
* The icon catalogue of datalayer.design
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* The icon catalogue of datalayer.design, in two views, chosen at the top of
|
|
8
|
+
* the page and kept in the address (`?view=viewer`) so a link opens either:
|
|
9
|
+
*
|
|
10
|
+
* - Grid, the default: every icon of `@datalayer/icons-react` (published on
|
|
11
|
+
* npm), searchable by name.
|
|
12
|
+
* - Viewer: the viewer of the icons repository, which `@datalayer/icons-react`
|
|
13
|
+
* ships as its subpath `@datalayer/icons-react/viewer` (in no barrel), the
|
|
14
|
+
* four treatments of each icon with their downloads. Imported when chosen,
|
|
15
|
+
* so the grid never loads its chunk.
|
|
16
|
+
*
|
|
17
|
+
* It read `@datalayer/icons-all` until 20 November 2026; that package is
|
|
18
|
+
* never published, and design is.
|
|
10
19
|
*/
|
|
11
20
|
import { Suspense, lazy, useMemo, useState } from "react";
|
|
12
|
-
import {
|
|
21
|
+
import { useSearchParams } from "react-router-dom";
|
|
22
|
+
import { SegmentedControl, Spinner, Text, TextInput } from "@primer/react";
|
|
13
23
|
import { SearchIcon } from "@primer/octicons-react";
|
|
14
24
|
import { Box } from "@datalayer/primer-addons";
|
|
25
|
+
/** A React component: a function, or a `forwardRef` / `memo` object. */
|
|
26
|
+
const isComponent = (value) => typeof value === "function" ||
|
|
27
|
+
(typeof value === "object" && value !== null && "$$typeof" in value);
|
|
15
28
|
const IconGrid = lazy(() => import("@datalayer/icons-react").then((module) => {
|
|
16
29
|
const icons = Object.entries(module)
|
|
17
|
-
|
|
30
|
+
// Each icon is a `forwardRef` component, an object (a `$$typeof` element
|
|
31
|
+
// type), not a function: a check for functions alone listed none.
|
|
32
|
+
.filter(([name, value]) => name.endsWith("Icon") && isComponent(value))
|
|
18
33
|
.map(([name, value]) => [name, value])
|
|
19
34
|
.sort(([a], [b]) => a.localeCompare(b));
|
|
20
35
|
function Grid({ query }) {
|
|
@@ -34,8 +49,33 @@ const IconGrid = lazy(() => import("@datalayer/icons-react").then((module) => {
|
|
|
34
49
|
}
|
|
35
50
|
return { default: Grid };
|
|
36
51
|
}));
|
|
37
|
-
|
|
52
|
+
/** The icons viewer of `@datalayer/icons-react`, loaded when chosen. */
|
|
53
|
+
const IconsViewer = lazy(() => import("@datalayer/icons-react/viewer"));
|
|
54
|
+
const VIEWS = ["grid", "viewer"];
|
|
55
|
+
const VIEW_LABELS = { grid: "Grid", viewer: "Viewer" };
|
|
56
|
+
function Loading({ children }) {
|
|
57
|
+
return (_jsxs(Box, { display: "flex", flexDirection: "column", alignItems: "center", justifyContent: "center", gap: 3, minHeight: "60vh", children: [_jsx(Spinner, { size: "large" }), _jsx(Text, { sx: { color: "fg.muted", fontSize: 2 }, children: children })] }));
|
|
58
|
+
}
|
|
59
|
+
function IconsGrid() {
|
|
38
60
|
const [query, setQuery] = useState("");
|
|
39
|
-
return (_jsxs(
|
|
61
|
+
return (_jsxs(_Fragment, { children: [_jsx(TextInput, { leadingVisual: SearchIcon, placeholder: "Search the icons", "aria-label": "Search the icons", value: query, onChange: (event) => setQuery(event.target.value), sx: { maxWidth: 420 } }), _jsx(Suspense, { fallback: _jsx(Loading, { children: "Loading the icons..." }), children: _jsx(IconGrid, { query: query }) })] }));
|
|
62
|
+
}
|
|
63
|
+
export function IconsPage() {
|
|
64
|
+
const [searchParams, setSearchParams] = useSearchParams();
|
|
65
|
+
const view = searchParams.get("view") === "viewer" ? "viewer" : "grid";
|
|
66
|
+
const choose = (index) => {
|
|
67
|
+
const next = VIEWS[index];
|
|
68
|
+
setSearchParams((current) => {
|
|
69
|
+
const params = new URLSearchParams(current);
|
|
70
|
+
if (next === "viewer")
|
|
71
|
+
params.set("view", "viewer");
|
|
72
|
+
else
|
|
73
|
+
params.delete("view");
|
|
74
|
+
// The viewer keeps its search in `q`; the grid has its own.
|
|
75
|
+
params.delete("q");
|
|
76
|
+
return params;
|
|
77
|
+
}, { replace: true });
|
|
78
|
+
};
|
|
79
|
+
return (_jsxs(Box, { display: "flex", flexDirection: "column", gap: 3, p: 4, children: [_jsx(Box, { alignSelf: "flex-start", children: _jsx(SegmentedControl, { "aria-label": "How to show the icons", onChange: choose, children: VIEWS.map((option) => (_jsx(SegmentedControl.Button, { selected: view === option, children: VIEW_LABELS[option] }, option))) }) }), view === "viewer" ? (_jsx(Box, { mx: -4, mt: -3, children: _jsx(Suspense, { fallback: _jsx(Loading, { children: "Loading the viewer..." }), children: _jsx(IconsViewer, {}) }) })) : (_jsx(IconsGrid, {}))] }));
|
|
40
80
|
}
|
|
41
81
|
export default IconsPage;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datalayer/design",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"license": "CC-BY-4.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"watch:lib": "npm run copy:svg-assets && tsc -w"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@datalayer/icons-react": "^1.
|
|
31
|
+
"@datalayer/icons-react": "^1.1.0",
|
|
32
32
|
"@datalayer/primer-addons": "^1.0.48",
|
|
33
33
|
"@primer/css": "^21.5.1",
|
|
34
34
|
"@primer/octicons-react": "^19.42.0",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"@primer/react": "^37.31.0",
|
|
37
37
|
"@types/gif.js": "^0.2.5",
|
|
38
38
|
"gif.js": "^0.2.0",
|
|
39
|
+
"html-to-image": "^1.11.0",
|
|
39
40
|
"html2canvas": "^1.4.1",
|
|
40
41
|
"react": "19.2.8",
|
|
41
42
|
"react-dom": "19.2.8",
|