@@ -1,13 +1,18 @@
1module Yoga.Block.Atom.Input.View where
1module Yoga.Block.Atom.Input.View where
3import Yoga.Prelude.View
3import Yoga.Prelude.View
4+import Data.Array as Array
5+import Data.Interpolate (i)
6+import Data.Semigroup.Foldable (intercalateMap)
4import Data.String.NonEmpty (NonEmptyString)
7import Data.String.NonEmpty (NonEmptyString)
5import Data.String.NonEmpty as NonEmptyString
8import Data.String.NonEmpty as NonEmptyString
6import Data.Symbol (SProxy(..))
9import Data.Symbol (SProxy(..))
10+import Debug.Trace (spy)
7import Foreign.Object (Object)
11import Foreign.Object (Object)
8import Foreign.Object as Object
12import Foreign.Object as Object
9import Framer.Motion as M
13import Framer.Motion as M
14+import Partial.Unsafe (unsafeCrashWith)
10−import React.Basic.DOM (css)
15+import React.Basic.DOM (CSS, css)
11import React.Basic.DOM as R
16import React.Basic.DOM as R
12import React.Basic.Hooks as React
17import React.Basic.Hooks as React
13import Web.HTML.HTMLInputElement as InputElement
18import Web.HTML.HTMLInputElement as InputElement
@@ -18,19 +23,19 @@ import Yoga.Block.Atom.Input.Types as HTMLInput
18import Yoga.Block.Icon.SVG as SVGIcon
23import Yoga.Block.Icon.SVG as SVGIcon
19import Yoga.Block.Internal.OptionalProp (asMaybe)
24import Yoga.Block.Internal.OptionalProp (asMaybe)
21−type PropsF f
26+type PropsF f =
22− = ( leading ∷ f JSX
27+ ( leading ∷ f JSX
23− , trailing ∷ f JSX
28+ , trailing ∷ f JSX
24− , label ∷ f NonEmptyString
29+ , label ∷ f NonEmptyString
25− , type ∷ f HTMLInput
30+ , type ∷ f HTMLInput
26− | Style.Props f InputProps
31+ | Style.Props f InputProps
29−type Props
34+type Props =
30− = PropsF Id
35+ PropsF Id
32−type PropsOptional
37+type PropsOptional =
33− = PropsF OptionalProp
38+ PropsF OptionalProp
35component ∷ ∀ p p_. Union p p_ Props => ReactComponent { | p }
40component ∷ ∀ p p_. Union p p_ Props => ReactComponent { | p }
36component = rawComponent
41component = rawComponent
@@ -47,6 +52,68 @@ mkLeftIcon icon =
63+ , transition: { duration: 1.3 }
68+ drawPathUntil (Array.length path) path
72+ clipPath = 3 Array... (Array.length path / 2 + 1) <#> \ln -> drawPathUntil (ln * 2) path
77+p ∷ Int -> Int -> Point
80+drawPathUntil ∷ Int -> Array Point -> String
81+drawPathUntil idx thePath = do
82+ let fn { x, y } = i x "%" " " y "%"
83+ let firstFew = Array.take idx thePath
84+ let lastFew = Array.drop idx thePath $> (Array.last firstFew # fromMaybe' \_ -> unsafeCrashWith "ogod")
85+ let rendered = intercalate "," $ fn <$> (firstFew <> lastFew)
86+ spy "polybius" $ i "polygon(" rendered ")"
91+mkPath ∷ Int -> Array Point
97+ , p (100 - d) (100 - d)
107+ , p d 0 -- one turn, starting way back
109+ inside <> outside <> (Array.reverse inside)
111+containerVariantLabels ∷
112+ { blurred ∷ M.VariantLabel
113+ , focussed ∷ M.VariantLabel
115+containerVariantLabels = M.makeVariantLabels containerVariants
50rawComponent ∷ ∀ p. ReactComponent { | p }
117rawComponent ∷ ∀ p. ReactComponent { | p }
51rawComponent =
118rawComponent =
52 mkForwardRefComponent "Input" do
119 mkForwardRefComponent "Input" do
@@ -54,8 +121,7 @@ rawComponent =
54 inputBbox /\ setInputBbox <- useState' (zero ∷ DOMRect)
121 inputBbox /\ setInputBbox <- useState' (zero ∷ DOMRect)
55 hasFocus /\ setHasFocus <- useState' false
122 hasFocus /\ setHasFocus <- useState' false
56 backupRef ∷ NodeRef <- useRef null -- [TODO] test this
123 backupRef ∷ NodeRef <- useRef null -- [TODO] test this
58− ref = forwardedRefAsMaybe propsRef # fromMaybe backupRef
124+ let ref = forwardedRefAsMaybe propsRef # fromMaybe backupRef
59 useEffectOnce do
125 useEffectOnce do
60 maybeBBox <- getBoundingBoxFromRef ref
126 maybeBBox <- getBoundingBoxFromRef ref
61 for_ maybeBBox setInputBbox
127 for_ maybeBBox setInputBbox
@@ -73,8 +139,7 @@ rawComponent =
73 maybeBBox <- getBoundingBoxFromRef leftIconRef
139 maybeBBox <- getBoundingBoxFromRef leftIconRef
74 for_ maybeBBox (setLeftIconBbox <<< Just)
140 for_ maybeBBox (setLeftIconBbox <<< Just)
77− (maybeValue ∷ Maybe String) = cast props.value # opToMaybe
142+ let (maybeValue ∷ Maybe String) = cast props.value # opToMaybe
78 hasValue /\ setHasValue <- useState' ((maybeValue # isJust) && (maybeValue /= Just ""))
143 hasValue /\ setHasValue <- useState' ((maybeValue # isJust) && (maybeValue /= Just ""))
80 aria ∷ Object String
145 aria ∷ Object String
@@ -138,22 +203,25 @@ rawComponent =
138 ( const do
203 ( const do
139 when hasFocus $ setHasFocus false
204 when hasFocus $ setHasFocus false
140 el <- getHTMLElementFromRef ref
205 el <- getHTMLElementFromRef ref
142− inputEl = InputElement.fromHTMLElement =<< el
206+ let inputEl = InputElement.fromHTMLElement =<< el
143 for_ inputEl \ie -> do
207 for_ inputEl \ie -> do
144 v <- InputElement.value ie
208 v <- InputElement.value ie
145 setHasValue (v /= "")
209 setHasValue (v /= "")
147 onFocus = handler preventDefault (const $ unless hasFocus $ setHasFocus true)
211 onFocus = handler preventDefault (const $ unless hasFocus $ setHasFocus true)
148 inputWrapper =
212 inputWrapper =
215+ { variants: M.variants containerVariants
216+ , animate: M.animate if hasFocus then containerVariantLabels.focussed else containerVariantLabels.blurred
150− </* { className: "ry-input-wrapper"
218+ { className: "ry-input-wrapper"
151− , css: Style.inputWrapper props
219+ , css: Style.inputWrapper props
152− , _data:
220+ , _data:
153− Object.fromHomogeneous
221+ Object.fromHomogeneous
154− { "invalid": aria # Object.lookup "invalid" # fromMaybe ""
222+ { "invalid": aria # Object.lookup "invalid" # fromMaybe ""
157 /> [ leading # foldMap \l -> div </ { ref: leftIconRef } /> [ l ]
225 /> [ leading # foldMap \l -> div </ { ref: leftIconRef } /> [ l ]
158 , emotionInput
226 , emotionInput
@@ -230,10 +298,8 @@ password =
234− trailing = props.trailing ?|| eyeCon
301+ let trailing = props.trailing ?|| eyeCon
236− leading = props.leading ?|| mempty
302+ let leading = props.leading ?|| mempty
239 </* { className: "ry-input-wrapper"
305 </* { className: "ry-input-wrapper"