Some checks failed
CI Check / check (push) Has been cancelled
- 替换所有浏览器原生弹窗(confirm/alert/prompt) - 创建 ConfirmDialog、AlertDialog、PromptDialog 组件 - 创建 DialogProvider 和 useDialog Hook - 替换所有 admin 组件、首页、分享页面中的原生弹窗 - 素材预览面板统一 - 创建 MaterialPreviewModal 组件 - 使用统一弹窗组件,统一退出逻辑 - 首页UI统一到三层架构 - 迁移主要按钮和输入框样式 - 迁移筛选弹窗中的所有按钮样式 - 使用 useThemeStyles() Hook - 更新文档 - 更新优化记录、优化计划、后续修改、更新日志
45 lines
872 B
TypeScript
45 lines
872 B
TypeScript
'use client'
|
|
|
|
import { useState, useCallback } from 'react'
|
|
|
|
interface AlertOptions {
|
|
title?: string
|
|
message: string
|
|
buttonText?: string
|
|
variant?: 'default' | 'success' | 'warning' | 'error'
|
|
}
|
|
|
|
export function useAlert() {
|
|
const [isOpen, setIsOpen] = useState(false)
|
|
const [options, setOptions] = useState<AlertOptions>({ message: '' })
|
|
|
|
const alert = useCallback((opts: AlertOptions | string) => {
|
|
if (typeof opts === 'string') {
|
|
setOptions({
|
|
title: '提示',
|
|
message: opts,
|
|
})
|
|
} else {
|
|
setOptions({
|
|
title: opts.title || '提示',
|
|
message: opts.message,
|
|
buttonText: opts.buttonText,
|
|
variant: opts.variant,
|
|
})
|
|
}
|
|
setIsOpen(true)
|
|
}, [])
|
|
|
|
const close = useCallback(() => {
|
|
setIsOpen(false)
|
|
}, [])
|
|
|
|
return {
|
|
isOpen,
|
|
options,
|
|
alert,
|
|
close,
|
|
}
|
|
}
|
|
|