import { Meta, Story, Controls, Canvas } from "@storybook/blocks";
import * as MultipleSelectStories from "./MultipleSelect.stories";
<Meta of={MultipleSelectStories} parameters={{ layout: "centered", docs: { story: { inline: true, iframeHeight: 200, }, }, }} />
A flexible multi-select component with grouped options, exclusive selections, and collapsible sections.
options
:MultipleSelectGroup[]
- Array of option groupsdefaultValue
:Record<string, string[]>
- Initial selections per groupplaceholder
:string
- Text shown when nothing selected if defaultValue then placeholder will be ignoredclassName
:string
- Popover container CSS classesvariants
:object
- Style customizations with the following options:color
:"default" | "grey"
- Controls the overall color schemesize
:"default" | "sm"
- Controls component sizingrounded
:"default"
- Controls border radius stylingitemsPosition
:"start" | "end" | "center"
- Controls alignment of items in the listheaderPosition
:"start" | "end" | "center"
- Controls alignment of group headerstriggerTextColor
:"default" | "red" | "green"
- Controls the trigger text coloritemsColor
:"default" | "light-grey"
- Controls the color of items and their icons
onChange
:(values: Record<string, string[]>) => void
- Selection change handler
groupLabel?
:string
- Group name (omit for ungrouped items)multiple?
:boolean
- Allow multiple selections (default: true)collapsible?
:boolean
- Enable group toggleitems
:MultipleSelectItem[]
- Array of options
value
:string
- Unique identifierlabel
:string
- Display textexclusive?
:boolean
- Clear other selections when chosenexclusiveScope?
:"group" | "global"
- Clear scope for exclusive itemsiconType?
:IconType
- Optional icon identifier check@/primitives/Icon story
icon?
:React.ComponentType
- Optional icon component used if no iconType is provideditemClassName?
:string
- Item-specific CSS classes
Below are several usage examples showcasing common patterns and advanced features.
Description
A single ungrouped set of items (no group label) with simple placeholder text.
- Options: 3 items, no exclusivity.
onChange
logs the selection to console.
Description Demonstrates exclusive items across two single-select groups (“Order by time” and
“Order by name”). Each item has exclusive: true, exclusiveScope: 'global'
, ensuring that if you pick
“Recent,” it clears any “A-Z” or “Z-A” selection.
defaultValue
sets the initial selection to["Recent"]
in the “ORDER BY TIME” group.variants
example usage for adjusting text color, alignment, etc.
Description A filter scenario with an “All” exclusive item for resetting.
- “All” is in an ungrouped set with
exclusive: true, exclusiveScope: 'global'
. - Two collapsible groups, “Network” and “Status,” each with
multiple: true
. defaultValue
starts with “All” selected in the ungrouped items.
Description Shows a combination of:
- A group with an exclusive item called “Reset All.”
- Another group that’s multi-select with standard options.
This approach is useful when you have a special action (like “Reset” or “Clear All”) plus normal multi-select items.
Description
Showcases using all variant props (triggerTextColor
, headerPosition
, itemsPosition
, etc.) or whatever your MultipleSelect has to customize.
- You can set text color, alignment, plus a collapsible group.
- Useful to see how to pass styling variants from tailwind-variants to the component.
- Use
defaultValue
for initial selections, or manage selections outside if you want it to be “controlled.” exclusive
items are great for “select all,” “select none,” or “reset.”- Collapsible groups let you nest large sets of items without overwhelming the user.
MultipleSelect
is highly configurable for your needs: from a simple single group with no advanced logic, to multi-group filters, collapsible sections, exclusive “all” items, or complex order-by pickers.
Check out the source code & stories for additional usage details.