@gluestack-ui/core
Version:
Universal UI components for React Native, Expo, and Next.js
25 lines • 1.16 kB
JavaScript
import { mergeProps } from '@react-aria/utils';
import { usePress } from '@gluestack-ui-nightly/utils/aria';
import { getLabel } from '@gluestack-ui-nightly/utils/aria';
export function useRadio(props, state, _ref) {
let { value, isReadOnly, isDisabled, children } = props;
let hasChildren = children != null;
const label = getLabel(props);
if (!hasChildren && !label) {
console.warn('If you do not provide children, you must specify an aria-label for accessibility');
}
let preventChanges = isDisabled || isReadOnly;
preventChanges = preventChanges !== null && preventChanges !== void 0 ? preventChanges : false;
let checked = state.selectedValue === value;
let onPress = () => {
state.setSelectedValue(value);
};
let { pressProps } = usePress({
isDisabled: preventChanges,
onPress,
});
return {
inputProps: mergeProps(props, Object.assign(Object.assign({}, pressProps), { checked, 'disabled': preventChanges, value, 'aria-label': label, 'role': 'radio', 'aria-disabled': preventChanges, 'aria-checked': checked })),
};
}
//# sourceMappingURL=useRadio.js.map