diff --git a/scss/components/_toast.scss b/scss/components/_toast.scss index 76862c07..579304d3 100644 --- a/scss/components/_toast.scss +++ b/scss/components/_toast.scss @@ -90,6 +90,20 @@ animation-name: bounceOut; } + &-close { + position: absolute; + top: $gap-xs; + right: $gap-sm; + color: $white; + line-height: 1; + opacity: 0.8; + + &:hover { + color: $white; + opacity: 1; + } + } + &-title { display: $Toast-display; font-size: $fontSizeMd; diff --git a/src/components/Toast.tsx b/src/components/Toast.tsx index db9f63a7..e50a937d 100644 --- a/src/components/Toast.tsx +++ b/src/components/Toast.tsx @@ -13,8 +13,14 @@ import Transition, { import React from 'react'; import cx from 'classnames'; import Html from './Html'; -import {uuid, autobind} from '../utils/helper'; -import {ClassNamesFn, themeable} from '../theme'; +import {uuid, autobind, noop} from '../utils/helper'; +import {ClassNamesFn, themeable, classnames} from '../theme'; +import {Icon} from './icons'; + +interface Config { + closeButton?: boolean; + timeout?: number; +} const fadeStyles: { [propName: string]: string; @@ -25,12 +31,6 @@ const fadeStyles: { }; let toastRef: any = null; -let config: { - closeButton?: boolean; - timeOut?: number; - extendedTimeOut?: number; -} = {}; - const show = ( content: string, title: string = '', @@ -40,7 +40,7 @@ const show = ( if (!toastRef || !toastRef[method]) { return; } - toastRef[method](content, title || '', {...config, ...conf}); + toastRef[method](content, title || '', {...conf}); }; interface ToastComponentProps { @@ -52,14 +52,13 @@ interface ToastComponentProps { | 'bottom-left' | 'bottom-right'; closeButton: boolean; - timeOut: number; - extendedTimeOut: number; + timeout: number; classPrefix: string; classnames: ClassNamesFn; className?: string; } -interface Item { +interface Item extends Config { title?: string; body: string; level: 'info' | 'success' | 'error' | 'warning'; @@ -76,12 +75,11 @@ export class ToastComponent extends React.Component< > { static defaultProps: Pick< ToastComponentProps, - 'position' | 'closeButton' | 'timeOut' | 'extendedTimeOut' + 'position' | 'closeButton' | 'timeout' > = { position: 'top-right', closeButton: false, - timeOut: 5000, - extendedTimeOut: 3000 + timeout: 5000 }; // 当前ToastComponent是否真正render了 @@ -90,15 +88,6 @@ export class ToastComponent extends React.Component< items: [] }; - componentWillMount() { - const {closeButton, timeOut, extendedTimeOut} = this.props; - config = { - closeButton, - timeOut, - extendedTimeOut - }; - } - componentDidMount() { this.hasRendered = true; toastRef = this; @@ -157,27 +146,27 @@ export class ToastComponent extends React.Component< return null; } - const {classPrefix: ns, className, timeOut, position} = this.props; + const {classnames: cx, className, timeout, position} = this.props; const items = this.state.items; return (