Skip to content

Repository files navigation

React Native Button Multiselect

React Native Button Multiselect is a versatile component designed for seamless integration of button-based multi-select functionality into React Native applications.

npm versionnpm downloadsnpm licence

DEMO

Table of Contents

  1. Installation
  2. Demo
  3. Usage
  4. Props
  5. Button Layout

Installation

Install the package using Yarn or npm:

yarn add react-native-button-multiselect
# or
npm install --save react-native-button-multiselect

Demo

You can see a live demo on this Expo Snack.

You can also experiment with the example app in the repo using Expo:

  1. Clone this repository.
  2. Navigate to the example folder.
  3. Install dependencies:
cd example
yarn install

Now, you can run the app with

yarn start

Basic Usage

Implement the component in your app:

importButtonMultiselect,{ButtonLayout,}from'react-native-button-multiselect';// ...constApp=()=>{// Define your button optionsconstbuttons=[{label: 'Option 1',value: 'option1'},{label: 'Option 2',value: 'option2'},];// Set up state and handlers for selected buttonsconst[selectedButtons,setSelectedButtons]=useState([]);consthandleButtonSelected=(selectedValues)=>{setSelectedButtons(selectedValues);};return(<ButtonMultiselectlayout={ButtonLayout.CAROUSEL}// Choose from ButtonLayout enum: CAROUSEL, FULL_WIDTH, GRIDbuttons={buttons}selectedButtons={selectedButtons}onButtonSelected={handleButtonSelected}// Additional props can be customized as needed/>);};exportdefaultApp;

Props

Detailed descriptions of the available props:

PropTypeDescriptionRequired
layoutButtonLayoutLayout type for rendering buttons: ButtonLayout.CAROUSEL, ButtonLayout.FULL_WIDTH, or ButtonLayout.GRID.Yes
buttonsButtonProps[]Array of button options, each with a label and unique value. DetailsYes
selectedButtonsstring | string[]Currently selected button(s). Use an array for multi-select mode, and a string for single-select mode.Yes
onButtonSelectedFunctionCallback function invoked when a button is selected. Receives the selected value(s).Yes
containerStyleViewStyle | Array<ViewStyle>Custom styles for the container wrapping the buttons.No
horizontalPaddingnumberHorizontal padding for the buttons.No
buttonStyleViewStyle | Array<ViewStyle>Custom styles for the buttons.No
textStyleTextStyle | Array<TextStyle>Custom styles for the button text.No
selectedColorsThemeColorsTheme colors for selected buttons, including backgroundColor, textColor, and borderColor. DetailsNo
unselectedColorsThemeColorsTheme colors for unselected buttons, including backgroundColor, textColor, and borderColor. DetailsNo
buttonMarginnumberMargin between buttons.No
multiselectbooleanEnable multi-select mode. Default is false (single-select). DetailsNo

ButtonProps

PropTypeDescription
labelstringLabel for the button.
valuestringUnique value for the button.

ThemeColors

PropTypeDescription
backgroundColorstringButton's background.
textColorstringButton's text color.
borderColorstringButton's border.

Conditional Props (multiselect)

ConditionPropsDescription
multiselect:true{ selectedButtons: string[]; onButtonSelected: (value: string[]) => void; }Conditional prop for multi-select mode. Requires selectedButtons as an array and the onButtonSelected callback function that will return an array of strings.
multiselect:false{ selectedButtons: string; onButtonSelected: (value: string) => void; }Conditional prop for single-select mode. Requires selectedButtons as a string and the onButtonSelected callback function that will return a string.

Button Layout

FULL_WIDTH

DEMO

<ButtonMultiselectbuttons={[]}layout={ButtonLayout.FULL_WIDTH}onButtonSelected={setSelectedOption}selectedButtons={selectedOption}/>

CAROUSEL

DEMO

<ButtonMultiselectbuttons={[]}layout={ButtonLayout.CAROUSEL}onButtonSelected={setSelectedOption}selectedButtons={selectedOption}/>

GRID

DEMO

<ButtonMultiselectbuttons={[]}layout={ButtonLayout.GRID}onButtonSelected={setSelectedOption}selectedButtons={selectedOption}/>

Multiselect

Single-select mode (like radio)

DEMO

<ButtonMultiselectbuttons={[...]}layout={ButtonLayout.GRID}onButtonSelected={setSelectedOption}selectedButtons={selectedOption}/>

Multi-select (like checkbox)

DEMO

<ButtonMultiselectbuttons={[...]}multiselectlayout={ButtonLayout.CAROUSEL}onButtonSelected={setSelectedOptions}selectedButtons={selectedOptions}/>

License

This project is licensed under the MIT License. See the License tab for more details.


About

a React Native component for easy integration of button-based multi-select functionality

Topics

Resources

Code of conduct

Contributing

Stars

3 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages