1
1
module Html.Attributes exposing
2
- ( style, property, attribute, map
2
+ ( SrcsetImageSizeDescriptor
3
+ , style, property, attribute, map
3
4
, class, classList, id, title, hidden
4
5
, type_, value, checked, placeholder, selected
5
6
, accept, acceptCharset, action, autocomplete, autofocus
@@ -9,7 +10,7 @@ module Html.Attributes exposing
9
10
, cols, rows, wrap
10
11
, href, target, download, hreflang, media, ping, rel
11
12
, ismap, usemap, shape, coords
12
- , src, height, width, alt
13
+ , src, srcset , height, width, alt
13
14
, autoplay, controls, loop, preload, poster, default, kind, srclang
14
15
, sandbox, srcdoc
15
16
, reversed, start
@@ -52,7 +53,7 @@ just search the page for `video` if you want video stuff.
52
53
53
54
54
55
# Embedded Content
55
- @docs src, height, width, alt
56
+ @docs src, srcset, height, width, alt
56
57
57
58
## Audio and Video
58
59
@docs autoplay, controls, loop, preload, poster, default, kind, srclang
@@ -309,6 +310,36 @@ src url =
309
310
stringProperty " src" ( Elm . Kernel . VirtualDom . noJavaScriptOrHtmlUri url)
310
311
311
312
313
+ {- | Image size descriptor for `srcset` source
314
+ -}
315
+ type SrcsetImageSizeDescriptor
316
+ = PixelWidth Int
317
+ | PixelDensity Number
318
+
319
+
320
+ {- | Declare the source set of a `source` within a `picture`
321
+ -}
322
+ srcset : List ( String , Maybe SrcsetImageSizeDescriptor ) -> Attribute msg
323
+ srcset sources =
324
+ List . map
325
+ ( \ ( src, size ) ->
326
+ Elm . Kernel . VirtualDom . noJavaScriptOrHtmlUri src
327
+ ++ ( case size of
328
+ Just ( Width px) ->
329
+ " " ++ String . fromInt px ++ " w"
330
+
331
+ Just ( PixelDensity d) ->
332
+ " " ++ String . fromFloat d ++ " x"
333
+
334
+ Nothing ->
335
+ " "
336
+ )
337
+ )
338
+ sources
339
+ |> String . join " , "
340
+ |> stringProperty " srcset"
341
+
342
+
312
343
{- | Declare the height of a `canvas`, `embed`, `iframe`, `img`, `input`,
313
344
`object`, or `video`.
314
345
-}
0 commit comments