Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switched the CheckboxInput component to use Checkbox.Item to stay mor… #56

Merged
merged 4 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
himrocks33 marked this conversation as resolved.
Show resolved Hide resolved
},
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