style: update Alert (#3923)

* chore: update Alert

* fix: update
pull/3924/head
ajuner 2021-04-11 21:35:33 +08:00 committed by GitHub
parent a20b49b808
commit efb382c9ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 15 deletions

View File

@ -11,16 +11,12 @@ import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled';
import classNames from '../_util/classNames'; import classNames from '../_util/classNames';
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
import { getTransitionProps, Transition } from '../_util/transition'; 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 { defaultConfigProvider } from '../config-provider';
import { tuple, withInstall } from '../_util/type'; import { tuple, withInstall } from '../_util/type';
function noop() {} function noop() {}
function getDefaultSlot(slots: Record<string, any>, props: Record<string, any>, prop: string) {
return slots[prop]?.() ?? props[prop];
}
const iconMapFilled = { const iconMapFilled = {
success: CheckCircleFilled, success: CheckCircleFilled,
info: InfoCircleFilled, info: InfoCircleFilled,
@ -39,7 +35,7 @@ const AlertTypes = tuple('success', 'info', 'warning', 'error');
export type AlertType = typeof AlertTypes[number]; export type AlertType = typeof AlertTypes[number];
const alertProps = () => ({ const alertProps = {
/** /**
* Type of Alert styles, options: `success`, `info`, `warning`, `error` * Type of Alert styles, options: `success`, `info`, `warning`, `error`
*/ */
@ -52,8 +48,6 @@ const alertProps = () => ({
message: PropTypes.VNodeChild, message: PropTypes.VNodeChild,
/** Additional content of Alert */ /** Additional content of Alert */
description: PropTypes.VNodeChild, description: PropTypes.VNodeChild,
/** Callback when close Alert */
// onClose?: React.MouseEventHandler<HTMLAnchorElement>;
/** Trigger when animation ending of Alert */ /** Trigger when animation ending of Alert */
afterClose: PropTypes.func.def(noop), afterClose: PropTypes.func.def(noop),
/** Whether to show icon */ /** Whether to show icon */
@ -62,14 +56,14 @@ const alertProps = () => ({
banner: PropTypes.looseBool, banner: PropTypes.looseBool,
icon: PropTypes.VNodeChild, icon: PropTypes.VNodeChild,
onClose: PropTypes.VNodeChild, onClose: PropTypes.VNodeChild,
}); };
export type AlertProps = Partial<ExtractPropTypes<ReturnType<typeof alertProps>>>; export type AlertProps = Partial<ExtractPropTypes<typeof alertProps>>;
const Alert = defineComponent({ const Alert = defineComponent({
name: 'AAlert', name: 'AAlert',
inheritAttrs: false, inheritAttrs: false,
props: alertProps(), props: alertProps,
emits: ['close'], emits: ['close'],
setup(props, { slots, emit, attrs, expose }) { setup(props, { slots, emit, attrs, expose }) {
const configProvider = inject('configProvider', defaultConfigProvider); const configProvider = inject('configProvider', defaultConfigProvider);
@ -106,10 +100,10 @@ const Alert = defineComponent({
let { closable, type, showIcon } = props; let { closable, type, showIcon } = props;
const closeText = getDefaultSlot(slots, props, 'closeText'); const closeText = getPropsSlot(slots, props, 'closeText');
const description = getDefaultSlot(slots, props, 'description'); const description = getPropsSlot(slots, props, 'description');
const message = getDefaultSlot(slots, props, 'message'); const message = getPropsSlot(slots, props, 'message');
const icon = getDefaultSlot(slots, props, 'icon'); const icon = getPropsSlot(slots, props, 'icon');
// banner Icon // banner Icon
showIcon = banner && showIcon === undefined ? true : showIcon; showIcon = banner && showIcon === undefined ? true : showIcon;