2024-12-14 13:16:29 +01:00
|
|
|
import React, { FC, PropsWithChildren, useState, useCallback } from 'react';
|
2019-12-07 21:43:08 +02:00
|
|
|
import clsx from 'clsx';
|
2016-08-07 22:18:11 +03:00
|
|
|
|
2016-01-08 15:14:35 +02:00
|
|
|
import styles from './panel.scss';
|
2016-01-09 13:59:42 +02:00
|
|
|
import icons from './icons.scss';
|
2016-01-08 15:14:35 +02:00
|
|
|
|
2024-12-14 13:16:29 +01:00
|
|
|
interface PanelProps extends PropsWithChildren<any> {
|
|
|
|
title?: string;
|
|
|
|
icon?: string;
|
|
|
|
}
|
2020-05-24 02:08:24 +03:00
|
|
|
|
2024-12-14 13:16:29 +01:00
|
|
|
export const Panel: FC<PanelProps> = ({ title, icon, children }) => {
|
2020-05-24 02:08:24 +03:00
|
|
|
return (
|
|
|
|
<div className={styles.panel}>
|
2024-12-14 13:16:29 +01:00
|
|
|
{title && (
|
|
|
|
<PanelHeader>
|
|
|
|
{icon && (
|
|
|
|
<button className={styles.headerControl}>
|
|
|
|
<span className={icons[icon]} />
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
{title}
|
|
|
|
</PanelHeader>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{children}
|
2020-05-24 02:08:24 +03:00
|
|
|
</div>
|
|
|
|
);
|
2024-12-14 13:16:29 +01:00
|
|
|
};
|
2016-01-08 15:14:35 +02:00
|
|
|
|
2024-12-14 13:16:29 +01:00
|
|
|
export const PanelHeader: FC<PropsWithChildren<any>> = ({ children }) => {
|
2020-05-24 02:08:24 +03:00
|
|
|
return (
|
2024-12-14 13:16:29 +01:00
|
|
|
<div className={styles.header} data-testid="auth-header">
|
|
|
|
{children}
|
2020-05-24 02:08:24 +03:00
|
|
|
</div>
|
|
|
|
);
|
2024-12-14 13:16:29 +01:00
|
|
|
};
|
2016-01-08 15:14:35 +02:00
|
|
|
|
2024-12-14 13:16:29 +01:00
|
|
|
export const PanelBody: FC<PropsWithChildren<any>> = ({ children }) => {
|
2020-05-24 02:08:24 +03:00
|
|
|
return (
|
2024-12-14 13:16:29 +01:00
|
|
|
<div className={styles.body} data-testid="auth-body">
|
|
|
|
{children}
|
2020-05-24 02:08:24 +03:00
|
|
|
</div>
|
|
|
|
);
|
2024-12-14 13:16:29 +01:00
|
|
|
};
|
2016-01-08 15:14:35 +02:00
|
|
|
|
2024-12-14 13:16:29 +01:00
|
|
|
export const PanelFooter: FC<PropsWithChildren<any>> = ({ children }) => {
|
2020-05-24 02:08:24 +03:00
|
|
|
return (
|
2024-12-14 13:16:29 +01:00
|
|
|
<div className={styles.footer} data-testid="auth-controls">
|
|
|
|
{children}
|
2020-05-24 02:08:24 +03:00
|
|
|
</div>
|
|
|
|
);
|
2024-12-14 13:16:29 +01:00
|
|
|
};
|
2019-11-27 11:03:32 +02:00
|
|
|
|
2024-12-14 13:16:29 +01:00
|
|
|
interface PanelBodyHeaderProps extends PropsWithChildren<any> {
|
|
|
|
type?: 'default' | 'error';
|
|
|
|
onClose?: () => void;
|
|
|
|
}
|
2019-11-27 11:03:32 +02:00
|
|
|
|
2024-12-17 23:11:39 +01:00
|
|
|
export const PanelBodyHeader: FC<PanelBodyHeaderProps> = ({ type = 'default', onClose, children, ...props }) => {
|
2024-12-14 13:16:29 +01:00
|
|
|
const [isClosed, setIsClosed] = useState<boolean>(false);
|
|
|
|
const handleCloseClick = useCallback(() => {
|
|
|
|
setIsClosed(true);
|
|
|
|
onClose?.();
|
|
|
|
}, [onClose]);
|
2019-12-07 13:28:52 +02:00
|
|
|
|
2024-12-14 13:16:29 +01:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={clsx({
|
|
|
|
[styles.defaultBodyHeader]: type === 'default',
|
|
|
|
[styles.errorBodyHeader]: type === 'error',
|
|
|
|
[styles.isClosed]: isClosed,
|
|
|
|
})}
|
2024-12-17 23:11:39 +01:00
|
|
|
{...props}
|
2024-12-14 13:16:29 +01:00
|
|
|
>
|
|
|
|
{type === 'error' && <span className={styles.close} onClick={handleCloseClick} />}
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2019-11-27 11:03:32 +02:00
|
|
|
|
2024-12-14 13:16:29 +01:00
|
|
|
interface PanelIconProps {
|
|
|
|
icon: string;
|
2019-11-27 11:03:32 +02:00
|
|
|
}
|
|
|
|
|
2024-12-14 13:16:29 +01:00
|
|
|
export const PanelIcon: FC<PanelIconProps> = ({ icon }) => {
|
2020-05-24 02:08:24 +03:00
|
|
|
return (
|
|
|
|
<div className={styles.panelIcon}>
|
|
|
|
<span className={icons[icon]} />
|
|
|
|
</div>
|
|
|
|
);
|
2024-12-14 13:16:29 +01:00
|
|
|
};
|