1.0.6 • Published 1 year ago

npm-native-dropdown v1.0.6

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

npm-native-dropdown

The npm-native-dropdown package provides a versatile and customizable dropdown component for React applications. With this package, you can easily integrate dropdown menus into your UI, offering users a seamless way to select options from a list.

Badges

MIT License

Installation

Install my-project with npm

  npm install npm-native-dropdown
  cd my-project

or

  yarn add npm-native-dropdown
  cd my-project

Features

  • Easy to use
  • Single or Multiselect option for items
  • Responsive for Cross platform
  • Have wast option for customization
  • Implemented with typescript

Screenshots

App gif

Array example -

  const options = [
    "Heart",
    "Thumbs Up",
    "Star",
    "Smiley",
  ];

npm Import -

import DropdownMenu from 'npm-native-dropdown';

Usage/Examples 1 - Simple

      <DropdownMenu
        placeHolder={selected ? selected : 'Select Option'}
        options={options}
        onSelect={(selectedItem: string, index: number) => {
          console.log('>>>', selectedItem, index);
        }}
      />

Usage/Examples 2 - With renderitem and renderButton

      <DropdownMenu
        options={options}
        onSelect={(selectedItem: string, index: number) => {
          console.log('>>>', selectedItem, index);
        }}
        renderButton={(buttonRef, toggleMenu) => {
          return (
            <TouchableOpacity style={[$button]} ref={buttonRef} onPress={toggleMenu}>
              <Text>{selected ? selected : 'Select'}</Text>
            </TouchableOpacity>
          )
        }}
        renderItem={(setIsMenuOpen: () => any) => {
          return options.map((option, index) => {
            return (<TouchableOpacity
              key={index}
              onPress={() => {setIsMenuOpen(),setSelected(option)}}
              style={[$menuItem(options?.length === index + 1)]}
            >
              <Text style={[$textStyle]}>{option} </Text>
            </TouchableOpacity>)
          })
        }}
      />
      
const $menuItem = (isLast: boolean): ViewStyle => ({
  padding: 12,
  flex: 1,
  paddingVertical: 8,
  width: 200,
  borderBottomWidth: isLast ? 0 : 0.5,
  borderColor: 'gray',
  alignItems: 'center'
})

const $textStyle: TextStyle = {
  fontSize: 16,
  fontWeight: '400',
  color: 'green'
}

const $button: TextStyle = {
  backgroundColor: '#e1ecf7',
  height: 44,
  width: 200,
  borderColor: '#71a5de',
  borderWidth: 1,
  borderRadius: 4,
  alignItems: 'center',
  justifyContent: 'center',
}

Usage/Examples 3 - With Icons

(Note - You can use any JSX.Element)

      <DropdownMenu
        placeHolder={selected ? selected : 'Select Option'}
        options={options}
        onSelect={(selectedItem: string, index: number) => {
          console.log('>>>', selectedItem, index);
        }}
        leftRenderIcon={
          <Image
            style={$tinyLogo}
            source={{
              uri: 'https://image.png',
            }}
          />
        }
        rightRenderIcon={
          <Image
            style={$tinyLogo}
            source={{
              uri: 'https://image.png',
            }}
          />
        }
      />

const $tinyLogo: ImageStyle = {
  width: 20,
  height: 20,
}

API Reference

Props

PropsParamsisRequireDescription
optionsstring[]YesPlain array containing dropdown options.
rightRenderIconReactElementNoCustom component to be used as the dropdown icon.
placeHolderstringNoPlaceholder text when no option is selected.
onSelect(option: string, index: number) => voidYesfunction recieves selected item and its index in data array
disabledbooleanNodisable dropdown
buttonStyleViewStyleNostyle object for dropdown Button.
placeHolderTextStyleTextStyleNostyle object for dropdown placeholder Text.
contentStyleViewStyleNostyle object for dropdown content.
menuItemStyleViewStyleNostyle object for dropdown menu items.
optionStyleTextStyleNostyle object for dropdown options.
leftRenderIconJSX.ElementNoCustom component to be used as the dropdown icon.
renderItemJSX.ElementNoReact component for each dropdown item.
renderButtonJSX.ElementNoReact component for the dropdown button.
dropDownWidthnumberNodropdown width.

Author

License

MIT

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago