aleman 1.1.33 → 1.1.35
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/menu/addons/click.js
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
<ul data-name="menu" class="menu menu-hidden">
|
|
2
|
-
<li data-name='menu-item' className='menu-item'>
|
|
3
|
-
<label>hello</label>
|
|
4
|
-
</li>
|
|
5
|
-
<li data-name='menu-item' className='menu-item'>
|
|
6
|
-
<label>world</label>
|
|
7
|
-
</li>
|
|
8
|
-
</ul>;
|
|
1
|
+
<ul data-name="menu" class="menu menu-hidden"><li data-name='menu-item' className='menu-item'><label>hello</label></li><li data-name='menu-item' className='menu-item'><label>world</label></li></ul>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<ul data-name="menu" class="menu menu-hidden"><li data-name='menu-item' className='menu-item icon icon-hello'><label>hello</label></li><li data-name='menu-item' className='menu-item icon icon-world'><label>world</label></li></ul>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<ul data-name="menu" class="menu menu-hidden"></ul>;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import {types, template} from 'putout';
|
|
2
2
|
|
|
3
|
-
const {entries} = Object;
|
|
3
|
+
const {entries, keys} = Object;
|
|
4
4
|
const noop = () => {};
|
|
5
5
|
const {jsxText} = types;
|
|
6
6
|
|
|
7
7
|
export const report = () => `Build menu`;
|
|
8
8
|
|
|
9
9
|
const createMenuItem = template(`
|
|
10
|
-
<li data-name="menu-item" className="menu-item">
|
|
11
|
-
<label>NAME</label>
|
|
12
|
-
</li>
|
|
10
|
+
<li data-name="menu-item" className="menu-item"><label>NAME</label></li>
|
|
13
11
|
`);
|
|
14
12
|
|
|
15
13
|
const NEWLINE = jsxText('\n');
|
|
@@ -20,17 +18,20 @@ const DefaultMenu = {
|
|
|
20
18
|
world: noop,
|
|
21
19
|
};
|
|
22
20
|
|
|
23
|
-
export const fix = ({path, menu}) => {
|
|
21
|
+
export const fix = ({path, menu, icon}) => {
|
|
24
22
|
const items = [];
|
|
25
23
|
|
|
26
|
-
for (const
|
|
24
|
+
for (const key of keys(menu)) {
|
|
27
25
|
const menuItem = createMenuItem();
|
|
28
26
|
|
|
29
|
-
menuItem.children[
|
|
30
|
-
|
|
27
|
+
menuItem.children[0].children[0].value = key;
|
|
28
|
+
|
|
29
|
+
if (icon)
|
|
30
|
+
setIcon(key, menuItem);
|
|
31
|
+
|
|
32
|
+
items.push(menuItem);
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
items.push(NEWLINE);
|
|
34
35
|
path.parentPath.node.children = items;
|
|
35
36
|
};
|
|
36
37
|
|
|
@@ -39,6 +40,7 @@ export const traverse = ({options, push}) => ({
|
|
|
39
40
|
const {
|
|
40
41
|
name = 'menu',
|
|
41
42
|
menu = DefaultMenu,
|
|
43
|
+
icon = false,
|
|
42
44
|
} = options;
|
|
43
45
|
|
|
44
46
|
if (!checkDataName(path, name))
|
|
@@ -50,6 +52,7 @@ export const traverse = ({options, push}) => ({
|
|
|
50
52
|
push({
|
|
51
53
|
path,
|
|
52
54
|
menu,
|
|
55
|
+
icon,
|
|
53
56
|
});
|
|
54
57
|
},
|
|
55
58
|
});
|
|
@@ -64,3 +67,21 @@ function checkDataName(path, dataName) {
|
|
|
64
67
|
|
|
65
68
|
return false;
|
|
66
69
|
}
|
|
70
|
+
|
|
71
|
+
function setIcon(name, menuItem) {
|
|
72
|
+
const {attributes} = menuItem.openingElement;
|
|
73
|
+
|
|
74
|
+
for (const attr of attributes) {
|
|
75
|
+
if (attr.name.name === 'className') {
|
|
76
|
+
attr.value.value += ` icon ${getIconName(name)}`;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function getIconName(name) {
|
|
83
|
+
return 'icon-' + name
|
|
84
|
+
.replace(/[()]/g, '')
|
|
85
|
+
.replace(/\s/g, '-')
|
|
86
|
+
.toLowerCase();
|
|
87
|
+
}
|