@smart-react-components/ui
Version:
SRC UI includes React and Styled components.
66 lines (65 loc) • 3.57 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const element_props_1 = __importDefault(require("@smart-react-components/core/element-props"));
const click_events_1 = __importDefault(require("@smart-react-components/core/element-props/click-events"));
const intrinsic_styled_core_props_1 = __importDefault(require("@smart-react-components/core/element-props/intrinsic-styled-core-props"));
const react_1 = __importDefault(require("react"));
const AlertContent_1 = __importDefault(require("../components/Alert/AlertContent"));
const AlertElement_1 = __importDefault(require("../components/Alert/AlertElement"));
const types_1 = require("../types");
const Alert = props => {
const { children, hasIconLeft, hasIconRight, hasThickBorder } = react_1.default.useMemo(() => {
var _a, _b;
const children = !Array.isArray(props.children) ? [props.children] : props.children;
const content = [];
let iconLeft = null;
let iconRight = null;
for (let i = 0; i < children.length; i++) {
const item = children[i];
if (!item) {
continue;
}
if (((_a = item.type) === null || _a === void 0 ? void 0 : _a.displayName) === 'SRCAlertIcon') {
const iconEl = react_1.default.cloneElement(item, {
alertPalette: props.palette,
isOutline: props.isOutline,
isSoft: props.isSoft,
position: i === 0 ? types_1.OrderPosition.LEFT : types_1.OrderPosition.RIGHT,
size: props.size,
sizeSm: props.sizeSm,
sizeMd: props.sizeMd,
sizeLg: props.sizeLg,
sizeXl: props.sizeXl,
});
if (i === 0) {
iconLeft = iconEl;
}
else if (i === children.length - 1) {
iconRight = iconEl;
}
continue;
}
content.push(typeof children[i] === 'string' ? children[i] : react_1.default.cloneElement(item, { key: (_b = item.key) !== null && _b !== void 0 ? _b : i }));
}
return {
children: (react_1.default.createElement(react_1.default.Fragment, null,
iconLeft && iconLeft,
react_1.default.createElement(AlertContent_1.default, null, content),
iconRight && iconRight)),
hasIconLeft: !!iconLeft,
hasIconRight: !!iconRight,
hasThickBorder: !(iconLeft && (iconLeft.props.hasBackground !== false || (iconLeft.props.palette && iconLeft.props.palette !== props.palette))),
};
}, [props.children]);
return (react_1.default.createElement(AlertElement_1.default, Object.assign({ alertSize: props.size, alertSizeSm: props.sizeSm, alertSizeMd: props.sizeMd, alertSizeLg: props.sizeLg, alertSizeXl: props.sizeXl, hasIconLeft: hasIconLeft, hasIconRight: hasIconRight, hasThickBorder: hasThickBorder, isOutline: props.isOutline, isSoft: props.isSoft, palette: props.palette, shape: props.shape }, (0, element_props_1.default)(props, [click_events_1.default, intrinsic_styled_core_props_1.default]), props.elementProps), children));
};
Alert.defaultProps = {
elementProps: {},
palette: 'primary',
shape: 'rectangle',
size: 'medium',
};
exports.default = Alert;