UNPKG

@prosperitainova/dumbo-react-native

Version:
90 lines (88 loc) 2.54 kB
"use strict"; import React from 'react'; import { Pressable, StyleSheet, View } from 'react-native'; import { defaultText } from '../../constants/defaultText'; import { createIcon, styleReferenceBreaker } from '../../helpers'; import { getColor } from '../../styles/colors'; import { Text } from '../Text'; import RadioButtonIcon from '@carbon/icons/es/radio-button/20'; import RadioButtonCheckedIcon from '@carbon/icons/es/radio-button--checked/20'; import { checkboxRadioBaseStyle } from '../Checkbox'; /** * 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} */ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; export class RadioButton extends React.Component { get styles() { return StyleSheet.create({ wrapper: checkboxRadioBaseStyle }); } get textStyle() { const { disabled } = this.props; const finalStyle = { color: getColor(disabled ? 'textDisabled' : 'textPrimary'), marginLeft: 8, lineHeight: 20 }; return finalStyle; } get radioButton() { const { checked, disabled } = this.props; const color = disabled ? getColor('iconDisabled') : getColor('iconPrimary'); return /*#__PURE__*/_jsx(View, { children: checked ? createIcon(RadioButtonCheckedIcon, 20, 20, color) : createIcon(RadioButtonIcon, 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__*/_jsxs(Pressable, { style: styleReferenceBreaker(this.styles.wrapper, style), disabled: disabled, accessibilityLabel: accessibleText || defaultText.radioButton, accessibilityHint: label, accessibilityRole: "radio", onPress: this.onPress, onLongPress: this.onLongPress, ...(componentProps || {}), children: [this.radioButton, !hideLabel && /*#__PURE__*/_jsx(Text, { style: this.textStyle, text: label })] }); } } //# sourceMappingURL=index.js.map