// Copyright 2021 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React, { ReactNode } from 'react'; import classNames from 'classnames'; const BASE_CLASS_NAME = 'LeftPaneDialog'; export type PropsType = { type?: 'warning' | 'error'; icon?: 'update' | 'relink' | 'network' | ReactNode; title?: string; subtitle?: string; children?: ReactNode; hoverText?: string; } & ( | { onClick?: undefined; clickLabel?: undefined; hasAction?: false; } | { onClick: () => void; clickLabel: string; hasAction: true; } ) & ( | { onClose?: undefined; closeLabel?: undefined; hasXButton?: false; } | { onClose: () => void; closeLabel: string; hasXButton: true; } ); export const LeftPaneDialog: React.FC = ({ icon, type, onClick, clickLabel, title, subtitle, children, hoverText, hasAction, hasXButton, onClose, closeLabel, }) => { const onClickWrap = (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); onClick?.(); }; const onKeyDownWrap = (e: React.KeyboardEvent) => { if (e.key !== 'Enter' && e.key !== ' ') { return; } e.preventDefault(); e.stopPropagation(); onClick?.(); }; const onCloseWrap = (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); onClose?.(); }; const iconClassName = typeof icon === 'string' ? classNames([ `${BASE_CLASS_NAME}__icon`, `${BASE_CLASS_NAME}__icon--${icon}`, ]) : undefined; let action: ReactNode; if (hasAction) { action = ( ); } let xButton: ReactNode; if (hasXButton) { xButton = (
); } const className = classNames([ BASE_CLASS_NAME, type === undefined ? undefined : `${BASE_CLASS_NAME}--${type}`, onClick === undefined ? undefined : `${BASE_CLASS_NAME}--clickable`, ]); const content = ( <>
{typeof icon === 'string' ?
: icon}
{title === undefined ? undefined :

{title}

} {subtitle === undefined ? undefined :
{subtitle}
} {children} {action}
{xButton} ); if (onClick) { return (
{content}
); } return (
{content}
); };