npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-button-multiselect

v0.1.7

Published

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

Downloads

263

Readme

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.

Table of Contents

  1. Demo
  2. Installation
  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

Try it out

To experiment with an example app 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:

import ButtonMultiselect, {
  ButtonLayout,
} from 'react-native-button-multiselect';

// ...

const App = () => {
  // Define your button options
  const buttons = [
    { label: 'Option 1', value: 'option1' },
    { label: 'Option 2', value: 'option2' },
  ];

  // Set up state and handlers for selected buttons
  const [selectedButtons, setSelectedButtons] = useState([]);

  const handleButtonSelected = (selectedValues) => {
    setSelectedButtons(selectedValues);
  };

  return (
    <ButtonMultiselect
      layout={ButtonLayout.CAROUSEL} // Choose from ButtonLayout enum: CAROUSEL, FULL_WIDTH, GRID
      buttons={buttons}
      selectedButtons={selectedButtons}
      onButtonSelected={handleButtonSelected}
      // Additional props can be customized as needed
    />
  );
};

export default App;

Props

Detailed descriptions of the available props:

| Prop | Type | Description | Required | | ------------------- | ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | | layout | ButtonLayout | Layout type for rendering buttons: ButtonLayout.CAROUSEL, ButtonLayout.FULL_WIDTH, or ButtonLayout.GRID. | Yes | | buttons | ButtonProps[] | Array of button options, each with a label and unique value. Details | Yes | | selectedButtons | string \| string[] | Currently selected button(s). Use an array for multi-select mode, and a string for single-select mode. | Yes | | onButtonSelected | Function | Callback function invoked when a button is selected. Receives the selected value(s). | Yes | | containerStyle | ViewStyle \| Array<ViewStyle> | Custom styles for the container wrapping the buttons. | No | | horizontalPadding | number | Horizontal padding for the buttons. | No | | buttonStyle | ViewStyle \| Array<ViewStyle> | Custom styles for the buttons. | No | | textStyle | TextStyle \| Array<TextStyle> | Custom styles for the button text. | No | | selectedColors | ThemeColors | Theme colors for selected buttons, including backgroundColor, textColor, and borderColor. Details | No | | unselectedColors | ThemeColors | Theme colors for unselected buttons, including backgroundColor, textColor, and borderColor. Details | No | | buttonMargin | number | Margin between buttons. | No | | multiselect | boolean | Enable multi-select mode. Default is false (single-select). Details | No |

ButtonProps

| Prop | Type | Description | | ------- | -------- | ---------------------------------------- | | label | string | Label for the button. | | value | string | Unique value for the button. |

ThemeColors

| Prop | Type | Description | | ----------------- | -------- | ------------------------------- | | backgroundColor | string | Button's background. | | textColor | string | Button's text color. | | borderColor | string | Button's border. |

Conditional Props (multiselect)

| Condition | Props | Description | | ------------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | | 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

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

CAROUSEL

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

GRID

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

Multiselect

Single-select mode (like radio)

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

Multi-select (like checkbox)

<ButtonMultiselect
  buttons={[...]}
  multiselect
  layout={ButtonLayout.CAROUSEL}
  onButtonSelected={setSelectedOptions}
  selectedButtons={selectedOptions}
/>

License

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