码桶
发现社区成员的开源项目
index-DihvOmSo.js2.7 KB
import{Y as g,Z as y,ac as E,a2 as C,R as t,bb as $,aV as v,a5 as m,T as u,a8 as o}from"./index-GWuvg2UH.js";import{I,b as N,c as x,a as B}from"./IconTickCircle-BYgwCdAe.js";const P={PREFIX:`${g}-banner`},w={TYPE:["info","success","danger","warning"]};class l extends y{constructor(e){super(Object.assign(Object.assign({},l.defaultAdapter),e))}removeBanner(e){this._adapter.notifyClose(e),this._adapter.setVisible()}}const n=P.PREFIX,T=w.TYPE;class b extends E{constructor(e){super(e),this.remove=s=>{s&&s.stopPropagation(),this.foundation.removeBanner(s)},this.state={visible:!0},C("target"in this.props,"[Semi Banner] 'target' has been deprecated, please write JSX directly instead.")}get adapter(){return Object.assign(Object.assign({},super.adapter),{setVisible:()=>{this.setState({visible:!1})},notifyClose:e=>{const{onClose:s}=this.props;s(e)}})}componentDidMount(){this.foundation=new l(this.adapter),this.foundation.init()}componentWillUnmount(){this.foundation.destroy()}renderCloser(){const{closeIcon:e}=this.props;return e===null?e:t.createElement($,{className:`${n}-close`,onClick:this.remove,icon:e||t.createElement(v,{"x-semi-prop":"closeIcon","aria-hidden":!0}),theme:"borderless",size:"small",type:"tertiary","aria-label":"Close"})}renderIcon(){const{type:e,icon:s}=this.props;let a={warning:t.createElement(B,{size:"large","aria-label":"warning"}),success:t.createElement(x,{size:"large","aria-label":"success"}),info:t.createElement(N,{size:"large","aria-label":"info"}),danger:t.createElement(I,{size:"large","aria-label":"danger"})}[e];const r=m({[`${n}-icon`]:!0});return typeof s<"u"&&(a=s),a?t.createElement("div",{className:r,"x-semi-prop":"icon"},a):null}render(){const{children:e,type:s,className:c,style:a,bordered:r,title:p,description:d,fullMode:i}=this.props,{visible:h}=this.state,f=m(n,c,{[`${n}-${s}`]:s,[`${n}-full`]:i,[`${n}-in-container`]:!i,[`${n}-bordered`]:!i&&r});return h?t.createElement("div",Object.assign({className:f,style:a,role:"alert"},this.getDataAttr(this.props)),t.createElement("div",{className:`${n}-content-wrapper`},t.createElement("div",{className:`${n}-content`},this.renderIcon(),t.createElement("div",{className:`${n}-content-body`},p?t.createElement(u.Title,{heading:5,className:`${n}-title`,component:"div","x-semi-prop":"title"},p):null,d?t.createElement(u.Paragraph,{className:`${n}-description`,component:"div","x-semi-prop":"description"},d):null)),this.renderCloser()),e?t.createElement("div",{className:`${n}-extra`,"x-semi-prop":"children"},e):null):null}}b.propTypes={fullMode:o.bool,type:o.oneOf(T),title:o.node,description:o.node,icon:o.node,closeIcon:o.node,children:o.node,style:o.object,className:o.string,onClose:o.func,bordered:o.bool};b.defaultProps={onClose:()=>{},type:"info",fullMode:!0};export{b as B};