From efb382c9ce82a660da6916bf5ef22d6251036ec0 Mon Sep 17 00:00:00 2001 From: ajuner <106791576@qq.com> Date: Sun, 11 Apr 2021 21:35:33 +0800 Subject: [PATCH] style: update Alert (#3923) * chore: update Alert * fix: update --- components/alert/index.tsx | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/components/alert/index.tsx b/components/alert/index.tsx index b80353dfa..b01c7a281 100644 --- a/components/alert/index.tsx +++ b/components/alert/index.tsx @@ -11,16 +11,12 @@ import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled'; import classNames from '../_util/classNames'; import PropTypes from '../_util/vue-types'; import { getTransitionProps, Transition } from '../_util/transition'; -import { isValidElement } from '../_util/props-util'; +import { isValidElement, getPropsSlot } from '../_util/props-util'; import { defaultConfigProvider } from '../config-provider'; import { tuple, withInstall } from '../_util/type'; function noop() {} -function getDefaultSlot(slots: Record, props: Record, prop: string) { - return slots[prop]?.() ?? props[prop]; -} - const iconMapFilled = { success: CheckCircleFilled, info: InfoCircleFilled, @@ -39,7 +35,7 @@ const AlertTypes = tuple('success', 'info', 'warning', 'error'); export type AlertType = typeof AlertTypes[number]; -const alertProps = () => ({ +const alertProps = { /** * Type of Alert styles, options: `success`, `info`, `warning`, `error` */ @@ -52,8 +48,6 @@ const alertProps = () => ({ message: PropTypes.VNodeChild, /** Additional content of Alert */ description: PropTypes.VNodeChild, - /** Callback when close Alert */ - // onClose?: React.MouseEventHandler; /** Trigger when animation ending of Alert */ afterClose: PropTypes.func.def(noop), /** Whether to show icon */ @@ -62,14 +56,14 @@ const alertProps = () => ({ banner: PropTypes.looseBool, icon: PropTypes.VNodeChild, onClose: PropTypes.VNodeChild, -}); +}; -export type AlertProps = Partial>>; +export type AlertProps = Partial>; const Alert = defineComponent({ name: 'AAlert', inheritAttrs: false, - props: alertProps(), + props: alertProps, emits: ['close'], setup(props, { slots, emit, attrs, expose }) { const configProvider = inject('configProvider', defaultConfigProvider); @@ -106,10 +100,10 @@ const Alert = defineComponent({ let { closable, type, showIcon } = props; - const closeText = getDefaultSlot(slots, props, 'closeText'); - const description = getDefaultSlot(slots, props, 'description'); - const message = getDefaultSlot(slots, props, 'message'); - const icon = getDefaultSlot(slots, props, 'icon'); + const closeText = getPropsSlot(slots, props, 'closeText'); + const description = getPropsSlot(slots, props, 'description'); + const message = getPropsSlot(slots, props, 'message'); + const icon = getPropsSlot(slots, props, 'icon'); // banner模式默认有 Icon showIcon = banner && showIcon === undefined ? true : showIcon;