desck 0.4.2

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.
@@ -0,0 +1,302 @@
1
+ module Palette exposing (..)
2
+
3
+ import Html as H exposing (Html)
4
+ import Html.Attributes as HA exposing (style)
5
+ import Html.Events as E
6
+
7
+
8
+ type Color
9
+ = Black
10
+ | White
11
+ | Red
12
+ | Orange
13
+ | Yellow
14
+ | Green
15
+ | Cyan
16
+ | Blue
17
+ | Violet
18
+ | Pink
19
+ | DarkGray
20
+ | MidGray
21
+ | LightGray
22
+ | Transparent
23
+
24
+
25
+ colorAsString : Color -> String
26
+ colorAsString c =
27
+ case c of
28
+ Black ->
29
+ "black"
30
+
31
+ White ->
32
+ "white"
33
+
34
+ Red ->
35
+ "red"
36
+
37
+ Orange ->
38
+ "orange"
39
+
40
+ Yellow ->
41
+ "yellow"
42
+
43
+ Green ->
44
+ "green"
45
+
46
+ Cyan ->
47
+ "cyan"
48
+
49
+ Blue ->
50
+ "blue"
51
+
52
+ Violet ->
53
+ "violet"
54
+
55
+ Pink ->
56
+ "pink"
57
+
58
+ DarkGray ->
59
+ "darkGray"
60
+
61
+ MidGray ->
62
+ "midGray"
63
+
64
+ LightGray ->
65
+ "lightGray"
66
+
67
+ Transparent ->
68
+ "transparent"
69
+
70
+
71
+ colorFromString : String -> Color
72
+ colorFromString s =
73
+ case s of
74
+ "black" ->
75
+ Black
76
+
77
+ "white" ->
78
+ White
79
+
80
+ "red" ->
81
+ Red
82
+
83
+ "orange" ->
84
+ Orange
85
+
86
+ "yellow" ->
87
+ Yellow
88
+
89
+ "green" ->
90
+ Green
91
+
92
+ "cyan" ->
93
+ Cyan
94
+
95
+ "blue" ->
96
+ Blue
97
+
98
+ "violet" ->
99
+ Violet
100
+
101
+ "pink" ->
102
+ Pink
103
+
104
+ "darkGray" ->
105
+ DarkGray
106
+
107
+ "midGray" ->
108
+ MidGray
109
+
110
+ "lightGray" ->
111
+ LightGray
112
+
113
+ "transparent" ->
114
+ Transparent
115
+
116
+ _ ->
117
+ Pink
118
+
119
+
120
+ type alias Palette =
121
+ { black : String
122
+ , white : String
123
+ , red : String
124
+ , orange : String
125
+ , yellow : String
126
+ , green : String
127
+ , cyan : String
128
+ , blue : String
129
+ , violet : String
130
+ , pink : String
131
+ , darkGray : String
132
+ , midGray : String
133
+ , lightGray : String
134
+ }
135
+
136
+
137
+ paletteAsList : Palette -> List ( Color, String )
138
+ paletteAsList palette =
139
+ [ ( Black, palette.black )
140
+ , ( DarkGray, palette.darkGray )
141
+ , ( MidGray, palette.midGray )
142
+ , ( LightGray, palette.lightGray )
143
+ , ( White, palette.white )
144
+ , ( Red, palette.red )
145
+ , ( Orange, palette.orange )
146
+ , ( Yellow, palette.yellow )
147
+ , ( Green, palette.green )
148
+ , ( Cyan, palette.cyan )
149
+ , ( Blue, palette.blue )
150
+ , ( Violet, palette.violet )
151
+ , ( Pink, palette.pink )
152
+ ]
153
+
154
+
155
+ getColor : Palette -> Color -> String
156
+ getColor palette color =
157
+ case color of
158
+ Black ->
159
+ palette.black
160
+
161
+ White ->
162
+ palette.white
163
+
164
+ Red ->
165
+ palette.red
166
+
167
+ Orange ->
168
+ palette.orange
169
+
170
+ Yellow ->
171
+ palette.yellow
172
+
173
+ Green ->
174
+ palette.green
175
+
176
+ Cyan ->
177
+ palette.cyan
178
+
179
+ Blue ->
180
+ palette.blue
181
+
182
+ Violet ->
183
+ palette.violet
184
+
185
+ Pink ->
186
+ palette.pink
187
+
188
+ DarkGray ->
189
+ palette.darkGray
190
+
191
+ MidGray ->
192
+ palette.midGray
193
+
194
+ LightGray ->
195
+ palette.lightGray
196
+
197
+ Transparent ->
198
+ "#00000000"
199
+
200
+
201
+ setPaletteColor : Palette -> Color -> String -> Palette
202
+ setPaletteColor p c v =
203
+ case c of
204
+ Black ->
205
+ { p | black = v }
206
+
207
+ White ->
208
+ { p | white = v }
209
+
210
+ Red ->
211
+ { p | red = v }
212
+
213
+ Orange ->
214
+ { p | orange = v }
215
+
216
+ Yellow ->
217
+ { p | yellow = v }
218
+
219
+ Green ->
220
+ { p | green = v }
221
+
222
+ Cyan ->
223
+ { p | cyan = v }
224
+
225
+ Blue ->
226
+ { p | blue = v }
227
+
228
+ Violet ->
229
+ { p | violet = v }
230
+
231
+ Pink ->
232
+ { p | pink = v }
233
+
234
+ DarkGray ->
235
+ { p | darkGray = v }
236
+
237
+ MidGray ->
238
+ { p | midGray = v }
239
+
240
+ LightGray ->
241
+ { p | lightGray = v }
242
+
243
+ Transparent ->
244
+ p
245
+
246
+
247
+ colorPicker : Bool -> Palette -> (String -> msg) -> Color -> Html msg
248
+ colorPicker addTransparent palette message current =
249
+ let
250
+ sections : List (List ( Color, String ))
251
+ sections =
252
+ [ [ Red, Orange, Yellow, Green, Cyan, Blue, Violet ]
253
+ , [ Transparent, Black, DarkGray, MidGray, LightGray, White, Pink ]
254
+ ]
255
+ |> List.map (\s -> List.map (\c -> ( c, getColor palette c )) s)
256
+
257
+ colorButton : Int -> ( Color, String ) -> Html msg
258
+ colorButton i ( color, c ) =
259
+ let
260
+ name =
261
+ colorAsString color
262
+ in
263
+ H.button
264
+ ([ style "background-color" c
265
+ , style "color" c
266
+ , HA.title name
267
+ , HA.class "palette-color"
268
+ , HA.class name
269
+ , HA.class
270
+ (if color == current then
271
+ "palette-color-selected"
272
+
273
+ else
274
+ ""
275
+ )
276
+ ]
277
+ ++ (if color /= Transparent || addTransparent then
278
+ [ E.onClick <| message name
279
+ ]
280
+
281
+ else
282
+ [ style "opacity" <| String.fromFloat 0.0 ]
283
+ )
284
+ )
285
+ []
286
+ in
287
+ sections
288
+ |> List.indexedMap
289
+ (\i colors ->
290
+ List.indexedMap
291
+ (\j c -> colorButton (i * 7 + j) c)
292
+ colors
293
+ |> H.div
294
+ [ HA.class "color-palette"
295
+ ]
296
+ )
297
+ |> H.span []
298
+
299
+
300
+ colorPickerWithTransparent : Palette -> (String -> msg) -> Color -> Html msg
301
+ colorPickerWithTransparent =
302
+ colorPicker True