This repository has been archived by the owner on Oct 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
/
position.js
128 lines (122 loc) · 3.58 KB
/
position.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import stream from "mithril/stream";
import { styler } from "polythene-core-css";
const iconMoreVertSVG = "<svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path d=\"M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z\"/></svg>";
const styles = [
{
" .position-container": {
position: "relative",
width: "47%",
height: "230px",
background: "#fff",
margin: "0 0 10px 0",
" .bar": {
position: "relative",
width: "100%",
},
" .bar-row.pe-dark-tone": {
background: "#3F51B5",
padding: "4px 0"
}
}
}
];
styler.add("test-menu-position", styles);
const createPositionContainer = ({ h, k, Menu, List, ListTile, Shadow, IconButton }) => ({
oninit: vnode => {
const show = stream(false);
Object.assign(vnode.state, {
show,
redrawOnUpdate: stream.merge([show]) // for React
});
},
view: vnode => {
const state = vnode.state;
const attrs = vnode.attrs;
const show = state.show();
return h(".position-container.layout.vertical",
{ key: attrs.id },
[
vnode.attrs.barPosition === "bottom"
? h(".flex")
: null,
h(".bar", [
h(Shadow, { shadowDepth: 1 }),
h(Menu, {
className: "pe-light-tone",
target: `#${attrs.id}`,
origin: attrs.origin,
show,
didHide: () => state.show(false),
width: 3,
offsetH: "50%",
hideDelay: .360,
content: h(List, {
tiles: ["Refresh", "Help & Feedback", "Settings", "Sign Out"].map(title =>
h(ListTile, {
title,
positionSelected: false,
ink: true,
hoverable: true,
key: title
})
)
})
}),
h(".bar-row.pe-dark-tone.layout.horizontal", [
attrs.buttonPosition === "right"
? h(".flex")
: null,
h(IconButton, {
id: attrs.id,
icon: { svg: { content: h.trust(iconMoreVertSVG) } },
events: {
[k.onclick]: () => state.show(true)
}
})
])
])
]);
}
});
export default ({ renderer: h, keys: k, Menu, List, ListTile, Shadow, IconButton }) => {
const PositionContainer = createPositionContainer({ h, k, Menu, List, ListTile, Shadow, IconButton });
return {
view: () =>
h("div", null, [
h(".layout.horizontal",
[
h(PositionContainer, {
id: "show_menu_top_left",
origin: "top-left",
barPosition: "top",
buttonPosition: "left"
}),
h(".flex"),
h(PositionContainer, {
id: "show_menu_top_right",
origin: "top-right",
barPosition: "top",
buttonPosition: "right"
})
]
),
h(".layout.horizontal",
[
h(PositionContainer, {
id: "show_menu_bottom_left",
origin: "bottom-left",
barPosition: "bottom",
buttonPosition: "left"
}),
h(".flex"),
h(PositionContainer, {
id: "show_menu_bottom_right",
origin: "bottom-right",
barPosition: "bottom",
buttonPosition: "right"
})
]
)
])
};
};