mirror of
				https://gitlab.nic.cz/turris/reforis/foris-js.git
				synced 2025-11-03 23:00:31 +01:00 
			
		
		
		
	Refactor Alert component to use useFocusTrap hook
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user