summaryrefslogtreecommitdiff
path: root/material/material.ur
blob: 72a3e982aae0a95de2798c3df7201ae0a34638bd (plain)
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
(* 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 stackingContext

fun inNewStackingContext x = <xml><div class={stackingContext}>{x}</div></xml>

(* TODO(bbaren): Support attributes in the arguments. *)
fun page p = <xml>
  <head>
    <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
  style ink

  (* Pixel dimensions of the checkbox.  If you update these, you must also
  update the CSS file. *)
  val width = 24
  val height = 24

  fun centeredAtXY x y : css_style =
    let
      val x' = x - width / 2
      val y' = y - width / 2
    in
      oneProperty (oneProperty
                     noStyle
                     (value (property "left") (atom (show x' ^ "px"))))
                  (value (property "top") (atom (show y' ^ "px")))
    end

  fun inkAnimation (s : source (option {X : int, Y : int})) =
    <xml>
      <dyn
        signal={
          v <- signal s;
          return (case v of
                      None => <xml></xml>
                    | Some xy => <xml>
                        <span class={ink} style={centeredAtXY xy.X xy.Y}></span>
                      </xml>)
        }
      />
    </xml>

  val make c onChange =
    s <- source c;
    inkCenter <- source None;
    return (inNewStackingContext <xml>
      {inkAnimation inkCenter}
      <span
        dynClass={
          c <- signal s;
          return (classes checkbox (if c then checked else null))
        }
        onclick={fn click =>
          set inkCenter (Some {X = click.ClientX, Y = click.ClientY});
          c <- get s;
          let
            val c' = not c
          in
            set s c';
            onChange c'
          end
        }
      >
      </span>
      </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