feat: modal, alert and message use new icon (#1932)

* feat: modal and alert use new icon

* chore: icons without treeShaking

* chore: message icon support h => VNode;
remove warning in ConfirmDialog
pull/1949/head
Amour1688 2020-03-24 16:58:53 +08:00 committed by GitHub
parent a61d4b30bb
commit 15daa48f7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 79 deletions

View File

@ -1,4 +1,12 @@
import Icon from '../icon'; import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
import CheckCircleOutlined from '@ant-design/icons-vue/CheckCircleOutlined';
import ExclamationCircleOutlined from '@ant-design/icons-vue/ExclamationCircleOutlined';
import InfoCircleOutlined from '@ant-design/icons-vue/InfoCircleOutlined';
import CloseCircleOutlined from '@ant-design/icons-vue/CloseCircleOutlined';
import CheckCircleFilled from '@ant-design/icons-vue/CheckCircleFilled';
import ExclamationCircleFilled from '@ant-design/icons-vue/ExclamationCircleFilled';
import InfoCircleFilled from '@ant-design/icons-vue/InfoCircleFilled';
import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled';
import classNames from 'classnames'; import classNames from 'classnames';
import BaseMixin from '../_util/BaseMixin'; import BaseMixin from '../_util/BaseMixin';
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
@ -9,6 +17,21 @@ import { ConfigConsumerProps } from '../config-provider';
import Base from '../base'; import Base from '../base';
function noop() {} function noop() {}
const iconMapFilled = {
success: CheckCircleFilled,
info: InfoCircleFilled,
error: CloseCircleFilled,
warning: ExclamationCircleFilled,
};
const iconMapOutlined = {
success: CheckCircleOutlined,
info: InfoCircleOutlined,
error: CloseCircleOutlined,
warning: ExclamationCircleOutlined,
};
export const AlertProps = { export const AlertProps = {
/** /**
* Type of Alert styles, options:`success`, `info`, `warning`, `error` * Type of Alert styles, options:`success`, `info`, `warning`, `error`
@ -28,7 +51,6 @@ export const AlertProps = {
afterClose: PropTypes.func.def(noop), afterClose: PropTypes.func.def(noop),
/** Whether to show icon */ /** Whether to show icon */
showIcon: PropTypes.bool, showIcon: PropTypes.bool,
iconType: PropTypes.string,
prefixCls: PropTypes.string, prefixCls: PropTypes.string,
banner: PropTypes.bool, banner: PropTypes.bool,
icon: PropTypes.any, icon: PropTypes.any,
@ -70,12 +92,12 @@ const Alert = {
}, },
}, },
render() { render(h) {
const { prefixCls: customizePrefixCls, banner, closing, closed } = this; const { prefixCls: customizePrefixCls, banner, closing, closed } = this;
const getPrefixCls = this.configProvider.getPrefixCls; const getPrefixCls = this.configProvider.getPrefixCls;
const prefixCls = getPrefixCls('alert', customizePrefixCls); const prefixCls = getPrefixCls('alert', customizePrefixCls);
let { closable, type, showIcon, iconType } = this; let { closable, type, showIcon } = this;
const closeText = getComponentFromProp(this, 'closeText'); const closeText = getComponentFromProp(this, 'closeText');
const description = getComponentFromProp(this, 'description'); const description = getComponentFromProp(this, 'description');
const message = getComponentFromProp(this, 'message'); const message = getComponentFromProp(this, 'message');
@ -84,31 +106,8 @@ const Alert = {
showIcon = banner && showIcon === undefined ? true : showIcon; showIcon = banner && showIcon === undefined ? true : showIcon;
// banner // banner
type = banner && type === undefined ? 'warning' : type || 'info'; type = banner && type === undefined ? 'warning' : type || 'info';
let iconTheme = 'filled';
if (!iconType) { const iconType = (description ? iconMapOutlined : iconMapFilled)[type] || null;
switch (type) {
case 'success':
iconType = 'check-circle';
break;
case 'info':
iconType = 'info-circle';
break;
case 'error':
iconType = 'close-circle';
break;
case 'warning':
iconType = 'exclamation-circle';
break;
default:
iconType = 'default';
}
// use outline icon in alert with description
if (description) {
iconTheme = 'outlined';
}
}
// closeable when closeText is assigned // closeable when closeText is assigned
if (closeText) { if (closeText) {
@ -126,22 +125,20 @@ const Alert = {
const closeIcon = closable ? ( const closeIcon = closable ? (
<a type="button" onClick={this.handleClose} class={`${prefixCls}-close-icon`} tabIndex={0}> <a type="button" onClick={this.handleClose} class={`${prefixCls}-close-icon`} tabIndex={0}>
{closeText ? ( {closeText ? <span class={`${prefixCls}-close-text`}>{closeText}</span> : <CloseOutlined />}
<span class={`${prefixCls}-close-text`}>{closeText}</span>
) : (
<Icon type="close" />
)}
</a> </a>
) : null; ) : null;
const iconNode = (icon && const iconNode =
(isValidElement(icon) ? ( (icon &&
cloneElement(icon, { (isValidElement(icon) ? (
class: `${prefixCls}-icon`, cloneElement(icon, {
}) class: `${prefixCls}-icon`,
) : ( })
<span class={`${prefixCls}-icon`}>{icon}</span> ) : (
))) || <Icon class={`${prefixCls}-icon`} type={iconType} theme={iconTheme} />; <span class={`${prefixCls}-icon`}>{icon}</span>
))) ||
h(iconType, { class: `${prefixCls}-icon` });
const transitionProps = getTransitionProps(`${prefixCls}-slide-up`, { const transitionProps = getTransitionProps(`${prefixCls}-slide-up`, {
appear: false, appear: false,

View File

@ -1,5 +1,9 @@
import Notification from '../vc-notification'; import Notification from '../vc-notification';
import Icon from '../icon'; import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined';
import ExclamationCircleFilled from '@ant-design/icons-vue/ExclamationCircleFilled';
import CloseCircleFilled from '@ant-design/icons-vue/CloseCircleFilled';
import CheckCircleFilled from '@ant-design/icons-vue/CheckCircleFilled';
import InfoCircleFilled from '@ant-design/icons-vue/InfoCircleFilled';
let defaultDuration = 3; let defaultDuration = 3;
let defaultTop; let defaultTop;
@ -34,17 +38,17 @@ function getMessageInstance(callback) {
); );
} }
// type NoticeType = 'info' | 'success' | 'error' | 'warning' | 'loading'; const iconMap = {
info: InfoCircleFilled,
success: CheckCircleFilled,
error: CloseCircleFilled,
warning: ExclamationCircleFilled,
loading: LoadingOutlined,
};
function notice(args) { function notice(args) {
const duration = args.duration !== undefined ? args.duration : defaultDuration; const duration = args.duration !== undefined ? args.duration : defaultDuration;
const iconType = { const Icon = iconMap[args.type];
info: 'info-circle',
success: 'check-circle',
error: 'close-circle',
warning: 'exclamation-circle',
loading: 'loading',
}[args.type];
const target = args.key || key++; const target = args.key || key++;
const closePromise = new Promise(resolve => { const closePromise = new Promise(resolve => {
@ -60,19 +64,11 @@ function notice(args) {
duration, duration,
style: {}, style: {},
content: h => { content: h => {
const iconNode = (
<Icon type={iconType} theme={iconType === 'loading' ? 'outlined' : 'filled'} />
);
const switchIconNode = iconType ? iconNode : '';
return ( return (
<div <div
class={`${prefixCls}-custom-content${args.type ? ` ${prefixCls}-${args.type}` : ''}`} class={`${prefixCls}-custom-content${args.type ? ` ${prefixCls}-${args.type}` : ''}`}
> >
{args.icon {args.icon ? typeof args.icon === 'function' ? args.icon(h) : args.icon : <Icon />}
? typeof args.icon === 'function'
? args.icon(h)
: args.icon
: switchIconNode}
<span>{typeof args.content === 'function' ? args.content(h) : args.content}</span> <span>{typeof args.content === 'function' ? args.content(h) : args.content}</span>
</div> </div>
); );

View File

@ -1,15 +1,14 @@
import classNames from 'classnames'; import classNames from 'classnames';
import Icon from '../icon';
import Dialog from './Modal'; import Dialog from './Modal';
import ActionButton from './ActionButton'; import ActionButton from './ActionButton';
import { getConfirmLocale } from './locale'; import { getConfirmLocale } from './locale';
import warning from '../_util/warning';
export default { export default {
functional: true, functional: true,
render(h, context) { render(h, context) {
const { props } = context; const { props } = context;
const { const {
icon,
onCancel, onCancel,
onOk, onOk,
close, close,
@ -22,15 +21,8 @@ export default {
maskStyle, maskStyle,
okButtonProps, okButtonProps,
cancelButtonProps, cancelButtonProps,
iconType = 'question-circle',
closable = false, closable = false,
} = props; } = props;
warning(
!('iconType' in props),
'Modal',
`The property 'iconType' is deprecated. Use the property 'icon' instead.`,
);
const icon = props.icon ? props.icon : iconType;
const okType = props.okType || 'primary'; const okType = props.okType || 'primary';
const prefixCls = props.prefixCls || 'ant-modal'; const prefixCls = props.prefixCls || 'ant-modal';
const contentPrefixCls = `${prefixCls}-confirm`; const contentPrefixCls = `${prefixCls}-confirm`;
@ -65,7 +57,6 @@ export default {
{cancelText} {cancelText}
</ActionButton> </ActionButton>
); );
const iconNode = typeof icon === 'string' ? <Icon type={icon} /> : icon(h);
return ( return (
<Dialog <Dialog
@ -92,7 +83,7 @@ export default {
> >
<div class={`${contentPrefixCls}-body-wrapper`}> <div class={`${contentPrefixCls}-body-wrapper`}>
<div class={`${contentPrefixCls}-body`}> <div class={`${contentPrefixCls}-body`}>
{iconNode} {typeof icon === 'function' ? icon(h) : icon}
{props.title === undefined ? null : ( {props.title === undefined ? null : (
<span class={`${contentPrefixCls}-title`}>{props.title}</span> <span class={`${contentPrefixCls}-title`}>{props.title}</span>
)} )}

View File

@ -3,7 +3,7 @@ import Dialog from '../vc-dialog';
import PropTypes from '../_util/vue-types'; import PropTypes from '../_util/vue-types';
import addEventListener from '../vc-util/Dom/addEventListener'; import addEventListener from '../vc-util/Dom/addEventListener';
import { getConfirmLocale } from './locale'; import { getConfirmLocale } from './locale';
import Icon from '../icon'; import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
import Button from '../button'; import Button from '../button';
import buttonTypes from '../button/buttonTypes'; import buttonTypes from '../button/buttonTypes';
const ButtonType = buttonTypes().type; const ButtonType = buttonTypes().type;
@ -186,7 +186,7 @@ export default {
const closeIcon = getComponentFromProp(this, 'closeIcon'); const closeIcon = getComponentFromProp(this, 'closeIcon');
const closeIconToRender = ( const closeIconToRender = (
<span class={`${prefixCls}-close-x`}> <span class={`${prefixCls}-close-x`}>
{closeIcon || <Icon class={`${prefixCls}-close-icon`} type={'close'} />} {closeIcon || <CloseOutlined class={`${prefixCls}-close-icon`} />}
</span> </span>
); );
const footer = getComponentFromProp(this, 'footer'); const footer = getComponentFromProp(this, 'footer');

View File

@ -1,6 +1,9 @@
import Modal, { destroyFns } from './Modal'; import Modal, { destroyFns } from './Modal';
import modalConfirm from './confirm'; import modalConfirm from './confirm';
import Icon from '../icon'; import InfoCircleOutlined from '@ant-design/icons-vue/InfoCircleOutlined';
import CheckCircleOutlined from '@ant-design/icons-vue/CheckCircleOutlined';
import CloseCircleOutlined from '@ant-design/icons-vue/CloseCircleOutlined';
import ExclamationCircleOutlined from '@ant-design/icons-vue/ExclamationCircleOutlined';
import Base from '../base'; import Base from '../base';
// export { ActionButtonProps } from './ActionButton' // export { ActionButtonProps } from './ActionButton'
@ -10,7 +13,7 @@ const info = function(props) {
const config = { const config = {
type: 'info', type: 'info',
icon: h => { icon: h => {
return <Icon type="info-circle" />; return <InfoCircleOutlined />;
}, },
okCancel: false, okCancel: false,
...props, ...props,
@ -22,7 +25,7 @@ const success = function(props) {
const config = { const config = {
type: 'success', type: 'success',
icon: h => { icon: h => {
return <Icon type="check-circle" />; return <CheckCircleOutlined />;
}, },
okCancel: false, okCancel: false,
...props, ...props,
@ -34,7 +37,7 @@ const error = function(props) {
const config = { const config = {
type: 'error', type: 'error',
icon: h => { icon: h => {
return <Icon type="close-circle" />; return <CloseCircleOutlined />;
}, },
okCancel: false, okCancel: false,
...props, ...props,
@ -46,7 +49,7 @@ const warning = function(props) {
const config = { const config = {
type: 'warning', type: 'warning',
icon: h => { icon: h => {
return <Icon type="exclamation-circle" />; return <ExclamationCircleOutlined />;
}, },
okCancel: false, okCancel: false,
...props, ...props,

View File

@ -1,4 +1,4 @@
import { getComponentFromProp, initDefaultProps } from '../_util/props-util'; import { initDefaultProps } from '../_util/props-util';
import KeyCode from '../_util/KeyCode'; import KeyCode from '../_util/KeyCode';
import contains from '../vc-util/Dom/contains'; import contains from '../vc-util/Dom/contains';
import LazyRenderBox from './LazyRenderBox'; import LazyRenderBox from './LazyRenderBox';
@ -218,6 +218,7 @@ export default {
visible, visible,
bodyProps, bodyProps,
forceRender, forceRender,
closeIcon,
} = this; } = this;
const dest = {}; const dest = {};
if (width !== undefined) { if (width !== undefined) {
@ -249,7 +250,6 @@ export default {
let closer; let closer;
if (closable) { if (closable) {
const closeIcon = getComponentFromProp(this, 'closeIcon');
closer = ( closer = (
<button <button
type="button" type="button"