5180 fichiers 38.5 Mo 0 téléchargements 242 vues mis à jour il y a 5 heures ui
nitro-v36-with-renderer-v36 / src / common / layout / LayoutNotificationAlertView.tsx
LayoutNotificationAlertView.tsx 1.9 Ko Télécharger le fichier
import { FC, useEffect, useMemo, useRef } from 'react';
import { NotificationAlertType } from '../../api';
import { OctaneCardContentView, OctaneCardHeaderView, OctaneCardView, OctaneCardViewProps } from '../card';

export interface LayoutNotificationAlertViewProps extends OctaneCardViewProps {
    title?: string;
    type?: string;
    /**
     * Seconds after which the alert closes on its own. Left out, it stays open
     * until the user dismisses it.
     */
    autoCloseSeconds?: number;
    onClose: () => void;
}

export const LayoutNotificationAlertView: FC<LayoutNotificationAlertViewProps> = (props) => {
    const { title = '', onClose = null, classNames = [], children = null, type = NotificationAlertType.DEFAULT, autoCloseSeconds = null, ...rest } = props;

    // Held in a ref so the countdown is not restarted every time the parent
    // hands down a fresh close callback - a second alert arriving must not give
    // the first one another full delay.
    const closeRef = useRef(onClose);

    closeRef.current = onClose;

    useEffect(() => {
        if (!autoCloseSeconds || autoCloseSeconds <= 0) return;

        const timeout = setTimeout(() => closeRef.current?.(), autoCloseSeconds * 1000);

        return () => clearTimeout(timeout);
    }, [autoCloseSeconds]);

    const getClassNames = useMemo(() => {
        const newClassNames: string[] = ['octane-alert'];

        newClassNames.push('octane-alert-' + type);

        if (classNames.length) newClassNames.push(...classNames);

        return newClassNames;
    }, [classNames, type]);

    return (
        <OctaneCardView classNames={getClassNames} theme="primary-slim" {...rest}>
            <OctaneCardHeaderView headerText={title} onCloseClick={onClose} />
            <OctaneCardContentView grow className="text-black" gap={0} justifyContent="between" overflow="hidden">
                {children}
            </OctaneCardContentView>
        </OctaneCardView>
    );
};
15Sujets
1Dépôts
20Membres
2En ligne
Profile
Inscrit
Dernière visite
Messages
0
Votes positifs
0
Votes négatifs
0

Nous utilisons des cookies pour assurer le bon fonctionnement du site et améliorer votre expérience. en savoir plus

Autoriser