parent
a20b49b808
commit
efb382c9ce
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue