@@ -669,304 +669,157 @@ type alias Text msg =
673− = Padding Int Int Int Int
676−inheritablePlaceholderAttributes attr =
678− Internal.StyleClass _ (Internal.PaddingStyle _ _ _ _ _) ->
681− Internal.StyleClass _ (Internal.BorderWidth _ _ _ _ _) ->
684− Internal.StyleClass _ (Internal.Transform _) ->
696− attribute::width/height fill
697− attribtue::alignment
699− attribute::fontsize/family/lineheight
701− attribute::nearby(placeholder)
702− attribute::width/height fill
710− special height for height-content
712− attribute::lineHeight
717textHelper : TextInput -> List (Attribute msg) -> Text msg -> Element msg
673textHelper : TextInput -> List (Attribute msg) -> Text msg -> Element msg
718textHelper textInput attrs textOptions =
674textHelper textInput attrs textOptions =
720− attributes =
676+ withDefaults =
721 defaultTextBoxStyle ++ attrs
677 defaultTextBoxStyle ++ attrs
723− behavior =
679+ redistributed =
724− [ Internal.Attr (Html.Events.onInput textOptions.onChange) ]
680+ redistribute withDefaults
726− forPlaceholder =
682+ moveUpToCompensateForPadding =
727− List.filter inheritablePlaceholderAttributes attributes
683+ calcMoveToCompensateForPadding withDefaults
729− noNearbys =
685+ onlySpacing attr =
730− List.filter (not << forNearby) attributes
733 case attr of
686 case attr of
734− Internal.Nearby _ _ ->
687+ Internal.StyleClass _ (Internal.SpacingStyle _ _ _) ->
740− ( inputNode, inputAttrs, inputChildren ) =
693+ isHeightContent attr =
741− case textInput.type_ of
742− TextInputNode inputType ->
744− , [ Internal.Attr (Html.Attributes.type_ inputType)
745− , value textOptions.text
746− , spellcheck textInput.spellchecked
747− , Internal.htmlClass classes.inputText
748− , case textInput.autofill of
750− Internal.NoAttribute
761− { maybePadding, heightContent, maybeSpacing, adjustedAttributes, maybeBorder } =
762− (value textOptions.text :: attributes)
765− case attr of
694+ case attr of
766− Internal.Describe _ ->
769− Internal.Height len ->
770− case found.heightContent of
773− | heightContent = Just (Internal.isContent len)
774− , adjustedAttributes = attr :: found.adjustedAttributes
780− Internal.StyleClass _ (Internal.BorderWidth _ t r b l) ->
781− case found.maybeBorder of
784− | maybeBorder = Just (Padding t r b l)
785− , adjustedAttributes = attr :: found.adjustedAttributes
791− Internal.StyleClass _ (Internal.PaddingStyle _ t r b l) ->
792− case found.maybePadding of
795− | maybePadding = Just (Padding t r b l)
797− -- Skip storing padding because it's being customized later
798− , adjustedAttributes = found.adjustedAttributes
804− Internal.StyleClass _ (Internal.SpacingStyle _ x y) ->
805− case found.maybeSpacing of
808− | maybeSpacing = Just y
809− , adjustedAttributes = attr :: found.adjustedAttributes
816− { found | adjustedAttributes = attr :: found.adjustedAttributes }
818− { maybePadding = Nothing
819− , heightContent = Nothing
820− , maybeBorder = Nothing
821− , maybeSpacing = Nothing
822− , adjustedAttributes = []
825− -- NOTE: This is where default text spacing is set
827− Maybe.withDefault 5 maybeSpacing
830− , [ spellcheck textInput.spellchecked
831− , Internal.htmlClass classes.inputMultiline
832− , Maybe.map autofill textInput.autofill
833− |> Maybe.withDefault Internal.NoAttribute
834− , case maybePadding of
836− Internal.NoAttribute
838− Just (Padding t r b l) ->
840− { top = max 0 (t - (spacing // 2))
841− , bottom = max 0 (b - (spacing // 2))
845− , case heightContent of
847− Internal.NoAttribute
850− textHeightContent textOptions.text spacing maybePadding maybeBorder
853− Internal.NoAttribute
855− ++ adjustedAttributes
859− heightFillFromChild =
860− Internal.get attributes <|
863− Internal.Height (Internal.Fill _) ->
695+ Internal.Height Internal.Content ->
869− attributesFromChild =
870− Internal.get attributes <|
873− Internal.Width (Internal.Fill _) ->
876− Internal.Height (Internal.Fill _) ->
879− Internal.AlignX _ ->
882− Internal.AlignY _ ->
885− Internal.StyleClass _ (Internal.SpacingStyle _ _ _) ->
888− Internal.StyleClass _ (Internal.FontSize _) ->
891− Internal.StyleClass _ (Internal.FontFamily _ _) ->
897− nearbys =
701+ bottomPadding attr =
898− Internal.get attributes <|
702+ case attr of
899− \attr ->
703+ Internal.StyleClass cls (Internal.PaddingStyle pad t r b l) ->
900− case attr of
704+ Just <|
901− Internal.Nearby _ _ ->
705+ Element.paddingEach
907− inputPadding =
715+ heightContent =
908− Internal.get attributes <|
716+ case textInput.type_ of
909− \attr ->
717+ TextInputNode inputType ->
910− case attr of
718+ False
911− Internal.StyleClass _ (Internal.PaddingStyle _ _ _ _ _) ->
914− _ ->
720+ TextArea ->
915− False
721+ List.any isHeightContent withDefaults
917 inputElement =
723 inputElement =
918 Internal.element
724 Internal.element
919 Internal.asEl
725 Internal.asEl
920− Internal.div
726+ (case textInput.type_ of
921− (Element.width Element.fill
727+ TextInputNode inputType ->
922− :: List.concat
728+ Internal.NodeName "input"
924− , heightFillFromChild
730+ TextArea ->
925− , case textOptions.placeholder of
731+ Internal.NodeName "textarea"
927− []
733+ ([ value textOptions.text
928−
734+ , Internal.Attr (Html.Events.onInput textOptions.onChange)
929− Just (Placeholder placeholderAttrs placeholderEl) ->
735+ , hiddenLabelAttribute textOptions.label
930− [ Element.inFront
736+ , spellcheck textInput.spellchecked
931− (Element.el
737+ , Maybe.map autofill textInput.autofill
932− (defaultTextPadding
738+ |> Maybe.withDefault Internal.NoAttribute
933− :: forPlaceholder
739+ ]
934− ++ [ Font.color charcoal
740+ ++ (case textInput.type_ of
935− , Internal.htmlClass (classes.noTextSelection ++ " " ++ classes.passPointerEvents)
741+ TextInputNode inputType ->
936− , Border.color (Element.rgba 0 0 0 0)
742+ [ Internal.Attr (Html.Attributes.type_ inputType)
937− , Background.color (Element.rgba 0 0 0 0)
743+ , Internal.htmlClass classes.inputText
744+ , Internal.htmlClass "focusable"
938− , Element.height Element.fill
749+ , Element.height Element.fill
939− , Element.width Element.fill
750+ , Internal.htmlClass classes.inputMultiline
940− , Element.alpha
751+ , Element.alpha 0.3
941− (if textOptions.text == "" then
752+ , moveUpToCompensateForPadding
755+ ++ redistributed.input
955− (Internal.Unkeyed
757+ (Internal.Unkeyed [])
760+ -- if heightContent then
761+ case textInput.type_ of
763+ -- textarea with height-content means that
764+ -- the input element is rendered `inFront` and transparently.
765+ -- Then the input text is rendered as the actual element.
956− [ Internal.element
766+ Internal.element
957 Internal.asEl
767 Internal.asEl
958− (Internal.NodeName inputNode)
768+ Internal.div
769+ ([ Element.width Element.fill
770+ , Element.height (Element.px 100)
771+ , Element.scrollbarY
772+ , Internal.htmlClass classes.focusedWithin
774+ ++ redistributed.parent
778+ Internal.asParagraph
780+ (Element.width Element.fill
781+ :: Element.height Element.fill
782+ :: Element.inFront inputElement
783+ :: Internal.htmlClass classes.inputMultiline
959− (List.concat
784+ :: List.concat
960− [ [ focusDefault attrs
785+ [ if heightContent then
961− , hiddenLabelAttribute textOptions.label
786+ redistributed.wrapper
789+ redistributed.wrapper
790+ ++ List.filterMap bottomPadding redistributed.parent
791+ , case textOptions.placeholder of
964− , behavior
795+ Just place ->
796+ [ renderPlaceholder place redistributed.cover (textOptions.text == "")
801+ [ Internal.unstyled (Html.text textOptions.text) ]
806+ TextInputNode inputType ->
810+ (Element.width Element.fill
812+ [ redistributed.parent
813+ , case textOptions.placeholder of
818+ [ renderPlaceholder place redistributed.cover (textOptions.text == "")
967− (Internal.Unkeyed inputChildren)
822+ (Internal.Unkeyed [ inputElement ])
971 applyLabel
824 applyLabel
972 (Internal.Class Flag.cursor classes.cursorText
825 (Internal.Class Flag.cursor classes.cursorText
@@ -978,45 +831,207 @@ textHelper textInput attrs textOptions =
980 :: Region.announce
833 :: Region.announce
981− :: attributesFromChild
834+ :: redistributed.fullParent
983 textOptions.label
836 textOptions.label
984− inputElement
837+ wrappedInput
840+renderPlaceholder (Placeholder placeholderAttrs placeholderEl) forPlaceholder on =
845+ ++ [ Font.color charcoal
846+ , Internal.htmlClass (classes.noTextSelection ++ " " ++ classes.passPointerEvents)
847+ , Border.color (Element.rgba 0 0 0 0)
848+ , Background.color (Element.rgba 0 0 0 0)
849+ , Element.height Element.fill
850+ , Element.width Element.fill
987−textHeightContent textValue spacing maybePadding maybeBorder =
865+{-| Because textareas are now shadowed, where they're rendered twice,
866+we to move the literal text area up because spacing is based on line height.
868+calcMoveToCompensateForPadding : List (Attribute msg) -> Attribute msg
869+calcMoveToCompensateForPadding attrs =
989− newlineCount =
871+ gatherSpacing attr found =
990− String.lines textValue
872+ case attr of
991− |> List.length
873+ Internal.StyleClass _ (Internal.SpacingStyle _ x y) ->
992− |> (\x ->
874+ case found of
993− if x < 1 then
875+ Nothing ->
1000− topBottom (Padding t _ b _) =
881+ _ ->
884+ case List.foldr gatherSpacing Nothing attrs of
886+ Internal.NoAttribute
1003− additionalSpacing =
888+ Just vSpace ->
1004− ((newlineCount - 1) * spacing)
889+ Element.moveUp (toFloat vSpace / 2)
1005− + Maybe.withDefault 0 (Maybe.map topBottom maybePadding)
1006− + Maybe.withDefault 0 (Maybe.map topBottom maybeBorder)
1008− heightValue count =
891+
1009− "calc("
892+{-| Given the list of attributes provided to `Input.multiline` or `Input.text`,
1010− ++ String.fromInt count
893+
1011− ++ "em + "
894+redistribute them to the parent, the input, or the cover.
1012− ++ String.fromInt additionalSpacing
895+
1013− ++ "px) !important"
896+ - fullParent -> Wrapper around label and input
1014− in
897+ - parent -> parent of wrapper
898+ - wrapper -> the element that is here to take up space.
899+ - cover -> things like placeholders or text areas which are layered on top of input.
900+ - input -> actual input element
904+ List (Attribute msg)
906+ { fullParent : List (Attribute msg)
907+ , parent : List (Attribute msg)
908+ , wrapper : List (Attribute msg)
909+ , input : List (Attribute msg)
910+ , cover : List (Attribute msg)
913+ List.foldl redistributeOver
922+ { parent = List.reverse redist.parent
923+ , fullParent = List.reverse redist.fullParent
924+ , wrapper = List.reverse redist.wrapper
925+ , input = List.reverse redist.input
926+ , cover = List.reverse redist.cover
931+redistributeOver attr els =
933+ Internal.Nearby _ _ ->
934+ { els | parent = attr :: els.parent }
936+ Internal.Width (Internal.Fill _) ->
937+ { els | fullParent = attr :: els.fullParent }
940+ { els | parent = attr :: els.parent }
942+ Internal.Height (Internal.Fill _) ->
944+ | fullParent = attr :: els.fullParent
945+ , parent = attr :: els.parent
948+ Internal.Height h ->
950+ | parent = attr :: els.parent
953+ Internal.AlignX _ ->
954+ { els | fullParent = attr :: els.fullParent }
956+ Internal.AlignY _ ->
957+ { els | fullParent = attr :: els.fullParent }
959+ Internal.StyleClass _ (Internal.SpacingStyle _ _ _) ->
961+ | fullParent = attr :: els.fullParent
962+ , parent = attr :: els.parent
963+ , input = attr :: els.input
964+ , wrapper = attr :: els.wrapper
967+ Internal.StyleClass _ (Internal.PaddingStyle _ _ _ _ _) ->
969+ | parent = attr :: els.parent
971+ -- input = attr :: els.input
972+ -- , wrapper = attr :: els.wrapper
973+ , cover = attr :: els.cover
976+ Internal.StyleClass _ (Internal.BorderWidth _ _ _ _ _) ->
978+ | parent = attr :: els.parent
979+ , cover = attr :: els.cover
982+ Internal.StyleClass _ (Internal.Transform _) ->
984+ | parent = attr :: els.parent
985+ , cover = attr :: els.cover
988+ Internal.StyleClass _ (Internal.FontSize _) ->
989+ { els | fullParent = attr :: els.fullParent }
991+ Internal.StyleClass _ (Internal.FontFamily _ _) ->
992+ { els | fullParent = attr :: els.fullParent }
994+ Internal.StyleClass _ _ ->
995+ { els | parent = attr :: els.parent }
997+ Internal.NoAttribute ->
1001+ { els | input = attr :: els.input }
1003+ Internal.Describe _ ->
1004+ { els | input = attr :: els.input }
1006+ Internal.Class _ _ ->
1007+ { els | parent = attr :: els.parent }
1009+ Internal.TransformComponent _ _ ->
1010+ { els | input = attr :: els.input }
1013+orElse thing maybe =
1022+inheritablePlaceholderAttributes attr =
1015− Internal.StyleClass Flag.heightTextAreaContent
1024+ Internal.StyleClass _ (Internal.PaddingStyle _ _ _ _ _) ->
1016− (Internal.Single ("textarea-height-" ++ String.fromInt newlineCount)
1025+ True
1018− (heightValue newlineCount)
1027+ Internal.StyleClass _ (Internal.BorderWidth _ _ _ _ _) ->
1030+ Internal.StyleClass _ (Internal.Transform _) ->