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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
(* Copyright 2015 Google Inc.
Copyright 2016, 2017 Benjamin Barenblat
Licensed under the Apache License, Version 2.0 (the “License”); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License. *)
style materialIcon
style stackingContext
fun icon s = <xml><i class={materialIcon}>{[s]}</i></xml>
fun inNewStackingContext x = <xml><div class={stackingContext}>{x}</div></xml>
structure Ripple : sig
val make : int (* radius *)
-> transaction { Placeholder : xbody,
Trigger : { X : int, Y : int }
-> transaction unit }
end = struct
style ink
fun inkStyle radius xy =
let
fun p a b = value (property a) (atom (show b ^ "px"))
val diameter = 2 * radius
in
oneProperty
(oneProperty
(oneProperty
(oneProperty noStyle
(p "width" diameter))
(p "height" diameter))
(p "left" (xy.X - radius)))
(p "top" (xy.Y - radius))
end
fun inkAnimation radius s = <xml>
<dyn signal={v <- signal s;
return (case v of
None => <xml></xml>
| Some xy =>
<xml>
<span class={ink}
style={inkStyle radius xy}>
</span>
</xml>)} />
</xml>
fun make radius =
center <- source None;
return {Placeholder = inkAnimation radius center,
Trigger = fn xy => set center (Some xy)}
end
(* TODO(bbaren): Support attributes in the arguments. *)
fun page p = <xml>
<head>
<link rel="stylesheet"
href="https://fonts.googleapis.com/icon?family=Material+Icons" />
<link rel="stylesheet" href="/material.css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
(* Disable tap highlight on IE. *)
<meta name="msapplication-tap-highlight" content="no" />
(* Color the status bar on mobile devices. *)
<meta name="theme-color" content="#9c27b0" />
{p.Head}
</head>
<body>{p.Body}</body>
</xml>
structure AppBar = struct
style bar
style title
fun make t = <xml>
<header class={bar}>
<h1 class={title}>{[t]}</h1>
</header>
</xml>
end
structure Checkbox = struct
style checkbox
style checked
style container
(* Pixel dimensions of the checkbox. If you update these, you must also
update the CSS file. *)
val width = 24
val height = 24
val make c onChange =
s <- source c;
ink <- Ripple.make (width / 2);
return (inNewStackingContext <xml>
<div class={container}>
{ink.Placeholder}
<span dynClass={c <- signal s;
return (classes checkbox
(if c then checked else null))}
onclick={fn click =>
ink.Trigger {X = click.ClientX,
Y = click.ClientY};
c <- get s;
let
val c' = not c
in
set s c';
onChange c'
end}></span>
</div>
</xml>)
end
structure FloatingActionButton = struct
style container
style element
(* Pixel dimensions of the button. If you update these, you must also
update the CSS file. *)
val width = 56
val height = 56
fun make s clickHandler =
ink <- Ripple.make (width / 2);
return <xml>
<div class={container}>
<button class={element}
onclick={fn click =>
ink.Trigger {X = click.ClientX,
Y = click.ClientY};
clickHandler click}>
{icon s}
</button>
{ink.Placeholder}
</div>
</xml>
end
structure List = struct
structure SingleLine = struct
style element
style icon
style list
fun make es = <xml><ul class={list}>{es}</ul></xml>
fun item i = <xml>
<li class={element}>
<span class={icon}>{i.Icon}</span>
{i.Content}
</li>
</xml>
end
end
|