Skip to content

Commit af04dd4

Browse files
committed
give user full control over text rendering
We used to take a default label String and a text render function for a single selection with `Maybe` in `renderToolbarSearchDropdown`. Now we want to support multiple selections with `Array`, the presentation of text as a summary of selections could vary depending on different situations, e.g. a comma separated list of all selections, or the count of selections, etc. so we let users to provide the render function instead of making a decision for them.
1 parent ce39ac9 commit af04dd4

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

src/Interfaces/Typeahead/Interface.purs

+4-2
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,10 @@ searchDropdownInputToToolbarSingleInput r =
300300
, disabled: false
301301
, render: renderToolbarSearchDropdown
302302
r.placeholder
303-
r.resetLabel
304-
renderLabel
303+
( case _ of
304+
Nothing -> HH.text r.resetLabel
305+
Just x -> renderLabel x
306+
)
305307
renderFuzzy
306308
}
307309
where

src/Typeahead.purs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1015,14 +1015,14 @@ renderSingle iprops renderItem renderContainer st =
10151015
showSelected = Data.Maybe.isJust st.selected && st.visibility == Select.Off
10161016

10171017
renderToolbarSearchDropdown
1018-
:: action item m
1018+
:: action f item m
10191019
. Eq item
1020+
=> Data.Foldable.Foldable f
10201021
=> String
1021-
-> String
1022-
-> (item -> Halogen.HTML.PlainHTML)
1022+
-> (f item -> Halogen.HTML.PlainHTML)
10231023
-> (Data.Fuzzy.Fuzzy item -> Halogen.HTML.PlainHTML)
1024-
-> CompositeComponentRender action Maybe item m
1025-
renderToolbarSearchDropdown defaultLabel resetLabel renderItem renderFuzzy st =
1024+
-> CompositeComponentRender action f item m
1025+
renderToolbarSearchDropdown resetLabel renderText renderFuzzy st =
10261026
renderSearchDropdown resetLabel label renderFuzzy st
10271027
where
10281028
label = Ocelot.Block.ItemContainer.dropdownButton
@@ -1032,7 +1032,7 @@ renderToolbarSearchDropdown defaultLabel resetLabel renderItem renderFuzzy st =
10321032
: Ocelot.Block.Button.buttonMainClasses
10331033
<> Ocelot.Block.Button.buttonClearClasses
10341034
]
1035-
[ Data.Maybe.maybe (Halogen.HTML.text defaultLabel) (Halogen.HTML.fromPlainHTML <<< renderItem) st.selected ]
1035+
[ (Halogen.HTML.fromPlainHTML <<< renderText) st.selected ]
10361036

10371037
replaceSelected
10381038
:: forall action f item m

ui-guide/Components/Typeaheads.purs

+36-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Prelude
44

55
import Control.Parallel as Control.Parallel
66
import Data.Array (head, take)
7+
import Data.Array as Data.Array
78
import Data.Maybe (Maybe(..))
89
import Data.Newtype (unwrap)
910
import Effect.Aff.Class (class MonadAff)
@@ -647,8 +648,42 @@ cnDocumentationBlocks =
647648
, disabled: false
648649
, render: TA.renderToolbarSearchDropdown
649650
"All Locations"
651+
( case _ of
652+
Nothing -> HH.text "All Locations"
653+
Just (Async.Location x) -> HH.text x.name
654+
)
655+
(HH.span_ <<< IC.boldMatches "name")
656+
}
657+
]
658+
]
659+
, content
660+
[ Card.card
661+
[ HP.class_ $ HH.ClassName "flex-1" ]
662+
[ HH.h3
663+
[ HP.classes Format.captionClasses ]
664+
[ HH.text "Multi - Searchable Dropdown in a Toolbar (e.g. for filtering)" ]
665+
, HH.slot_ _multiLocation 11
666+
( TA.component
667+
{ runSelect: Data.Array.cons
668+
, runRemove: Data.Array.filter <<< (/=)
669+
, runFilterFuzzy: identity
670+
, runFilterItems: const
671+
}
672+
)
673+
{ items: NotAsked
674+
, insertable: TA.NotInsertable
675+
, keepOpen: true
676+
, debounceTime: Nothing
677+
, async: Nothing
678+
, itemToObject: Async.locationToObject
679+
, disabled: false
680+
, render: TA.renderToolbarSearchDropdown
650681
"All Locations"
651-
(HH.text <<< _.name <<< unwrap)
682+
( case _ of
683+
[] -> HH.text "All Locations"
684+
[ Async.Location x ] -> HH.text x.name
685+
xs -> HH.text (show (Data.Array.length xs) <> " Locations Selected")
686+
)
652687
(HH.span_ <<< IC.boldMatches "name")
653688
}
654689
]

0 commit comments

Comments
 (0)