/
Buttons.purs
108 lines (83 loc) · 3.11 KB
/
Buttons.purs
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
-- | See <https://materializecss.com/buttons.html>,
-- | <https://materializecss.com/floating-action-button.html>, and
-- | <https://materializecss.com/pulse.html>.
module Materialize.Buttons
( Button(..)
, ButtonType
, HalfwayFab
, Pulse
, button
, raised
, floating
, flat
, floatingActionButton
, halfwayFab
, pulse
) where
import Data.Either (Either(..))
import Data.Maybe (Maybe(..), maybe)
import Data.Newtype (class Newtype, wrap)
import Data.Typelevel.Undefined (undefined)
import Prelude
import Materialize.Markup (class Decorate, class Render, class Variadic, liftVariadic, render, (<$~))
import Materialize.Overriden (Disabled, Large, Small)
import Materialize.Types (Class)
newtype Button = Button { type' :: ButtonType
, size :: Maybe (Either Small Large)
, disabled :: Maybe Disabled
, halfwayFab :: Maybe HalfwayFab
, pulse :: Maybe Pulse
}
data ButtonType = Raised
| Floating
| Flat
data HalfwayFab
data Pulse
button :: forall r. Variadic Button r => r
button = liftVariadic $ wrap { type': Raised
, size: Nothing
, disabled: Nothing
, halfwayFab: Nothing
, pulse: Nothing
}
instance variadicReturnButton :: Variadic Button Button where
liftVariadic = identity
raised :: ButtonType
raised = Raised
floating :: ButtonType
floating = Floating
flat :: ButtonType
flat = Flat
floatingActionButton :: forall r. Variadic Class r => r
floatingActionButton = liftVariadic "fixed-action-btn"
halfwayFab :: HalfwayFab
halfwayFab = undefined
pulse :: Pulse
pulse = undefined
instance decorateButtonDisabled :: Decorate Button Disabled where
decorate (Button b) d = wrap b { disabled = pure d }
instance decorateButtonType :: Decorate Button ButtonType where
decorate (Button b) t = wrap b { type' = t }
instance decorateButtonSmall :: Decorate Button Small where
decorate (Button b) s = wrap b { size = pure $ Left s }
instance decorateButtonLarge :: Decorate Button Large where
decorate (Button b) l = wrap b { size = pure $ Right l }
instance decorateButtonHalfwayFab :: Decorate Button HalfwayFab where
decorate (Button b) h = wrap b { halfwayFab = pure h }
instance decorateButtonPulse :: Decorate Button Pulse where
decorate (Button b) p = wrap b { pulse = pure p }
instance renderButton :: Render Button where
render (Button { type': t, size: s, disabled: d, halfwayFab: h, pulse: p }) =
render d
<> ("btn" <$~ render s)
<> (case t of
Raised -> render $ maybe (pure "btn") (const Nothing) s
Floating -> render "btn-floating"
Flat -> render "btn-flat")
<> render h
<> render p
instance renderHalfwayFab :: Render HalfwayFab where
render _ = render "halfway-fab"
instance renderPulse :: Render Pulse where
render _ = render "pulse"
derive instance newtypeButton :: Newtype Button _