import { createRoot } from 'react-dom/client';
import { IconButton } from '@/components/button';
import CloseIcon from '@/icons/close.svg';
import ReturnIcon from '@/icons/return.svg';
import LoadingIcon from '@/icons/three-dots.svg';
import Locale from '@/locales';
import styles from '@/styles/module/ui-lib.module.scss';
import clsx from 'clsx';
export function Popover(props: {
children: JSX.Element;
content: JSX.Element;
open?: boolean;
onClose?: () => void;
}) {
return (
{props.children}
{props.open && (
)}
);
}
export function Card(props: { children: JSX.Element[]; className?: string }) {
return (
{props.children}
);
}
export function ListItem(props: { children: JSX.Element | JSX.Element[] }) {
/*if (props.children.length > 2) {
throw Error('Only Support Two Children');
}*/
return {props.children}
;
}
export function List(props: { children: JSX.Element | JSX.Element[] }) {
return {props.children}
;
}
export function Loading() {
return (
);
}
export function LoadingSmall() {
return (
);
}
interface ModalProps {
title: string;
children?: JSX.Element;
actions?: JSX.Element[];
onClose?: () => void;
className?: string;
style?: React.CSSProperties;
}
export function Modal(props: ModalProps) {
return (
{props.children}
{props.actions && (
{props.actions?.map((action, i) => (
{action}
))}
)}
);
}
export function showModal(props: ModalProps) {
const div = document.createElement('div');
div.className = 'modal-mask';
document.body.appendChild(div);
const root = createRoot(div);
const closeModal = () => {
props.onClose?.();
root.unmount();
div.remove();
};
div.onclick = (e) => {
if (e.target === div) {
closeModal();
}
};
root.render();
}
export type ToastProps = { content: string };
export function Toast(props: ToastProps) {
return (
);
}
export function showToast(content: string, delay = 3000) {
const div = document.createElement('div');
div.className = styles.show;
document.body.appendChild(div);
const root = createRoot(div);
const close = () => {
div.classList.add(styles.hide);
setTimeout(() => {
root.unmount();
div.remove();
}, 300);
};
setTimeout(() => {
close();
}, delay);
root.render();
}
export function ReturnButton(props: { onClick: () => void }) {
return (
}
onClick={props.onClick}
bordered
title={Locale.Settings.Actions.Close}
/>
);
}