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