2.3.0 • Published 1 year ago

react-native-switch-selector v2.3.0

Weekly downloads
3,043
License
MIT
Repository
github
Last release
1 year ago

SwitchSelector

Switch Selector to React Native.

npm version downloads

SwitchSelector

SwitchSelector

SwitchSelector - Custom Example

SwitchSelector

Installing

yarn add react-native-switch-selector

or

npm i react-native-switch-selector --save

Usage

import SwitchSelector from "react-native-switch-selector";
const options = [
  { label: "01:00", value: "1" },
  { label: "01:30", value: "1.5" },
  { label: "02:00", value: "2" }
];

you can also add testID and accessibilityLabel to each option:

const options = [
  { label: "01:00", value: "1", testID: "switch-one", accessibilityLabel: "switch-one" },
  { label: "01:30", value: "1.5", testID: "switch-one-thirty", accessibilityLabel: "switch-one-thirty" },
  { label: "02:00", value: "2", testID: "switch-two", accessibilityLabel: "switch-two" }
];
<SwitchSelector
  options={options}
  initial={0}
  onPress={value => console.log(`Call onPress with value: ${value}`)}
/>

Custom Example

<SwitchSelector
  initial={0}
  onPress={value => this.setState({ gender: value })}
  textColor={colors.purple} //'#7a44cf'
  selectedColor={colors.white}
  buttonColor={colors.purple}
  borderColor={colors.purple}
  hasPadding
  options={[
    { label: "Feminino", value: "f", imageIcon: images.feminino }, //images.feminino = require('./path_to/assets/img/feminino.png')
    { label: "Masculino", value: "m", imageIcon: images.masculino } //images.masculino = require('./path_to/assets/img/masculino.png')
  ]}
  testID="gender-switch-selector"
  accessibilityLabel="gender-switch-selector"
/>

Props

PropTypeDefaultRequiredNote
optionsarraynulltrueItems array to render. Each item has a label and a value and optionals icons
options[].labelstringnulltrueLabel from each item
options[].valuestringnulltrueValue from each item
options[].customIconJsx element ou FunctionnullfalseOptional custom icon from each item
options[].imageIconstringnullfalseSource from a image icon form each item. Has the same color then label in render
options[].activeColorstringnullfalseColor from each item when is selected
options[].testIDstringundefinedfalseTest ID for each item used for testing (e.g. with Appium)
options[].accessibilityLabelstringundefinedfalseAccessibility Label for each item used for testing (e.g. with Appium)
options[].disabledbooleanfalsefalseDisables an item
initialnumber-1falseItem selected in initial render
valuenumberundefinedfalseThe switch value (will call onPress)
onPressfunctionconsole.logtrueCallback function called after change value.
disableValueChangeOnPressboolfalsefalseDisables the onPress call when the value is manually changed
fontSizenumbernullfalseFont size from labels. If null default fontSize of the app is used.
selectedColorstring'#fff'falseColor text of the item selected
buttonMarginnumber0falseMargin of the item selected to component
buttonColorstring'#BCD635'falseColor bg of the item selected
textColorstring'#000'falseColor text of the not selecteds items
backgroundColorstring'#ffffff'falseColor bg of the component
borderColorstring'#c9c9c9'falseBorder Color of the component
borderRadiusnumber50falseBorder Radius of the component
hasPaddingboolfalsefalseIndicate if item has padding
animationDurationnumber250falseDuration of the animation
valuePaddingnumber1falseSize of padding
heightnumber40falseHeight of component
boldboolfalsefalseIndicate if text has fontWeight bold
textStyleobject{}falseText style
selectedTextStyleobject{}falseSelected text style
textContainerStyleobject{}falseStyle for text (and icon) container (TouchableOpacity)
selectedTextContainerStyleobject{}falseStyle for selected text (and icon) container (TouchableOpacity)
imageStyleobject{}falseImage style
styleobject{}falseContainer style
returnObjectboolfalsefalseIndicate if onPress function return an option instead of option.value
disabledboolfalsefalseDisables the switch
borderWidthnumber1falseDefine border width
testIDstringnullfalseTest ID used for testing (e.g. with Appium)
accessibilityLabelstringnullfalseAccessibility Label used for testing (e.g. with Appium)
touchablePropsobject{}falseCustom props for TouchableOpacity element

Authors

Contribute

Contributions are always welcome! Create a new Pull Request

2.3.0

1 year ago

2.2.1

2 years ago

2.2.0

2 years ago

2.1.4

3 years ago

2.0.6

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.0

5 years ago

1.1.14

5 years ago

1.1.13

5 years ago

1.1.12

5 years ago

1.1.11

5 years ago

1.1.10

5 years ago

1.1.8

6 years ago

1.1.7

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago