freshyo/packages/ui/src/components/checkbox.tsx
2026-11-18 16:52:41 +05:30

61 lines
1.8 KiB
TypeScript
Executable file

import { useTheme } from "common-ui";
import MaterialIcons from '@expo/vector-icons/MaterialIcons';
import React from 'react';
import { Platform, TouchableOpacity, ViewStyle } from 'react-native';
// import { useTheme } from '../hooks/theme-context';
interface CheckboxProps {
checked: boolean;
onPress?: () => void;
style?: ViewStyle;
size?: number;
color?: string;
disabled?: boolean;
checkedColor?: string; // deprecated, use checkColor
fillColor?: string; // new prop for box/circle fill
checkColor?: string; // new prop for check/tick color
testID?: string;
}
const Checkbox: React.FC<CheckboxProps> = ({
checked,
onPress,
style,
size = 24,
disabled = false,
checkedColor, // deprecated
fillColor,
checkColor,
testID,
}) => {
const { colors } = useTheme().theme;
const fill = fillColor || colors.brand500;
const check = checkColor || colors.white1;
// MaterialIcons glyphs: filled box/circle with the tick knocked out, same
// visual as the MaterialCommunityIcons set this used to require (1.3 MB).
const iconName = Platform.OS === 'android'
? checked ? 'check-box' : 'check-box-outline-blank'
: checked ? 'check-circle' : 'radio-button-unchecked';
return (
<TouchableOpacity
onPress={onPress}
style={style}
activeOpacity={0.7}
disabled={disabled}
testID={testID}
accessibilityRole="checkbox"
accessibilityState={{ checked, disabled }}
>
<MaterialIcons
name={iconName}
size={size}
color={disabled ? colors.gray1 : fill}
/>
{/* If checked, overlay a check icon with checkColor (for circle/box) */}
{/* Not implemented here due to icon limitations, but checkColor is available for future use */}
</TouchableOpacity>
);
};
export default Checkbox;