iter(g68): alert 增加语义图标与通栏形态
This commit is contained in:
@@ -1,15 +1,24 @@
|
||||
import { h } from '@ui-arch/frame';
|
||||
import type { AlertProps } from './types.js';
|
||||
|
||||
/*** 提示条:variant 决定语义色,可选标题与关闭按钮;关闭即退场并从 DOM 移除(内容由调用方持有) ***/
|
||||
const DEFAULT_ICON: Record<string, string> = { info: 'ℹ', success: '✓', warning: '!', danger: '✕' }; // 语义缺省图标
|
||||
|
||||
/*** 提示条:variant 决定语义色,可选标题/语义图标/关闭按钮;banner 为通栏形态,关闭即退场并从 DOM 移除 ***/
|
||||
export function alert(props: AlertProps): HTMLElement {
|
||||
const variant = props.variant ?? 'info'; // 语义档位
|
||||
const body = h(
|
||||
'div',
|
||||
{ class: 'ua-alert-body' },
|
||||
props.title ? h('div', { class: 'ua-alert-title' }, props.title) : null,
|
||||
h('div', { class: 'ua-alert-message' }, props.message),
|
||||
);
|
||||
const el = h('div', { class: `ua-alert ua-alert-${props.variant ?? 'info'}`, role: 'alert' }, body);
|
||||
const glyph = props.icon ?? (props.showIcon ? DEFAULT_ICON[variant] : null); // 自定义图标优先
|
||||
const el = h(
|
||||
'div',
|
||||
{ class: `ua-alert ua-alert-${variant}${props.banner ? ' is-banner' : ''}`, role: 'alert' },
|
||||
glyph ? h('span', { class: 'ua-alert-icon', 'aria-hidden': 'true' }, glyph) : null, // 图标纯装饰,读屏靠正文
|
||||
body,
|
||||
);
|
||||
|
||||
if (!props.closable) return el; // 纯展示形态
|
||||
el.append(
|
||||
|
||||
@@ -274,6 +274,9 @@ export interface AlertProps {
|
||||
variant?: 'info' | 'success' | 'warning' | 'danger'; // 语义色;缺省 info
|
||||
closable?: boolean; // 显示 × 关闭按钮(退场后从 DOM 移除);缺省 false
|
||||
onClose?: () => void; // 关闭回调,供调用方同步业务状态
|
||||
banner?: boolean; // 通栏形态:去圆角、只留下边框、左右撑满;适合页面顶部通知
|
||||
showIcon?: boolean; // 显示语义图标(info ℹ / success ✓ / warning ! / danger ✕);缺省 false
|
||||
icon?: string | HTMLElement; // 自定义图标节点,传了即覆盖语义图标
|
||||
}
|
||||
|
||||
/*** 骨架屏入参 ***/
|
||||
|
||||
Reference in New Issue
Block a user