vanilla-jui 1.4.3 → 1.4.4
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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
- package/src/components/menu.ts +10 -4
package/package.json
CHANGED
package/src/components/menu.ts
CHANGED
|
@@ -34,7 +34,7 @@ export interface MenuItem extends Record<string, unknown> {
|
|
|
34
34
|
title: string | number;
|
|
35
35
|
url?: string;
|
|
36
36
|
target?: string;
|
|
37
|
-
classes?: string[];
|
|
37
|
+
classes?: string | string[];
|
|
38
38
|
children?: MenuItem[];
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -118,6 +118,13 @@ function classList(...tokens: Array<string | null | undefined>): string {
|
|
|
118
118
|
return tokens.filter(Boolean).join(' ');
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
function normalizeItemClasses(classes: MenuItem['classes']): string[] {
|
|
122
|
+
if (classes == null) return [];
|
|
123
|
+
if (typeof classes === 'string')
|
|
124
|
+
return classes.trim().split(/\s+/).filter(Boolean);
|
|
125
|
+
return classes;
|
|
126
|
+
}
|
|
127
|
+
|
|
121
128
|
function itemId(id: MenuItemId | undefined): string {
|
|
122
129
|
return `menu-item-${id ?? randomId()}`;
|
|
123
130
|
}
|
|
@@ -141,6 +148,7 @@ function isMenuItem(value: unknown): value is MenuItem {
|
|
|
141
148
|
(item.url == null || typeof item.url === 'string') &&
|
|
142
149
|
(item.target == null || typeof item.target === 'string') &&
|
|
143
150
|
(item.classes == null ||
|
|
151
|
+
typeof item.classes === 'string' ||
|
|
144
152
|
(Array.isArray(item.classes) &&
|
|
145
153
|
item.classes.every((className) => typeof className === 'string'))) &&
|
|
146
154
|
(item.children == null ||
|
|
@@ -301,9 +309,7 @@ export class Menu {
|
|
|
301
309
|
classes.push(className.hasChildren);
|
|
302
310
|
}
|
|
303
311
|
|
|
304
|
-
|
|
305
|
-
classes.push(...item.classes);
|
|
306
|
-
}
|
|
312
|
+
classes.push(...normalizeItemClasses(item.classes));
|
|
307
313
|
|
|
308
314
|
const children: Node[] = [
|
|
309
315
|
jsx('a', {
|