1 | import classNames from 'classnames';
|
2 | import * as React from 'react';
|
3 | import { useUncontrolled } from 'uncontrollable';
|
4 | import useEventCallback from '@restart/hooks/useEventCallback';
|
5 | import Anchor from '@restart/ui/Anchor';
|
6 | import { useBootstrapPrefix } from './ThemeProvider';
|
7 | import Fade from './Fade';
|
8 | import CloseButton from './CloseButton';
|
9 | import divWithClassName from './divWithClassName';
|
10 | import createWithBsPrefix from './createWithBsPrefix';
|
11 | import { jsx as _jsx } from "react/jsx-runtime";
|
12 | import { jsxs as _jsxs } from "react/jsx-runtime";
|
13 | const DivStyledAsH4 = divWithClassName('h4');
|
14 | DivStyledAsH4.displayName = 'DivStyledAsH4';
|
15 | const AlertHeading = createWithBsPrefix('alert-heading', {
|
16 | Component: DivStyledAsH4
|
17 | });
|
18 | const AlertLink = createWithBsPrefix('alert-link', {
|
19 | Component: Anchor
|
20 | });
|
21 | const defaultProps = {
|
22 | variant: 'primary',
|
23 | show: true,
|
24 | transition: Fade,
|
25 | closeLabel: 'Close alert'
|
26 | };
|
27 | const Alert = React.forwardRef((uncontrolledProps, ref) => {
|
28 | const {
|
29 | bsPrefix,
|
30 | show,
|
31 | closeLabel,
|
32 | closeVariant,
|
33 | className,
|
34 | children,
|
35 | variant,
|
36 | onClose,
|
37 | dismissible,
|
38 | transition,
|
39 | ...props
|
40 | } = useUncontrolled(uncontrolledProps, {
|
41 | show: 'onClose'
|
42 | });
|
43 | const prefix = useBootstrapPrefix(bsPrefix, 'alert');
|
44 | const handleClose = useEventCallback(e => {
|
45 | if (onClose) {
|
46 | onClose(false, e);
|
47 | }
|
48 | });
|
49 | const Transition = transition === true ? Fade : transition;
|
50 |
|
51 | const alert = _jsxs("div", {
|
52 | role: "alert",
|
53 | ...(!Transition ? props : undefined),
|
54 | ref: ref,
|
55 | className: classNames(className, prefix, variant && `${prefix}-${variant}`, dismissible && `${prefix}-dismissible`),
|
56 | children: [dismissible && _jsx(CloseButton, {
|
57 | onClick: handleClose,
|
58 | "aria-label": closeLabel,
|
59 | variant: closeVariant
|
60 | }), children]
|
61 | });
|
62 |
|
63 | if (!Transition) return show ? alert : null;
|
64 | return _jsx(Transition, {
|
65 | unmountOnExit: true,
|
66 | ...props,
|
67 | ref: undefined,
|
68 | in: show,
|
69 | children: alert
|
70 | });
|
71 | });
|
72 | Alert.displayName = 'Alert';
|
73 | Alert.defaultProps = defaultProps;
|
74 | export default Object.assign(Alert, {
|
75 | Link: AlertLink,
|
76 | Heading: AlertHeading
|
77 | }); |
\ | No newline at end of file |