git.iko.soy/rowtype-yoga/psfp
on master help sign in
Small improvements
commitfd4a42d47f7ce35ae14c7272aa4c42bdd45cb2fa authorMark Eibes <mark.eibes@gmail.com> dateTue 12 May 2020, 21:45 (6 years ago) parent8e9130c
5 files changed+62−75
components/src/Yoga/Grimoire/Component.purs+46−58 components/src/Yoga/Grimoire/Spell/Component.purs+2−6 components/src/Yoga/Grimoire/Spell/Styles.purs+6−4 components/src/Yoga/Grimoire/Styles.purs+5−4 components/src/Yoga/Theme/Default.purs+3−3
components/src/Yoga/Grimoire/Component.purs+46−58
@@ -13,7 +13,6 @@ import Data.Nullable as Nullable
1313import Data.Symbol (SProxy(..))
1414import Data.Traversable (for, sequence)
1515import Data.Tuple.Nested ((/\), type (/\))
16−import Debug.Trace (spy)
1716import Effect (Effect)
1817import Effect.Class.Console (log)
1918import Justifill (justifill)
@@ -88,6 +87,19 @@ swap i j arr = swapped # orDie "Couldn't swap"
8887 valueJ <- arr !! j
8988 pure $ (set (ix i) valueJ <<< set (ix j) valueI) arr
9089
90+regularScale = "scale3d(1.0, 1.0, 1.0)"
91+
92+scaledUp = "scale3d(1.1, 1.1, 1.1)"
93+
94+defaultSprings =
95+ { x: 0.0
96+ , y: 0.0
97+ , shadow: 5
98+ , zIndex: 0
99+ , immediate: const true
100+ , transform: "scale3d(1.0,1.0,1.0)"
101+ }
102+
91103springsteen init rectsRef positionsRef arg mx my down springs = do
92104 init
93105 rects <- readRef rectsRef
@@ -96,55 +108,43 @@ springsteen init rectsRef positionsRef arg mx my down springs = do
96108 rectDragged = rects !!! (positionsBefore !!! arg)
97109 currentPosDragged = rectDragged # translate (mx /\ my)
98110 orderedRectsBefore = positionsBefore <#> (rects !!! _)
99− overlapsOtherBefore = orderedRectsBefore # findWithIndex \i rect -> i /= arg && overlaps currentPosDragged rect
100− case down, overlapsOtherBefore of
111+ overlapsOther = orderedRectsBefore # findWithIndex \i rect -> i /= arg && overlaps currentPosDragged rect
112+ case down, overlapsOther of
101113 false, Just { index } -> do
102114 let
103115 newPositions = swap arg index positionsBefore
104− writeRef positionsRef $ spy "new posis" newPositions
116+ writeRef positionsRef newPositions
105117 _, _ -> mempty
106− -- alles gut bis hierher, glaube ich
107118 positions <- readRef positionsRef
108119 springs.set \i -> do
109120 let
110− j = positions !!! i
111− isTheDraggedOne = i == arg
112121 originalRect = rects !!! i
113− currentRect = rects !!! j
122+ currentRect = rects !!! (positions !!! i)
114123 leftOffset = currentRect.left - originalRect.left
115124 topOffset = currentRect.top - originalRect.top
116− case isTheDraggedOne, down, overlapsOtherBefore of
125+ case i == arg, down, overlapsOther of
117126 true, true, _ ->
118− { x: mx + leftOffset
119− , y: my + topOffset
120− , zIndex: 1
121− , transform: "scale3d(1.1, 1.1, 1.1)"
122− , borderRadius: "var(--s-2)"
123− , height: "100px"
124− , shadow: 20
125− , immediate: \n -> n == "x" || n == "y" || n == "zIndex"
126− }
127+ defaultSprings
128+ { x = mx + leftOffset
129+ , y = my + topOffset
130+ , zIndex = 1
131+ , transform = scaledUp
132+ , shadow = 20
133+ , immediate = \n -> n == "x" || n == "y" || n == "zIndex"
134+ }
127135 false, true, Just { index, value }
128136 | index == i ->
129− { x: rectDragged.left - currentRect.left + leftOffset
130− , y: rectDragged.top - currentRect.top + topOffset
131− , zIndex: 0
132− , shadow: 2
133− , height: "100px"
134− , transform: "scale3d(1.0, 1.0, 1.0)"
135− , borderRadius: "var(--s-2)"
136− , immediate: const false
137− }
137+ defaultSprings
138+ { x = rectDragged.left - currentRect.left + leftOffset
139+ , y = rectDragged.top - currentRect.top + topOffset
140+ , immediate = const false
141+ }
138142 _, _, _ ->
139− { x: leftOffset
140− , y: topOffset
141− , shadow: 2
142− , height: "100px"
143− , borderRadius: "var(--s-2)"
144− , zIndex: 0
145− , transform: "scale3d(1.0, 1.0, 1.0)"
146− , immediate: const false
147− }
143+ defaultSprings
144+ { x = leftOffset
145+ , y = topOffset
146+ , immediate = const false
147+ }
148148
149149makeComponent ∷ Effect (ReactComponent Props)
150150makeComponent = do
@@ -152,19 +152,8 @@ makeComponent = do
152152 spellComponent <- GrimoireSpell.makeComponent
153153 useStyles <- makeStylesJSS styles
154154 component "Grimoire" \(props ∷ Props) -> React.do
155− {} <- useStyles (pick props)
156− let
157− defaultSprings = \_ ->
158− { x: 0.0
159− , y: 0.0
160− , height: "100px"
161− , shadow: 2
162− , borderRadius: "var(--s-2)"
163− , zIndex: 0
164− , immediate: const true
165− , transform: "scale3d(1.0,1.0,1.0)"
166− }
167− springs <- useSprings (Array.length props.spells) defaultSprings
155+ classes <- useStyles (pick props)
156+ springs <- useSprings (Array.length props.spells) (const defaultSprings)
168157 nodeRefs ∷ Ref (Array (Nullable (_))) <- useRef (props.spells $> Nullable.null)
169158 spells /\ updateSpells <- useState props.spells
170159 positionsRef <- useRef ([] ∷ _ Int)
@@ -184,7 +173,7 @@ makeComponent = do
184173 writeRef rectsRef rects
185174 writeRef initialisedRef true
186175 useLayoutEffect windowSize do
187− springs.set defaultSprings
176+ springs.set (const defaultSprings)
188177 positionsBefore <- readRef positionsRef
189178 when (positionsBefore == []) do
190179 log "resetting positions"
@@ -204,15 +193,14 @@ makeComponent = do
204193 renderSpells =
205194 mapWithIndex \i (spell /\ style) ->
206195 animatedDiv
207− $ { style: css (Record.insert (SProxy ∷ _ "boxShadow") ((unsafeCoerce (style.shadow ∷ Int)).interpolate (\s -> Interp.i "rgba(0, 0, 0, 0.15) 0px " s "px " (2 * s) "px 0px" ∷ String)) style)
196+ $ { style:
197+ css
198+ $ Record.insert (SProxy ∷ _ "boxShadow")
199+ ((unsafeCoerce (style.shadow ∷ Int)).interpolate (\s -> Interp.i "rgba(0, 0, 0, 0.15) 0px " s "px " (2 * s) "px 0px" ∷ String))
200+ style
201+ , className: classes.container
208202 , ref: unsafeCoerce (unsafeUpdateRefs nodeRefs i)
209− , children:
210− [ element
211− spellComponent
212− { spell
213− , cardRef: Nothing
214− }
215− ]
203+ , children: [ element spellComponent { spell } ]
216204 }
217205 `withDragProps`
218206 bindDragProps i
components/src/Yoga/Grimoire/Spell/Component.purs+2−6
@@ -3,16 +3,13 @@ module Yoga.Grimoire.Spell.Component where
33import Prelude
44import CSS (AlignItemsValue, JustifyContentValue, spaceBetween)
55import CSS.Common (baseline)
6−import Data.Maybe (Maybe)
7−import Data.Nullable (Nullable)
86import Effect (Effect)
97import React.Basic (ReactComponent)
108import React.Basic.DOM as R
119import React.Basic.Helpers (classSpan, jsx)
12−import React.Basic.Hooks (Ref, component)
10+import React.Basic.Hooks (component)
1311import React.Basic.Hooks as React
1412import Record.Extra (pick)
15−import Web.DOM (Node)
1613import Yoga.Box.Component as Box
1714import Yoga.Card.Component (mkCard)
1815import Yoga.Centre.Component as Centre
@@ -27,7 +24,6 @@ import Yoga.Theme.Types (CSSTheme)
2724
2825type Props
2926 = { spell ∷ Spell
30− , cardRef ∷ Maybe (Ref (Nullable Node))
3127 | Style.PropsR
3228 }
3329
@@ -56,7 +52,7 @@ makeComponent = do
5652 ]
5753 ]
5854 pure
59− $ jsx card { divRef: props.cardRef, className: style.card }
55+ $ jsx card { className: style.card }
6056 [ jsx box { className: style.container, padding: "var(--s-1)" }
6157 [ jsx stack { space: "var(--s-3)" }
6258 [ headerCluster
components/src/Yoga/Grimoire/Spell/Styles.purs+6−4
@@ -1,9 +1,9 @@
11module Yoga.Grimoire.Spell.Styles where
22
33import Prelude hiding (top)
4−import CSS (backgroundColor, black, block, boxShadow, color, display, fontFamily, fontSize, fontStyle, fromString, height, inlineBlock, key, lineHeight, maxHeight, pct, px, sansSerif, textOverflow, textWhitespace, unitless, whitespaceNoWrap, width)
4+import CSS (backgroundColor, black, boxShadow, color, darken, display, fontFamily, fontSize, fontStyle, fromString, height, inlineBlock, key, pct, rgba, sansSerif, textOverflow, textWhitespace, unitless, white, whitespaceNoWrap, width)
55import CSS.FontStyle (italic)
6−import CSS.Overflow (overflow, overflowY)
6+import CSS.Overflow (overflow)
77import CSS.Overflow as Overflow
88import CSS.Text.Overflow (ellipsis)
99import CSS.TextAlign (rightTextAlign, textAlign)
@@ -34,10 +34,12 @@ styles =
3434 do
3535 width (100.0 # pct)
3636 height (100.0 # pct)
37− boxShadow (0.0 # unitless) (0.0 # unitless) (0.0 # unitless) black
37+ boxShadow (0.0 # unitless) (0.0 # unitless) (0.0 # unitless) white
38+ backgroundColor $ rgba 0 0 0 0.0
3839 , container:
3940 jss do
40− backgroundColor theme.backgroundColourLighter
41+ backgroundColor $ rgba 0 0 0 0.0
42+ width (100.0 # pct)
4143 (key $ fromString "user-select") "none"
4244 height (100.0 # pct)
4345 , signature:
components/src/Yoga/Grimoire/Styles.purs+5−4
@@ -1,7 +1,7 @@
11module Yoga.Grimoire.Styles where
22
33import Prelude hiding (top)
4−import CSS (backgroundColor, borderRadius)
4+import CSS (backgroundColor, borderRadius, height, px)
55import JSS (JSSClasses, JSSElem, jssClasses)
66import Yoga.Theme.Types (YogaTheme)
77
@@ -17,9 +17,10 @@ type Classes a
1717
1818styles ∷ JSSClasses YogaTheme Props (Classes (JSSElem Props))
1919styles =
20− jssClasses \theme@{ s0 } ->
20+ jssClasses \theme@{ s0, s_2 } ->
2121 { container:
2222 do
23− borderRadius s0 s0 s0 s0
24− backgroundColor theme.backgroundColourDarker
23+ height (100.0 # px)
24+ borderRadius s_2 s_2 s_2 s_2
25+ backgroundColor $ theme.interfaceColour
2526 }
components/src/Yoga/Theme/Default.purs+3−3
@@ -24,7 +24,7 @@ darkTheme ∷ Theme
2424darkTheme =
2525 { backgroundColour: Color.hsl 238.0 0.18 0.30
2626 , textColour: Color.hsl 225.0 0.28 0.90
27− , interfaceColour: Color.hsl 225.0 0.48 0.12
27+ , interfaceColour: Color.hsl 235.0 0.22 0.28
2828 , highlightColour: Color.hsl 285.0 0.88 0.72
2929 , altHighlightColour: Color.hsl 84.0 0.617 0.631
3030 , textFontFamily: cons' "Rubik" systemFontStack
@@ -47,8 +47,8 @@ lightTheme ∷ Theme
4747lightTheme =
4848 darkTheme
4949 { textColour = Color.hsl 220.0 0.18 0.30
50− , backgroundColour = Color.hsl 30.0 0.50 0.96
51− , interfaceColour = Color.hsl 210.0 0.10 0.89
50+ , backgroundColour = Color.hsl 30.0 0.50 0.97
51+ , interfaceColour = Color.hsl 350.0 0.40 0.97
5252 , highlightColour = Color.hsl 350.0 0.93 0.67
5353 , altHighlightColour = Color.hsl 84.0 0.617 0.631
5454 , green = Color.hsl 170.0 0.39 0.40