@@ -3,12 +3,16 @@ module Yoga.Block.Atom.Button.Style where
33import Yoga.Prelude.Style
44
55import Data.Interpolate (i)
6−import Fahrtwind (background', hover, zIndex)
7−import Yoga.Block.Container.Style (col, colour, size)
6+import Unsafe.Coerce (unsafeCoerce)
87
98type Props :: forall k. (Type -> k) -> Row k -> Row k
109type Props f r =
1110 ( css ∷ f Style
11+ , width :: f StyleProperty
12+ , backgroundCol :: f StyleProperty
13+ , borderCol :: f StyleProperty
14+ , textCol :: f StyleProperty
15+ , hoverBackgroundCol :: f StyleProperty
1216 | r
1317 )
1418
@@ -35,11 +39,25 @@ backgroundAnimation =
3539 , "to": css { backgroundPosition: str "100% 50%" }
3640 }
3741
42+varOr :: String -> StyleProperty -> StyleProperty
43+varOr varName alternative = str $ "var(" <> varName <> ", " <> unsafeCoerce alternative <> ")"
44+
45+style =
46+ { background: prefix <> "background"
47+ , textCol: prefix <> "color"
48+ , borderCol: prefix <> "border-color"
49+ , width: prefix <> "width"
50+ , hoverBackgroundCol: prefix <> "hover-background-color"
51+ }
52+ where
53+ prefix = "--ry-button-"
54+
3855button ∷ Style
3956button =
4057 inlineFlex <>
4158 css
42− { background: str colour.backgroundLayer5
59+ { background: varOr style.background (str colour.backgroundLayer5)
60+ , width: varOr style.width auto
4361 , borderWidth: int 0
4462 , position: relative
4563 , overflow: hidden
@@ -47,9 +65,10 @@ button =
4765 , padding: str "calc(var(--s-1) * 0.8) var(--s0)"
4866 , paddingBottom: str "calc(var(--s-1) * 0.8 + 1px)"
4967 , justifyContent: center
68+ , textAlign: str "start"
5069 , alignItems: center
5170 , borderRadius: var "--s-1"
52− , color: str colour.text
71+ , color: varOr style.textCol (str colour.text)
5372 , touchAction: manipulation
5473 , boxSizing: borderBox
5574 , fontSize: str size.text.interactive
@@ -61,17 +80,23 @@ button =
6180 , "& > .ry-drip": nested (zIndex 0)
6281 , "& > :not(.ry-drip)": nested (zIndex 1)
6382 , """&[data-button-shape="flat"]""":
64− nested $ hover (background' col.highlightAlpha10) <> css
65− { background: str "transparent"
66− , boxShadow: none
67− , color: str colour.highlightTextOnBackground
68− , "&:active": nest { boxShadow: none }
69− , """&[data-button-type="primary"]""":
70− nest
71− { background: str colour.highlight
72− , boxShadow: none
83+ nested
84+ $
85+ ( hover $ css
86+ { background: varOr style.hoverBackgroundCol col.highlightAlpha10
7387 }
74− }
88+ )
89+ <> css
90+ { background: varOr style.background (str "transparent")
91+ , boxShadow: none
92+ , color: varOr style.textCol (str colour.highlightTextOnBackground)
93+ , "&:active": nest { boxShadow: none }
94+ , """&[data-button-type="primary"]""":
95+ nest
96+ { background: str colour.highlight
97+ , boxShadow: none
98+ }
99+ }
75100 , """&[data-button-shape="pill"]""":
76101 nest
77102 { borderRadius: str "calc(var(--s1) * 0.85)"
@@ -80,14 +105,14 @@ button =
80105 }
81106 , """&[data-button-type="primary"]""":
82107 nest
83− { background: gradientBackground
108+ { background: varOr style.background gradientBackground
84109 , backgroundSize: str "200% 200%"
85110 , fontWeight: str "500"
86111 , letterSpacing: str "calc(var(--s-5)* (0.1))"
87112 , animation: backgroundAnimation <> str " alternate ease-out 10s infinite"
88113 , boxShadow: str "0 1px 4px 0px rgba(0,0,0,0.40)"
89114 , borderColor: str "transparent"
90− , color: str colour.highlightText
115+ , color: varOr style.textCol (str colour.highlightText)
91116 , "&:focus-visible":
92117 nest
93118 { borderColor: col.background
@@ -99,7 +124,7 @@ button =
99124 }
100125 , """&[data-button-type="dangerous"]""":
101126 nest
102− { color: str $ colour.interfaceDangerousText
127+ { color: varOr style.textCol (str colour.interfaceDangerousText)
103128 , background: str $ colour.interfaceBackgroundDangerous
104129 , fontWeight: str "500"
105130 , letterSpacing: str "calc(var(--s-5) * -0.10)"
@@ -112,12 +137,12 @@ button =
112137 , "&:active":
113138 nest
114139 { boxShadow: str $ "inset 0 1px calc(var(--s0) * var(--dark-mode) + var(--s-2) * var(--light-mode)) rgba(0,0,0, calc(0.18 * var(--dark-mode) + 0.09 * var(--light-mode)))"
115− , transform: str "scale3d(0.96,0.96,0.36)"
140+ , transform: str "scale3d(0.98,0.98, 0.98)"
116141 , transition: str "transform 100ms ease"
117142 }
118143 , "&:disabled, &:disabled:active":
119144 nest
120− { color: str colour.interfaceTextDisabled
145+ { color: varOr style.textCol (str colour.interfaceTextDisabled)
121146 , boxShadow: none
122147 , background: str colour.interfaceBackgroundDisabled
123148 , transform: str "none"