23 lines
3.5 KiB
JavaScript
23 lines
3.5 KiB
JavaScript
import{css as p,html as c,Component as l,bind as a,unbind as d,styleMap as f,offset as h,outsideClick as m,clearOutsideClick as x}from"wkit";import"../base/button.js";const w="\u8BF7\u786E\u8BA4\u4F60\u7684\u64CD\u4F5C!";class b extends l{static props={title:"str!",confirmButtonType:"str!primary",disabled:!1};static styles=[p`:host{display:inline-flex}.container{position:relative}.container .wrapper{cursor:pointer}:host([disabled]){opacity:.6}:host([disabled]) .container .wrapper{cursor:not-allowed}.tooltip{display:none;position:fixed;z-index:9;justify-content:center;align-items:center;max-width:260px;min-width:32px;padding:8px 12px 12px;border-radius:3px;font-size:var(--wc-popconfirm-font, 14px);background:var(--wc-popconfirm-background, #fff);color:var(--wc-popconfirm-color, var(--color-dark-1));box-shadow:0 0 3px var(--wc-popconfirm-shadow, rgba(0, 0, 0, 0.3));word-break:break-all;-webkit-user-select:none;user-select:none}.tooltip::after{position:absolute;display:block;width:8px;height:8px;border-radius:2px;background:var(--wc-popconfirm-background, #fff);content:"";transform:rotate(45deg);box-shadow:-1px -1px 0 var(--wc-popconfirm-shadow, rgba(0, 0, 0, 0.1))}.tooltip[placement=left-top]::after{right:16px;bottom:-4px;box-shadow:1px 1px 0 var(--wc-popconfirm-shadow, rgba(0, 0, 0, 0.1))}.tooltip[placement=left-bottom]::after{right:16px;top:-4px}.tooltip[placement=right-top]::after{left:16px;bottom:-4px;box-shadow:1px 1px 0 var(--wc-popconfirm-shadow, rgba(0, 0, 0, 0.1))}.tooltip[placement=right-bottom]::after{left:16px;top:-4px}`,p`.title{display:flex;align-items:center;gap:6px;padding:8px 0;--wc-icon-size: 16px}.title wc-icon{flex-shrink:0;color:var(--wc-popconfirm-icon-color, var(--color-red-1))}:host([hide-icon]) .title wc-icon{display:none}.actions{display:flex;justify-content:flex-end;gap:4px;margin-top:8px}.actions wc-button{min-width:40px;height:20px;font-size:12px}.actions wc-button:first-child{--wc-button-border-color: none}`];#t=!1;#i(n){let{left:t,top:e}=h(this),s="left",o={display:"block"},r=document.documentElement.scrollTop;if(!(this.disabled||this.#t)){if(t<260||t>260&&window.innerWidth-t>260)s="right",t-=12,t<0&&(t=0),o.left=t+"px";else{let i=window.innerWidth-t-this.clientWidth-12;i<0&&(i=0),o.right=i+"px"}if(e<160)e+=8+this.clientHeight,s+="-bottom",o.top=e+"px";else{let i=window.innerHeight-e+8;s+="-top",o.bottom=i+"px",r>0&&(o.transform=`translateY(-${r}px)`)}this.#t=!0,this.$refs.tips.setAttribute("placement",s),this.$refs.tips.style.cssText=f(o),this.$refs.tips.$animate()}}#o(){this.#t&&(this.#t=!1,this.$refs.tips.$animate(!0))}#e(){this.$emit("confirm"),this.#o()}mounted(){this._outFn=m(this,n=>this.#o()),this._scrollFn=a(document,"scroll",n=>{if(this.#t){let t=document.documentElement.scrollTop;this.$refs.tips.style.transform=`translateY(-${t}px)`}})}unmounted(){d(document,"scroll",this._scrollFn),x(this._outFn)}render(){return c`
|
|
<main class="container">
|
|
<div class="wrapper" @click=${this.#i}>
|
|
<slot></slot>
|
|
</div>
|
|
<div class="tooltip" ref="tips" #animation=${{}}>
|
|
<header class="title">
|
|
<wc-icon name="info"></wc-icon>
|
|
${this.title||w}
|
|
</header>
|
|
<footer class="actions">
|
|
<wc-button @click=${this.#o}>取消</wc-button>
|
|
<wc-button
|
|
solid
|
|
type=${this.confirmButtonType||"primary"}
|
|
@click=${this.#e}
|
|
>确定</wc-button
|
|
>
|
|
</footer>
|
|
</div>
|
|
</main>
|
|
`}}b.reg("popconfirm");
|