Skip to content

FBCM-4913 Expand MultiInput inner input field to fill the whole container #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "purescript-ocelot",
"version": "0.33.2",
"version": "0.33.3",
"private": true,
"scripts": {
"build-all": "make build",
Expand Down
58 changes: 36 additions & 22 deletions src/Components/MultiInput/Component.purs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,8 @@ render ::
render state =
Halogen.HTML.div
[ Halogen.HTML.Properties.classes containerClasses ]
[ Halogen.HTML.div_
[ Halogen.HTML.div
[ Ocelot.HTML.Properties.css "flex flex-wrap items-start" ]
(Data.FunctorWithIndex.mapWithIndex (renderItem state.placeholder) state.items)
, renderTextWidth
]
Expand All @@ -585,7 +586,7 @@ renderItem ::
renderItem placeholder index = case _ of
Display { text } -> renderItemDisplay index text
Edit { inputBox } -> renderItemEdit placeholder index inputBox
New { inputBox } -> renderAutoSizeInput placeholder index true inputBox
New { inputBox } -> renderItemNew placeholder index inputBox

renderItemDisplay ::
forall m.
Expand Down Expand Up @@ -622,6 +623,17 @@ renderItemEdit placeholder index inputBox =
[ Ocelot.Block.Icon.delete_ ]
]

renderItemNew ::
forall m.
Placeholder ->
Int ->
InputBox ->
ComponentHTML m
renderItemNew placeholder index inputBox =
Halogen.HTML.div
[ Ocelot.HTML.Properties.css "block flex-1" ]
[ renderAutoSizeInput placeholder index true inputBox ]

renderAutoSizeInput ::
forall m.
Placeholder ->
Expand All @@ -630,29 +642,30 @@ renderAutoSizeInput ::
InputBox ->
ComponentHTML m
renderAutoSizeInput placeholder index new inputBox =
Halogen.HTML.div
[ Ocelot.HTML.Properties.css "inline-block" ]
[ Halogen.HTML.input
[ Halogen.HTML.Properties.attr (Halogen.HTML.AttrName "style") css
, Halogen.HTML.Properties.classes inputClasses
, Halogen.HTML.Events.onBlur \_ -> OnBlur index
, Halogen.HTML.Events.onFocus \_ -> OnFocus index
, Halogen.HTML.Events.onKeyDown (OnKeyDown index)
, Halogen.HTML.Events.onMouseDown (OnMouseDown index)
, Halogen.HTML.Events.onValueInput (OnInput index)
, Halogen.HTML.Properties.placeholder case new of
false -> ""
true
| index == 0 -> placeholder.primary.text
| otherwise -> placeholder.secondary.text
, Halogen.HTML.Properties.ref (inputRef index)
, Halogen.HTML.Properties.type_ Halogen.HTML.Properties.InputText
, Halogen.HTML.Properties.value inputBox.text
]
Halogen.HTML.input
[ Halogen.HTML.Properties.attr (Halogen.HTML.AttrName "style") css
, Halogen.HTML.Properties.classes inputClasses
, Halogen.HTML.Events.onBlur \_ -> OnBlur index
, Halogen.HTML.Events.onFocus \_ -> OnFocus index
, Halogen.HTML.Events.onKeyDown (OnKeyDown index)
, Halogen.HTML.Events.onMouseDown (OnMouseDown index)
, Halogen.HTML.Events.onValueInput (OnInput index)
, Halogen.HTML.Properties.placeholder case new of
false -> ""
true
| index == 0 -> placeholder.primary.text
| otherwise -> placeholder.secondary.text
, Halogen.HTML.Properties.ref (inputRef index)
, Halogen.HTML.Properties.type_ Halogen.HTML.Properties.InputText
, Halogen.HTML.Properties.value inputBox.text
]
where
css :: String
css = "width: " <> show width <> "px"
css =
if new then
"min-width: " <> show width <> "px"
else
"width: " <> show width <> "px"

width :: Number
width
Expand Down Expand Up @@ -713,6 +726,7 @@ inputClasses =
[ "my-1"
, "outline-none"
, "px-1"
, "w-full"
]
<#> Halogen.ClassName

Expand Down