1 line
8.2 KiB
JavaScript
1 line
8.2 KiB
JavaScript
import{$t as e,Bn as t,Bt as n,Ct as r,F as i,Or as a,Sr as o,St as s,Tr as c,Vn as l,an as u,cn as d,dn as f,et as p,fn as m,hn as h,it as g,lt as _,sn as v,st as y,ur as b,xn as x,xr as S}from"./jsx-runtime-NwRKtVrk.js";import{a as C,i as w,x as T}from"./statusUtils-G17j4Ng-.js";import{n as E,r as D}from"./useClosable-s-Ss4Zwd.js";import{i as O,n as k}from"./ColorPresets-BBbJffTn.js";var A=a(c()),j=t=>{let{paddingXXS:n,lineWidth:r,tagPaddingHorizontal:i,componentCls:a,calc:o}=t,s=o(i).sub(r).equal(),c=o(n).sub(r).equal();return{[a]:{...e(t),display:`inline-block`,height:`auto`,paddingInline:s,fontSize:t.tagFontSize,lineHeight:t.tagLineHeight,whiteSpace:`nowrap`,backgroundColor:t.defaultBg,border:`${u(t.lineWidth)} ${t.lineType} ${t.colorBorder}`,borderRadius:t.borderRadiusSM,opacity:1,transition:`all ${t.motionDurationMid}`,textAlign:`start`,position:`relative`,[`&${a}-rtl`]:{direction:`rtl`},"&, a, a:hover":{color:t.defaultColor},[`${a}-close-icon`]:{marginInlineStart:c,fontSize:t.tagIconSize,color:t.colorIcon,cursor:`pointer`,transition:`all ${t.motionDurationMid}`,"&:hover":{color:t.colorTextHeading}},"&-checkable":{backgroundColor:`transparent`,borderColor:`transparent`,cursor:`pointer`,[`&:not(${a}-checkable-checked):hover`]:{color:t.colorPrimary,backgroundColor:t.colorFillSecondary},"&:active, &-checked":{color:t.colorTextLightSolid},"&-checked":{backgroundColor:t.colorPrimary,"&:hover":{backgroundColor:t.colorPrimaryHover}},"&:active":{backgroundColor:t.colorPrimaryActive},"&-disabled":{cursor:`not-allowed`,[`&:not(${a}-checkable-checked)`]:{color:t.colorTextDisabled,"&:hover":{backgroundColor:`transparent`}},[`&${a}-checkable-checked`]:{color:t.colorTextDisabled,backgroundColor:t.colorBgContainerDisabled},"&:hover, &:active":{backgroundColor:t.colorBgContainerDisabled,color:t.colorTextDisabled},[`&:not(${a}-checkable-checked):hover`]:{color:t.colorTextDisabled}},"&-group":{display:`flex`,flexWrap:`wrap`,gap:t.paddingXS}},"&-hidden":{display:`none`},[`> ${t.iconCls} + span, > span + ${t.iconCls}`]:{marginInlineStart:s}},[`&${t.componentCls}-solid`]:{borderColor:`transparent`,color:t.colorTextLightSolid,backgroundColor:t.colorBgSolid,[`&${a}-default`]:{color:t.solidTextColor}},[`${a}-filled`]:{borderColor:`transparent`,backgroundColor:t.tagBorderlessBg},[`&${a}-disabled`]:{color:t.colorTextDisabled,cursor:`not-allowed`,backgroundColor:t.colorBgContainerDisabled,a:{cursor:`not-allowed`,pointerEvents:`none`,color:t.colorTextDisabled,"&:hover":{color:t.colorTextDisabled}},"a&":{"&:hover, &:active":{color:t.colorTextDisabled}},[`&${a}-outlined`]:{borderColor:t.colorBorderDisabled},[`&${a}-solid, &${a}-filled`]:{color:t.colorTextDisabled,[`${a}-close-icon`]:{color:t.colorTextDisabled}},[`${a}-close-icon`]:{cursor:`not-allowed`,color:t.colorTextDisabled,"&:hover":{color:t.colorTextDisabled}}}}},M=e=>{let{lineWidth:t,fontSizeIcon:r,calc:i}=e,a=e.fontSizeSM;return n(e,{tagFontSize:a,tagLineHeight:u(i(e.lineHeightSM).mul(a).equal()),tagIconSize:i(r).sub(i(t).mul(2)).equal(),tagPaddingHorizontal:8,tagBorderlessBg:e.defaultBg})},N=e=>{let t=k(new i(e.colorBgSolid),`#fff`)?`#000`:`#fff`;return{defaultBg:new S(e.colorFillTertiary).onBackground(e.colorBgContainer).toHexString(),defaultColor:e.colorText,solidTextColor:t}},P=s(`Tag`,e=>j(M(e)),N),F=A.forwardRef((e,t)=>{let{prefixCls:n,style:r,className:i,checked:a,children:s,icon:c,onChange:l,onClick:u,onKeyDown:d,disabled:f,...p}=e,{getPrefixCls:m,tag:h}=A.useContext(v),_=A.useContext(g),y=f??_,b=e=>{y||(l?.(!a),u?.(e))},x=e=>{d?.(e),!(e.defaultPrevented||y)&&e.key===` `&&(e.preventDefault(),l?.(!a))},S=m(`tag`,n),[C,w]=P(S),T=o(S,`${S}-checkable`,{[`${S}-checkable-checked`]:a,[`${S}-checkable-disabled`]:y},h?.className,i,C,w);return A.createElement(`span`,{...p,ref:t,role:`checkbox`,"aria-checked":a,"aria-disabled":y||void 0,tabIndex:y?-1:0,style:{...r,...h?.style},className:T,onClick:b,onKeyDown:x},c,A.createElement(`span`,null,s))}),I=A.forwardRef((e,n)=>{let{id:r,prefixCls:i,rootClassName:a,className:s,style:c,classNames:l,styles:u,disabled:m,options:g,value:_,defaultValue:v,onChange:y,multiple:S,...C}=e,{getPrefixCls:w,direction:T,className:E,style:D,classNames:O,styles:k}=d(`tag`),j=w(`tag`,i),M=`${j}-checkable-group`,[N,I]=P(j,p(j)),[L,R]=f([O,l],[k,u],{props:e}),z=(0,A.useMemo)(()=>Array.isArray(g)?g.map(e=>h(e)?e:{value:e,label:e}):[],[g]),[B,V]=b(v,_),H=(e,t)=>{let n=null;if(S){let r=B||[];n=e?[].concat(x(r),[t.value]):r.filter(e=>e!==t.value)}else n=e?t.value:null;V(n),y?.(n)},U=A.useRef(null);(0,A.useImperativeHandle)(n,()=>({nativeElement:U.current}));let W=t(C,{aria:!0,data:!0});return A.createElement(`div`,{...W,className:o(M,E,a,{[`${M}-disabled`]:m,[`${M}-rtl`]:T===`rtl`},N,I,s,L.root),style:{...D,...R.root,...c},id:r,ref:U},z.map(e=>A.createElement(F,{key:e.value,className:o(`${M}-item`,L.item,e.className),style:{...R.item,...e.style},checked:S?(B||[]).includes(e.value):B===e.value,onChange:t=>H(t,e),disabled:m},e.label)))});function L(e,t){let{color:n,variant:r,bordered:i}=e;return A.useMemo(()=>{let e=n?.endsWith(`-inverse`),a;a=r||(e?`solid`:i===!1?`filled`:t||`filled`);let o=e?n?.replace(`-inverse`,``):n;o===void 0&&a===`solid`&&(o=`default`);let s=w(o),c=C(o),l={};if(!s&&!c&&o)if(a===`solid`)l.backgroundColor=n;else{let e=new S(o).toHsl();e.l=.95,l.backgroundColor=new S(e).toHexString(),l.color=n,a===`outlined`&&(l.borderColor=n)}return[a,o,s,c,l]},[n,r,i,t])}var R=e=>T(e,(t,{textColor:n,lightBorderColor:r,lightColor:i,darkColor:a})=>({[`${e.componentCls}${e.componentCls}-${t}:not(${e.componentCls}-disabled)`]:{[`&${e.componentCls}-outlined`]:{backgroundColor:i,borderColor:r,color:n},[`&${e.componentCls}-solid`]:{backgroundColor:a,borderColor:a,color:e.colorTextLightSolid},[`&${e.componentCls}-filled`]:{backgroundColor:i,color:n}}})),z=r([`Tag`,`preset`],e=>R(M(e)),N);function B(e){return typeof e==`string`?e.charAt(0).toUpperCase()+e.slice(1):e}var V=(e,t,n)=>{let r=B(n);return{[`${e.componentCls}${e.componentCls}-${t}:not(${e.componentCls}-disabled)`]:{[`&${e.componentCls}-outlined`]:{backgroundColor:e[`color${r}Bg`],borderColor:e[`color${r}Border`],color:e[`color${n}`]},[`&${e.componentCls}-solid`]:{backgroundColor:e[`color${n}`],borderColor:e[`color${n}`]},[`&${e.componentCls}-filled`]:{backgroundColor:e[`color${r}Bg`],color:e[`color${n}`]}}}},H=r([`Tag`,`status`],e=>{let t=M(e);return[V(t,`success`,`Success`),V(t,`processing`,`Info`),V(t,`error`,`Error`),V(t,`warning`,`Warning`)]},N),U=A.forwardRef((e,t)=>{let{prefixCls:n,className:r,rootClassName:i,style:a,children:s,icon:c,color:u,variant:p,onClose:h,bordered:b,disabled:x,href:S,target:C,styles:w,classNames:T,...k}=e,{getPrefixCls:j,direction:M,className:N,variant:F,style:I,classNames:R,styles:B}=d(`tag`),[V,U,W,G,K]=L(e,F),ee=W||G,te=A.useContext(g),q=x??te,{tag:ne}=A.useContext(v),[re,ie]=A.useState(!0),J=l(k,[`closeIcon`,`closable`]),ae={...e,color:U,variant:V,disabled:q},[Y,X]=f([R,T],[B,w],{props:ae}),oe=A.useMemo(()=>{let e={...X.root,...I,...a};return q||(e={...K,...e}),e},[X.root,I,a,K,q]),Z=j(`tag`,n),[se,ce]=P(Z),le=o(Z,N,Y.root,`${Z}-${V}`,{[`${Z}-${U}`]:ee,[`${Z}-hidden`]:!re,[`${Z}-rtl`]:M===`rtl`,[`${Z}-disabled`]:q},r,i,se,ce),Q=e=>{q||(e.stopPropagation(),h?.(e),!e.defaultPrevented&&ie(!1))},$=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.currentTarget.click())},[,ue]=D(E(e),E(ne),{closable:!1,closeIconRender:e=>_(e,A.createElement(`span`,{role:`button`,tabIndex:q?-1:0,"aria-disabled":q||void 0,className:o(`${Z}-close-icon`,Y.close),onClick:Q,onKeyDown:$,style:X.close},e),e=>({onClick:t=>{e?.onClick?.(t),Q(t)},onKeyDown:t=>{e?.onKeyDown?.(t),t.defaultPrevented||$(t)},role:`button`,tabIndex:q?-1:0,"aria-disabled":q||void 0,className:o(e?.className,`${Z}-close-icon`,Y.close),style:{...X.close,...e?.style}}))}),de=m(k.onClick)||s&&s.type===`a`,fe=y(c,{className:o(A.isValidElement(c)?c.props?.className:void 0,Y.icon),style:X.icon}),pe=fe?A.createElement(A.Fragment,null,fe,s&&A.createElement(`span`,{className:Y.content,style:X.content},s)):s,me=S?`a`:`span`,he=A.createElement(me,{...J,ref:t,className:le,style:oe,href:q?void 0:S,target:C,onClick:q?void 0:J.onClick,...S&&q?{"aria-disabled":!0}:{}},pe,ue,W&&A.createElement(z,{key:`preset`,prefixCls:Z}),G&&A.createElement(H,{key:`status`,prefixCls:Z}));return de?A.createElement(O,{component:`Tag`},he):he});U.CheckableTag=F,U.CheckableTagGroup=I;export{U as t}; |