import color from 'color'; import * as React from 'react'; import { StyleSheet, View } from 'react-native'; import { withTheme } from '../../core/theming'; import type { $RemoveChildren } from '../../types'; import MaterialCommunityIcon from '../MaterialCommunityIcon'; import TouchableRipple from '../TouchableRipple/TouchableRipple'; type Props = $RemoveChildren & { /** * Status of checkbox. */ status: 'checked' | 'unchecked' | 'indeterminate'; /** * Whether checkbox is disabled. */ disabled?: boolean; /** * Function to execute on press. */ onPress?: () => void; /** * Custom color for checkbox. */ color?: string; /** * @optional */ theme: ReactNativePaper.Theme; /** * testID to be used on tests. */ testID?: string; }; /** * Checkboxes allow the selection of multiple options from a set. * This component follows platform guidelines for iOS, but can be used * on any platform. * *
*
* *
Enabled
*
*
* *
Disabled
*
*
*/ const CheckboxIOS = ({ status, disabled, onPress, theme, testID, ...rest }: Props) => { const checked = status === 'checked'; const indeterminate = status === 'indeterminate'; const checkedColor = disabled ? theme.colors.disabled : rest.color || theme.colors.accent; let rippleColor; if (disabled) { rippleColor = color(theme.colors.text).alpha(0.16).rgb().string(); } else { rippleColor = color(checkedColor).fade(0.32).rgb().string(); } const icon = indeterminate ? 'minus' : 'check'; return ( ); }; CheckboxIOS.displayName = 'Checkbox.IOS'; const styles = StyleSheet.create({ container: { borderRadius: 18, padding: 6, }, }); export default withTheme(CheckboxIOS); // @component-docs ignore-next-line const CheckboxIOSWithTheme = withTheme(CheckboxIOS); // @component-docs ignore-next-line export { CheckboxIOSWithTheme as CheckboxIOS };