@prosperitainova/dumbo-react-native
Version:
Dumbo for React Native Library
95 lines (94 loc) • 2.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.RadioButton = void 0;
var _react = _interopRequireDefault(require("react"));
var _reactNative = require("react-native");
var _defaultText = require("../../constants/defaultText");
var _helpers = require("../../helpers");
var _colors = require("../../styles/colors");
var _Text = require("../Text");
var _ = _interopRequireDefault(require("@carbon/icons/es/radio-button/20"));
var _2 = _interopRequireDefault(require("@carbon/icons/es/radio-button--checked/20"));
var _Checkbox = require("../Checkbox");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* RadioButton component for rendering a radio button
*
* {@link https://github.com/carbon-design-system/carbon-react-native/blob/main/example/src/Views/RadioButton.tsx | Example code}
*/
class RadioButton extends _react.default.Component {
get styles() {
return _reactNative.StyleSheet.create({
wrapper: _Checkbox.checkboxRadioBaseStyle
});
}
get textStyle() {
const {
disabled
} = this.props;
const finalStyle = {
color: (0, _colors.getColor)(disabled ? 'textDisabled' : 'textPrimary'),
marginLeft: 8,
lineHeight: 20
};
return finalStyle;
}
get radioButton() {
const {
checked,
disabled
} = this.props;
const color = disabled ? (0, _colors.getColor)('iconDisabled') : (0, _colors.getColor)('iconPrimary');
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
children: checked ? (0, _helpers.createIcon)(_2.default, 20, 20, color) : (0, _helpers.createIcon)(_.default, 20, 20, color)
});
}
onPress = event => {
const {
onPress,
checked,
id
} = this.props;
if (typeof onPress === 'function') {
onPress(!checked, id, event);
}
};
onLongPress = event => {
const {
onLongPress,
id
} = this.props;
if (typeof onLongPress === 'function') {
onLongPress(id, event);
}
};
render() {
const {
disabled,
componentProps,
label,
accessibleText,
hideLabel,
style
} = this.props;
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.Pressable, {
style: (0, _helpers.styleReferenceBreaker)(this.styles.wrapper, style),
disabled: disabled,
accessibilityLabel: accessibleText || _defaultText.defaultText.radioButton,
accessibilityHint: label,
accessibilityRole: "radio",
onPress: this.onPress,
onLongPress: this.onLongPress,
...(componentProps || {}),
children: [this.radioButton, !hideLabel && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.Text, {
style: this.textStyle,
text: label
})]
});
}
}
exports.RadioButton = RadioButton;
//# sourceMappingURL=index.js.map