@coreui/react
Version:
UI Components Library for React.js
39 lines (36 loc) • 1.88 kB
JavaScript
import { __rest } from '../../node_modules/tslib/tslib.es6.js';
import React, { forwardRef, useRef, useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import classNames from '../../_virtual/index.js';
import { CCloseButton } from '../close-button/CCloseButton.js';
import { useForkedRef } from '../../hooks/useForkedRef.js';
import '@popperjs/core';
import { colorPropType } from '../../props.js';
import Transition from '../../node_modules/react-transition-group/esm/Transition.js';
const CAlert = forwardRef((_a, ref) => {
var { children, className, color = 'primary', dismissible, variant, visible = true, onClose } = _a, rest = __rest(_a, ["children", "className", "color", "dismissible", "variant", "visible", "onClose"]);
const alertRef = useRef(null);
const forkedRef = useForkedRef(ref, alertRef);
const [_visible, setVisible] = useState(visible);
useEffect(() => {
setVisible(visible);
}, [visible]);
return (React.createElement(Transition, { in: _visible, mountOnEnter: true, nodeRef: alertRef, onExit: onClose, timeout: 150, unmountOnExit: true }, (state) => (React.createElement("div", Object.assign({ className: classNames('alert', variant === 'solid' ? `bg-${color} text-white` : `alert-${color}`, {
'alert-dismissible fade': dismissible,
show: state === 'entered',
}, className), role: "alert" }, rest, { ref: forkedRef }),
children,
dismissible && React.createElement(CCloseButton, { onClick: () => setVisible(false) })))));
});
CAlert.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
color: colorPropType.isRequired,
dismissible: PropTypes.bool,
onClose: PropTypes.func,
variant: PropTypes.string,
visible: PropTypes.bool,
};
CAlert.displayName = 'CAlert';
export { CAlert };
//# sourceMappingURL=CAlert.js.map