import './alert.scss'; import {computed, designComponent, getComponentCls, mergeAttrs, PropType, reactive, useClasses, useRefs} from "@peryl/react-compose"; import {StyleProps, ThemeStatus, useStyle} from "../../uses/useStyle"; import CollapseTransition from "../CollapseTransition"; import Icon from "../Icon"; import {ThemeStatusIcons} from "../Application/theme/theme.utils"; export const Alert = designComponent({ name: 'alert', inheritAttrs: false, inheritPropsType: HTMLDivElement, props: { ...StyleProps, label: { type: String }, // 提示文本 align: { type: String, default: 'left' }, // 文本对其方式 theme: { type: String, default: 'lite' }, // 主题,lite轻色,deep深色 noClose: { type: Boolean }, // 禁用关闭 icon: { type: String as PropType, default: undefined }, // 显示的图标 description: { type: String }, // desc内容消息 }, slots: ['desc', 'close', 'default'], setup({ props, slots, attrs }) { const { refs, onRef } = useRefs({ el: HTMLDivElement, }); const state = reactive({ isClosed: false, }); const { styleComputed } = useStyle({ status: ThemeStatus.primary }); const icon = computed(() => { if (props.icon === null) { return null; } return props.icon || ThemeStatusIcons[styleComputed.value.status!]; }); const classes = useClasses(() => [ getComponentCls('alert'), `alert-status-${styleComputed.value.status}`, `alert-shape-${styleComputed.value.shape}`, `alert-theme-${props.theme}`, `alert-align-${props.align}`, { 'alert-has-icon': !!icon.value, 'alert-has-desc': !!props.description || slots.desc.isExist(), 'alert-has-close': !props.noClose, } ]); const handler = { onClickClosed: () => { state.isClosed = true; } }; return { refer: { refs, }, render: () => (
{!!icon.value &&
} {!props.noClose &&
{slots.close()}
} {(!!props.label || slots.default.isExist()) && (
{slots.default(props.label)}
)} {(props.description || slots.desc.isExist()) && (
{slots.desc(props.description)}
)}
) }; }, }); export default Alert;