1
0
mirror of https://gitlab.nic.cz/turris/reforis/foris-js.git synced 2025-06-17 13:56:15 +02:00
Files
foris-js/src/bootstrap/Alert.js
Aleksandr Gumroian 912f8facdb Fix linting issues
2024-06-10 16:28:25 +02:00

60 lines
1.4 KiB
JavaScript

/*
* Copyright (C) 2019-2024 CZ.NIC z.s.p.o. (https://www.nic.cz/)
*
* This is free software, licensed under the GNU General Public License v3.
* See /LICENSE for more information.
*/
import React from "react";
import PropTypes from "prop-types";
export const ALERT_TYPES = Object.freeze({
PRIMARY: "primary",
SECONDARY: "secondary",
SUCCESS: "success",
DANGER: "danger",
WARNING: "warning",
INFO: "info",
LIGHT: "light",
DARK: "dark",
});
Alert.propTypes = {
/** Type of the alert it adds as `alert-${type}` class. */
type: PropTypes.oneOf(Object.values(ALERT_TYPES)),
/** Alert content. */
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]),
/** onDismiss handler. */
onDismiss: PropTypes.func,
};
Alert.defaultProps = {
type: ALERT_TYPES.DANGER,
};
function Alert({ type, onDismiss, children }) {
return (
<div
className={`alert alert-${type} ${
onDismiss ? "alert-dismissible" : ""
}`.trim()}
>
{onDismiss && (
<button
type="button"
className="btn-close"
onClick={onDismiss}
aria-label={_("Close")}
/>
)}
{children}
</div>
);
}
export default Alert;