import * as React from 'react'; import classnames from 'classnames'; import { messageProps, configProps } from 'src/types/op-message'; import { SuccessIcon, WarnIcon, ErrorIcon } from '../common-view'; import Layout from '../op-layout'; import event from '../event'; import PlaySound from '../op-play-sound/index'; import './index.scss'; const { Content, Left, Right } = Layout; export const styleConfig = { success: { icon: , style: { 'background-color': '#00bf29', color: '#ffffff', }, }, warning: { icon: , style: { 'background-color': '#ffd119', color: '#000000', }, }, error: { icon: , style: { 'background-color': '#FE3824', color: '#ffffff', }, }, }; export default function Message(props: messageProps) { const { visible, type = 'success', title, subTitle, right, left, content, onChange, customConfig, style, className, } = props; const mergedConfig = { ...styleConfig, ...(customConfig || {}), }; const bindEsc = React.useCallback(() => { onChange(false); }, []); React.useEffect(() => { if (visible) { event.bind('esc', bindEsc); } else { event.unbind('esc', bindEsc); } return () => { event.unbind('esc', bindEsc); }; }, [visible]); const config = (mergedConfig[type] || mergedConfig.success) as configProps; const newStyle = { ...style, ...config.style } as React.CSSProperties; return visible ? ( <> {left ||
{config.icon}
}
{content || (
{title}
{subTitle}
)} { onChange(false); }} > {right || (
关闭 [Esc]
)}
) : null; }