1.0.7 • Published 1 year ago

react-native-chipgroup v1.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

React Native Chipgroup

react-native-chipgroup is a library that provides custom React Native components for creating interactive chip elements and selectable chip groups. These components are designed to enhance user interaction in React Native applications by offering intuitive and customizable UI elements.

The library includes the following components:

  • Chip: A versatile chip component that supports different modes, custom icons, and actions.
  • SelectChip: A group of selectable chips allowing users to choose from a set of options, with customizable styling and selection handling.

Installation

Using npm:

  npm i react-native-chipgroup

Note: react-native-responsive-dimensions is a required dependency for react-native-chipgroup. Make sure to install it for proper functionality.

Basic Usage

import React from 'react';
import { View } from 'react-native';
import { Chip, SelectChip } from 'react-native-chipgroup';

const data = [
  { label: 'Option 1', value: 1 },
  { label: 'Option 2', value: 2 },
  { label: 'Option 3', value: 3 }
];

const App = () => {

  const handleSelect = (item, index) => {
    console.log(`Selected: ${item.value} at index ${index}`);
  };

  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>

      <Chip
        mode="outlined"
        onPress={() => console.log('Chip pressed')}
        isCloseIcon={true}
        onClose={() => console.log('Close icon pressed')}
      >
        Example Chip
      </Chip>

      <SelectChip
        data={data}
        onSelect={handleSelect}
        renderLabel={(item) => item.label}
        defaultSelectedIndex={0}
        containerStyle={{ marginTop: 20 }}
      />

    </View>
  );
};

export default App;

Props

Chip

Prop nameTypeRequiredDefault valueDescription
mode'flat' \| 'outlined'No'flat'The mode of the chip, either 'flat' or 'outlined'.
childrenReactNodeNo-The content of the chip.
onPress() => voidNo-A function called when the chip is pressed.
leftIconReactNodeNo-An icon to be displayed on the left side of the chip.
rightIconReactNodeNo-An icon to be displayed on the right side of the chip.
isCloseIconBooleanNo-Determines whether to show a close icon on the chip.
onClose() => voidNo-A function called when the close icon is pressed.
containerStyleStyleProp<ViewStyle> or undefinedNo-Optional styling for the container of the Chip component.
styleStyleProp<ViewStyle> or (selected: boolean) => StyleProp<ViewStyle> or undefinedNo-Optional styling for the chip. It can be either a style object or a function.
labelStyleStyleProp<TextStyle> or (selected: boolean) => StyleProp<TextStyle> or undefinedNo-Optional styling for the label of the chip. It can be either a style object or a function.

SelectChip

Prop nameTypeRequiredDefault valueDescription
dataany[]Yes-An array of items to display as tags.
onSelect(item: any, index: number) => voidNo-A function called when a tag is selected. It receives the selected item and its index.
renderLabel(item: any) => stringYes-A function used to render the label of each tag.
containerStyleStyleProp<ViewStyle> or undefinedNo-Optional styling for the container of the Tag component.
styleStyleProp<ViewStyle> or (selected: boolean) => StyleProp<ViewStyle> or undefinedNo-Optional styling for the tags. It can be either a style object or a function.
labelStyleStyleProp<TextStyle> or (selected: boolean) => StyleProp<TextStyle> or undefinedNo-Optional styling for the label of the tags. It can be either a style object or a function.
defaultSelectedIndexnumber or undefinedNo0The default index of the selected tag.

License

The library is released under the ISC license. For more information see the License Tab.