@gopherium/godmin 0.15.0 → 0.16.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 +8 -3
- package/dist/avatar.d.ts +4 -2
- package/dist/avatar.js +18 -3
- package/dist/base.css +48 -0
- package/dist/bulk.d.ts +22 -0
- package/dist/bulk.js +18 -0
- package/dist/confirm.d.ts +23 -0
- package/dist/confirm.js +12 -0
- package/dist/file-button.d.ts +24 -0
- package/dist/file-button.js +25 -0
- package/dist/frame.d.ts +2 -0
- package/dist/frame.js +9 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.js +5 -1
- package/dist/list-chrome/es-ES.js +48 -34
- package/dist/list-empty.d.ts +16 -0
- package/dist/list-empty.js +11 -0
- package/dist/list-view.d.ts +114 -0
- package/dist/list-view.js +246 -0
- package/dist/page-tabs.d.ts +1 -1
- package/dist/page-tabs.js +106 -7
- package/dist/rename.d.ts +24 -0
- package/dist/rename.js +20 -0
- package/dist/router.d.ts +2 -0
- package/dist/router.js +1 -0
- package/dist/testing.d.ts +21 -1
- package/dist/testing.js +37 -0
- package/dist/toaster.d.ts +6 -2
- package/dist/toaster.js +26 -3
- package/package.json +2 -1
package/dist/toaster.js
CHANGED
|
@@ -19,6 +19,28 @@ const DISMISS_GLYPH = '✕';
|
|
|
19
19
|
* How many toasts stay on screen at once.
|
|
20
20
|
*/
|
|
21
21
|
const LIMIT = 3;
|
|
22
|
+
/**
|
|
23
|
+
* How many characters of a name a toast shows before the ellipsis.
|
|
24
|
+
*/
|
|
25
|
+
const NAME_LENGTH = 45;
|
|
26
|
+
/**
|
|
27
|
+
* The mark that ends a name a toast cut short.
|
|
28
|
+
*/
|
|
29
|
+
const ELLIPSIS = '…';
|
|
30
|
+
/**
|
|
31
|
+
* Returns a title cut to the given number of characters, its trailing spaces trimmed and an ellipsis added.
|
|
32
|
+
* @param title - The title to name.
|
|
33
|
+
* @param length - How many characters to keep.
|
|
34
|
+
* @returns The title whole when it fits, the cut title otherwise.
|
|
35
|
+
*/
|
|
36
|
+
function cutName(title, length) {
|
|
37
|
+
const characters = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
|
|
38
|
+
const parts = Array.from(characters.segment(title), (part) => part.segment);
|
|
39
|
+
if (parts.length <= length) {
|
|
40
|
+
return title;
|
|
41
|
+
}
|
|
42
|
+
return `${parts.slice(0, length).join('').trimEnd()}${ELLIPSIS}`;
|
|
43
|
+
}
|
|
22
44
|
const ToasterContext = createContext(null);
|
|
23
45
|
/**
|
|
24
46
|
* Returns the handle raising messages in the toast region.
|
|
@@ -129,10 +151,10 @@ function ActionToast({ toast, action, dismissAfter, dismissLabel, region, onLeav
|
|
|
129
151
|
}
|
|
130
152
|
/**
|
|
131
153
|
* Renders the region holding raised messages around the given tree.
|
|
132
|
-
* @param props - The tree the region wraps,
|
|
154
|
+
* @param props - The tree the region wraps, the toast time, the close button name, how many stay and the name length.
|
|
133
155
|
* @returns The wrapped tree with its region.
|
|
134
156
|
*/
|
|
135
|
-
export function Toaster({ children, dismissAfter = DISMISS_AFTER, dismissLabel = DISMISS_LABEL, limit = LIMIT, }) {
|
|
157
|
+
export function Toaster({ children, dismissAfter = DISMISS_AFTER, dismissLabel = DISMISS_LABEL, limit = LIMIT, nameLength = NAME_LENGTH, }) {
|
|
136
158
|
const [toasts, setToasts] = useState([]);
|
|
137
159
|
const nextId = useRef(0);
|
|
138
160
|
const region = useRef(null);
|
|
@@ -158,7 +180,8 @@ export function Toaster({ children, dismissAfter = DISMISS_AFTER, dismissLabel =
|
|
|
158
180
|
speak(message, 'polite');
|
|
159
181
|
setToasts((held) => admit(held, { id, message, action, leaving: false }, limit));
|
|
160
182
|
}, [limit]);
|
|
161
|
-
const
|
|
183
|
+
const name = useCallback((title) => cutName(title, nameLength), [nameLength]);
|
|
184
|
+
const handle = useMemo(() => ({ show, name }), [show, name]);
|
|
162
185
|
const hint = useId();
|
|
163
186
|
return (_jsxs(ToasterContext.Provider, { value: handle, children: [children, _jsx("div", { ref: region, className: "godmin-toasts", tabIndex: -1, children: toasts.map((toast) => toast.action === undefined ? (_jsx(PlainToast, { toast: toast, dismissAfter: dismissAfter, hint: hint, region: region, onLeave: leave, onGone: gone }, toast.id)) : (_jsx(ActionToast, { toast: toast, action: toast.action, dismissAfter: dismissAfter, dismissLabel: dismissLabel, region: region, onLeave: leave, onGone: gone }, toast.id))) }), _jsx("span", { id: hint, hidden: true, children: dismissLabel })] }));
|
|
164
187
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gopherium/godmin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "The admin kit for Gopherium projects: host layer for React admin applications on the WordPress Design System.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -84,6 +84,7 @@
|
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@tanstack/react-router": "^1.170.18",
|
|
86
86
|
"@testing-library/react": "^16.3.2",
|
|
87
|
+
"@testing-library/user-event": "^14.6.7",
|
|
87
88
|
"@types/node": "^26.1.2",
|
|
88
89
|
"@types/react": "^19.2.17",
|
|
89
90
|
"@vitejs/plugin-react": "^6.0.3",
|