23 lines
2.3 KiB
TypeScript
23 lines
2.3 KiB
TypeScript
'use client'
|
|
import { useEffect, useRef, type ReactNode } from 'react'
|
|
import { X } from 'lucide-react'
|
|
|
|
export const salaryButton = 'inline-flex min-h-11 items-center justify-center gap-2 rounded-lg px-4 text-sm font-semibold transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#5a9ce6] disabled:cursor-not-allowed disabled:opacity-50'
|
|
export const salarySecondary = `${salaryButton} border border-[#cbd5e1] bg-white text-[#334155] hover:bg-[#f1f5f9]`
|
|
export const salaryPrimary = `${salaryButton} bg-[#0050cb] text-white hover:bg-[#003fa3]`
|
|
export const salaryDanger = `${salaryButton} text-[#b42318] hover:bg-[#fff4f2]`
|
|
export const salaryInput = 'min-h-11 w-full min-w-0 rounded-lg border border-[#cbd5e1] bg-white px-3 py-2 text-base text-[#101828] outline-none focus:border-[#0050cb] focus:ring-2 focus:ring-[#cce3ff] aria-[invalid=true]:border-[#b42318] disabled:bg-[#f1f5f9] sm:text-sm'
|
|
export function SalaryConfigurationDialog({ title, busy, children, onClose, wide = false }: { title: string; busy?: boolean; children: ReactNode; onClose: () => void; wide?: boolean }) {
|
|
const ref = useRef<HTMLDialogElement>(null)
|
|
const previous = useRef(typeof document !== 'undefined' && document.activeElement instanceof HTMLElement ? document.activeElement : null)
|
|
useEffect(() => {
|
|
const dialog = ref.current!
|
|
dialog.showModal(); const overflow = document.body.style.overflow; document.body.style.overflow = 'hidden'
|
|
return () => { dialog.close(); document.body.style.overflow = overflow; if (previous.current?.isConnected) previous.current.focus() }
|
|
}, [])
|
|
return <dialog ref={ref} aria-label={title} onCancel={event => { event.preventDefault(); if (!busy) onClose() }} onClick={event => { if (event.target === event.currentTarget && !busy) onClose() }} className={`m-auto max-h-[calc(100dvh-24px)] w-[calc(100%-24px)] overflow-y-auto rounded-lg bg-white p-0 text-[#101828] shadow-xl backdrop:bg-[#101828]/50 ${wide ? 'max-w-5xl' : 'max-w-lg'}`}>
|
|
<header className="flex items-center justify-between gap-3 border-b border-[#e2e8f0] px-5 py-4"><h2 className="text-lg font-bold">{title}</h2><button type="button" aria-label="关闭弹窗" disabled={busy} onClick={onClose} className={`${salaryButton} px-3`}><X className="h-5 w-5" aria-hidden="true" /></button></header>
|
|
{children}
|
|
</dialog>
|
|
}
|