/* eslint-disable max-len */ import React from 'react'; import cls from 'classnames'; import PropTypes from 'prop-types'; import Button from '../iconButton'; import { strings, cssClasses } from '@douyinfe/semi-foundation/banner/constants'; import BannerFoundation, { BannerAdapter } from '@douyinfe/semi-foundation/banner/foundation'; import '@douyinfe/semi-foundation/banner/banner.scss'; import Typography from '../typography'; import { IconClose, IconAlertTriangle, IconInfoCircle, IconTickCircle, IconAlertCircle } from '@douyinfe/semi-icons'; import warning from '@douyinfe/semi-foundation/utils/warning'; import BaseComponent from '../_base/baseComponent'; const prefixCls = cssClasses.PREFIX; const types = strings.TYPE; export type Type = 'info' | 'danger' | 'warning' | 'success'; export interface BannerProps { type?: Type; className?: string; children?: React.ReactNode; fullMode?: boolean; title?: React.ReactNode; description?: React.ReactNode; icon?: React.ReactNode; closeIcon?: React.ReactNode; style?: React.CSSProperties; bordered?: boolean; onClose?(e: React.MouseEvent):void; } export interface BannerState { visible: boolean; } export default class Banner extends BaseComponent { static propTypes = { // target: PropTypes.func, fullMode: PropTypes.bool, // insertAfter: PropTypes.func, type: PropTypes.oneOf(types), title: PropTypes.node, description: PropTypes.node, icon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]), closeIcon: PropTypes.oneOfType([PropTypes.string, PropTypes.node]), children: PropTypes.node, style: PropTypes.object, className: PropTypes.string, onClose: PropTypes.func, bordered: PropTypes.bool, }; static defaultProps = { // eslint-disable-next-line @typescript-eslint/no-empty-function onClose: () => { }, type: 'info', fullMode: true, }; foundation: BannerFoundation; constructor(props: BannerProps) { super(props); this.state = { visible: true, }; warning( 'target' in this.props, '[Semi Banner] \'target\' has been deprecated, please write JSX directly instead.' ); } get adapter(): BannerAdapter { return { ...super.adapter, setVisible: () => { this.setState({ visible: false }); }, notifyClose: (e: React.MouseEvent) => { const { onClose } = this.props; onClose(e); }, }; } componentDidMount() { this.foundation = new BannerFoundation(this.adapter); this.foundation.init(); } componentWillUnmount() { this.foundation.destroy(); } remove: React.MouseEventHandler = e => { e && e.stopPropagation(); this.foundation.removeBanner(e); }; renderCloser() { const { closeIcon } = this.props; if (closeIcon === null) { return closeIcon; } const closer = (