@@ -5,12 +5,13 @@ import Data.Tuple.Nested ((/\))
5import Debug.Trace (spy)
5import Debug.Trace (spy)
6import Effect (Effect)
6import Effect (Effect)
7import Effect.Unsafe (unsafePerformEffect)
7import Effect.Unsafe (unsafePerformEffect)
8+import JSS (jssClasses)
8import Justifill (justifill)
9import Justifill (justifill)
9import React.Basic.DOM (css)
10import React.Basic.DOM (css)
10import React.Basic.DOM as R
11import React.Basic.DOM as R
11import React.Basic.Events (handler_)
12import React.Basic.Events (handler_)
12import React.Basic.Helpers (jsx)
13import React.Basic.Helpers (jsx)
13−import React.Basic.Hooks (component, element, fragment, useLayoutEffect, useState)
14+import React.Basic.Hooks (ReactComponent, component, element, fragment, useLayoutEffect, useState)
14import React.Basic.Hooks as React
15import React.Basic.Hooks as React
15import React.Basic.Hooks.Spring (animated, animatedDiv, useSpring, useSpringImpl)
16import React.Basic.Hooks.Spring (animated, animatedDiv, useSpring, useSpringImpl)
16import React.Basic.Hooks.UseGesture (useDrag, withDragProps)
17import React.Basic.Hooks.UseGesture (useDrag, withDragProps)
@@ -20,6 +21,7 @@ import Web.DOM.DOMTokenList (toggle)
20import Yoga.Box.Component as Box
21import Yoga.Box.Component as Box
21import Yoga.Spec.Helpers (withDarkTheme)
22import Yoga.Spec.Helpers (withDarkTheme)
22import Yoga.Stack.Component as Stack
23import Yoga.Stack.Component as Stack
24+import Yoga.Theme.Styles (makeStylesJSS)
24stories ∷ Effect Storybook
26stories ∷ Effect Storybook
25stories = do
27stories = do
@@ -29,37 +31,40 @@ stories = do
29 add "The Drag" (withDarkTheme mkDragAnimated)
31 add "The Drag" (withDarkTheme mkDragAnimated)
34+mkAnimated ∷ Effect (ReactComponent {})
32mkAnimated = do
35mkAnimated = do
33 box <- Box.makeComponent
36 box <- Box.makeComponent
34 component "Animated Example" \{} -> React.do
37 component "Animated Example" \{} -> React.do
35 toggled /\ modifyToggled <- useState false
38 toggled /\ modifyToggled <- useState false
36− springStyles /\ set <- useSpring $ const { marginTop: "80px", transform: "scale3d(" <> if toggled then "0.9, 0.9, 1.0" else "1.0, 2.0, 1.0" <> ")" }
39+ springStyles /\ set <- useSpring $ const { marginTop: "80px", marginBottom: "80px", opacity: 0.7, transform: "scale3d(" <> if toggled then "0.9, 0.9, 1.0" else "1.0, 2.0, 1.0" <> ")" }
37 useLayoutEffect toggled do
40 useLayoutEffect toggled do
38− set { marginTop: "80px", transform: "scale3d(" <> if toggled then "0.9, 0.9, 1.0" else "1.0, 2.0, 1.0" <> ")" }
41+ set { marginTop: "80px", marginBottom: "30px", opacity: if toggled then 0.7 else 0.9, transform: "scale3d(" <> if toggled then "0.9, 0.9, 1.0" else "1.0, 2.0, 1.0" <> ")" }
39 pure mempty
42 pure mempty
41 $ fragment
44 $ fragment
42− [ R.button { children: [ R.text "Toggle" ], onClick: handler_ (modifyToggled not) }
43− , animatedDiv
45+ [ animatedDiv
44− { style: css (spy "toni" springStyles)
46+ { style: css springStyles
45− , children: [ jsx box {} [ R.text "HIIIIIIIIIIIIOOOO" ] ]
47+ , children: [ jsx box {} [ R.text "Click the button" ] ]
49+ , R.button { children: [ R.text "Toggle" ], onClick: handler_ (modifyToggled not) }
52+mkDragAnimated ∷ Effect (ReactComponent {})
49mkDragAnimated = do
53mkDragAnimated = do
50 box <- Box.makeComponent
54 box <- Box.makeComponent
55+ useStyles <- makeStylesJSS $ jssClasses \t -> { div: { width: "200px", height: "200px", background: "hotpink" } }
51− component "Animated Example" \{} -> React.do
56+ component "Draggable Example" \{} -> React.do
52− toggled /\ modifyToggled <- useState false
53 springStyles /\ set <- useSpring $ const { x: 0.0, y: 0.0 }
57 springStyles /\ set <- useSpring $ const { x: 0.0, y: 0.0 }
58+ classes <- useStyles {}
54 mkDragProps <-
59 mkDragProps <-
55 useDrag \{ down, movement: mx /\ my } ->
60 useDrag \{ down, movement: mx /\ my } ->
56 set { x: if down then mx else 0.0, y: if down then my else 0.0 }
61 set { x: if down then mx else 0.0, y: if down then my else 0.0 }
58 $ fragment
63 $ fragment
59− [ R.button { children: [ R.text "Toggle" ], onClick: handler_ (modifyToggled not) }
60− , animatedDiv
64+ [ animatedDiv
61 ( { style: css springStyles
65 ( { style: css springStyles
66+ , className: classes.div
62− , children: [ jsx box {} [ R.text "HIIIIIIIIIIIIOOOO" ] ]
67+ , children: [ jsx box {} [ R.text "Drag me somewhere" ] ]
64 `withDragProps`
69 `withDragProps`
65 mkDragProps
70 mkDragProps