@audira/carbon-react-native
Version:
Build React Native apps with component and shared patterns using Carbon
132 lines (128 loc) • 4.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.CheckboxGroup = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _carbonReactNativeElements = require("@audira/carbon-react-native-elements");
var _warningAltFilled = _interopRequireDefault(require("@carbon/icons/svg/32/warning--alt--filled.svg"));
var _warningFilled = _interopRequireDefault(require("@carbon/icons/svg/32/warning--filled.svg"));
var _index = require("../../_internal/contexts/index.js");
var _index2 = require("../../_internal/style-sheets/index.js");
var _index3 = require("../../contexts/index.js");
var _index4 = require("../checkbox/index.js");
var _index5 = require("../form-helper-text/index.js");
var _index6 = require("../form-label/index.js");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const Component = /*#__PURE__*/(0, _react.forwardRef)(function CheckboxGroup({
orientation = 'vertical',
legend,
helperText,
helperTextMode,
helperTextModeIcon = true,
formHelperTextProps,
children,
style,
dir,
...props
}, ref) {
const globalConfigContext = (0, _react.useContext)(_index.GlobalConfigContext);
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
...props,
dir: dir ?? globalConfigContext.rtl ? 'rtl' : undefined,
style: [globalConfigContext.rtl ? _index2.CommonStyleSheet.rtl : undefined, style],
ref: ref,
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_index6.FormLabel, {
label: legend,
style: baseStyle.legend
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
style: [baseStyle.wrapper, wrapperOrientationStyle[orientation]],
children: children
}), !!helperText && /*#__PURE__*/(0, _jsxRuntime.jsx)(_index5.FormHelperText, {
...formHelperTextProps,
error: helperTextMode === 'error',
text: helperText,
textLeading: helperTextModeIcon && helperTextMode === 'error' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(IconErrorRenderer, {}) : helperTextModeIcon && helperTextMode === 'warning' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(IconWarningRenderer, {}) : formHelperTextProps?.textLeading,
style: [baseStyle.formHelperText, formHelperTextProps?.style]
})]
});
});
const CheckboxGroup = exports.CheckboxGroup = Object.assign(Component, {
Item: _index4.Checkbox
});
const baseStyle = _reactNative.StyleSheet.create({
wrapper: {
columnGap: _carbonReactNativeElements.Spacing.spacing_05,
rowGap: _carbonReactNativeElements.Spacing.spacing_03
},
legend: {
marginBottom: _carbonReactNativeElements.Spacing.spacing_03
},
formHelperText: {
marginTop: _carbonReactNativeElements.Spacing.spacing_03
}
}),
wrapperOrientationStyle = _reactNative.StyleSheet.create({
vertical: {
flexDirection: 'column'
},
horizontal: {
..._index2.FlexStyleSheet.flex_wrap,
flexDirection: 'row'
}
}),
mapIconErrorFillColor = {
gray_10: _carbonReactNativeElements.Color.Token.gray_10.support_error,
gray_100: _carbonReactNativeElements.Color.Token.gray_10.support_error
},
mapIconErrorStrokeColor = {
gray_10: _carbonReactNativeElements.Color.Token.gray_10.background,
gray_100: _carbonReactNativeElements.Color.Token.gray_100.background
},
mapIconWarningFillColor = {
gray_10: _carbonReactNativeElements.Color.Token.gray_10.support_warning,
gray_100: _carbonReactNativeElements.Color.Token.gray_100.support_warning
};
function IconErrorRenderer(props) {
const themeContext = (0, _react.useContext)(_index3.ThemeContext);
// return (
// <Icon
// { ...props }
// src={ IconWarningFilled }
// fill={ mapIconErrorFillColor[themeContext.colorScheme] }
// stroke={ mapIconErrorStrokeColor[themeContext.colorScheme] }
// width={ 18 }
// height={ 18 }
// />
// )
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_warningFilled.default, {
...props,
fill: mapIconErrorFillColor[themeContext.colorScheme],
stroke: mapIconErrorStrokeColor[themeContext.colorScheme],
width: 18,
height: 18
});
}
// // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
// IconWarningAltFilled.content[0].attrs.fill = 'black'
function IconWarningRenderer(props) {
const themeContext = (0, _react.useContext)(_index3.ThemeContext);
// return (
// <Icon
// { ...props }
// src={ IconWarningAltFilled }
// fill={ mapIconWarningFillColor[themeContext.colorScheme] }
// width={ 18 }
// height={ 18 }
// />
// )
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_warningAltFilled.default, {
...props,
fill: mapIconWarningFillColor[themeContext.colorScheme],
width: 18,
height: 18
});
}
//# sourceMappingURL=CheckboxGroup.js.map