Checkbox
Controlled or uncontrolled checkbox (Pressable, checkbox role) with a 44pt hit area around a 20pt box. Uses the Lucide check glyph. Requires react-native-svg (lucide-react-native peer, a native module — run pod install on bare RN after adding).
Install
First install? Set up the registry in your app.
npx --yes --package=https://native.uipkge.dev/cli/uipkge-native-0.1.1.tgz uipkge-native add checkboxSource files
Expand a file to read the source the installer copies into your app.
components/ui/checkbox/Checkbox.tsx
import * as React from 'react'
import { Pressable, View, type PressableProps } from 'react-native'
import { Check } from 'lucide-react-native'
import { cn } from '@/lib/utils'
import { useThemeColors } from '@/lib/theme'
export interface CheckboxProps extends Omit<PressableProps, 'children'> {
className?: string
checked?: boolean
defaultChecked?: boolean
onCheckedChange?: (checked: boolean) => void
}
const Checkbox = React.forwardRef<React.ComponentRef<typeof Pressable>, CheckboxProps>(
({ className, checked, defaultChecked, onCheckedChange, onPress, disabled, accessibilityState, ...props }, ref) => {
const colors = useThemeColors()
const isControlled = checked !== undefined
const [internal, setInternal] = React.useState(defaultChecked ?? false)
const resolved = checked ?? internal
function handlePress(event: Parameters<NonNullable<PressableProps['onPress']>>[0]) {
if (disabled) return
const next = !resolved
if (!isControlled) setInternal(next)
onCheckedChange?.(next)
onPress?.(event)
}
return (
<Pressable
ref={ref}
accessibilityRole="checkbox"
accessibilityState={{ ...accessibilityState, checked: resolved, disabled: !!disabled }}
disabled={disabled}
onPress={handlePress}
className={cn(
'size-[48px] shrink-0 items-center justify-center active:opacity-80',
disabled && 'opacity-50',
className,
)}
{...props}
>
<View
pointerEvents="none"
className={cn(
'size-[20px] items-center justify-center rounded-sm border',
resolved ? 'border-primary bg-primary' : 'border-input bg-background',
)}
>
{resolved ? <Check size={14} strokeWidth={3} color={colors.primaryForeground} /> : null}
</View>
</Pressable>
)
},
)
Checkbox.displayName = 'Checkbox'
export { Checkbox }
components/ui/checkbox/index.ts
export { Checkbox, type CheckboxProps } from './Checkbox'
Dependencies
npm packages
lucide-react-nativereact-native-svg