-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathLayout.elm
1079 lines (898 loc) · 30.9 KB
/
Layout.elm
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module Material.Layout
exposing
( init
, subscriptions
, Model
, defaultModel
, Msg(ToggleDrawer)
, update
, Property
, fixedDrawer
, fixedTabs
, fixedHeader
, rippleTabs
, waterfall
, seamed
, scrolling
, selectedTab
, onSelectTab
, row
, spacer
, title
, navigation
, link
, href
, setTabsWidth
, Contents
, view
, sub0
, subs
, render
, react
, toggleDrawer
, transparentHeader
)
{-| From the
[Material Design Lite documentation](https://www.getmdl.io/components/index.html#layout-section):
> The Material Design Lite (MDL) layout component is a comprehensive approach to
> page layout that uses MDL development tenets, allows for efficient use of MDL
> components, and automatically adapts to different browsers, screen sizes, and
> devices.
>
> Appropriate and accessible layout is a critical feature of all user interfaces,
> regardless of a site's content or function. Page design and presentation is
> therefore an important factor in the overall user experience. See the layout
> component's
> [Material Design specifications page](https://www.google.com/design/spec/layout/structure.html#structure-system-bars)
> for details.
>
> Use of MDL layout principles simplifies the creation of scalable pages by
> providing reusable components and encourages consistency across environments by
> establishing recognizable visual elements, adhering to logical structural
> grids, and maintaining appropriate spacing across multiple platforms and screen
> sizes. MDL layout is extremely powerful and dynamic, allowing for great
> consistency in outward appearance and behavior while maintaining development
> flexibility and ease of use.
Refer to [this site](https://debois.github.io/elm-mdl/#layout)
for a live demo and example code.
# Subscriptions
The layout needs to be initialised with and subscribe to changes in viewport
sizes. Example initialisation of containing app:
import Material.Layout as Layout
import Material
type alias Model =
{ ...
, mdl : Material.Model -- Boilerplate
}
type Msg =
...
| Mdl Material.Msg -- Boilerplate
...
App.program
{ init = ( model, Layout.sub0 Mdl )
, view = view
, subscriptions = Layout.subs Mdl model
, update = update
}
## Tabs width
Tabs display chevrons when the viewport is too small to show all tabs
simultaneously. Unfortunately, Elm currently does not give us a way to
automatically detect the width of the tabs at app launch. If you have tabs,
to make the chevron display correctly at app lauch, you must set
`model.tabScrollState.width` manually in `init`. If you're using shorthands,
use `setTabScrollState` to accomplish this. Initialisation would in this case
be (assuming a tab width of 1384 pixels):
App.program
{ init =
( { model | mdl = Layout.setTabsWidth 1384 model.mdl }
, Layout.sub0 Mdl
)
, view = view
, subscriptions = .mdl >> Layout.subs Mdl
, update = update
}
@docs sub0, subs
# Render
@docs Contents, render, toggleDrawer
# Options
@docs Property
## Tabs
@docs fixedTabs, rippleTabs
@docs selectedTab, setTabsWidth
## Header
@docs fixedHeader, fixedDrawer
@docs waterfall, seamed, scrolling
@docs transparentHeader
## Events
@docs onSelectTab
# Sub-views
@docs row, spacer, title, navigation, link, href
# Elm architecture
@docs view, Msg, Model, defaultModel, update, init, subscriptions
# Internal use
@docs react
-}
import Dict exposing (Dict)
import Maybe exposing (andThen, map)
import Html exposing (..)
import Html.Attributes exposing (class, classList, tabindex)
import Html.Events as Events exposing (on)
import Html.Keyed as Keyed
import Platform.Cmd exposing (Cmd)
import Window
import Json.Decode as Decoder exposing (field)
import Task
import Material.Component as Component exposing (Indexed, indexed, render1, subs)
import Material.Helpers as Helpers exposing (filter, delay, pure, map1st, map2nd)
import Material.Ripple as Ripple
import Material.Icon as Icon
import Material.Options as Options exposing (Style, cs, nop, css, when, styled)
import Material.Options.Internal as Internal
import DOM
-- SETUP
{-| Layout needs initial viewport size
-}
init : ( Model, Cmd Msg )
init =
let
measureScreenSize =
Task.perform Resize Window.width
in
( defaultModel, measureScreenSize )
{-| Layout subscribes to changes in viewport size.
-}
subscriptions : Model -> Sub Msg
subscriptions model =
Window.resizes (.width >> Resize)
-- MODEL
type alias TabScrollState =
{ canScrollLeft : Bool
, canScrollRight : Bool
, width : Maybe Int
}
{- Elm don't give us a good way to measure the width of the tabs, so we
arbitrarily decide that they probably can't scroll. The user can adjust this
decision by supplying his own estimate of what the width of the tabsWidth might
be.
-}
defaultTabScrollState : TabScrollState
defaultTabScrollState =
{ canScrollRight = True
, canScrollLeft = False
, width = Nothing
}
setTabsWidth_ : Int -> Model -> Model
setTabsWidth_ width model =
let
x =
model.tabScrollState
in
{ model
| tabScrollState =
{ x | width = Just width }
}
{-| Component model.
-}
type alias Model =
{ ripples : Dict Int Ripple.Model
, isSmallScreen : Bool
, isCompact : Bool
, isAnimating : Bool
, isScrolled : Bool
, isDrawerOpen : Bool
, tabScrollState : TabScrollState
}
{-| Default component model.
-}
defaultModel : Model
defaultModel =
{ ripples = Dict.empty
, isSmallScreen = False
, isCompact = False
, isAnimating = False
, isScrolled = False
, isDrawerOpen = False
, tabScrollState = defaultTabScrollState
}
-- ACTIONS, UPDATE
{-| Component messages.
-}
type Msg
= ToggleDrawer
| Resize Int
| ScrollTab TabScrollState
| ScrollPane Bool Float
-- True means fixedHeader
| TransitionHeader { toCompact : Bool, fixedHeader : Bool }
| TransitionEnd
| NOP
-- Subcomponents
| Ripple Int Ripple.Msg
{-| Component update.
-}
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
update_ identity msg model
|> Maybe.withDefault ( model, Cmd.none )
{-| Component update for shorthand.
-}
update_ : (Msg -> msg) -> Msg -> Model -> Maybe ( Model, Cmd msg )
update_ f action model =
case action of
NOP ->
Nothing
Resize width ->
{- High-frequency message. To avoid stuttering during resizes, we must
return referentially the same model if we're not making any updates. (And
the user must be using Html.Lazy.)
-}
let
isSmall =
1024 >= width
tabScrollState =
model.tabScrollState.width
|> Maybe.map
(\tabsWidth ->
let
tabScrollState =
model.tabScrollState
in
{ tabScrollState
| canScrollRight = tabsWidth + (2 * 56) {- chevrons -} > width
}
)
|> Maybe.withDefault model.tabScrollState
{- We have no idea how much horisontal space tabs consume, so we have no
idea whether they scroll or not.
-}
in
if
isSmall
== model.isSmallScreen
&& tabScrollState.canScrollRight
== model.tabScrollState.canScrollRight
then
Nothing
else
Just <|
pure
{ model
| isSmallScreen = isSmall
, isDrawerOpen = not isSmall && model.isDrawerOpen
, tabScrollState = tabScrollState
}
ToggleDrawer ->
Just <| pure { model | isDrawerOpen = not model.isDrawerOpen }
Ripple tabIndex action_ ->
Dict.get tabIndex model.ripples
|> Maybe.withDefault Ripple.model
|> Ripple.update action_
|> map1st
(\ripple_ ->
{ model | ripples = Dict.insert tabIndex ripple_ model.ripples }
)
|> map2nd (Cmd.map (f << Ripple tabIndex))
|> Just
ScrollTab state ->
{- High-frequency message. To avoid stuttering during scrolling, we must
return a referentially identical model if we're making no changes.
-}
if model.tabScrollState /= state then
Just <| pure { model | tabScrollState = state }
else
Nothing
ScrollPane fixedHeader offset ->
{- High-frequency message. To avoid stuttering during scrolling, we must
return a referentially identical model if we're making no changes.
-}
let
isScrolled =
0.0 < offset
in
if isScrolled /= model.isScrolled then
update_ f
(TransitionHeader { toCompact = isScrolled, fixedHeader = fixedHeader })
{ model | isScrolled = isScrolled }
else
Nothing
TransitionHeader { toCompact, fixedHeader } ->
if not model.isAnimating then
Just
( { model
| isCompact = toCompact
, isAnimating = (not model.isSmallScreen) || fixedHeader
}
, Cmd.none
)
else
Nothing
TransitionEnd ->
pure { model | isAnimating = False } |> Just
-- PROPERTIES
type alias Config m =
{ fixedHeader : Bool
, fixedDrawer : Bool
, fixedTabs : Bool
, rippleTabs : Bool
, mode : Mode
, selectedTab : Int
, onSelectTab : Maybe (Int -> Attribute m)
, transparentHeader : Bool
, moreTabs : Bool
}
defaultConfig : Config m
defaultConfig =
{ fixedHeader = False
, fixedDrawer = False
, fixedTabs = False
, rippleTabs = True
, mode = Standard
, onSelectTab = Nothing
, selectedTab = -1
, moreTabs = False
, transparentHeader = False
}
{-| Layout options.
-}
type alias Property m =
Options.Property (Config m) m
{-| Header is "fixed": It appears even on small screens.
-}
fixedHeader : Property m
fixedHeader =
Internal.option (\config -> { config | fixedHeader = True })
{-| Drawer is "fixed": It is always open on large screens.
-}
fixedDrawer : Property m
fixedDrawer =
Internal.option (\config -> { config | fixedDrawer = True })
{-| Tabs are spread out to consume available space and do not scroll horisontally.
-}
fixedTabs : Property m
fixedTabs =
Internal.option (\config -> { config | fixedTabs = True })
{-| Make tabs ripple when clicked.
-}
rippleTabs : Property m
rippleTabs =
Internal.option (\config -> { config | rippleTabs = True })
{-| Header behaves as "Waterfall" header: On scroll, the top (argument `True`) or
the bottom (argument `False`) of the header disappears.
-}
waterfall : Bool -> Property m
waterfall =
Internal.option
<< (\b config -> { config | mode = Waterfall b })
{-| Header behaves as "Seamed" header: it does not cast shadow, is permanently
affixed to the top of the screen.
-}
seamed : Property m
seamed =
Internal.option (\config -> { config | mode = Seamed })
{-| Header is transparent: It draws on top of the layout's background
-}
transparentHeader : Property m
transparentHeader =
Internal.option (\config -> { config | transparentHeader = True })
{-| Header scrolls with contents.
-}
scrolling : Property m
scrolling =
Internal.option (\config -> { config | mode = Scrolling })
{-| Set the selected tab.
-}
selectedTab : Int -> Property m
selectedTab =
Internal.option
<< (\k config -> { config | selectedTab = k })
{-| Set this property if tabs are missing the "more tabs on the right" indicator
chevron on app launch.
(Elm core libraries currently don't give us a good way to determine this situation
automatically.)
-}
moreTabs : Property m
moreTabs =
Internal.option (\config -> { config | moreTabs = True })
{-| Receieve notification when tab `k` is selected.
-}
onSelectTab : (Int -> m) -> Property m
onSelectTab =
Internal.option << (\f config -> { config | onSelectTab = Just (f >> Events.onClick) })
-- AUXILIARY VIEWS
{-| Push subsequent elements in header row or drawer column to the right/bottom.
-}
spacer : Html m
spacer =
div [ class "mdl-layout-spacer" ] []
{-| Title in header row or drawer.
-}
title : List (Options.Style m) -> List (Html m) -> Html m
title styles =
Options.span (cs "mdl-layout__title" :: styles)
{-| Container for links.
-}
navigation : List (Options.Style m) -> List (Html m) -> Html m
navigation styles contents =
Options.styled Html.nav (cs "mdl-navigation" :: styles) contents
{-| href attribute for links
-}
href : String -> Options.Style m
href url =
Options.attribute <| Html.Attributes.href url
{-| Link.
-}
link : List (Options.Style m) -> List (Html m) -> Html m
link styles contents =
Options.styled a
(cs "mdl-navigation__link"
:: Internal.attribute (Html.Attributes.attribute "tabindex" "1")
:: styles
)
contents
{-| Header row.
-}
row : List (Options.Style m) -> List (Html m) -> Html m
row styles =
Options.div (cs "mdl-layout__header-row" :: styles)
-- MAIN VIEWS
{-| Mode for the header.
- A `Standard` header casts shadow, is permanently affixed to the top of the screen.
- A `Seamed` header does not cast shadow, is permanently affixed to the top of the
screen.
- A `Scroll`'ing header scrolls with contents.
- A `Waterfall` header drops either the top (argument True) or bottom (argument False)
header-row when content scrolls.
-}
type Mode
= Standard
| Seamed
| Scrolling
| Waterfall Bool
isWaterfall : Mode -> Bool
isWaterfall mode =
case mode of
Waterfall _ ->
True
_ ->
False
toList : Maybe a -> List a
toList x =
case x of
Nothing ->
[]
Just y ->
[ y ]
type Direction
= Left
| Right
tabsView : (Msg -> m) -> Config m -> Model -> ( List (Html m), List (Style m) ) -> Html m
tabsView lift config model ( tabs, tabStyles ) =
let
chevron direction offset =
let
dir =
case direction of
Left ->
"left"
Right ->
"right"
in
styled div
[ cs "mdl-layout__tab-bar-button"
, cs ("mdl-layout__tab-bar-" ++ dir ++ "-button")
, (cs "is-active")
|> when
((direction == Left && model.tabScrollState.canScrollLeft)
|| (direction == Right && model.tabScrollState.canScrollRight)
)
, Options.many tabStyles
]
[ Icon.view ("chevron_" ++ dir)
[ Icon.size24
, Html.Attributes.attribute
"onclick"
("document.getElementsByClassName('mdl-layout__tab-bar')[0].scrollLeft += " ++ toString offset)
|> Internal.attribute
]
]
in
Options.div
[ cs "mdl-layout__tab-bar-container" ]
[ chevron Left -100
, Options.div
[ cs "mdl-layout__tab-bar"
, css "position" "relative"
-- Workaround for debois/elm-dom#4.
, css "scroll-behavior" "smooth"
, if config.rippleTabs then
Options.many
[ cs "mdl-js-ripple-effect"
, cs "mds-js-ripple-effect--ignore-events"
]
else
nop
, if config.mode == Standard then
cs "is-casting-shadow"
else
nop
, Options.many tabStyles
, Internal.attribute <|
on "scroll"
(DOM.target
(Decoder.map3
(\scrollWidth clientWidth scrollLeft ->
{ canScrollLeft = scrollLeft > 0
, canScrollRight = scrollWidth - clientWidth > scrollLeft + 1
, width = Just scrollWidth
}
|> ScrollTab
|> lift
)
(field "scrollWidth" Decoder.float)
(field "clientWidth" Decoder.float)
(field "scrollLeft" Decoder.float)
)
)
]
(tabs
|> List.indexedMap
(\tabIndex tab ->
filter a
[ classList
[ ( "mdl-layout__tab", True )
, ( "is-active", tabIndex == config.selectedTab )
]
, config.onSelectTab
|> Maybe.map ((|>) tabIndex)
|> Maybe.withDefault Helpers.noAttr
]
[ Just tab
, if config.rippleTabs then
Dict.get tabIndex model.ripples
|> Maybe.withDefault Ripple.model
|> Ripple.view [ class "mdl-layout__tab-ripple-container" ]
|> Html.map (Ripple tabIndex >> lift)
|> Just
else
Nothing
]
)
)
, chevron Right 100
]
headerView :
(Msg -> m)
-> Config m
-> Model
-> ( Maybe (Html m), List (Html m), Maybe (Html m) )
-> Html m
headerView lift config model ( drawerButton, rows, tabs ) =
let
mode =
case config.mode of
Standard ->
nop
Scrolling ->
cs "mdl-layout__header--scroll"
Seamed ->
cs "mdl-layout__header--seamed"
Waterfall True ->
cs "mdl-layout__header--waterfall mdl-layout__header--waterfall-hide-top"
Waterfall False ->
cs "mdl-layout__header--waterfall"
in
Options.styled Html.header
[ cs "mdl-layout__header"
, when
(config.mode
== Standard
|| (isWaterfall config.mode && model.isCompact)
)
(cs "is-casting-shadow")
, when model.isAnimating (cs "is-animating")
, when model.isCompact (cs "is-compact")
, mode
, when config.transparentHeader (cs "mdl-layout__header--transparent")
, Options.onClick
(TransitionHeader { toCompact = False, fixedHeader = config.fixedHeader }
|> lift
)
, Options.on "transitionend" (Decoder.succeed <| lift TransitionEnd)
]
(List.concatMap (\x -> x)
[ toList drawerButton
, rows
, toList tabs
]
)
onKeypressFilterSpaceAndEnter : Html.Attribute x
onKeypressFilterSpaceAndEnter =
"""
(function (evt) {
if (evt && evt.type === "keydown" && (evt.keyCode === 32 || evt.keyCode === 13)) {
evt.preventDefault();
}
})(window.event);
"""
|> Html.Attributes.attribute "onkeypress"
drawerButton : (Msg -> m) -> Bool -> Html m
drawerButton lift isVisible =
div
[--onKeypressFilterSpaceAndEnter
]
[ div
[ classList
[ ( "mdl-layout__drawer-button", True )
]
, Html.Attributes.attribute
"aria-expanded"
(if isVisible then
"true"
else
"false"
)
, tabindex 1
{- No-one else is putting events on the drawerbutton, so we don't
need to go through dispatch here. -}
, Events.onClick (lift ToggleDrawer)
, Events.onWithOptions
"keydown"
{ stopPropagation = False
, preventDefault =
False
-- True
{- Should stop propagation exclusively on ENTER, but elm
currently require me to decide on options before the keycode
value is available.
-}
}
(Decoder.map
(lift
<< \key ->
case key of
32
{- SPACE -}
->
ToggleDrawer
13
{- ENTER -}
->
ToggleDrawer
_ ->
NOP
)
Events.keyCode
)
]
[ Icon.i "menu" ]
]
obfuscator : (Msg -> m) -> Bool -> Html m
obfuscator lift isVisible =
div
[ classList
[ ( "mdl-layout__obfuscator", True )
, ( "is-visible", isVisible )
]
, Events.onClick (lift ToggleDrawer)
]
[]
drawerView : (Msg -> m) -> Bool -> List (Html m) -> Html m
drawerView lift isVisible elems =
div
[ classList
[ ( "mdl-layout__drawer", True )
, ( "is-visible", isVisible )
]
, Html.Attributes.attribute
"aria-hidden"
(if isVisible then
"false"
else
"true"
)
]
elems
{-| Content of the layout only (contents of main pane is set elsewhere). Every
part is optional; if you supply an empty list for either, the sub-component is
omitted.
The `header` and `drawer` contains the contents of the header rows and drawer,
respectively. Use `row`, `spacer`, `title`, `nav`, and `link`, as well as
regular Html to construct these. The `tabs` contains
the title of each tab.
-}
type alias Contents m =
{ header : List (Html m)
, drawer : List (Html m)
, tabs : ( List (Html m), List (Style m) )
, main : List (Html m)
}
{-| Main layout view.
-}
view : (Msg -> m) -> Model -> List (Property m) -> Contents m -> Html m
view lift model options { drawer, header, tabs, main } =
let
summary =
Internal.collect defaultConfig options
config =
summary.config
( contentDrawerButton, headerDrawerButton ) =
case ( drawer, header, config.fixedHeader ) of
( _ :: _, _ :: _, True ) ->
-- Drawer with fixedHeader: Add the button to the header
( Nothing, Just <| drawerButton lift drawerIsVisible )
( _ :: _, _, _ ) ->
-- Drawer, no or non-fixed header: Add the button before contents.
( Just <| drawerButton lift drawerIsVisible, Nothing )
_ ->
-- No drawer: no button.
( Nothing, Nothing )
hasTabs =
not (List.isEmpty (Tuple.first tabs))
hasHeader =
hasTabs || (not (List.isEmpty header))
hasDrawer =
drawer /= []
drawerIsFixed =
config.fixedDrawer && not model.isSmallScreen
drawerIsVisible =
model.isDrawerOpen && not drawerIsFixed
tabsElems =
if not hasTabs then
Nothing
else
Just (tabsView lift config model tabs)
in
div
[ classList
[ ( "mdl-layout__container", True )
, ( "has-scrolling-header", config.mode == Scrolling )
]
]
[ filter (Keyed.node "div")
([ Just <|
classList
[ ( "mdl-layout ", True )
, ( "is-upgraded", True )
, ( "is-small-screen", model.isSmallScreen )
, ( "has-drawer", hasDrawer )
, ( "has-tabs", hasTabs )
, ( "mdl-js-layout", True )
, ( "mdl-layout--fixed-drawer", config.fixedDrawer && hasDrawer )
, ( "mdl-layout--fixed-header", config.fixedHeader && hasHeader )
, ( "mdl-layout--fixed-tabs", config.fixedTabs && hasTabs )
]
{- MDL has code to close drawer on ESC, but it seems to be
non-operational. We fix it here. Elm 0.17 doesn't give us a way to
catch global keyboard events, but we can reasonably assume something inside
mdl-layout__container is focused.
-}
, if drawerIsVisible then
on "keydown"
(Decoder.map
(lift
<< \key ->
if key == 27 then
ToggleDrawer
else
NOP
)
Events.keyCode
)
|> Just
else
Nothing
]
|> List.filterMap identity
)
[ if hasHeader then
headerView lift config model ( headerDrawerButton, header, tabsElems )
|> (,) "elm-mdl-header"
|> Just
else
Nothing
, if not hasDrawer then
Nothing
else
Just ( "elm-mdl-drawer", drawerView lift drawerIsVisible drawer )
, if not hasDrawer then
Nothing
else
Just ( "elm-mdl-obfuscator", obfuscator lift drawerIsVisible )
, contentDrawerButton |> Maybe.map ((,) "elm-drawer-button")
, Options.styled main_
[ cs "mdl-layout__content"
, css "overflow-y" "visible" |> when (config.mode == Scrolling && config.fixedHeader)
, css "overflow-x" "visible" |> when (config.mode == Scrolling && config.fixedHeader)
, css "overflow" "visible" |> when (config.mode == Scrolling && config.fixedHeader) {- Above three lines fixes upstream bug #4180. -}
, when
(isWaterfall config.mode)
((on "scroll" >> Internal.attribute)
(Decoder.map
(ScrollPane config.fixedHeader >> lift)
(DOM.target DOM.scrollTop)
)
)
]
main
|> (,) (toString config.selectedTab)
|> Just
]
]
-- COMPONENT
type alias Store s =
{ s | layout : Model }
( get, set ) =
( .layout
, \x s -> { s | layout = x }
)
{-| Component react function
-}
react :
(Msg -> m)
-> Msg
-> Store s