git.iko.soy/typeable/elm-ui
on master help sign in
Input.multiline height:shrink with min/max being respected.
commit151122157c2641caaadd26190ed3613302cb136f authorMatthew Griffith <mdg.griffith@gmail.com> dateFri 14 Sep 2018, 10:20 (8 years ago) parentc2a2f6d
3 files changed+235−56
src/Element/Input.elm+40−40 src/Internal/Flag.elm+60−1 src/Internal/Model.elm+135−15
src/Element/Input.elm+40−40
@@ -654,7 +654,7 @@ textHelper : TextInput -> List (Attribute msg) -> Text msg -> Element msg
654654textHelper textInput attrs textOptions =
655655 let
656656 attributes =
657− Element.width Element.fill :: (defaultTextBoxStyle ++ attrs)
657+ defaultTextBoxStyle ++ attrs
658658
659659 behavior =
660660 [ Internal.Attr (Html.Events.onInput textOptions.onChange) ]
@@ -699,20 +699,15 @@ textHelper textInput attrs textOptions =
699699 Internal.Describe _ ->
700700 found
701701
702− Internal.Height val ->
702+ Internal.Height len ->
703703 case found.heightContent of
704704 Nothing ->
705− case val of
706− Internal.Content ->
707− { found
708− | heightContent = Just val
709− , adjustedAttributes = found.adjustedAttributes
710− }
711−
712− _ ->
713− { found | heightContent = Just val }
705+ { found
706+ | heightContent = Just (Internal.isContent len)
707+ , adjustedAttributes = attr :: found.adjustedAttributes
708+ }
714709
715− Just i ->
710+ _ ->
716711 found
717712
718713 Internal.StyleClass _ (Internal.PaddingStyle _ t r b l) ->
@@ -770,35 +765,11 @@ textHelper textInput attrs textOptions =
770765 Nothing ->
771766 Internal.NoAttribute
772767
773− Just Internal.Content ->
774− let
775− newlineCount =
776− String.lines textOptions.text
777− |> List.length
778− |> (\x ->
779− if x < 1 then
780− 1
781−
782− else
783− x
784− )
785−
786− heightValue count =
787− case maybePadding of
788− Nothing ->
789− "calc(" ++ String.fromInt count ++ "em + " ++ String.fromInt ((count - 1) * spacing) ++ "px) !important"
790−
791− Just (Padding t r b l) ->
792− "calc(" ++ String.fromInt count ++ "em + " ++ String.fromInt ((t + b) + ((count - 1) * spacing)) ++ "px) !important"
793− in
794− Internal.StyleClass Flag.height
795− (Internal.Single ("textarea-height-" ++ String.fromInt newlineCount)
796− "height"
797− (heightValue newlineCount)
798− )
768+ Just True ->
769+ textHeightContent textOptions.text spacing maybePadding
799770
800− Just x ->
801− Internal.Height x
771+ Just False ->
772+ Internal.NoAttribute
802773 ]
803774 ++ adjustedAttributes
804775 , [ Internal.unstyled (Html.text textOptions.text) ]
@@ -925,6 +896,34 @@ textHelper textInput attrs textOptions =
925896 inputElement
926897
927898
899+textHeightContent textValue spacing maybePadding =
900+ let
901+ newlineCount =
902+ String.lines textValue
903+ |> List.length
904+ |> (\x ->
905+ if x < 1 then
906+ 1
907+
908+ else
909+ x
910+ )
911+
912+ heightValue count =
913+ case maybePadding of
914+ Nothing ->
915+ "calc(" ++ String.fromInt count ++ "em + " ++ String.fromInt ((count - 1) * spacing) ++ "px) !important"
916+
917+ Just (Padding t r b l) ->
918+ "calc(" ++ String.fromInt count ++ "em + " ++ String.fromInt ((t + b) + ((count - 1) * spacing)) ++ "px) !important"
919+ in
920+ Internal.StyleClass Flag.heightTextAreaContent
921+ (Internal.Single ("textarea-height-" ++ String.fromInt newlineCount)
922+ "height"
923+ (heightValue newlineCount)
924+ )
925+
926+
928927{-| -}
929928text :
930929 List (Attribute msg)
@@ -1811,6 +1810,7 @@ defaultTextBoxStyle =
18111810 , Background.color white
18121811 , Border.width 1
18131812 , Element.spacing 3
1813+ , Element.width Element.fill
18141814 ]
18151815
18161816
src/Internal/Flag.elm+60−1
@@ -1,4 +1,59 @@
1−module Internal.Flag exposing (Field(..), Flag(..), active, add, alignBottom, alignRight, behind, bgColor, bgGradient, bgImage, borderColor, borderRound, borderStyle, borderWidth, centerX, centerY, cursor, flag, focus, fontAlignment, fontColor, fontFamily, fontSize, fontWeight, gridPosition, gridTemplate, height, heightBetween, heightContent, heightFill, hover, letterSpacing, merge, moveX, moveY, none, overflow, padding, present, rotate, scale, shadows, spacing, transparency, txtShadows, value, width, widthBetween, widthContent, widthFill, wordSpacing, xAlign, yAlign)
1+module Internal.Flag exposing
2+ ( Field(..)
3+ , Flag(..)
4+ , active
5+ , add
6+ , alignBottom
7+ , alignRight
8+ , behind
9+ , bgColor
10+ , bgGradient
11+ , bgImage
12+ , borderColor
13+ , borderRound
14+ , borderStyle
15+ , borderWidth
16+ , centerX
17+ , centerY
18+ , cursor
19+ , flag
20+ , focus
21+ , fontAlignment
22+ , fontColor
23+ , fontFamily
24+ , fontSize
25+ , fontWeight
26+ , gridPosition
27+ , gridTemplate
28+ , height
29+ , heightBetween
30+ , heightContent
31+ , heightFill
32+ , heightTextAreaContent
33+ , hover
34+ , letterSpacing
35+ , merge
36+ , moveX
37+ , moveY
38+ , none
39+ , overflow
40+ , padding
41+ , present
42+ , rotate
43+ , scale
44+ , shadows
45+ , spacing
46+ , transparency
47+ , txtShadows
48+ , value
49+ , width
50+ , widthBetween
51+ , widthContent
52+ , widthFill
53+ , wordSpacing
54+ , xAlign
55+ , yAlign
56+ )
257
358{-| -}
459
@@ -259,3 +314,7 @@ heightBetween =
259314
260315behind =
261316 flag 46
317+
318+
319+heightTextAreaContent =
320+ flag 47
src/Internal/Model.elm+135−15
@@ -1,4 +1,117 @@
1−module Internal.Model exposing (Aligned(..), Angle, Attribute(..), Axis(..), Children(..), Color(..), Description(..), Element(..), EmbedStyle(..), FocusStyle, Font(..), Gathered, HAlign(..), HoverSetting(..), LayoutContext(..), Length(..), Location(..), NodeName(..), Option(..), OptionRecord, Padding(..), Property(..), PseudoClass(..), RenderMode(..), Shadow, Spacing(..), Style(..), TransformComponent(..), Transformation(..), VAlign(..), XYZ, addNodeName, addWhen, alignXName, alignYName, asColumn, asEl, asGrid, asParagraph, asRow, asTextColumn, boxShadowName, columnClass, composeTransformation, contextClasses, createElement, defaultOptions, div, element, embedKeyed, embedWith, extractSpacingAndPadding, filter, finalizeNode, floatClass, focusDefaultStyle, formatBoxShadow, formatColor, formatColorClass, formatDropShadow, formatTextShadow, gatherAttrRecursive, get, getHeight, getSpacing, getStyleName, getWidth, gridClass, htmlClass, lengthClassName, map, mapAttr, mapAttrFromStyle, noStyleSheet, onlyStyles, optionsToRecord, paddingName, pageClass, paragraphClass, reduceRecursive, reduceRecursiveCalcName, reduceStyles, reduceStylesRecursive, removeNever, renderFocusStyle, renderFont, renderFontClassName, renderHeight, renderRoot, renderWidth, rootStyle, rowClass, singleClass, skippable, sortedReduce, spacingName, staticRoot, tag, textElement, textElementFill, textShadowName, toHtml, toStyleSheet, toStyleSheetString, transformClass, transformValue, unit, unstyled, untransformed, unwrapDecorations, unwrapDecsHelper)
1+module Internal.Model exposing
2+ ( Aligned(..)
3+ , Angle
4+ , Attribute(..)
5+ , Axis(..)
6+ , Children(..)
7+ , Color(..)
8+ , Description(..)
9+ , Element(..)
10+ , EmbedStyle(..)
11+ , FocusStyle
12+ , Font(..)
13+ , Gathered
14+ , HAlign(..)
15+ , HoverSetting(..)
16+ , LayoutContext(..)
17+ , Length(..)
18+ , Location(..)
19+ , NodeName(..)
20+ , Option(..)
21+ , OptionRecord
22+ , Padding(..)
23+ , Property(..)
24+ , PseudoClass(..)
25+ , RenderMode(..)
26+ , Shadow
27+ , Spacing(..)
28+ , Style(..)
29+ , TransformComponent(..)
30+ , Transformation(..)
31+ , VAlign(..)
32+ , XYZ
33+ , addNodeName
34+ , addWhen
35+ , alignXName
36+ , alignYName
37+ , asColumn
38+ , asEl
39+ , asGrid
40+ , asParagraph
41+ , asRow
42+ , asTextColumn
43+ , boxShadowName
44+ , columnClass
45+ , composeTransformation
46+ , contextClasses
47+ , createElement
48+ , defaultOptions
49+ , div
50+ , element
51+ , embedKeyed
52+ , embedWith
53+ , extractSpacingAndPadding
54+ , filter
55+ , finalizeNode
56+ , floatClass
57+ , focusDefaultStyle
58+ , formatBoxShadow
59+ , formatColor
60+ , formatColorClass
61+ , formatDropShadow
62+ , formatTextShadow
63+ , gatherAttrRecursive
64+ , get
65+ , getHeight
66+ , getSpacing
67+ , getStyleName
68+ , getWidth
69+ , gridClass
70+ , htmlClass
71+ , lengthClassName
72+ , map
73+ , mapAttr
74+ , mapAttrFromStyle
75+ , noStyleSheet
76+ , onlyStyles
77+ , optionsToRecord
78+ , paddingName
79+ , pageClass
80+ , paragraphClass
81+ , reduceRecursive
82+ , reduceRecursiveCalcName
83+ , reduceStyles
84+ , reduceStylesRecursive
85+ , removeNever
86+ , renderFocusStyle
87+ , renderFont
88+ , renderFontClassName
89+ , renderHeight
90+ , renderRoot
91+ , renderWidth
92+ , rootStyle
93+ , rowClass
94+ , singleClass
95+ , skippable
96+ , sortedReduce
97+ , spacingName
98+ , staticRoot
99+ , tag
100+ , textElement
101+ , textElementFill
102+ , textShadowName
103+ , toHtml
104+ , toStyleSheet
105+ , toStyleSheetString
106+ , transformClass
107+ , transformValue
108+ , unit
109+ , unstyled
110+ , untransformed
111+ , unwrapDecorations
112+ , unwrapDecsHelper
113+ , isContent
114+ )
2115
3116{-| -}
4117
@@ -1002,50 +1115,42 @@ gatherAttrRecursive classes node has transform styles attrs children elementAttr
10021115 case location of
10031116 Above ->
10041117 String.join " "
1005− [
1006− Internal.Style.classes.nearby
1118+ [ Internal.Style.classes.nearby
10071119 , Internal.Style.classes.single
10081120 , Internal.Style.classes.above
10091121 ]
10101122
10111123 Below ->
10121124 String.join " "
1013− [
1014− Internal.Style.classes.nearby
1125+ [ Internal.Style.classes.nearby
10151126 , Internal.Style.classes.single
10161127 , Internal.Style.classes.below
10171128 ]
10181129
10191130 OnRight ->
10201131 String.join " "
1021− [
1022− Internal.Style.classes.nearby
1132+ [ Internal.Style.classes.nearby
10231133 , Internal.Style.classes.single
10241134 , Internal.Style.classes.onRight
10251135 ]
10261136
10271137 OnLeft ->
1028−
1029−
10301138 String.join " "
1031− [
1032− Internal.Style.classes.nearby
1139+ [ Internal.Style.classes.nearby
10331140 , Internal.Style.classes.single
10341141 , Internal.Style.classes.onLeft
10351142 ]
10361143
10371144 InFront ->
10381145 String.join " "
1039− [
1040− Internal.Style.classes.nearby
1146+ [ Internal.Style.classes.nearby
10411147 , Internal.Style.classes.single
10421148 , Internal.Style.classes.inFront
10431149 ]
10441150
10451151 Behind ->
10461152 String.join " "
1047− [
1048− Internal.Style.classes.nearby
1153+ [ Internal.Style.classes.nearby
10491154 , Internal.Style.classes.single
10501155 , Internal.Style.classes.behind
10511156 ]
@@ -1648,6 +1753,21 @@ filter attrs =
16481753 attrs
16491754
16501755
1756+isContent len =
1757+ case len of
1758+ Content ->
1759+ True
1760+
1761+ Max _ l ->
1762+ isContent l
1763+
1764+ Min _ l ->
1765+ isContent l
1766+
1767+ _ ->
1768+ False
1769+
1770+
16511771get : List (Attribute aligned msg) -> (Attribute aligned msg -> Bool) -> List (Attribute aligned msg)
16521772get attrs isAttr =
16531773 attrs