UNPKG

react-native-advanced-checkbox

Version:

A customizable, animated checkbox component for React Native with group support, haptic feedback, and accessibility features, compatible with React Native 0.72.0 and above.

70 lines 3.06 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const react_1 = __importStar(require("react")); const react_native_1 = require("react-native"); const CheckboxGroup = ({ onValueChange, initialValues = [], // Controlled by parent style, children, }) => { const handleValueChange = (0, react_1.useCallback)((value) => { if (typeof value !== 'string' || !onValueChange) return; console.log('Group handleValueChange, value:', value, 'currentValues:', initialValues); const newValues = initialValues.includes(value) ? initialValues.filter((v) => v !== value) : [...initialValues, value]; console.log('New values:', newValues); onValueChange(newValues); // Pass the computed array directly }, [onValueChange, initialValues]); return (<react_native_1.View style={[styles.container, style]}> {react_1.default.Children.map(children, (child) => { if (react_1.default.isValidElement(child)) { const childValue = String(child.props.value); return react_1.default.cloneElement(child, { value: childValue, // Pass the string value onValueChange: handleValueChange, checkMarkContent: initialValues.includes(childValue) ? <react_native_1.Text></react_native_1.Text> : null, // Reflect checked state }); } return child; })} </react_native_1.View>); }; const styles = react_native_1.StyleSheet.create({ container: { marginVertical: 12, }, }); exports.default = CheckboxGroup; //# sourceMappingURL=CheckboxGroup.js.map