🎨
Valence
🎨
Valence
  • Overview
    • 👋Welcome to Valence
    • 🏄‍♂️Getting started
  • Core Concepts
    • Responsiveness
    • Color
      • List of colors
      • Color types
    • Polymorphism
  • Valence Core
    • 🏃‍♂️Fundamentals
      • 🎬The ValenceProvider
      • ✍️Using custom fonts
    • 🧱Components
      • 🔘Buttons
        • Button with icon
        • Grid Button
        • Text button
        • Icon button
        • Multi-part button
        • Unstyled button
        • Primitive button
      • ⌨️Inputs
        • Color Picker
        • Text input
        • Text area
        • Number input
        • Select input
        • Switch
        • Slider
        • Range slider
        • Pill selector
        • Input container
        • Dropdown container
      • 🖥️Display
        • Accordion
        • Alert
        • Color Swatch
        • Icon
        • Image
        • Avatar
        • Avatar Group
        • Loader
        • Pill
        • Spoiler
        • Stepper
        • Text
        • Title
      • 🧩Layout
        • App Container
        • Card
        • Flex
          • Flex Center
          • Styled Flex
        • Floating Toolbar
        • Grid
        • Header
        • Overflow Container
        • Space
      • 🗺️Navigation
        • App Nav
      • 🔼Overlays
        • Modal
        • Tooltip
        • Modal background
        • 📰Sheets
          • Bottom Sheet
          • Dynamic Sheet
          • Side Sheet
    • 🪝Hooks
      • UseColorScheme
      • UseColors
      • UseControlledList
      • UseDetectKeyDown
      • UseDisclosure
      • UseFloating
      • UseTooltip
      • UseBreakpoint
      • UseResponsiveProps
    • 🤚Generics
      • Generic button props
      • Generic input props
      • Generic Sheet Props
  • Valence Plugins
    • 🎠Valence Carousel
      • Carousel Child Props
  • Valence Utils
    • ✋Generics
      • Clickable
      • Events
      • Global
      • Grid
      • Layout
      • Overlay
      • Polymorphic
    • 🧜‍♀️Polymorphism
      • Polymorphic Button
      • Polymorphic Layout
      • Polymorphic Text
  • Update Notes
    • 3.0.0
    • 2.7.0
    • 2.6.0
    • 2.5.0
    • 2.4.0
    • 2.3.0
    • 2.2.0
    • 2.1.0
    • 2.0.0
Powered by GitBook
On this page
  • Usage
  • Add new pills
  • Change wrap style
  • Props
  • PillSelectorEventProps

Was this helpful?

Edit on GitHub
  1. Valence Core
  2. Components
  3. Inputs

Pill selector

Last updated: 2.0.0 (18/01/2024)

PreviousRange sliderNextInput container

Last updated 1 year ago

Was this helpful?

Usage

import { PillSelector } from "@valence-ui/core";

function MyComponent() { 
    const [value, setValue] = React.useState(["hello", "world"]);

    return ( 
        <PillSelector 
            value={value}
            setValue={setValue}
            pills={["hello", "there", "world"]}
        />
    )
}

Add new pills

To allow users to add new pills to this input, the allowEditing prop must be used. Additionally, the pills and setPills props must be tied to a React state, allowing them to be updated.

Allowing editing will create a new above the Pill selector. Using this text editor, the user may type out a new pill and use the Enter key or the accompanying add button to create and select that pill. If the user then de-selects a pill they have created, it will be deleted from the list of pills as well.

The placeholder, inputProps, addButtonProps and addButtonIcon props can be used to modify the appearance and behavior of the inputs created when adding new pills.

import { PillSelector } from "@valence-ui/core";

function MyComponent() { 
    const [selected, setSelected] = React.useState(["hello", "world"]);
    const [pills, setPills] = React.useState(["hello", "there", "world"]);

    return ( 
        <PillSelector 
            value={selected}
            setValue={setSelected}
            
            pills={pills}
            setPills={setPills}
            allowEditing
        />
    )
}

Change wrap style

By default, the Pill selector will be formatted as a horizontally-scrolling series of pills, but the wrap prop exists to allow different wrapping of the input.

Setting wrap="wrap" allows the input to display every pill at once as a block:

import { PillSelector } from "@valence-ui/core";

function MyComponent() { 
    const [value, setValue] = React.useState(["hello", "world"]);

    return ( 
        <PillSelector 
            value={value}
            setValue={setValue}
            pills={["hello", "there", "world"]}
            
            wrap="wrap"
        />
    )
}

Props

Property
Type
Description

pills (required)

string[]

A list of pills to display.

setPills

(pills: string[]) => void

Optional callback to complete the state.

allowClear

boolean

Whether to allow pills to be cleared. true by default.

grow

boolean

Shorthand for flex-grow = 1

gap

number

Sets the gaps between everything. 5 by default.

wrap

CSSProperties["flexWrap"]

How the pills should wrap within their container. Defaults to "nowrap".

maxSelectable

number

The maxmimum number of pills that can be selected. Infinity by default.

clearButtonIcon

ReactNode

An icon to use for the clear button. Defaults to IconX

clearButtonProps

Omit<IconButtonProps, "children">

Optional props to pass to the clear button.

pillProps

Omit<TextButtonProps, "children">

Optional props to pass to all pills.

selectedPillProps

Omit<TextButtonProps, "children">

Optional props to pass to selected pills. Will override attributes from pillProps.

pillContainerProps

Omit<FlexProps, "children">

Optional props to pass to the pill container.

allowEditing

boolean

Whether to allow the creation of new pills.

placeholder

string

Placeholder text to display in the Text input. Will only show if allowEditing = true.

inputProps

Omit<TextInputProps, "value"|"setValue">

Optional styles to pass to the Text input.

addButtonProps

Omit<IconButtonProps, "children">

Optional props to pass to the add button.

addButtonIcon

ReactNode

Optional icon to use for the add button.

PillSelectorEventProps

Extends MouseClickEvents, MouseEvents, PointerEvents, FocusEvents and KeyboardEvents.

Property
Type
Description

onPillSelected

(value: string) => void

Callback to be fired when a pill is selected.

onPillDeselected

(value: string) => void

Callback to be fired when a pill is deselected.

Extends and PillSelectorEventProps.

🧱
⌨️
Text input
GenericInputProps<string[]>