UNPKG

@audira/carbon-react-native

Version:

Build React Native apps with component and shared patterns using Carbon

116 lines (115 loc) 3.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RadioButton = void 0; var _react = require("react"); var _reactNative = require("react-native"); var _carbonReactNativeElements = require("@audira/carbon-react-native-elements"); var _index = require("../../_internal/contexts/index.js"); var _index2 = require("../../_internal/style-sheets/index.js"); var _index3 = require("../../carbon-style-sheet/index.js"); var _index4 = require("../../contexts/index.js"); var _index5 = require("../form-label/index.js"); var _index6 = require("../radio-button-input/index.js"); var _jsxRuntime = require("react/jsx-runtime"); const RadioButton = exports.RadioButton = /*#__PURE__*/(0, _react.forwardRef)(function RadioButton({ defaultChecked, checked, value, interactiveState = 'normal', label, role = 'radio', 'aria-label': ariaLabel, onChange, onPress, radioButtonInputProps, formLabelProps, pressableProps, style, dir, ...props }, forwardedRef) { (0, _react.useContext)(_index4.ThemeContext); const radioButtonInputRef = (0, _react.useRef)(null), globalConfigContext = (0, _react.useContext)(_index.GlobalConfigContext), viewRef = (0, _react.useRef)(null), pressHandler = (0, _react.useCallback)(event => { onPress?.(event); radioButtonInputRef.current?.setChecked(true); }, [onPress]); (0, _react.useImperativeHandle)(forwardedRef, () => { return Object.assign(viewRef.current ?? {}, { get checked() { return radioButtonInputRef.current.checked; }, setChecked(checked_) { radioButtonInputRef.current?.setChecked(checked_); } }); }, []); return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { ...props, "aria-label": ariaLabel || label, dir: dir ?? globalConfigContext.rtl ? 'rtl' : undefined, style: [_index2.FlexStyleSheet.flex_row, globalConfigContext.rtl ? _index2.CommonStyleSheet.rtl : undefined, style], ref: viewRef, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, { ...pressableProps, role: role, disabled: interactiveState === 'disabled', "aria-label": pressableProps?.['aria-label'] ?? label, onPress: pressHandler, style: [_index2.CommonStyleSheet.absolute, _index2.CommonStyleSheet.w_full, _index2.CommonStyleSheet.h_full, baseStyle.pressable, pressableProps?.style] }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_index6.RadioButtonInput, { ...radioButtonInputProps, role: "none", defaultChecked: defaultChecked, checked: checked, value: value, interactiveState: interactiveState, onChange: onChange, onPress: onPress, style: [baseStyle.radioButtonInput, radioButtonInputProps?.style], ref: radioButtonInputRef }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_index5.FormLabel, { ...formLabelProps, label: label, textProps: { ...formLabelProps?.textProps, type: formLabelProps?.textProps?.type || 'body_compact_01', style: [textColorStyle[interactiveState], formLabelProps?.textProps?.style] }, style: [_index2.FlexStyleSheet.flex_1, baseStyle.label, formLabelProps?.style] })] }); }); const baseStyle = _reactNative.StyleSheet.create({ pressable: { zIndex: 1 }, radioButtonInput: { zIndex: 2 }, label: { marginStart: _carbonReactNativeElements.Spacing.spacing_03 } }), textColorStyle = _index3.CarbonStyleSheet.create({ normal: { color: _index3.CarbonStyleSheet.color.text_primary }, disabled: { color: _index3.CarbonStyleSheet.color.text_disabled }, error: { color: _index3.CarbonStyleSheet.color.text_primary }, read_only: { color: _index3.CarbonStyleSheet.color.text_primary }, warning: { color: _index3.CarbonStyleSheet.color.text_primary } }); //# sourceMappingURL=RadioButton.js.map