Skip to content

Commit

Permalink
Merge pull request #56 from himrocks33/master
Browse files Browse the repository at this point in the history
Switched the CheckboxInput component to use Checkbox.Item, added disable checkbox feature, limit the number of items one can select in multi-select and addressed some minor issues.
  • Loading branch information
srivastavaanurag79 committed Apr 18, 2024
2 parents fe6deef + e19c3cd commit 7e29539
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 99 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ react-native run-android
- Thom van den Akker [(@Thodor12)](https://github.com/Thodor12)
- Carlos Loureiro [(@CarlosSLoureiro)](https://github.com/CarlosSLoureiro)
- b. avianto [(@avianto)](https://github.com/avianto)
- Ben Walton [(@himrocks33)](https://github.com/himrocks33)

## Contributing

Expand Down
9 changes: 8 additions & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function App() {
list: [
{ _id: '1', value: 'MALE' },
{ _id: '2', value: 'FEMALE' },
{ _id: '3', value: 'OTHERS' },
{ _id: '3', value: 'OTHERS', disabled: true },
{
_id: '4',
value:
Expand All @@ -43,6 +43,12 @@ export default function App() {
{ _id: '6', value: 'BLACK' },
{ _id: '7', value: 'WHITE' },
{ _id: '8', value: 'CYAN' },
{ _id: '9', value: 'BLACK' },
{ _id: '10', value: 'Test 1' },
{ _id: '11', value: 'Test 2' },
{ _id: '12', value: 'Test 3' },
{ _id: '13', value: 'Test 4' },
{ _id: '14', value: 'Test 5' },
],
selectedList: [],
error: '',
Expand Down Expand Up @@ -162,6 +168,7 @@ export default function App() {
searchbarProps={{
iconColor: 'red',
}}
limit={2}
/>
<PaperButton
style={styles.button}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 27 additions & 13 deletions src/components/checkBox.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,54 @@
/* eslint-disable react-native/no-inline-styles */
import React, { memo } from 'react';
import { View, StyleSheet } from 'react-native';
import { Checkbox, Text } from 'react-native-paper';
import { Checkbox } from 'react-native-paper';
import type { PaperSelectCheckboxProps } from 'src/interface/checkbox.interface';

interface CheckboxPropsFull extends PaperSelectCheckboxProps {
isChecked: boolean;
label: string;
onPress: () => void;
disabled?: boolean;
}

const CheckboxInput = ({
isChecked,
label,
checkboxColor,
checkboxLabelStyle,
checkboxLabelVariant,
checkboxUncheckedColor,
checkboxMode,
disabled,
onPress,
}: CheckboxPropsFull) => (
<View style={styles.container}>
<Checkbox
uncheckedColor={checkboxUncheckedColor || '#000007'}
color={checkboxColor || 'blue'}
status={isChecked === true ? 'checked' : 'unchecked'}
<Checkbox.Item
uncheckedColor={checkboxUncheckedColor}
color={checkboxColor}
status={
disabled
? 'indeterminate'
: isChecked === true
? 'checked'
: 'unchecked'
}
label={label.trim()}
labelStyle={{ ...checkboxLabelStyle, textAlign: 'left' }}
labelVariant={checkboxLabelVariant}
mode={checkboxMode}
position={`leading`}
disabled={disabled}
onPress={disabled ? () => {} : onPress}
/>
<Text style={[styles.labelStyle, checkboxLabelStyle]}>{label.trim()}</Text>
</View>
);

const styles = StyleSheet.create({
container: {
flexDirection: 'row',
alignItems: 'center',
flexDirection: 'column',
flex: 1,
marginBottom: 1.5,
},
labelStyle: {
flexDirection: 'row',
flexShrink: 1,
justifyContent: 'center',
},
});

Expand Down
2 changes: 2 additions & 0 deletions src/interface/checkbox.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ export interface PaperSelectCheckboxProps {
checkboxColor?: string;
checkboxUncheckedColor?: string;
checkboxLabelStyle?: TextStyle;
checkboxLabelVariant?: any;
checkboxMode?: 'android' | 'ios';
}
4 changes: 4 additions & 0 deletions src/interface/paperSelect.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { PaperSelectCheckboxProps } from './checkbox.interface';
export interface ListItem {
_id: string;
value: string;
disabled?: boolean;
}

export interface SelectedItem {
Expand Down Expand Up @@ -47,6 +48,9 @@ export interface PaperSelectProps {
textInputMode?: TextInputProps['mode'];
theme?: ThemeProp;
inputRef?: MutableRefObject<any>;
limit?: number | null;
limitError?: string;
limitErrorStyle?: TextStyle;

// Localization props
dialogTitle?: ReactNode;
Expand Down
Loading

0 comments on commit 7e29539

Please sign in to comment.