mirror of
https://gitlab.nic.cz/turris/reforis/foris-js.git
synced 2024-12-25 00:11:36 +01:00
Refactor Alert component to use useFocusTrap hook
This commit is contained in:
parent
02f3803265
commit
83a6ff75f6
|
@ -5,10 +5,12 @@
|
|||
* See /LICENSE for more information.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import React, { useRef } from "react";
|
||||
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
import { useFocusTrap } from "../utils/hooks";
|
||||
|
||||
export const ALERT_TYPES = Object.freeze({
|
||||
PRIMARY: "primary",
|
||||
SECONDARY: "secondary",
|
||||
|
@ -37,11 +39,15 @@ Alert.defaultProps = {
|
|||
};
|
||||
|
||||
function Alert({ type, onDismiss, children }) {
|
||||
const alertRef = useRef();
|
||||
useFocusTrap(alertRef, !!onDismiss);
|
||||
return (
|
||||
<div
|
||||
ref={alertRef}
|
||||
className={`alert alert-${type} ${
|
||||
onDismiss ? "alert-dismissible" : ""
|
||||
}`.trim()}
|
||||
role="alert"
|
||||
>
|
||||
{onDismiss && (
|
||||
<button
|
||||
|
|
Loading…
Reference in New Issue
Block a user