| 1 |
- import{a as e,n as t}from"./react-dom-stZKkA6x.js";import{Bn as n,Dn as r,Dr as i,Et as a,Kt as o,Mn as s,Mr as c,Nn as l,Nr as u,Or as d,Qn as f,Tn as p,Xt as m,ar as h,er as g,jr as _,kn as v,nr as y,vn as b,wn as x,xn as S,yr as C}from"./jsx-runtime-C5RSiriy.js";var w=e(u()),T=e(t()),E=function(e,t){if(!e)return null;var n={left:e.offsetLeft,right:e.parentElement.clientWidth-e.clientWidth-e.offsetLeft,width:e.clientWidth,top:e.offsetTop,bottom:e.parentElement.clientHeight-e.clientHeight-e.offsetTop,height:e.clientHeight};return t?{left:0,right:0,width:0,top:n.top,bottom:n.bottom,height:n.height}:{left:n.left,right:n.right,width:n.width,top:0,bottom:0,height:0}},D=function(e){return e===void 0?void 0:`${e}px`};function O(e){var t=e.prefixCls,n=e.containerRef,r=e.value,a=e.getValueIndex,o=e.motionName,s=e.onMotionStart,c=e.onMotionEnd,l=e.direction,u=e.vertical,d=u===void 0?!1:u,p=T.useRef(null),m=h(T.useState(r),2),g=m[0],_=m[1],v=function(e){var r=a(e),i=n.current?.querySelectorAll(`.${t}-item`)[r];return i?.offsetParent&&i},y=h(T.useState(null),2),x=y[0],S=y[1],O=h(T.useState(null),2),k=O[0],A=O[1];f(function(){if(g!==r){var e=v(g),t=v(r),n=E(e,d),i=E(t,d);_(r),S(n),A(i),e&&t?s():c()}},[r]);var j=T.useMemo(function(){return D(d?x?.top??0:l===`rtl`?-x?.right:x?.left)},[d,l,x]),M=T.useMemo(function(){return D(d?k?.top??0:l===`rtl`?-k?.right:k?.left)},[d,l,k]);return!x||!k?null:T.createElement(b,{visible:!0,motionName:o,motionAppear:!0,onAppearStart:function(){return d?{transform:`translateY(var(--thumb-start-top))`,height:`var(--thumb-start-height)`}:{transform:`translateX(var(--thumb-start-left))`,width:`var(--thumb-start-width)`}},onAppearActive:function(){return d?{transform:`translateY(var(--thumb-active-top))`,height:`var(--thumb-active-height)`}:{transform:`translateX(var(--thumb-active-left))`,width:`var(--thumb-active-width)`}},onVisibleChanged:function(){S(null),A(null),c()}},function(e,n){var r=e.className,a=e.style,o=i(i({},a),{},{"--thumb-start-left":j,"--thumb-start-width":D(x?.width),"--thumb-active-left":M,"--thumb-active-width":D(k?.width),"--thumb-start-top":j,"--thumb-start-height":D(x?.height),"--thumb-active-top":M,"--thumb-active-height":D(k?.height)}),s={ref:C(p,n),style:o,className:(0,w.default)(`${t}-thumb`,r)};return T.createElement(`div`,s)})}var k=[`prefixCls`,`direction`,`vertical`,`options`,`disabled`,`defaultValue`,`value`,`name`,`onChange`,`className`,`motionName`];function A(e){if(e.title!==void 0)return e.title;if(_(e.label)!==`object`)return e.label?.toString()}function j(e){return e.map(function(e){if(_(e)===`object`&&e!==null){var t=A(e);return i(i({},e),{},{title:t})}return{label:e?.toString(),title:e?.toString(),value:e}})}var M=function(e){var t=e.prefixCls,n=e.className,r=e.disabled,i=e.checked,a=e.label,o=e.title,s=e.value,c=e.name,l=e.onChange,u=e.onFocus,f=e.onBlur,p=e.onKeyDown,m=e.onKeyUp,h=e.onMouseDown;return T.createElement(`label`,{className:(0,w.default)(n,d({},`${t}-item-disabled`,r)),onMouseDown:h},T.createElement(`input`,{name:c,className:`${t}-item-input`,type:`radio`,disabled:r,checked:i,onChange:function(e){r||l(e,s)},onFocus:u,onBlur:f,onKeyDown:p,onKeyUp:m}),T.createElement(`div`,{className:`${t}-item-label`,title:o},a))},N=T.forwardRef(function(e,t){var n=e.prefixCls,r=n===void 0?`rc-segmented`:n,i=e.direction,a=e.vertical,o=e.options,s=o===void 0?[]:o,u=e.disabled,f=e.defaultValue,p=e.value,g=e.name,_=e.onChange,v=e.className,b=v===void 0?``:v,x=e.motionName,S=x===void 0?`thumb-motion`:x,E=y(e,k),D=T.useRef(null),A=T.useMemo(function(){return C(D,t)},[D,t]),N=T.useMemo(function(){return j(s)},[s]),P=h(l(N[0]?.value,{value:p,defaultValue:f}),2),F=P[0],I=P[1],L=h(T.useState(!1),2),R=L[0],z=L[1],B=function(e,t){I(t),_?.(t)},V=m(E,[`children`]),H=h(T.useState(!1),2),U=H[0],W=H[1],G=h(T.useState(!1),2),K=G[0],q=G[1],J=function(){q(!0)},Y=function(){q(!1)},X=function(){W(!1)},Z=function(e){e.key===`Tab`&&W(!0)},Q=function(e){var t=N.findIndex(function(e){return e.value===F}),n=N.length,r=N[(t+e+n)%n];r&&(I(r.value),_?.(r.value))},$=function(e){switch(e.key){case`ArrowLeft`:case`ArrowUp`:Q(-1);break;case`ArrowRight`:case`ArrowDown`:Q(1);break}};return T.createElement(`div`,c({role:`radiogroup`,"aria-label":`segmented control`,tabIndex:u?void 0:0,"aria-orientation":a?`vertical`:`horizontal`},V,{className:(0,w.default)(r,d(d(d({},`${r}-rtl`,i===`rtl`),`${r}-disabled`,u),`${r}-vertical`,a),b),ref:A}),T.createElement(`div`,{className:`${r}-group`},T.createElement(O,{vertical:a,prefixCls:r,value:F,containerRef:D,motionName:`${r}-${S}`,direction:i,getValueIndex:function(e){return N.findIndex(function(t){return t.value===e})},onMotionStart:function(){z(!0)},onMotionEnd:function(){z(!1)}}),N.map(function(e){return T.createElement(M,c({},e,{name:g,key:e.value,prefixCls:r,className:(0,w.default)(e.className,`${r}-item`,d(d({},`${r}-item-selected`,e.value===F&&!R),`${r}-item-focused`,K&&U&&e.value===F)),checked:e.value===F,onChange:B,onFocus:J,onBlur:Y,onKeyDown:$,onKeyUp:Z,onMouseDown:X,disabled:!!u||!!e.disabled}))})))});function P(e,t){return{[`${e}, ${e}:hover, ${e}:focus`]:{color:t.colorTextDisabled,cursor:`not-allowed`}}}function F(e){return{background:e.itemSelectedBg,boxShadow:e.boxShadowTertiary}}var I=Object.assign({overflow:`hidden`},v),L=e=>{let{componentCls:t}=e,n=e.calc(e.controlHeight).sub(e.calc(e.trackPadding).mul(2)).equal(),i=e.calc(e.controlHeightLG).sub(e.calc(e.trackPadding).mul(2)).equal(),a=e.calc(e.controlHeightSM).sub(e.calc(e.trackPadding).mul(2)).equal();return{[t]:Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},r(e)),{display:`inline-block`,padding:e.trackPadding,color:e.itemColor,background:e.trackBg,borderRadius:e.borderRadius,transition:`all ${e.motionDurationMid}`}),p(e)),{[`${t}-group`]:{position:`relative`,display:`flex`,alignItems:`stretch`,justifyItems:`flex-start`,flexDirection:`row`,width:`100%`},[`&${t}-rtl`]:{direction:`rtl`},[`&${t}-vertical`]:{[`${t}-group`]:{flexDirection:`column`},[`${t}-thumb`]:{width:`100%`,height:0,padding:`0 ${g(e.paddingXXS)}`}},[`&${t}-block`]:{display:`flex`},[`&${t}-block ${t}-item`]:{flex:1,minWidth:0},[`${t}-item`]:{position:`relative`,textAlign:`center`,cursor:`pointer`,transition:`color ${e.motionDurationMid}`,borderRadius:e.borderRadiusSM,transform:`translateZ(0)`,"&-selected":Object.assign(Object.assign({},F(e)),{color:e.itemSelectedColor}),"&-focused":x(e),"&::after":{content:`""`,position:`absolute`,zIndex:-1,width:`100%`,height:`100%`,top:0,insetInlineStart:0,borderRadius:`inherit`,opacity:0,transition:`opacity ${e.motionDurationMid}, background-color ${e.motionDurationMid}`,pointerEvents:`none`},[`&:not(${t}-item-selected):not(${t}-item-disabled)`]:{"&:hover, &:active":{color:e.itemHoverColor},"&:hover::after":{opacity:1,backgroundColor:e.itemHoverBg},"&:active::after":{opacity:1,backgroundColor:e.itemActiveBg}},"&-label":Object.assign({minHeight:n,lineHeight:g(n),padding:`0 ${g(e.segmentedPaddingHorizontal)}`},I),"&-icon + *":{marginInlineStart:e.calc(e.marginSM).div(2).equal()},"&-input":{position:`absolute`,insetBlockStart:0,insetInlineStart:0,width:0,height:0,opacity:0,pointerEvents:`none`}},[`${t}-thumb`]:Object.assign(Object.assign({},F(e)),{position:`absolute`,insetBlockStart:0,insetInlineStart:0,width:0,height:`100%`,padding:`${g(e.paddingXXS)} 0`,borderRadius:e.borderRadiusSM,[`& ~ ${t}-item:not(${t}-item-selected):not(${t}-item-disabled)::after`]:{backgroundColor:`transparent`}}),[`&${t}-lg`]:{borderRadius:e.borderRadiusLG,[`${t}-item-label`]:{minHeight:i,lineHeight:g(i),padding:`0 ${g(e.segmentedPaddingHorizontal)}`,fontSize:e.fontSizeLG},[`${t}-item, ${t}-thumb`]:{borderRadius:e.borderRadius}},[`&${t}-sm`]:{borderRadius:e.borderRadiusSM,[`${t}-item-label`]:{minHeight:a,lineHeight:g(a),padding:`0 ${g(e.segmentedPaddingHorizontalSM)}`},[`${t}-item, ${t}-thumb`]:{borderRadius:e.borderRadiusXS}}}),P(`&-disabled ${t}-item`,e)),P(`${t}-item-disabled`,e)),{[`${t}-thumb-motion-appear-active`]:{transition:`transform ${e.motionDurationSlow} ${e.motionEaseInOut}, width ${e.motionDurationSlow} ${e.motionEaseInOut}`,willChange:`transform, width`},[`&${t}-shape-round`]:{borderRadius:9999,[`${t}-item, ${t}-thumb`]:{borderRadius:9999}}})}},R=S(`Segmented`,e=>{let{lineWidth:t,calc:n}=e;return L(s(e,{segmentedPaddingHorizontal:n(e.controlPaddingHorizontal).sub(t).equal(),segmentedPaddingHorizontalSM:n(e.controlPaddingHorizontalSM).sub(t).equal()}))},e=>{let{colorTextLabel:t,colorText:n,colorFillSecondary:r,colorBgElevated:i,colorFill:a,lineWidthBold:o,colorBgLayout:s}=e;return{trackPadding:o,trackBg:s,itemColor:t,itemHoverColor:n,itemHoverBg:r,itemSelectedBg:i,itemActiveBg:a,itemSelectedColor:n}}),z=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n};function B(e){return typeof e==`object`&&!!e?.icon}var V=T.forwardRef((e,t)=>{let r=a(),{prefixCls:i,className:s,rootClassName:c,block:l,options:u=[],size:d=`middle`,style:f,vertical:p,shape:m=`default`,name:h=r}=e,g=z(e,[`prefixCls`,`className`,`rootClassName`,`block`,`options`,`size`,`style`,`vertical`,`shape`,`name`]),{getPrefixCls:_,direction:v,className:y,style:b}=n(`segmented`),x=_(`segmented`,i),[S,C,E]=R(x),D=o(d),O=T.useMemo(()=>u.map(e=>{if(B(e)){let{icon:t,label:n}=e,r=z(e,[`icon`,`label`]);return Object.assign(Object.assign({},r),{label:T.createElement(T.Fragment,null,T.createElement(`span`,{className:`${x}-item-icon`},t),n&&T.createElement(`span`,null,n))})}return e}),[u,x]),k=(0,w.default)(s,c,y,{[`${x}-block`]:l,[`${x}-sm`]:D===`small`,[`${x}-lg`]:D===`large`,[`${x}-vertical`]:p,[`${x}-shape-${m}`]:m===`round`},C,E),A=Object.assign(Object.assign({},b),f);return S(T.createElement(N,Object.assign({},g,{name:h,className:k,style:A,options:O,ref:t,prefixCls:x,direction:v,vertical:p})))});export{V as t};
|