@@ -0,0 +1,130 @@
1+module Yoga.Block.Atom.Input.View.Container where
3+import Yoga.Prelude.View
4+import Data.Array as Array
5+import Data.Interpolate (i)
6+import Foreign.Object as Object
7+import Framer.Motion as M
8+import Partial.Unsafe (unsafeCrashWith)
9+import React.Basic.DOM (CSS, css)
10+import React.Basic.Emotion (Style)
11+import Yoga.Block.Atom.Input.Style as Style
15+ , isInvalid ∷ f Boolean
16+ | Style.Props f (MandatoryProps ())
19+type MandatoryProps r =
20+ ( children ∷ Array JSX
31+component ∷ ∀ p q. Union p q Props => ReactComponent { | MandatoryProps p }
32+component = rawContainer
35+ { css ∷ OptionalProp Style
37+ , isInvalid ∷ OptionalProp Boolean
38+ , children ∷ Array JSX
41+rawContainer ∷ ∀ p. ReactComponent { | p }
43+ mkForwardRefComponent "InputContainer" do
44+ \(props ∷ { | PropsOptional }) ref -> React.do
49+ { variants: M.variants containerVariants
50+ , animate: M.animate if props.hasFocus then containerVariantLabels.focussed else containerVariantLabels.blurred
52+ { className: "ry-input-container"
53+ , css: Style.inputContainer props
56+ # foldMap \isInvalid ->
57+ Object.fromHomogeneous
58+ { "invalid": show isInvalid
65+drawPathUntil ∷ Int -> Array Point -> String
66+drawPathUntil idx thePath = do
67+ let fn { x, y } = i x "%" " " y "%"
68+ let firstFew = Array.take idx thePath
69+ let lastFew = Array.drop idx thePath $> (Array.last firstFew # fromMaybe' \_ -> unsafeCrashWith "ogod")
70+ let rendered = intercalate "," $ fn <$> (firstFew <> lastFew)
71+ i "polygon(" rendered ")"
76+mkPath ∷ Int -> Int -> Array Point
77+mkPath borderX borderY = do
80+ [ {- ⌜ -} p borderX borderY
81+ , {- ⌞ -} p borderX (100 - borderY)
82+ , {- ⌟ -} p (100 - borderX) (100 - borderY)
83+ , {- ⌝ -} p (100 - borderX) borderY
84+ , {- ⌜ -} p borderX borderY
99+ inside <> outside <> (Array.reverse inside)
101+ p ∷ Int -> Int -> Point
104+containerVariantLabels ∷
105+ { blurred ∷ M.VariantLabel
106+ , focussed ∷ M.VariantLabel
108+containerVariantLabels = M.makeVariantLabels containerVariants
118+ , transition: { duration: 0.6 }
123+ drawPathUntil (Array.length path + 1) path
127+ clipPath = 6 Array... (Array.length path) <#> \ln -> drawPathUntil ln path
130+ { x ∷ Int, y ∷ Int }