UNPKG

@nexara/nativeflow

Version:

Beautiful, responsive, and customizable UI components for React Native – built for performance and seamless experiences.

41 lines (40 loc) 1.28 kB
"use strict"; import React, { useCallback, useState } from "react"; import { StyledView } from "../StyledComponents/index.js"; import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime"; const RadioGroup = ({ name, defaultValue, children, onSelect, ...rest }) => { const [selectedChildren, setSelectedChildren] = useState(defaultValue ?? ''); const renderChildren = useCallback(() => { return React.Children.toArray(children).map(child => { if (/*#__PURE__*/React.isValidElement(child)) { return /*#__PURE__*/React.cloneElement(child, { active: selectedChildren === child.props.value, onPress: () => { if (!('disabled' in child.props) && !child?.props?.disabled) { child.props?.onPress?.(); onSelect?.(name || child.props.name, child.props.value); setSelectedChildren(child?.props?.value); } } }); } return null; }); }, [children, selectedChildren]); return /*#__PURE__*/_jsx(_Fragment, { children: /*#__PURE__*/_jsx(StyledView, { flexDirection: "row", gap: 15, ...rest, children: renderChildren() }) }); }; export default RadioGroup; //# sourceMappingURL=RadioGroup.js.map