@oliasoft-open-source/react-ui-library 4.12.0-beta-2 → 4.12.0-beta-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{index-BVCFmQTa.js → index-BMWyiwz3.js} +169 -145
- package/dist/assets/{index-BU9wzZv9.css → index-BaYhOc6M.css} +37 -5
- package/dist/index.html +1 -1
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/dist/storybook/assets/{Color-KGDBMAHA-BODMLRvZ.js → Color-KGDBMAHA-BU5Cvr93.js} +1 -1
- package/dist/storybook/assets/{DocsRenderer-PKQXORMH-DEi7ICVq.js → DocsRenderer-PKQXORMH-giM41WN8.js} +1 -1
- package/dist/storybook/assets/{accordion.stories-C_Vx7GEC.js → accordion.stories-BlHfHegj.js} +1 -1
- package/dist/storybook/assets/{afe.stories-OEYJqexC.js → afe.stories-C9XjJj62.js} +1 -1
- package/dist/storybook/assets/{buttons-and-links-BHNS6Ebw.js → buttons-and-links-BA3MNFjq.js} +1 -1
- package/dist/storybook/assets/{casing-loads.stories-BAdZ87Oc.js → casing-loads.stories-Cl2tJipP.js} +1 -1
- package/dist/storybook/assets/{cell.stories-Bu5u9qEl.js → cell.stories-rzJE_qJC.js} +1 -1
- package/dist/storybook/assets/{chunk-HLWAVYOI-BbzmrmoZ.js → chunk-HLWAVYOI-Dvbg03uT.js} +1 -1
- package/dist/storybook/assets/{color-oeF0-Pph.js → color-DIyQ13kP.js} +1 -1
- package/dist/storybook/assets/{footer.stories-LUxEpSgD.js → footer.stories-C6M5S0UZ.js} +1 -1
- package/dist/storybook/assets/{form.stories-B7V77yuI.js → form.stories-BNORsn6Z.js} +1 -1
- package/dist/storybook/assets/{formation.stories-D7MX0dSY.js → formation.stories-1WX1Nu1P.js} +1 -1
- package/dist/storybook/assets/{iframe-nuCPRPrd.js → iframe-B0e2q2Zd.js} +2 -2
- package/dist/storybook/assets/{index-CN6H1a0D.js → index-BXJ79Lvz.js} +1 -1
- package/dist/storybook/assets/{index-BFtO1KgR.js → index-BlyDuQBv.js} +4 -4
- package/dist/storybook/assets/{initialize-context-rEvM6bdZ.js → initialize-context-Y03pJPr5.js} +1 -1
- package/dist/storybook/assets/{input-group.stories-BdQ1prY4.js → input-group.stories-BCajsqAk.js} +1 -1
- package/dist/storybook/assets/{input-validation-Ccu8WMpy.js → input-validation-CLZKtfoW.js} +1 -1
- package/dist/storybook/assets/{inputs-C4fsY4Ua.js → inputs-DlW6Jeem.js} +1 -1
- package/dist/storybook/assets/{layout-forms-DOgsanng.js → layout-forms-C6ZH-nYk.js} +1 -1
- package/dist/storybook/assets/{layout-general-DtDx77FI.js → layout-general-CWqOMwXA.js} +1 -1
- package/dist/storybook/assets/menu.test-case.stories-XN9XFV-D.js +3 -0
- package/dist/storybook/assets/{modal.stories-DUXRRhK-.js → modal.stories-C2d-Em5V.js} +1 -1
- package/dist/storybook/assets/{number-input-CNnU6gOF.js → number-input-B3_gmeWr.js} +1 -1
- package/dist/storybook/assets/{number-input.stories-Bo26PJmJ.js → number-input.stories-epjUq9ve.js} +1 -1
- package/dist/storybook/assets/number-input.test-case.stories-DeEtalIU.js +95 -0
- package/dist/storybook/assets/{padding-and-spacing-Mfm_1hn5.js → padding-and-spacing-CfnXk0Zn.js} +1 -1
- package/dist/storybook/assets/{pagination-CoyQUC4R.js → pagination-CR1nxnnq.js} +1 -1
- package/dist/storybook/assets/{pagination.stories-qfpnU8DC.js → pagination.stories-qXmBYwYc.js} +1 -1
- package/dist/storybook/assets/{popover.stories-TwNkFkWa.js → popover.stories-DZTfimDf.js} +1 -1
- package/dist/storybook/assets/{preview-BIv_KaBF.js → preview-b9pkIJl_.js} +2 -2
- package/dist/storybook/assets/{preview-DVjsIOwK.js → preview-jWpKVqju.js} +1 -1
- package/dist/storybook/assets/{reservoirs.stories-DE9FrS0f.js → reservoirs.stories-r1Ip90kJ.js} +1 -1
- package/dist/storybook/assets/{rich-text-input.stories-BNwcnp92.js → rich-text-input.stories-DwaseXZv.js} +1 -1
- package/dist/storybook/assets/{row.stories-D3Bnp8i4.js → row.stories-DRvH8Grn.js} +1 -1
- package/dist/storybook/assets/select-Cwks-WA0.js +61 -0
- package/dist/storybook/assets/{select.stories-BRGk9iYK.js → select.stories-DjGSNDXK.js} +1 -1
- package/dist/storybook/assets/select.test-case.stories-CrXzt4qn.js +82 -0
- package/dist/storybook/assets/{table-DPbEkZqw.js → table-DoyDBG6l.js} +1 -1
- package/dist/storybook/assets/{table.stories-BBzqpsyH.js → table.stories-BgWKzIob.js} +1 -1
- package/dist/storybook/assets/{title.stories-B4PYbA22.js → title.stories-Rv6ZO_Wl.js} +1 -1
- package/dist/storybook/assets/{unit-input-Byipu-z0.js → unit-input-BXg4VphV.js} +1 -1
- package/dist/storybook/assets/{unit-input.stories-CChVbxmI.js → unit-input.stories-Btz2M_TP.js} +1 -1
- package/dist/storybook/assets/{unit-input.test-case.stories-BeFM9DuK.js → unit-input.test-case.stories-CZD1jf36.js} +1 -1
- package/dist/storybook/assets/{unit-table.stories-9x5S71wv.js → unit-table.stories-CISvZMxX.js} +1 -1
- package/dist/storybook/assets/{unit-table.test-case.stories-DZJ-hZ72.js → unit-table.test-case.stories-tEype9om.js} +1 -1
- package/dist/storybook/iframe.html +1 -1
- package/dist/storybook/index.json +1 -1
- package/dist/storybook/project.json +1 -1
- package/package.json +1 -1
- package/dist/storybook/assets/menu.test-case.stories-W-jG-Jk8.js +0 -3
- package/dist/storybook/assets/number-input.test-case.stories-CHGSaGbj.js +0 -92
- package/dist/storybook/assets/select-BQzJMnK1.js +0 -61
- package/dist/storybook/assets/select.test-case.stories-BYMK9M8u.js +0 -82
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import{j as o}from"./jsx-runtime-eps93zm2.js";import{l as ae}from"./lodash-c4VUpsOs.js";import{r as q}from"./index-DhsZuJvc.js";import{c as G}from"./index-Bk2sglWO.js";import{G as ie,I as Ee}from"./common-types-Sih75Sav.js";import{D as me}from"./disabled-context-rmpd7YJS.js";import{i as ne}from"./types-Dx2TtIG9.js";import{T as pe,u as We,m as ze}from"./tooltip-1V7clEnw.js";import{A as P,E as B,K as Ge}from"./enum-Bnn40S8Q.js";import{a as $e,_ as Ue}from"./inheritsLoose-DP0QEDDI.js";import{_ as ge}from"./assertThisInitialized-B9jnkVVz.js";import{m as le}from"./memoize-one.esm-CcMeOnPo.js";import{M as se}from"./types-BmbYqTX_.js";import{T as ue}from"./text-B3-TSWok.js";import{A as Ve}from"./actions-Bax0KeqM.js";import{I as ce}from"./icon-BSFY3vDO.js";import{s as Ye}from"./select.input-CJed_LLR.js";const Ke="_inputInTable_sl2b5_1",Be="_inputHover_sl2b5_13",Ze="_inputFocus_sl2b5_18",Xe="_inputError_sl2b5_25",Je="_inputWarning_sl2b5_26",Qe="_inputDisabled_sl2b5_61",en="_hideScrollbars_sl2b5_67",nn="_select_sl2b5_77",tn="_isInTable_sl2b5_121",rn="_unSelected_sl2b5_133",an="_small_sl2b5_174",sn="_right_sl2b5_182",ln="_groupOrderFirst_sl2b5_193",on="_groupOrderMiddle_sl2b5_194",un="_groupOrderLast_sl2b5_198",U={inputInTable:Ke,inputHover:Be,inputFocus:Ze,inputError:Xe,inputWarning:Je,inputDisabled:Qe,hideScrollbars:en,select:nn,isInTable:tn,unSelected:rn,small:an,right:sn,groupOrderFirst:ln,groupOrderMiddle:on,groupOrderLast:un},we=({disabled:e=!1,error:n=null,warning:r=null,tooltip:a=null,options:s,onChange:g=ae.noop,onFocus:S=ae.noop,onBlur:u=ae.noop,right:c=!1,small:d=!1,tabIndex:T=0,selectedOption:m,width:b=null,groupOrder:E=null,testId:v,isInTable:t=!1,clearable:i,placeholder:l,hasNonExistentValue:p,maxTooltipWidth:y,borderRadius:I})=>{const f=q.useContext(me),h=m===null||(m==null?void 0:m.value)===null?"unselected":m==null?void 0:m.value,w=h==="unselected",N=(h==="unselected"||i?[o.jsx("option",{value:"unselected",disabled:!i,hidden:!i,children:l||"Select..."},"unselected")]:[]).concat(p?[o.jsx("option",{value:m==null?void 0:m.value,disabled:e||f,children:m==null?void 0:m.label},"selectedNonExistentValue")]:[]).concat(s.map((L,R)=>o.jsx("option",{value:L.value,"data-testid":L.testId,children:L.label},R))),x=(()=>{if(E)switch(E){case ie.FIRST:return U.groupOrderFirst;case ie.LAST:return U.groupOrderLast;default:return U.groupOrderMiddle}return""})();return o.jsx(pe,{error:!!n,warning:!!r,text:a||n||r,enabled:a&&ne(a)||n&&ne(n)||r&&ne(r)||!1,maxWidth:y,placement:"bottom-center",children:o.jsx("select",{className:G(U.select,w?U.unSelected:"",c?U.right:"",d?U.small:"",t?U.isInTable:"",x),style:{width:b||"",borderRadius:I||""},onChange:L=>{const{value:R}=L.target;let C;R==="unselected"?C={value:null}:C=s.find(F=>String(F.value)===String(R))||{value:null},g(L,C)},onFocus:S,onBlur:u,tabIndex:T,value:h,disabled:e||f,"data-error":n||null,"data-warning":r||null,"data-testid":v,children:N})})};we.__docgenInfo={description:"",methods:[],displayName:"NativeSelect",props:{borderRadius:{required:!1,tsType:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},description:""},disabled:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},error:{required:!1,tsType:{name:"union",raw:"TStringOrNumber | React.ReactNode | null",elements:[{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},{name:"ReactReactNode",raw:"React.ReactNode"},{name:"null"}]},description:"",defaultValue:{value:"null",computed:!1}},warning:{required:!1,tsType:{name:"union",raw:"TStringOrNumber | React.ReactNode | null",elements:[{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},{name:"ReactReactNode",raw:"React.ReactNode"},{name:"null"}]},description:"",defaultValue:{value:"null",computed:!1}},tooltip:{required:!1,tsType:{name:"union",raw:"TStringOrNumber | React.ReactNode | null",elements:[{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},{name:"ReactReactNode",raw:"React.ReactNode"},{name:"null"}]},description:"",defaultValue:{value:"null",computed:!1}},options:{required:!0,tsType:{name:"Array",elements:[{name:"ISelectSelectedOption"}],raw:"ISelectSelectedOption[]"},description:""},onChange:{required:!1,tsType:{name:"signature",type:"function",raw:`(
|
|
2
|
+
evt: ChangeEvent<HTMLSelectElement>,
|
|
3
|
+
value: ISelectSelectedOption | { value: null },
|
|
4
|
+
) => void`,signature:{arguments:[{type:{name:"ChangeEvent",elements:[{name:"HTMLSelectElement"}],raw:"ChangeEvent<HTMLSelectElement>"},name:"evt"},{type:{name:"union",raw:"ISelectSelectedOption | { value: null }",elements:[{name:"ISelectSelectedOption"},{name:"signature",type:"object",raw:"{ value: null }",signature:{properties:[{key:"value",value:{name:"null",required:!0}}]}}]},name:"value"}],return:{name:"void"}}},description:"",defaultValue:{value:"noop",computed:!0}},onFocus:{required:!1,tsType:{name:"signature",type:"function",raw:"() => void",signature:{arguments:[],return:{name:"void"}}},description:"",defaultValue:{value:"noop",computed:!0}},onBlur:{required:!1,tsType:{name:"signature",type:"function",raw:"() => void",signature:{arguments:[],return:{name:"void"}}},description:"",defaultValue:{value:"noop",computed:!0}},right:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},small:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},tabIndex:{required:!1,tsType:{name:"number"},description:"",defaultValue:{value:"0",computed:!1}},selectedOption:{required:!1,tsType:{name:"ISelectSelectedOption"},description:""},width:{required:!1,tsType:{name:"union",raw:"TStringOrNumber | null",elements:[{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},{name:"null"}]},description:"",defaultValue:{value:"null",computed:!1}},groupOrder:{required:!1,tsType:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}]},description:"",defaultValue:{value:"null",computed:!1}},testId:{required:!1,tsType:{name:"union",raw:"string | undefined",elements:[{name:"string"},{name:"undefined"}]},description:""},isInTable:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},clearable:{required:!1,tsType:{name:"boolean"},description:""},placeholder:{required:!1,tsType:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}]},description:""},hasNonExistentValue:{required:!1,tsType:{name:"boolean"},description:""},maxTooltipWidth:{required:!1,tsType:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},description:""}}};const Oe=()=>{const e=q.useRef(null);return[e,()=>{e.current&&e.current.focus()}]},Le=()=>{const[e,n]=q.useState(!1);return q.useEffect(()=>{(async()=>{document.fonts&&await document.fonts.ready.then(()=>n(!0))})()},[]),e};var cn=typeof performance=="object"&&typeof performance.now=="function",ve=cn?function(){return performance.now()}:function(){return Date.now()};function ye(e){cancelAnimationFrame(e.id)}function dn(e,n){var r=ve();function a(){ve()-r>=n?e.call(null):s.id=requestAnimationFrame(a)}var s={id:requestAnimationFrame(a)};return s}var oe=-1;function he(e){if(e===void 0&&(e=!1),oe===-1||e){var n=document.createElement("div"),r=n.style;r.width="50px",r.height="50px",r.overflow="scroll",document.body.appendChild(n),oe=n.offsetWidth-n.clientWidth,document.body.removeChild(n)}return oe}var ee=null;function Se(e){if(e===void 0&&(e=!1),ee===null||e){var n=document.createElement("div"),r=n.style;r.width="50px",r.height="50px",r.overflow="scroll",r.direction="rtl";var a=document.createElement("div"),s=a.style;return s.width="100px",s.height="100px",n.appendChild(a),document.body.appendChild(n),n.scrollLeft>0?ee="positive-descending":(n.scrollLeft=1,n.scrollLeft===0?ee="negative":ee="positive-ascending"),document.body.removeChild(n),ee}return ee}var mn=150,pn=function(n,r){return n};function fn(e){var n,r=e.getItemOffset,a=e.getEstimatedTotalSize,s=e.getItemSize,g=e.getOffsetForIndexAndAlignment,S=e.getStartIndexForOffset,u=e.getStopIndexForStartIndex,c=e.initInstanceProps,d=e.shouldResetStyleCacheOnItemSizeChange,T=e.validateProps;return n=function(m){$e(b,m);function b(v){var t;return t=m.call(this,v)||this,t._instanceProps=c(t.props,ge(t)),t._outerRef=void 0,t._resetIsScrollingTimeoutId=null,t.state={instance:ge(t),isScrolling:!1,scrollDirection:"forward",scrollOffset:typeof t.props.initialScrollOffset=="number"?t.props.initialScrollOffset:0,scrollUpdateWasRequested:!1},t._callOnItemsRendered=void 0,t._callOnItemsRendered=le(function(i,l,p,y){return t.props.onItemsRendered({overscanStartIndex:i,overscanStopIndex:l,visibleStartIndex:p,visibleStopIndex:y})}),t._callOnScroll=void 0,t._callOnScroll=le(function(i,l,p){return t.props.onScroll({scrollDirection:i,scrollOffset:l,scrollUpdateWasRequested:p})}),t._getItemStyle=void 0,t._getItemStyle=function(i){var l=t.props,p=l.direction,y=l.itemSize,I=l.layout,f=t._getItemStyleCache(d&&y,d&&I,d&&p),h;if(f.hasOwnProperty(i))h=f[i];else{var w=r(t.props,i,t._instanceProps),N=s(t.props,i,t._instanceProps),x=p==="horizontal"||I==="horizontal",L=p==="rtl",R=x?w:0;f[i]=h={position:"absolute",left:L?void 0:R,right:L?R:void 0,top:x?0:w,height:x?"100%":N,width:x?N:"100%"}}return h},t._getItemStyleCache=void 0,t._getItemStyleCache=le(function(i,l,p){return{}}),t._onScrollHorizontal=function(i){var l=i.currentTarget,p=l.clientWidth,y=l.scrollLeft,I=l.scrollWidth;t.setState(function(f){if(f.scrollOffset===y)return null;var h=t.props.direction,w=y;if(h==="rtl")switch(Se()){case"negative":w=-y;break;case"positive-descending":w=I-p-y;break}return w=Math.max(0,Math.min(w,I-p)),{isScrolling:!0,scrollDirection:f.scrollOffset<w?"forward":"backward",scrollOffset:w,scrollUpdateWasRequested:!1}},t._resetIsScrollingDebounced)},t._onScrollVertical=function(i){var l=i.currentTarget,p=l.clientHeight,y=l.scrollHeight,I=l.scrollTop;t.setState(function(f){if(f.scrollOffset===I)return null;var h=Math.max(0,Math.min(I,y-p));return{isScrolling:!0,scrollDirection:f.scrollOffset<h?"forward":"backward",scrollOffset:h,scrollUpdateWasRequested:!1}},t._resetIsScrollingDebounced)},t._outerRefSetter=function(i){var l=t.props.outerRef;t._outerRef=i,typeof l=="function"?l(i):l!=null&&typeof l=="object"&&l.hasOwnProperty("current")&&(l.current=i)},t._resetIsScrollingDebounced=function(){t._resetIsScrollingTimeoutId!==null&&ye(t._resetIsScrollingTimeoutId),t._resetIsScrollingTimeoutId=dn(t._resetIsScrolling,mn)},t._resetIsScrolling=function(){t._resetIsScrollingTimeoutId=null,t.setState({isScrolling:!1},function(){t._getItemStyleCache(-1,null)})},t}b.getDerivedStateFromProps=function(t,i){return gn(t,i),T(t),null};var E=b.prototype;return E.scrollTo=function(t){t=Math.max(0,t),this.setState(function(i){return i.scrollOffset===t?null:{scrollDirection:i.scrollOffset<t?"forward":"backward",scrollOffset:t,scrollUpdateWasRequested:!0}},this._resetIsScrollingDebounced)},E.scrollToItem=function(t,i){i===void 0&&(i="auto");var l=this.props,p=l.itemCount,y=l.layout,I=this.state.scrollOffset;t=Math.max(0,Math.min(t,p-1));var f=0;if(this._outerRef){var h=this._outerRef;y==="vertical"?f=h.scrollWidth>h.clientWidth?he():0:f=h.scrollHeight>h.clientHeight?he():0}this.scrollTo(g(this.props,t,i,I,this._instanceProps,f))},E.componentDidMount=function(){var t=this.props,i=t.direction,l=t.initialScrollOffset,p=t.layout;if(typeof l=="number"&&this._outerRef!=null){var y=this._outerRef;i==="horizontal"||p==="horizontal"?y.scrollLeft=l:y.scrollTop=l}this._callPropsCallbacks()},E.componentDidUpdate=function(){var t=this.props,i=t.direction,l=t.layout,p=this.state,y=p.scrollOffset,I=p.scrollUpdateWasRequested;if(I&&this._outerRef!=null){var f=this._outerRef;if(i==="horizontal"||l==="horizontal")if(i==="rtl")switch(Se()){case"negative":f.scrollLeft=-y;break;case"positive-ascending":f.scrollLeft=y;break;default:var h=f.clientWidth,w=f.scrollWidth;f.scrollLeft=w-h-y;break}else f.scrollLeft=y;else f.scrollTop=y}this._callPropsCallbacks()},E.componentWillUnmount=function(){this._resetIsScrollingTimeoutId!==null&&ye(this._resetIsScrollingTimeoutId)},E.render=function(){var t=this.props,i=t.children,l=t.className,p=t.direction,y=t.height,I=t.innerRef,f=t.innerElementType,h=t.innerTagName,w=t.itemCount,N=t.itemData,x=t.itemKey,L=x===void 0?pn:x,R=t.layout,C=t.outerElementType,A=t.outerTagName,F=t.style,z=t.useIsScrolling,V=t.width,$=this.state.isScrolling,j=p==="horizontal"||R==="horizontal",D=j?this._onScrollHorizontal:this._onScrollVertical,Z=this._getRangeToRender(),te=Z[0],re=Z[1],X=[];if(w>0)for(var k=te;k<=re;k++)X.push(q.createElement(i,{data:N,key:L(k,N),index:k,isScrolling:z?$:void 0,style:this._getItemStyle(k)}));var J=a(this.props,this._instanceProps);return q.createElement(C||A||"div",{className:l,onScroll:D,ref:this._outerRefSetter,style:Ue({position:"relative",height:y,width:V,overflow:"auto",WebkitOverflowScrolling:"touch",willChange:"transform",direction:p},F)},q.createElement(f||h||"div",{children:X,ref:I,style:{height:j?"100%":J,pointerEvents:$?"none":void 0,width:j?J:"100%"}}))},E._callPropsCallbacks=function(){if(typeof this.props.onItemsRendered=="function"){var t=this.props.itemCount;if(t>0){var i=this._getRangeToRender(),l=i[0],p=i[1],y=i[2],I=i[3];this._callOnItemsRendered(l,p,y,I)}}if(typeof this.props.onScroll=="function"){var f=this.state,h=f.scrollDirection,w=f.scrollOffset,N=f.scrollUpdateWasRequested;this._callOnScroll(h,w,N)}},E._getRangeToRender=function(){var t=this.props,i=t.itemCount,l=t.overscanCount,p=this.state,y=p.isScrolling,I=p.scrollDirection,f=p.scrollOffset;if(i===0)return[0,0,0,0];var h=S(this.props,f,this._instanceProps),w=u(this.props,h,f,this._instanceProps),N=!y||I==="backward"?Math.max(1,l):1,x=!y||I==="forward"?Math.max(1,l):1;return[Math.max(0,h-N),Math.max(0,Math.min(i-1,w+x)),h,w]},b}(q.PureComponent),n.defaultProps={direction:"ltr",itemData:void 0,layout:"vertical",overscanCount:2,useIsScrolling:!1},n}var gn=function(n,r){n.children,n.direction,n.height,n.layout,n.innerTagName,n.outerTagName,n.width,r.instance},vn=fn({getItemOffset:function(n,r){var a=n.itemSize;return r*a},getItemSize:function(n,r){var a=n.itemSize;return a},getEstimatedTotalSize:function(n){var r=n.itemCount,a=n.itemSize;return a*r},getOffsetForIndexAndAlignment:function(n,r,a,s,g,S){var u=n.direction,c=n.height,d=n.itemCount,T=n.itemSize,m=n.layout,b=n.width,E=u==="horizontal"||m==="horizontal",v=E?b:c,t=Math.max(0,d*T-v),i=Math.min(t,r*T),l=Math.max(0,r*T-v+T+S);switch(a==="smart"&&(s>=l-v&&s<=i+v?a="auto":a="center"),a){case"start":return i;case"end":return l;case"center":{var p=Math.round(l+(i-l)/2);return p<Math.ceil(v/2)?0:p>t+Math.floor(v/2)?t:p}case"auto":default:return s>=l&&s<=i?s:s<l?l:i}},getStartIndexForOffset:function(n,r){var a=n.itemCount,s=n.itemSize;return Math.max(0,Math.min(a-1,Math.floor(r/s)))},getStopIndexForStartIndex:function(n,r,a){var s=n.direction,g=n.height,S=n.itemCount,u=n.itemSize,c=n.layout,d=n.width,T=s==="horizontal"||c==="horizontal",m=r*u,b=T?d:g,E=Math.ceil((b+a-m)/u);return Math.max(0,Math.min(S-1,r+E-1))},initInstanceProps:function(n){},shouldResetStyleCacheOnItemSizeChange:!0,validateProps:function(n){n.itemSize}});const yn="_layerContainer_1lbvo_1",hn="_layer_1lbvo_1",Sn="_small_1lbvo_23",Tn="_heading_1lbvo_26",bn="_option_1lbvo_27",_n="_message_1lbvo_28",In="_focused_1lbvo_64",En="_selected_1lbvo_68",wn="_disabled_1lbvo_71",On="_check_1lbvo_75",Ln="_optionContent_1lbvo_92",Rn="_label_1lbvo_97",qn="_icon_1lbvo_104",xn="_details_1lbvo_109",H={layerContainer:yn,layer:hn,small:Sn,heading:Tn,option:bn,message:_n,focused:In,selected:En,disabled:wn,check:On,optionContent:Ln,label:Rn,icon:qn,details:xn},Re=({label:e})=>o.jsx("div",{onClick:n=>n.stopPropagation(),className:H.heading,children:e});Re.__docgenInfo={description:"",methods:[],displayName:"Heading",props:{label:{required:!0,tsType:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},description:""}}};const qe=({details:e,label:n,icon:r,disabled:a=!1,selected:s=!1,focused:g=!1,onSelectOption:S,actions:u,closeLayer:c,testId:d})=>o.jsxs("div",{className:G(H.option,a?H.disabled:"",s?H.selected:"",g?H.focused:""),onClick:!a&&S?S:void 0,"data-testid":d,children:[o.jsx("div",{className:H.optionContent,children:o.jsxs("span",{className:H.label,title:n,children:[n,r&&o.jsx("span",{className:H.icon,children:r})]})}),e&&o.jsx("div",{className:G(H.details),children:o.jsx(ue,{faint:!0,children:e})}),!!(u!=null&&u.length)&&o.jsx("div",{className:G(H.actions),children:o.jsx(Ve,{actions:u,closeLayer:c})}),o.jsx("span",{className:H.check,children:s?o.jsx(ce,{icon:Ee.CHECK}):null})]});qe.__docgenInfo={description:"",methods:[],displayName:"Option",props:{details:{required:!1,tsType:{name:"string"},description:""},label:{required:!0,tsType:{name:"string"},description:""},icon:{required:!1,tsType:{name:"ReactNode"},description:""},disabled:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},selected:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},focused:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},onSelectOption:{required:!1,tsType:{name:"signature",type:"function",raw:`(
|
|
5
|
+
event?: React.MouseEvent<HTMLDivElement, MouseEvent>,
|
|
6
|
+
section?: ISelectSectionProps,
|
|
7
|
+
) => void`,signature:{arguments:[{type:{name:"ReactMouseEvent",raw:"React.MouseEvent<HTMLDivElement, MouseEvent>",elements:[{name:"HTMLDivElement"},{name:"MouseEvent"}]},name:"event"},{type:{name:"signature",type:"object",raw:`{
|
|
8
|
+
section: ISelectSection;
|
|
9
|
+
selected?: boolean;
|
|
10
|
+
focused?: boolean;
|
|
11
|
+
onSelectOption?: (
|
|
12
|
+
event?: React.MouseEvent<HTMLDivElement, MouseEvent>,
|
|
13
|
+
section?: ISelectSectionProps,
|
|
14
|
+
) => void;
|
|
15
|
+
closeLayer?: TEmpty;
|
|
16
|
+
}`,signature:{properties:[{key:"section",value:{name:"ISelectSection",required:!0}},{key:"selected",value:{name:"boolean",required:!1}},{key:"focused",value:{name:"boolean",required:!1}},{key:"onSelectOption",value:{name:"signature",type:"function",raw:`(
|
|
17
|
+
event?: React.MouseEvent<HTMLDivElement, MouseEvent>,
|
|
18
|
+
section?: ISelectSectionProps,
|
|
19
|
+
) => void`,signature:{arguments:[{type:{name:"ReactMouseEvent",raw:"React.MouseEvent<HTMLDivElement, MouseEvent>",elements:[{name:"HTMLDivElement"},{name:"MouseEvent"}]},name:"event"},{type:{name:"ISelectSectionProps"},name:"section"}],return:{name:"void"}},required:!1}},{key:"closeLayer",value:{name:"signature",type:"function",raw:"() => void",signature:{arguments:[],return:{name:"void"}},required:!1}}]}},name:"section"}],return:{name:"void"}}},description:""},actions:{required:!1,tsType:{name:"Array",elements:[{name:"any"}],raw:"any[]"},description:""},closeLayer:{required:!1,tsType:{name:"signature",type:"function",raw:"() => void",signature:{arguments:[],return:{name:"void"}}},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};const xe=({section:e,selected:n,focused:r,onSelectOption:a,closeLayer:s})=>{const g=q.useContext(me);switch(e.type){case se.HEADING:return o.jsx(Re,{label:e.label});case se.OPTION:default:return o.jsx(qe,{closeLayer:s,actions:e.actions,label:e.label,details:e.details,icon:e.icon,disabled:e.disabled||g,selected:n,focused:r,onSelectOption:a,testId:e.testId})}};xe.__docgenInfo={description:"",methods:[],displayName:"Section",props:{section:{required:!0,tsType:{name:"ISelectSection"},description:""},selected:{required:!1,tsType:{name:"boolean"},description:""},focused:{required:!1,tsType:{name:"boolean"},description:""},onSelectOption:{required:!1,tsType:{name:"signature",type:"function",raw:`(
|
|
20
|
+
event?: React.MouseEvent<HTMLDivElement, MouseEvent>,
|
|
21
|
+
section?: ISelectSectionProps,
|
|
22
|
+
) => void`,signature:{arguments:[{type:{name:"ReactMouseEvent",raw:"React.MouseEvent<HTMLDivElement, MouseEvent>",elements:[{name:"HTMLDivElement"},{name:"MouseEvent"}]},name:"event"},{type:{name:"signature",type:"object",raw:`{
|
|
23
|
+
section: ISelectSection;
|
|
24
|
+
selected?: boolean;
|
|
25
|
+
focused?: boolean;
|
|
26
|
+
onSelectOption?: (
|
|
27
|
+
event?: React.MouseEvent<HTMLDivElement, MouseEvent>,
|
|
28
|
+
section?: ISelectSectionProps,
|
|
29
|
+
) => void;
|
|
30
|
+
closeLayer?: TEmpty;
|
|
31
|
+
}`,signature:{properties:[{key:"section",value:{name:"ISelectSection",required:!0}},{key:"selected",value:{name:"boolean",required:!1}},{key:"focused",value:{name:"boolean",required:!1}},{key:"onSelectOption",value:{name:"signature",type:"function",raw:`(
|
|
32
|
+
event?: React.MouseEvent<HTMLDivElement, MouseEvent>,
|
|
33
|
+
section?: ISelectSectionProps,
|
|
34
|
+
) => void`,signature:{arguments:[{type:{name:"ReactMouseEvent",raw:"React.MouseEvent<HTMLDivElement, MouseEvent>",elements:[{name:"HTMLDivElement"},{name:"MouseEvent"}]},name:"event"},{type:{name:"ISelectSectionProps"},name:"section"}],return:{name:"void"}},required:!1}},{key:"closeLayer",value:{name:"signature",type:"function",raw:"() => void",signature:{arguments:[],return:{name:"void"}},required:!1}}]}},name:"section"}],return:{name:"void"}}},description:""},closeLayer:{required:!1,tsType:{name:"signature",type:"function",raw:"() => void",signature:{arguments:[],return:{name:"void"}}},description:""}}};const de=(e,n)=>{const a=document.createElement("canvas").getContext("2d");return a?(a.font=n,a.measureText(e).width):0},Ce="13px",Me="12px",Cn="Roobert",Mn="sans-serif",Nn=12,An=8,Fn=30,Hn=24,jn=5,Dn=3,kn=1,Pn=2,Te=10,Ne=(e=!1,n=!1)=>`${e?Me:Ce} ${n?Cn:Mn}`,Wn=(e=!1,n=!1)=>(e?An:Nn)+(e?Hn:Fn)+(n?17:0),be=(e,n,r,a)=>{const s=Ne(n,r),g=a?de(a,s):0,S=Math.ceil(e.reduce((c,d)=>{var v;const T=(((v=d==null?void 0:d.actions)==null?void 0:v.length)??0)*24,m=d.icon?parseInt(n?Me:Ce)+7:0,b=`${d.label} ${d.details||""}`,E=de(b,s)+T+m;return c=E>c?E:c,c},g)),u=Wn(n,!0);return S+u},zn=(e,n,r)=>{const a=Ne(!0,r),s=de(e.label,a),g=(n?Dn:jn)*2+kn*2+Pn;return Math.ceil(s+g)},Ae=({listRef:e,isMulti:n,sections:r,selectedOptions:a,onSelectOption:s,focusedOptionIndex:g,width:S,small:u,firstSelectedOptionIndex:c,closeLayer:d,testId:T})=>{q.useEffect(()=>{c&&c!==null&&e.current!==null&&e.current.scrollToItem(c,"start")},[c,e]);const m=u?24:30;return o.jsx("div",{"data-testid":T,className:G(H.layer,u&&H.small),children:r.length?o.jsx(vn,{ref:e,height:r.length<Te?m*r.length:m*Te,itemCount:r.length,itemSize:m,width:S,children:({index:b,style:E})=>{var v;return o.jsx("div",{style:E,children:o.jsx(xe,{closeLayer:d,section:r[b],selected:n&&r[b].type!==se.HEADING&&Array.isArray(a)?a.some(t=>{var i;return t&&(t==null?void 0:t.value)===((i=r==null?void 0:r[b])==null?void 0:i.value)}):!Array.isArray(a)&&((v=r==null?void 0:r[b])==null?void 0:v.value)===(a==null?void 0:a.value),focused:g===b,onSelectOption:t=>s(t,r[b])})})}}):o.jsx("ul",{children:o.jsx("li",{children:o.jsx("div",{className:H.message,style:{width:S},children:"No matches"})})})})};Ae.__docgenInfo={description:"",methods:[],displayName:"Layer",props:{listRef:{required:!0,tsType:{name:"RefObject",elements:[{name:"any"}],raw:"RefObject<any>"},description:""},isMulti:{required:!1,tsType:{name:"boolean"},description:""},sections:{required:!0,tsType:{name:"Array",elements:[{name:"ISelectSection"}],raw:"ISelectSection[]"},description:""},selectedOptions:{required:!0,tsType:{name:"union",raw:"ISelectSelectedOption | ISelectSelectedOption[]",elements:[{name:"ISelectSelectedOption"},{name:"Array",elements:[{name:"ISelectSelectedOption"}],raw:"ISelectSelectedOption[]"}]},description:""},onSelectOption:{required:!0,tsType:{name:"signature",type:"function",raw:`(
|
|
35
|
+
event?: React.MouseEvent<HTMLDivElement, MouseEvent>,
|
|
36
|
+
section?: ISelectSection,
|
|
37
|
+
) => void`,signature:{arguments:[{type:{name:"ReactMouseEvent",raw:"React.MouseEvent<HTMLDivElement, MouseEvent>",elements:[{name:"HTMLDivElement"},{name:"MouseEvent"}]},name:"event"},{type:{name:"ISelectSection"},name:"section"}],return:{name:"void"}}},description:""},focusedOptionIndex:{required:!1,tsType:{name:"number"},description:""},width:{required:!0,tsType:{name:"number"},description:""},small:{required:!1,tsType:{name:"boolean"},description:""},firstSelectedOptionIndex:{required:!1,tsType:{name:"number"},description:""},closeLayer:{required:!0,tsType:{name:"signature",type:"function",raw:"() => void",signature:{arguments:[],return:{name:"void"}}},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};const Gn="_inputInTable_7uwhv_1",$n="_inputHover_7uwhv_13",Un="_inputFocus_7uwhv_18",Vn="_inputError_7uwhv_25",Yn="_inputWarning_7uwhv_26",Kn="_inputDisabled_7uwhv_61",Bn="_hideScrollbars_7uwhv_67",Zn="_trigger_7uwhv_77",Xn="_isInTable_7uwhv_93",Jn="_input_7uwhv_1",Qn="_isOpen_7uwhv_114",et="_disabled_7uwhv_156",nt="_icons_7uwhv_162",tt="_clearAll_7uwhv_169",rt="_iconOpen_7uwhv_170",at="_small_7uwhv_181",it="_triggerInputContainer_7uwhv_189",st="_right_7uwhv_198",lt="_multiOptions_7uwhv_211",ot="_multiOption_7uwhv_211",ut="_label_7uwhv_239",ct="_closeMultiOption_7uwhv_242",dt="_focus_7uwhv_253",mt="_selectedSingleValue_7uwhv_257",pt="_placeHolder_7uwhv_258",ft="_groupOrderFirst_7uwhv_297",gt="_groupOrderMiddle_7uwhv_298",vt="_groupOrderLast_7uwhv_302",yt="_detailedLabel_7uwhv_307",M={inputInTable:Gn,inputHover:$n,inputFocus:Un,inputError:Vn,inputWarning:Yn,inputDisabled:Kn,hideScrollbars:Bn,trigger:Zn,isInTable:Xn,input:Jn,isOpen:Qn,disabled:et,icons:nt,clearAll:tt,iconOpen:rt,small:at,triggerInputContainer:it,right:st,multiOptions:lt,multiOption:ot,label:ut,closeMultiOption:ct,focus:dt,selectedSingleValue:mt,placeHolder:pt,groupOrderFirst:ft,groupOrderMiddle:gt,groupOrderLast:vt,detailedLabel:yt},Fe=({selectedOptions:e,small:n,width:r,testId:a})=>{const s=Le(),[g,S]=q.useState([]),[u,c]=q.useState([]);return q.useEffect(()=>{let d=[],T=[],m=0;e.forEach((b,E)=>{m+=zn(b,n,s),E===e.length-1&&m<r||m<r-24?d.push(b):T.push(b)}),S(d),c(T)},[e,s,r]),o.jsxs("div",{className:M.multiOptions,"data-testid":a&&`${a}-value`,children:[g.filter(d=>d&&d.label).map((d,T)=>o.jsx("span",{className:M.multiOption,onClick:m=>{m.stopPropagation()},children:d.label},T)),u.length>0&&o.jsx(pe,{text:u.map((d,T)=>o.jsx("div",{children:d.label},T)),display:"inline-flex",children:o.jsx("span",{className:M.multiOption,children:g.length?`+${u.length}`:`${u.length} items`})})]})};Fe.__docgenInfo={description:"",methods:[],displayName:"MultiSelectedOptions",props:{selectedOptions:{required:!0,tsType:{name:"Array",elements:[{name:"ISelectSelectedOption"}],raw:"ISelectSelectedOption[]"},description:""},small:{required:!1,tsType:{name:"boolean"},description:""},width:{required:!0,tsType:{name:"number"},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};const He=({selectedOptions:e,searchable:n=!1,searchValue:r,onChange:a=ae.noop,inputRef:s,error:g,placeholder:S="Select...",small:u,testId:c})=>{const d=q.useRef(null),T=Array.isArray(e),m=T?e.length>0:!!e,b=r?r.length+1:1,E=()=>{var i,l;const v=((i=d.current)==null?void 0:i.offsetWidth)||0,t=((l=s.current)==null?void 0:l.offsetWidth)||0;return v-t};return o.jsxs("div",{className:M.triggerInputContainer,ref:d,children:[m?T?o.jsx(Fe,{selectedOptions:e,small:u,width:E(),testId:c}):o.jsx("span",{className:M.selectedSingleValue,"data-testid":c&&`${c}-value`,children:r!=null&&r.length?"":e==null?void 0:e.label}):o.jsx("span",{className:M.placeHolder,children:r!=null&&r.length?"":S}),n?o.jsx("input",{tabIndex:-1,ref:s,size:b,className:M.input,value:r,onChange:v=>a(v.target.value),"data-error":g||null,"data-testid":c&&`${c}-input`}):null]})};He.__docgenInfo={description:"",methods:[],displayName:"Input",props:{selectedOptions:{required:!1,tsType:{name:"union",raw:"ISelectSelectedOption | ISelectSelectedOption[]",elements:[{name:"ISelectSelectedOption"},{name:"Array",elements:[{name:"ISelectSelectedOption"}],raw:"ISelectSelectedOption[]"}]},description:""},searchable:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},searchValue:{required:!1,tsType:{name:"string"},description:""},inputRef:{required:!0,tsType:{name:"MutableRefObject",elements:[{name:"union",raw:"HTMLInputElement | null",elements:[{name:"HTMLInputElement"},{name:"null"}]}],raw:"MutableRefObject<HTMLInputElement | null>"},description:""},onChange:{required:!1,tsType:{name:"signature",type:"function",raw:"(value: string) => void",signature:{arguments:[{type:{name:"string"},name:"value"}],return:{name:"void"}}},description:"",defaultValue:{value:"noop",computed:!0}},error:{required:!1,tsType:{name:"union",raw:"string | ReactNode",elements:[{name:"string"},{name:"ReactNode"}]},description:""},placeholder:{required:!1,tsType:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}]},description:"",defaultValue:{value:"'Select...'",computed:!1}},small:{required:!1,tsType:{name:"boolean"},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};const je=({selectedOptions:e,searchValue:n,searchable:r,clearable:a,onClickTrigger:s,element:g,error:S,warning:u,tooltip:c,small:d,isInTable:T,disabled:m,onChangeSearch:b,onClickDeselect:E,onClickClear:v,tabIndex:t,isOpen:i,triggerRef:l,clearAllIsFocused:p,focusedSelectedOptionIndex:y,onFocus:I,onBlur:f,groupOrder:h,maxTooltipWidth:w,placeholder:N,right:x,testId:L})=>{var j;const[R,C]=Oe(),A=Array.isArray(e)?e.length>0&&((j=e[0])==null?void 0:j.value):e==null?void 0:e.value,F=a&&A,z=(()=>{if(h)switch(h){case ie.FIRST:return M.groupOrderFirst;case ie.LAST:return M.groupOrderLast;default:return M.groupOrderMiddle}return""})(),V=!Array.isArray(e)&&(e!=null&&e.details)?{...e,label:o.jsxs("div",{className:G(M.detailedLabel),children:[o.jsx(ue,{children:e.label}),o.jsx(ue,{muted:!0,children:e.details})]})}:e,$=o.jsxs(o.Fragment,{children:[g,o.jsxs("div",{ref:l,tabIndex:t,className:G(M.trigger,i?M.isOpen:"",m?M.disabled:"",d?M.small:"",T?M.isInTable:"",x?M.right:"",z),onClick:D=>{D.stopPropagation(),typeof C=="function"&&C(),s(D)},onFocus:I,onBlur:f,"data-error":S||null,"data-warning":u||null,"data-testid":L,children:[o.jsx(He,{selectedOptions:V,placeholder:N,searchable:r,searchValue:n,inputRef:R,onChange:b,error:S,small:d,testId:L}),o.jsx("span",{className:M.icons,children:F?o.jsx("span",{className:G(M.clearAll,p?M.focus:""),onClick:D=>{D.stopPropagation(),v&&v(D)},"data-testid":L&&`${L}-clear`,children:o.jsx(ce,{icon:Ee.CLOSE})}):o.jsx("span",{className:G(M.iconOpen),children:o.jsx(ce,{icon:"chevron down"})})})]})]});return o.jsx(o.Fragment,{children:o.jsx(pe,{error:!!S,warning:!!u,text:c||S||u,enabled:c&&ne(c)||S&&ne(S)||u&&ne(u)||!1,maxWidth:w,placement:"bottom-center",children:$})})};je.__docgenInfo={description:"",methods:[],displayName:"Trigger",props:{selectedOptions:{required:!1,tsType:{name:"union",raw:"ISelectSelectedOption | ISelectSelectedOption[]",elements:[{name:"ISelectSelectedOption"},{name:"Array",elements:[{name:"ISelectSelectedOption"}],raw:"ISelectSelectedOption[]"}]},description:""},searchValue:{required:!1,tsType:{name:"string"},description:""},searchable:{required:!1,tsType:{name:"boolean"},description:""},clearable:{required:!1,tsType:{name:"boolean"},description:""},onClickTrigger:{required:!0,tsType:{name:"signature",type:"function",raw:"(evt: React.MouseEvent<HTMLDivElement, MouseEvent>) => void",signature:{arguments:[{type:{name:"ReactMouseEvent",raw:"React.MouseEvent<HTMLDivElement, MouseEvent>",elements:[{name:"HTMLDivElement"},{name:"MouseEvent"}]},name:"evt"}],return:{name:"void"}}},description:""},element:{required:!1,tsType:{name:"ReactNode"},description:""},error:{required:!1,tsType:{name:"union",raw:"string | ReactNode",elements:[{name:"string"},{name:"ReactNode"}]},description:""},warning:{required:!1,tsType:{name:"union",raw:"string | ReactNode",elements:[{name:"string"},{name:"ReactNode"}]},description:""},tooltip:{required:!1,tsType:{name:"union",raw:"string | ReactNode",elements:[{name:"string"},{name:"ReactNode"}]},description:""},small:{required:!1,tsType:{name:"boolean"},description:""},isInTable:{required:!1,tsType:{name:"boolean"},description:""},disabled:{required:!1,tsType:{name:"boolean"},description:""},onChangeSearch:{required:!1,tsType:{name:"signature",type:"function",raw:"(value: string) => void",signature:{arguments:[{type:{name:"string"},name:"value"}],return:{name:"void"}}},description:""},onClickDeselect:{required:!1,tsType:{name:"signature",type:"function",raw:"(evt: React.MouseEvent<HTMLDivElement, MouseEvent>) => void",signature:{arguments:[{type:{name:"ReactMouseEvent",raw:"React.MouseEvent<HTMLDivElement, MouseEvent>",elements:[{name:"HTMLDivElement"},{name:"MouseEvent"}]},name:"evt"}],return:{name:"void"}}},description:""},onClickClear:{required:!1,tsType:{name:"signature",type:"function",raw:"(evt: React.MouseEvent<HTMLSpanElement, MouseEvent>) => void",signature:{arguments:[{type:{name:"ReactMouseEvent",raw:"React.MouseEvent<HTMLSpanElement, MouseEvent>",elements:[{name:"HTMLSpanElement"},{name:"MouseEvent"}]},name:"evt"}],return:{name:"void"}}},description:""},tabIndex:{required:!1,tsType:{name:"number"},description:""},isOpen:{required:!1,tsType:{name:"boolean"},description:""},triggerRef:{required:!1,tsType:{name:"RefObject",elements:[{name:"HTMLDivElement"}],raw:"RefObject<HTMLDivElement>"},description:""},clearAllIsFocused:{required:!1,tsType:{name:"boolean"},description:""},focusedSelectedOptionIndex:{required:!1,tsType:{name:"number"},description:""},onFocus:{required:!1,tsType:{name:"signature",type:"function",raw:"(evt: React.FocusEvent<HTMLDivElement>) => void",signature:{arguments:[{type:{name:"ReactFocusEvent",raw:"React.FocusEvent<HTMLDivElement>",elements:[{name:"HTMLDivElement"}]},name:"evt"}],return:{name:"void"}}},description:""},onBlur:{required:!1,tsType:{name:"signature",type:"function",raw:"(evt: React.FocusEvent<HTMLDivElement>) => void",signature:{arguments:[{type:{name:"ReactFocusEvent",raw:"React.FocusEvent<HTMLDivElement>",elements:[{name:"HTMLDivElement"}]},name:"evt"}],return:{name:"void"}}},description:""},groupOrder:{required:!1,tsType:{name:"union",raw:"TGroupOrder | string",elements:[{name:"union",raw:"'first' | 'middle' | 'last'",elements:[{name:"literal",value:"'first'"},{name:"literal",value:"'middle'"},{name:"literal",value:"'last'"}]},{name:"string"}]},description:""},maxTooltipWidth:{required:!1,tsType:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},description:""},placeholder:{required:!1,tsType:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}]},description:""},right:{required:!1,tsType:{name:"boolean"},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};var W=(e=>(e.SET_VISIBLE_OPTIONS="SET_VISIBLE_OPTIONS",e.RESET_LAYER_FOCUS="RESET_LAYER_FOCUS",e.CLEAR_SEARCH="CLEAR_SEARCH",e.ON_CHANGE_SEARCH="ON_CHANGE_SEARCH",e.FOCUS_TRIGGER_INPUTS="FOCUS_TRIGGER_INPUTS",e.BLUR_TRIGGER_INPUTS="BLUR_TRIGGER_INPUTS",e.FOCUS_LAYER_OPTIONS="FOCUS_LAYER_OPTIONS",e.OPEN_LAYER="OPEN_LAYER",e.CLOSE_LAYER="CLOSE_LAYER",e))(W||{});const De={options:["none","clearAll"],currentIndex:0,currentOption:!1,clearAll:!1},ht=e=>e!==null?e+1:0,ke=(e,n)=>{const r=["none",...e.map((s,g)=>s.type!==se.HEADING?g:null).filter(s=>s!==null)],a=ht(n);return{options:r,currentIndex:a,current:r[a]}},St=(e,n)=>{const r=e==="up"?-1:1,a=n.currentIndex+r,s=(a<0?n.options.length-1:a)%n.options.length,g=n.options[s];return{...n,currentIndex:s,current:g}},Tt=(e,n,r)=>{const a=e==="left"?-1:1,s=n&&n.length?["none",...Array.from({length:n.length},(d,T)=>T),"clearAll"]:["none","clearAll"],g=r.currentIndex+a,S=(g<0?s.length-1:g)%s.length,u=s[S];return{options:s,currentIndex:S,currentOption:u,clearAll:u==="clearAll"}},_e=()=>De,Ie=e=>({...e,currentIndex:0,current:"none"}),bt=(e,n)=>{switch(n.type){case W.SET_VISIBLE_OPTIONS:return{...e,visibleOptions:n.options||[]};case W.RESET_LAYER_FOCUS:return{...e,layerFocus:ke(n.options||[],n.firstSelectedOptionIndex||0)};case W.CLEAR_SEARCH:return{...e,visibleOptions:n.options||[],searchValue:""};case W.ON_CHANGE_SEARCH:{let a=[...(n.options||[]).filter(s=>(String(s.label)+(s.details?String(s.details):"")).toLowerCase().includes(String(n.value||"").toLowerCase()))];return n.createAble&&n.value&&n.value!==""&&a.push({label:`Create "${n.value}"`,value:n.value,createAble:!0}),{...e,searchValue:n.value,visibleOptions:a,layerFocus:Ie(e.layerFocus)}}case W.FOCUS_TRIGGER_INPUTS:return{...e,triggerFocus:Tt(n.direction||"right",n.selectedOptions||[],e.triggerFocus),layerFocus:Ie(e.layerFocus)};case W.BLUR_TRIGGER_INPUTS:return{...e,triggerFocus:_e()};case W.FOCUS_LAYER_OPTIONS:return n.nextLayerFocus?{...e,layerFocus:n.nextLayerFocus,triggerFocus:_e()}:e;case W.OPEN_LAYER:return{...e,isLayerOpen:!0};case W.CLOSE_LAYER:return{...e,isLayerOpen:!1};default:return e}},_t={auto:!0,possiblePlacements:["bottom-start","top-start"],placement:"bottom-start",preferX:"right",preferY:"bottom"},It=({state:e,dispatch:n,options:r,setTriggerFocus:a,disabled:s,disabledContext:g,onCreate:S,onChange:u,selectedOptions:c,width:d,small:T,isFontLoaded:m,placeholder:b,firstSelectedOptionIndex:E,createAble:v,listRef:t,autoLayerWidth:i})=>{const l=()=>{e.isLayerOpen&&n({type:P.CLOSE_LAYER}),a()},p=()=>n({type:P.OPEN_LAYER}),y=q.useRef(!0);q.useEffect(()=>{y.current?y.current=!1:n({type:P.SET_VISIBLE_OPTIONS,options:r})},[r]);const I=(_,O,Q)=>{if(!(s||g)){if(Q&&Q(),O){if(O.createAble&&S)S(O.value);else if(!O.disabled)if(Array.isArray(c))if(c.some(K=>K.label===O.label)){const K=c.filter(fe=>fe.label!==O.label);u&&u(_,K)}else{const K=[...c,O];u&&u(_,K)}else u&&u(_,O)}n({type:P.CLEAR_SEARCH,options:r}),a()}},f=q.useCallback(()=>d?d!=="auto"?d:be(r,T,m,b):"100%",[r,m]),h=q.useCallback(_=>i?Math.max(be(r,T,m,b),_==null?void 0:_.width):_==null?void 0:_.width,[r,m]),{renderLayer:w,layerProps:N,triggerProps:x,triggerBounds:L}=We({isOpen:(e==null?void 0:e.isLayerOpen)??!1,overflowContainer:!0,..._t,ResizeObserver,onOutsideClick:l,onParentClose:l}),R=()=>{if(!(s||g)){if(e.isLayerOpen){l();return}n({type:P.RESET_LAYER_FOCUS,options:r,firstSelectedOptionIndex:E}),p()}},C=q.useRef(!0);q.useEffect(()=>{C.current?C.current=!1:e.isLayerOpen||n({type:P.CLEAR_SEARCH,options:r})},[e.isLayerOpen]);const A=(_,O)=>{const Q=c instanceof Array?c.filter(Y=>Y.value!==O.value):null;u&&u(_,Q)},F=_=>{const O=c instanceof Array?[]:{value:null};u&&u(_,O)},z=_=>n({type:P.ON_CHANGE_SEARCH,options:r,value:_,createAble:v}),V=()=>{p(),n({type:P.BLUR_TRIGGER_INPUTS})},$=_=>{t.current&&Number.isInteger(_)&&t.current.scrollToItem(_)},j=_=>{const O=St(_,e.layerFocus);n({type:P.FOCUS_LAYER_OPTIONS,nextLayerFocus:O}),$(O.current)},D=_=>{n({type:P.FOCUS_TRIGGER_INPUTS,ICustomSelectDirection:_,selectedOptions:c})},Z=_=>F(_),te=c&&c[e.triggerFocus.currentOption],re=_=>{A(_,c[e.triggerFocus.currentOption])},X=_=>{var O;I(_,(O=e==null?void 0:e.visibleOptions)==null?void 0:O[e.layerFocus.current],l)},k=e.triggerFocus.clearAll;return{getTriggerWidth:f,onKeyEvent:(_,O)=>{switch(_){case B.UP:{j(_);break}case B.DOWN:{e.isLayerOpen?j(_):V();break}case B.LEFT:case B.RIGHT:{D(_);break}case B.ENTER:{k?Z(O):te?re(O):X(O);break}case B.ESC:{l();break}}},clearAllIsFocused:k,triggerProps:x,onClickTrigger:R,onChangeSearch:z,onClickDeselectOption:A,onClickClearAll:F,renderLayer:w,layerProps:N,closeLayer:l,onSelectOption:I,getLayerWidth:h,triggerBounds:L}},Pe=e=>{const{multi:n=!1,disabled:r=!1,error:a=null,warning:s=null,tooltip:g=null,options:S,selectedOptions:u,onCreate:c=null,placeholder:d="",small:T=!1,tabIndex:m=0,onFocus:b=()=>{},onBlur:E=()=>{},searchable:v=!0,clearable:t=!1,maxTooltipWidth:i,closeOnOptionActionClick:l,isInTable:p=!1,groupOrder:y,firstSelectedOptionIndex:I=0,right:f=!1,testId:h=void 0}=e,w=q.useContext(me),N=c!==null,x=q.useRef(null),[L,R]=Oe(),C=Le(),[A,F]=q.useReducer(bt,{options:S,firstSelectedOptionIndex:I},({options:Y})=>({searchValue:"",visibleOptions:Y,layerFocus:ke(Y,I??0),triggerFocus:De,isLayerOpen:!1})),{getTriggerWidth:z,onKeyEvent:V,clearAllIsFocused:$,triggerProps:j,onClickTrigger:D,onChangeSearch:Z,onClickDeselectOption:te,onClickClearAll:re,renderLayer:X,layerProps:k,closeLayer:J,onSelectOption:_,getLayerWidth:O,triggerBounds:Q}=It({...e,state:A,dispatch:F,setTriggerFocus:R,disabledContext:w,isFontLoaded:C,createAble:N,listRef:x});return o.jsx("div",{style:{width:z()},children:o.jsxs(Ge,{handleKeys:Object.values(B),onKeyEvent:V,children:[o.jsx(je,{selectedOptions:u,searchValue:A.searchValue,isOpen:A.isLayerOpen,focusedSelectedOptionIndex:A.triggerFocus.currentOption,clearAllIsFocused:$,searchable:v,triggerRef:ze(L,j.ref),error:a,warning:s,tooltip:g,small:T,isInTable:p,disabled:r||w,clearable:t,tabIndex:m,onClickTrigger:D,onChangeSearch:Z,onClickDeselect:te,onClickClear:re,onFocus:b,onBlur:E,groupOrder:y,maxTooltipWidth:i,placeholder:d,right:f,testId:h}),A.isLayerOpen&&X(o.jsx("div",{...k,className:H.layerContainer,children:o.jsx(Ae,{listRef:x,isMulti:n,sections:A.visibleOptions,selectedOptions:u,onSelectOption:(Y,K)=>{_(Y,K,n?void 0:J)},closeLayer:()=>{l&&J()},width:O(Q),small:T,focusedOptionIndex:A.layerFocus.current,firstSelectedOptionIndex:I??0,testId:h&&`${h}-layer`})}))]})})};Pe.__docgenInfo={description:"",methods:[],displayName:"CustomSelect",props:{multi:{required:!1,tsType:{name:"boolean"},description:""},disabled:{required:!1,tsType:{name:"boolean"},description:""},error:{required:!1,tsType:{name:"union",raw:"TStringOrNumber | ReactNode",elements:[{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},{name:"ReactNode"}]},description:""},warning:{required:!1,tsType:{name:"union",raw:"TStringOrNumber | ReactNode",elements:[{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},{name:"ReactNode"}]},description:""},tooltip:{required:!1,tsType:{name:"union",raw:"TStringOrNumber | ReactNode",elements:[{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},{name:"ReactNode"}]},description:""},options:{required:!0,tsType:{name:"Array",elements:[{name:"union",raw:"ISelectSelectedOption | Heading",elements:[{name:"ISelectSelectedOption"},{name:"Heading"}]}],raw:"TCustomSelectSelectOption[]"},description:""},selectedOptions:{required:!0,tsType:{name:"union",raw:"ISelectSelectedOption | ISelectSelectedOption[]",elements:[{name:"ISelectSelectedOption"},{name:"Array",elements:[{name:"ISelectSelectedOption"}],raw:"ISelectSelectedOption[]"}]},description:""},onChange:{required:!1,tsType:{name:"signature",type:"function",raw:`(
|
|
38
|
+
event: TChangeEvent<T>,
|
|
39
|
+
...additionalProps: { [key: string]: any }[]
|
|
40
|
+
) => void`,signature:{arguments:[{type:{name:"intersection",raw:`ChangeEvent<T> & {
|
|
41
|
+
target:
|
|
42
|
+
| T
|
|
43
|
+
| { name: string; value: any; label?: string; files?: FileList | null };
|
|
44
|
+
}`,elements:[{name:"ChangeEvent",elements:[{name:"T"}],raw:"ChangeEvent<T>"},{name:"signature",type:"object",raw:`{
|
|
45
|
+
target:
|
|
46
|
+
| T
|
|
47
|
+
| { name: string; value: any; label?: string; files?: FileList | null };
|
|
48
|
+
}`,signature:{properties:[{key:"target",value:{name:"union",raw:`| T
|
|
49
|
+
| { name: string; value: any; label?: string; files?: FileList | null }`,elements:[{name:"T"},{name:"signature",type:"object",raw:"{ name: string; value: any; label?: string; files?: FileList | null }",signature:{properties:[{key:"name",value:{name:"string",required:!0}},{key:"value",value:{name:"any",required:!0}},{key:"label",value:{name:"string",required:!1}},{key:"files",value:{name:"union",raw:"FileList | null",elements:[{name:"FileList"},{name:"null"}],required:!1}}]}}],required:!0}}]}}]},name:"event"},{type:{name:"Array",elements:[{name:"signature",type:"object",raw:"{ [key: string]: any }",signature:{properties:[{key:{name:"string"},value:{name:"any",required:!0}}]}}],raw:"{ [key: string]: any }[]"},name:"additionalProps",rest:!0}],return:{name:"void"}}},description:""},onCreate:{required:!1,tsType:{name:"signature",type:"function",raw:"(value: string) => void",signature:{arguments:[{type:{name:"string"},name:"value"}],return:{name:"void"}}},description:""},placeholder:{required:!1,tsType:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}]},description:""},small:{required:!1,tsType:{name:"boolean"},description:""},tabIndex:{required:!1,tsType:{name:"number"},description:""},width:{required:!1,tsType:{name:"union",raw:"TStringOrNumber | null",elements:[{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},{name:"null"}]},description:""},autoLayerWidth:{required:!1,tsType:{name:"boolean"},description:""},onFocus:{required:!1,tsType:{name:"signature",type:"function",raw:"() => void",signature:{arguments:[],return:{name:"void"}}},description:""},onBlur:{required:!1,tsType:{name:"signature",type:"function",raw:"() => void",signature:{arguments:[],return:{name:"void"}}},description:""},searchable:{required:!1,tsType:{name:"boolean"},description:""},clearable:{required:!1,tsType:{name:"boolean"},description:""},isInTable:{required:!1,tsType:{name:"boolean"},description:""},groupOrder:{required:!1,tsType:{name:"union",raw:"TGroupOrder | string",elements:[{name:"union",raw:"'first' | 'middle' | 'last'",elements:[{name:"literal",value:"'first'"},{name:"literal",value:"'middle'"},{name:"literal",value:"'last'"}]},{name:"string"}]},description:""},firstSelectedOptionIndex:{required:!0,tsType:{name:"union",raw:"number | null",elements:[{name:"number"},{name:"null"}]},description:""},right:{required:!1,tsType:{name:"boolean"},description:""},maxTooltipWidth:{required:!1,tsType:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},description:""},closeOnOptionActionClick:{required:!1,tsType:{name:"boolean"},description:""},testId:{required:!1,tsType:{name:"union",raw:"string | undefined",elements:[{name:"string"},{name:"undefined"}]},description:""}}};const Et=e=>{const{name:n="",options:r=[],value:a,native:s=!1,onChange:g=ae.noop,deprecatedEventHandler:S=!1,autoScroll:u=!0,warning:c,error:d,checkNonExistentValues:T=!0,closeOnOptionActionClick:m=!0,testId:b,disabled:E}=e,v=!s&&u===!0,{multi:t,simpleInputs:i,options:l,selectedOptions:p,firstSelectedOptionIndex:y,hasNonExistentValue:I}=Ye(r,a,v,T),f=!t,h=s&&f;s&&!f&&console.warn("Native select does not support provided props (see stories)");const w="Value no longer available for re-selection",N=I&&!E?c?o.jsxs("div",{children:[o.jsx("div",{children:w}),o.jsx("div",{children:c})]}):w:c,x=I&&d&&!E?o.jsxs("div",{children:[o.jsx("div",{children:w}),o.jsx("div",{children:d})]}):d,L=(R,C)=>{if(S){const A=t?C.map(F=>i?F.value:F):i?C.value:C;A&&g(A)}else{const A=!(R instanceof Event),F=t?C:C.value;if(A)R.target.name=n,R.target.value=F,t||(R.target.label=C.label),g(R);else{const z={...R,target:{...R.target,name:n,value:F,label:t?void 0:C.label}};g(z)}}};return h?o.jsx(we,{...e,options:l,selectedOption:p,onChange:L,hasNonExistentValue:I,warning:N,error:x,testId:b}):o.jsx(Pe,{...e,options:l,selectedOptions:p,onChange:L,multi:t,firstSelectedOptionIndex:y,warning:N,error:x,testId:b,closeOnOptionActionClick:m})};Et.__docgenInfo={description:"",methods:[],displayName:"Select",props:{name:{required:!1,tsType:{name:"string"},description:""},multi:{required:!1,tsType:{name:"boolean"},description:""},options:{required:!1,tsType:{name:"Array",elements:[{name:"ISelectSelectedOption"}],raw:"ISelectSelectedOption[]"},description:""},value:{required:!1,tsType:{name:"any"},description:""},native:{required:!1,tsType:{name:"boolean"},description:""},onChange:{required:!1,tsType:{name:"signature",type:"function",raw:`(
|
|
50
|
+
event: TChangeEvent<T>,
|
|
51
|
+
...additionalProps: { [key: string]: any }[]
|
|
52
|
+
) => void`,signature:{arguments:[{type:{name:"intersection",raw:`ChangeEvent<T> & {
|
|
53
|
+
target:
|
|
54
|
+
| T
|
|
55
|
+
| { name: string; value: any; label?: string; files?: FileList | null };
|
|
56
|
+
}`,elements:[{name:"ChangeEvent",elements:[{name:"T"}],raw:"ChangeEvent<T>"},{name:"signature",type:"object",raw:`{
|
|
57
|
+
target:
|
|
58
|
+
| T
|
|
59
|
+
| { name: string; value: any; label?: string; files?: FileList | null };
|
|
60
|
+
}`,signature:{properties:[{key:"target",value:{name:"union",raw:`| T
|
|
61
|
+
| { name: string; value: any; label?: string; files?: FileList | null }`,elements:[{name:"T"},{name:"signature",type:"object",raw:"{ name: string; value: any; label?: string; files?: FileList | null }",signature:{properties:[{key:"name",value:{name:"string",required:!0}},{key:"value",value:{name:"any",required:!0}},{key:"label",value:{name:"string",required:!1}},{key:"files",value:{name:"union",raw:"FileList | null",elements:[{name:"FileList"},{name:"null"}],required:!1}}]}}],required:!0}}]}}]},name:"event"},{type:{name:"Array",elements:[{name:"signature",type:"object",raw:"{ [key: string]: any }",signature:{properties:[{key:{name:"string"},value:{name:"any",required:!0}}]}}],raw:"{ [key: string]: any }[]"},name:"additionalProps",rest:!0}],return:{name:"void"}}},description:""},deprecatedEventHandler:{required:!1,tsType:{name:"boolean"},description:""},autoScroll:{required:!1,tsType:{name:"boolean"},description:""},warning:{required:!1,tsType:{name:"union",raw:"TStringOrNumber | ReactNode",elements:[{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},{name:"ReactNode"}]},description:""},error:{required:!1,tsType:{name:"union",raw:"TStringOrNumber | ReactNode",elements:[{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},{name:"ReactNode"}]},description:""},checkNonExistentValues:{required:!1,tsType:{name:"boolean"},description:""},closeOnOptionActionClick:{required:!1,tsType:{name:"boolean"},description:""},small:{required:!1,tsType:{name:"boolean"},description:""},width:{required:!1,tsType:{name:"union",raw:"TStringOrNumber | null",elements:[{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},{name:"null"}]},description:""},borderRadius:{required:!1,tsType:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},description:""},onCreate:{required:!1,tsType:{name:"signature",type:"function",raw:"(evt: any) => any",signature:{arguments:[{type:{name:"any"},name:"evt"}],return:{name:"any"}}},description:""},disabled:{required:!1,tsType:{name:"boolean"},description:""},placeholder:{required:!1,tsType:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}]},description:""},isInTable:{required:!1,tsType:{name:"boolean"},description:""},clearable:{required:!1,tsType:{name:"boolean"},description:""},searchable:{required:!1,tsType:{name:"boolean"},description:""},maxTooltipWidth:{required:!1,tsType:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},description:""},autoLayerWidth:{required:!1,tsType:{name:"boolean"},description:""},right:{required:!1,tsType:{name:"boolean"},description:""},tabIndex:{required:!1,tsType:{name:"number"},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};export{Et as S};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as s}from"./jsx-runtime-eps93zm2.js";import{r as _}from"./index-DhsZuJvc.js";import{S as F}from"./select-
|
|
1
|
+
import{j as s}from"./jsx-runtime-eps93zm2.js";import{r as _}from"./index-DhsZuJvc.js";import{S as F}from"./select-Cwks-WA0.js";import{S as Sn}from"./spacer-BWoNR27H.js";import{o as Vn,a as Cn,b as bn,c as xn,d as yn,e as fn,f as jn,g as Wn,h as On,i as En}from"./select.stories-data-DxgWKlU6.js";import"./lodash-c4VUpsOs.js";import"./index-Bk2sglWO.js";import"./common-types-Sih75Sav.js";import"./disabled-context-rmpd7YJS.js";import"./types-Dx2TtIG9.js";import"./tooltip-1V7clEnw.js";import"./index-CUZDtIZe.js";import"./enum-Bnn40S8Q.js";import"./index-CEuq6vkz.js";import"./inheritsLoose-DP0QEDDI.js";import"./assertThisInitialized-B9jnkVVz.js";import"./memoize-one.esm-CcMeOnPo.js";import"./types-BmbYqTX_.js";import"./text-B3-TSWok.js";import"./actions-Bax0KeqM.js";import"./button-Cbv7WK6k.js";import"./spinner-AWUe4xwQ.js";import"./icon-BSFY3vDO.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./badge-CLQ59MDF.js";import"./select.input-CJed_LLR.js";import"./helpers-JJxzGegQ.js";const na={title:"Forms/Select",component:F,args:{options:Vn,native:!1,multi:!1,disabled:!1,autoLayerWidth:!1,clearable:!1,searchable:!0,right:!1}},e=t=>{const{multi:o,value:P}=t,[M,H]=_.useState(P||(o?[]:void 0)),I=n=>{const{value:a}=n.target;H(o?a:{value:a})};return s.jsx(F,{value:M,onChange:I,...t})},k=e.bind({}),u=e.bind({});u.args={small:!0};const c=e.bind({});c.args={width:"auto"};const i=e.bind({});i.args={width:"200px"};const d=e.bind({});d.args={native:!0};const g=e.bind({});g.args={multi:!0,clearable:!0};const p=e.bind({});p.args={options:[]};const m=e.bind({});m.args={clearable:!0};const v=e.bind({});v.args={value:{label:"Vampires",value:"blood"}};const h=e.bind({});h.args={placeholder:"Select the best animal..."};const S=e.bind({});S.args={options:Cn};const V=e.bind({});V.args={options:bn};const C=e.bind({});C.args={options:xn};const b=e.bind({});b.args={options:yn};const x=e.bind({});x.args={options:fn};const y=e.bind({});y.args={searchable:!1};const f=e.bind({});f.args={right:!0};const l=e.bind({});l.parameters={docs:{description:{story:"Avoid autoLayerWidth for very long lists in custom selects (slow)"}}};l.args={width:"70px",autoLayerWidth:!0};const j=e.bind({});j.args={tooltip:"Some info"};const W=e.bind({});W.args={error:"Some info"};const O=e.bind({});O.args={warning:"Some info"};const E=e.bind({});E.args={disabled:!0};const w=e.bind({});w.args={options:jn,placeholder:void 0};const A=e.bind({});A.args={options:Wn};const L=e.bind({});L.args={options:On};const r=e.bind({});r.parameters={docs:{description:{story:"Avoid `width: auto` and autoLayerWidth for very long lists in custom selects (slow). Consider checkNonExistentValues={false}."}}};r.args={options:En};const N=e.bind({});N.args={deprecatedEventHandler:!0};const D=()=>{const[t,o]=_.useState([{label:"Aardvarks",value:"termites"},{label:"Kangaroos",value:"grass"},{label:"Monkeys",value:"bananas"},{label:"Possums",value:"slugs"}]),[P,M]=_.useState(void 0),[H,I]=_.useState([]);return s.jsxs(s.Fragment,{children:[s.jsx(F,{name:"example",options:t,onChange:n=>M({value:n.target.value}),onCreate:n=>{const a={label:n,value:n};o([...t,a]),M(a)},value:P,clearable:!0}),s.jsx(Sn,{}),s.jsx(F,{name:"example",options:t,onChange:n=>I(n.target.value),onCreate:n=>{const a={label:n,value:n};o([...t,a]),console.log(n),I([...H,a])},value:H,multi:!0,clearable:!0})]})};D.__docgenInfo={description:"",methods:[],displayName:"OnCreate"};var B,R,T;k.parameters={...k.parameters,docs:{...(B=k.parameters)==null?void 0:B.docs,source:{originalSource:`(args: any) => {
|
|
2
2
|
const {
|
|
3
3
|
multi,
|
|
4
4
|
value
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import{j as q}from"./jsx-runtime-eps93zm2.js";import{r as I}from"./index-DhsZuJvc.js";import{w as s,u as i,e as l}from"./index-DMAnyMX5.js";import{S as w}from"./select-Cwks-WA0.js";import{o as K}from"./select.stories-data-DxgWKlU6.js";import"./index-CF7H4eMJ.js";import"./lodash-c4VUpsOs.js";import"./index-Bk2sglWO.js";import"./common-types-Sih75Sav.js";import"./disabled-context-rmpd7YJS.js";import"./types-Dx2TtIG9.js";import"./tooltip-1V7clEnw.js";import"./index-CUZDtIZe.js";import"./enum-Bnn40S8Q.js";import"./index-CEuq6vkz.js";import"./inheritsLoose-DP0QEDDI.js";import"./assertThisInitialized-B9jnkVVz.js";import"./memoize-one.esm-CcMeOnPo.js";import"./types-BmbYqTX_.js";import"./text-B3-TSWok.js";import"./actions-Bax0KeqM.js";import"./button-Cbv7WK6k.js";import"./spinner-AWUe4xwQ.js";import"./icon-BSFY3vDO.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./badge-CLQ59MDF.js";import"./select.input-CJed_LLR.js";import"./helpers-JJxzGegQ.js";const de={title:"Forms/Select/Test Cases",component:w,args:{options:K},tags:["!autodocs"]},v=n=>{const{multi:o,value:a}=n,[r,t]=I.useState(a||(o?[]:void 0)),e=c=>{const{value:u}=c.target;t(o?u:{value:u})};return q.jsx(w,{value:r,onChange:e,...n})},y=v.bind({});y.args={value:{label:"Vampires",value:"blood"},disabled:!0};const m=v.bind({});m.args={testId:"testId",clearable:!0};m.play=async({canvasElement:n,step:o})=>{const a=s(n),r=s(n.ownerDocument.body);await o("Select item with click",async()=>{const t=a.getByTestId("testId");await i.click(t);const e=await r.findByTestId("testId-layer");l(e).toBeInTheDocument();const c=s(e).getByText("Wombats");await i.click(c);const u=await a.findByTestId("testId-value");l(s(u).getByText("Wombats")).toBeInTheDocument()}),await o("Clear selected value",async()=>{const t=a.getByTestId("testId-clear");await i.click(t);const e=a.queryByTestId("testId-value");l(e).not.toBeInTheDocument()})};const p=v.bind({});p.args={testId:"testId",clearable:!0,multi:!0};p.play=async({canvasElement:n,step:o})=>{const a=s(n),r=s(n.ownerDocument.body);await o("Select items with click",async()=>{const t=a.getByTestId("testId");await i.click(t);const e=await r.findByTestId("testId-layer");await l(e).toBeInTheDocument();const c=s(e).getByText("Wombats");await i.click(c);const u=s(e).getByText("Kangaroos");await i.click(u),await i.click(n),await l(e).not.toBeInTheDocument();const T=await a.findByTestId("testId-value");await l(s(T).getByText("Wombats")).toBeInTheDocument(),await l(s(T).getByText("Kangaroos")).toBeInTheDocument()}),await o("Deselect item with click",async()=>{const t=a.getByTestId("testId");await i.click(t);const e=await r.findByTestId("testId-layer");await l(e).toBeInTheDocument();const c=s(e).getByText("Wombats");await i.click(c),await i.click(n),await l(e).not.toBeInTheDocument();const u=await a.findByTestId("testId-value");await l(s(u).queryByText("Wombats")).not.toBeInTheDocument()}),await o("Clear selected values",async()=>{const t=a.getByTestId("testId-clear");await i.click(t);const e=a.queryByTestId("testId-value");await l(e).not.toBeInTheDocument()})};const g=v.bind({});g.args={testId:"testId",disabled:!0};g.play=async({canvasElement:n,step:o})=>{const a=s(n),r=s(n.ownerDocument.body);await o("Clicking disabled trigger should not show layer",async()=>{await a.getByTestId("testId").click();const e=r.queryByTestId("testId-layer");await l(e).not.toBeInTheDocument()})};const d=()=>{const[n,o]=I.useState(K),[a,r]=I.useState(void 0);return q.jsx(w,{testId:"testId",name:"example",options:n,onChange:t=>r({value:t.target.value}),onCreate:t=>{const e={label:t,value:t};o([...n,e]),r(e)},value:a})};d.args={testId:"testId"};d.play=async({canvasElement:n,step:o})=>{const a=s(n),r=s(n.ownerDocument.body);await o("Create new item",async()=>{const t=a.getByTestId("testId-input");if(await l(t).toBeInTheDocument(),!t)return;await i.type(t,"New value");const e=r.getByText('Create "New value"');await i.click(e);const c=await a.findByTestId("testId-value");await l(s(c).getByText("New value")).toBeInTheDocument()})};d.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"TestCreate"};var h,B,S;y.parameters={...y.parameters,docs:{...(h=y.parameters)==null?void 0:h.docs,source:{originalSource:`(args: any) => {
|
|
2
|
+
const {
|
|
3
|
+
multi,
|
|
4
|
+
value
|
|
5
|
+
} = args;
|
|
6
|
+
const [selectedValue, setSelectedValue] = useState(value || (multi ? [] : undefined));
|
|
7
|
+
const handleChange = (evt: any) => {
|
|
8
|
+
const {
|
|
9
|
+
value
|
|
10
|
+
} = evt.target;
|
|
11
|
+
setSelectedValue(multi ? value : {
|
|
12
|
+
value
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
return <Select value={selectedValue} onChange={handleChange}
|
|
16
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
17
|
+
{...args} />;
|
|
18
|
+
}`,...(S=(B=y.parameters)==null?void 0:B.docs)==null?void 0:S.source}}};var b,V,x;m.parameters={...m.parameters,docs:{...(b=m.parameters)==null?void 0:b.docs,source:{originalSource:`(args: any) => {
|
|
19
|
+
const {
|
|
20
|
+
multi,
|
|
21
|
+
value
|
|
22
|
+
} = args;
|
|
23
|
+
const [selectedValue, setSelectedValue] = useState(value || (multi ? [] : undefined));
|
|
24
|
+
const handleChange = (evt: any) => {
|
|
25
|
+
const {
|
|
26
|
+
value
|
|
27
|
+
} = evt.target;
|
|
28
|
+
setSelectedValue(multi ? value : {
|
|
29
|
+
value
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
return <Select value={selectedValue} onChange={handleChange}
|
|
33
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
34
|
+
{...args} />;
|
|
35
|
+
}`,...(x=(V=m.parameters)==null?void 0:V.docs)==null?void 0:x.source}}};var C,D,f;p.parameters={...p.parameters,docs:{...(C=p.parameters)==null?void 0:C.docs,source:{originalSource:`(args: any) => {
|
|
36
|
+
const {
|
|
37
|
+
multi,
|
|
38
|
+
value
|
|
39
|
+
} = args;
|
|
40
|
+
const [selectedValue, setSelectedValue] = useState(value || (multi ? [] : undefined));
|
|
41
|
+
const handleChange = (evt: any) => {
|
|
42
|
+
const {
|
|
43
|
+
value
|
|
44
|
+
} = evt.target;
|
|
45
|
+
setSelectedValue(multi ? value : {
|
|
46
|
+
value
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
return <Select value={selectedValue} onChange={handleChange}
|
|
50
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
51
|
+
{...args} />;
|
|
52
|
+
}`,...(f=(D=p.parameters)==null?void 0:D.docs)==null?void 0:f.source}}};var k,j,N;g.parameters={...g.parameters,docs:{...(k=g.parameters)==null?void 0:k.docs,source:{originalSource:`(args: any) => {
|
|
53
|
+
const {
|
|
54
|
+
multi,
|
|
55
|
+
value
|
|
56
|
+
} = args;
|
|
57
|
+
const [selectedValue, setSelectedValue] = useState(value || (multi ? [] : undefined));
|
|
58
|
+
const handleChange = (evt: any) => {
|
|
59
|
+
const {
|
|
60
|
+
value
|
|
61
|
+
} = evt.target;
|
|
62
|
+
setSelectedValue(multi ? value : {
|
|
63
|
+
value
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
return <Select value={selectedValue} onChange={handleChange}
|
|
67
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
68
|
+
{...args} />;
|
|
69
|
+
}`,...(N=(j=g.parameters)==null?void 0:j.docs)==null?void 0:N.source}}};var W,_,O;d.parameters={...d.parameters,docs:{...(W=d.parameters)==null?void 0:W.docs,source:{originalSource:`() => {
|
|
70
|
+
const [options, setOptions] = useState(storyData.options);
|
|
71
|
+
const [singleValue, setSingleValue] = useState<ISelectSelectedOption | undefined>(undefined);
|
|
72
|
+
return <Select testId="testId" name="example" options={options} onChange={evt => setSingleValue({
|
|
73
|
+
value: evt.target.value
|
|
74
|
+
})} onCreate={value => {
|
|
75
|
+
const newValue = {
|
|
76
|
+
label: value,
|
|
77
|
+
value
|
|
78
|
+
};
|
|
79
|
+
setOptions([...options, newValue]);
|
|
80
|
+
setSingleValue(newValue);
|
|
81
|
+
}} value={singleValue} />;
|
|
82
|
+
}`,...(O=(_=d.parameters)==null?void 0:_.docs)==null?void 0:O.source}}};const me=["TestDisabledNonExistentValue","Test","TestMulti","TestDisabled","TestCreate"];export{m as Test,d as TestCreate,g as TestDisabled,y as TestDisabledNonExistentValue,p as TestMulti,me as __namedExportsOrder,de as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as n}from"./jsx-runtime-eps93zm2.js";import{r as S}from"./index-DhsZuJvc.js";import{c as T}from"./index-Bk2sglWO.js";import{I as Le,D as We,C as Fe,P as Pe}from"./index.es-DazXb-ul.js";import{l as De}from"./lodash-c4VUpsOs.js";import{A as ae}from"./actions-Bax0KeqM.js";import{H as Oe}from"./heading-CRNoBc7q.js";import{P as Be}from"./pagination-CoyQUC4R.js";import{A as h,I as $}from"./common-types-Sih75Sav.js";import{I as $e}from"./input-Db9WkmPP.js";import{N as Me}from"./number-input-CNnU6gOF.js";import{S as Ge}from"./select-BQzJMnK1.js";import{D as Ve}from"./disabled-context-rmpd7YJS.js";import{i as M}from"./types-Dx2TtIG9.js";import{T as ie}from"./tooltip-1V7clEnw.js";import{C as Ue}from"./check-box-DPLaOkRR.js";import{S as ze}from"./slider-CcpE4BLD.js";import{I as G}from"./icon-BSFY3vDO.js";import{P as Ke}from"./popover-C_2P8LFJ.js";import{H as fe}from"./help-icon-Buhx5nl6.js";import{T as Y}from"./text-B3-TSWok.js";const Xe="_inputInTable_1dg3w_1",Ye="_inputHover_1dg3w_13",Je="_inputFocus_1dg3w_18",Qe="_inputError_1dg3w_25",Ze="_inputWarning_1dg3w_26",en="_inputDisabled_1dg3w_61",nn="_hideScrollbars_1dg3w_67",tn="_wrapper_1dg3w_85",rn="_bordered_1dg3w_93",an="_scroll_1dg3w_98",on="_table_1dg3w_108",sn="_striped_1dg3w_188",L={inputInTable:Xe,inputHover:Ye,inputFocus:Je,inputError:Qe,inputWarning:Ze,inputDisabled:en,hideScrollbars:nn,wrapper:tn,bordered:rn,scroll:an,table:on,striped:sn},ln="_title_zn5s7_1",dn={title:ln},Q=({name:e=null,actions:t=null,actionsRight:r=!1,testId:i})=>{const a=e!==null,o=t!==null;if(!a&&!o)return null;const s=()=>{if(!o)return null;const c=n.jsx(ae,{actions:t});return r?c:n.jsx("div",{children:c})};return n.jsxs("div",{className:dn.title,children:[a?n.jsx(Oe,{children:n.jsx("span",{"data-testid":i,children:e})}):null,s()]})};Q.__docgenInfo={description:"",methods:[],displayName:"Title",props:{name:{required:!1,tsType:{name:"union",raw:"TStringOrNumber | ReactNode",elements:[{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},{name:"ReactNode"}]},description:"",defaultValue:{value:"null",computed:!1}},actions:{required:!1,tsType:{name:"any"},description:"",defaultValue:{value:"null",computed:!1}},actionsRight:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},testId:{required:!1,tsType:{name:"string"},description:""}}};const un="_footer_4sumy_1",cn="_section_4sumy_7",J={footer:un,section:cn},Z=({colSpan:e,pagination:t,actions:r,content:i})=>{const a=r&&r.length,o=i!=null,s=()=>{var d,p;if(t){const{rowCount:u,rowsPerPage:y}=t,I=Number((p=(d=y==null?void 0:y.options)==null?void 0:d[0])==null?void 0:p.value);return u>I}return!1};return a||o||s()?n.jsxs("div",{className:J.footer,children:[o?n.jsx("div",{className:J.section,children:n.jsx("div",{children:i})}):null,a||s()?n.jsxs("div",{className:J.section,children:[s()?n.jsx(Be,{pagination:t}):n.jsx("div",{}),a&&n.jsx("div",{children:n.jsx(ae,{actions:r})})]}):null]}):null};Z.__docgenInfo={description:"",methods:[],displayName:"Footer",props:{colSpan:{required:!1,tsType:{name:"number"},description:""},pagination:{required:!0,tsType:{name:"IPagination"},description:""},actions:{required:!1,tsType:{name:"Array",elements:[{name:"IAction"}],raw:"IAction[]"},description:""},content:{required:!1,tsType:{name:"ReactNode"},description:""}}};const Ce=e=>{const t=Math.max(...e.reduce((r,i)=>{const a=i.cells.map(o=>o.colSpan?o.colSpan:1).reduce((o,s)=>o+s,0);return r.concat(a)},[]));return isNaN(t)?0:t},pn=(e,t)=>{const r=[Ce(t),Ce(e)];return Math.max(...r)},be=e=>e.reduce((t,r)=>r.actions&&r.actions.length>0?1:t,0),mn=(e,t)=>be(t)>0||be(e)>0,ee=({table:e,children:t})=>{const{rows:r,infiniteScroll:i}=e,a=Math.ceil(window.innerHeight/30),[o,s]=i?S.useState(a):[r.length,null],[c,d]=i?S.useState(o<r.length):[!1,null],p=()=>{if(o>=r.length&&d){d(!1);return}s&&s(o+a)};return n.jsx("div",{id:"scrollWrapper",className:L.scroll,children:i?n.jsx(Le,{dataLength:Math.min(r.length,o+a),next:p,hasMore:c,scrollableTarget:"scrollWrapper",style:{overflow:"initial"},loader:null,children:t({visibleRows:o})}):t({visibleRows:o})})};ee.__docgenInfo={description:"",methods:[],displayName:"TableScrollWrapper",props:{table:{required:!0,tsType:{name:"ITableProps"},description:""},children:{required:!0,tsType:{name:"signature",type:"function",raw:"(props: { visibleRows: number }) => ReactNode",signature:{arguments:[{type:{name:"signature",type:"object",raw:"{ visibleRows: number }",signature:{properties:[{key:"visibleRows",value:{name:"number",required:!0}}]}},name:"props"}],return:{name:"ReactNode"}}},description:""}}};const gn="_clickableRow_m64j5_1",In="_hoverableRow_m64j5_4",yn="_rowActive_m64j5_4",Cn="_expandableRow_m64j5_8",bn="_flush_m64j5_8",hn="_dragIconCell_m64j5_34",fn="_dragIcon_m64j5_34",R={clickableRow:gn,hoverableRow:In,rowActive:yn,expandableRow:Cn,flush:bn,dragIconCell:hn,dragIcon:fn},ne=({colSpan:e,children:t,flush:r})=>n.jsx("tr",{children:n.jsx("td",{colSpan:e,className:T(R.expandableRow,r?R.flush:""),children:t})});ne.__docgenInfo={description:"",methods:[],displayName:"ExpandedContentRow",props:{colSpan:{required:!0,tsType:{name:"number"},description:""},children:{required:!0,tsType:{name:"ReactNode"},description:""},flush:{required:!1,tsType:{name:"boolean"},description:""}}};const he=(e,t={leftAligned:"",rightAligned:"",centerAligned:""},r=!1)=>{if(!e)return null;const{bodyAlignment:i,headerAlignment:a,isHeader:o}=e;switch(o&&a?a:i){case h.LEFT:return r?h.LEFT:t.leftAligned;case h.RIGHT:return r?h.RIGHT:t.rightAligned;case h.CENTER:return r?h.CENTER:t.centerAligned;default:return r?h.LEFT:t.leftAligned}},_n=(e,t=!1,r=0)=>{if(!e||e.length===0)return[];const i=e.every(o=>Array.isArray(o)),a=e.every(o=>typeof o=="string");return i&&t?e[r]||[]:a?e:(console.warn("getHeaderAlignment: alignments array contains a mix of strings and arrays, returning an empty array."),[])},wn="_inputInTable_ie6ng_1",xn="_inputHover_ie6ng_13",Tn="_inputFocus_ie6ng_18",vn="_inputError_ie6ng_25",An="_inputWarning_ie6ng_26",Rn="_inputDisabled_ie6ng_61",jn="_hideScrollbars_ie6ng_67",kn="_cell_ie6ng_77",qn="_disabledLink_ie6ng_87",Nn="_inputWrapper_ie6ng_91",Sn="_numberInputWrapper_ie6ng_106",En="_breakWord_ie6ng_113",Hn="_inputCell_ie6ng_116",Ln="_sliderCell_ie6ng_119",Wn="_staticCell_ie6ng_123",Fn="_staticCellContent_ie6ng_126",Pn="_unit_ie6ng_148",Dn="_sortingCell_ie6ng_151",On="_sortingCellIcon_ie6ng_162",Bn="_icon_ie6ng_173",$n="_checkBoxCell_ie6ng_177",Mn="_iconCellWrapper_ie6ng_181",Gn="_actionsCell_ie6ng_185",Vn="_rightAligned_ie6ng_193",Un="_centerAligned_ie6ng_199",zn="_leftAligned_ie6ng_205",Kn="_popover_ie6ng_208",Xn="_disabledPointerEvents_ie6ng_211",l={inputInTable:wn,inputHover:xn,inputFocus:Tn,inputError:vn,inputWarning:An,inputDisabled:Rn,hideScrollbars:jn,cell:kn,disabledLink:qn,inputWrapper:Nn,numberInputWrapper:Sn,breakWord:En,inputCell:Hn,sliderCell:Ln,staticCell:Wn,staticCellContent:Fn,unit:Pn,sortingCell:Dn,sortingCellIcon:On,icon:Bn,checkBoxCell:$n,iconCellWrapper:Mn,actionsCell:Gn,rightAligned:Vn,centerAligned:Un,leftAligned:zn,popover:Kn,disabledPointerEvents:Xn},te=({cell:e,columnAlignment:t,testId:r,type:i})=>n.jsx($e,{name:e.name,value:e.value,onChange:a=>{var o;return(o=e.onChange)==null?void 0:o.call(e,a)},onFocus:e.onFocus,onBlur:e.onBlur,onPaste:a=>{var o;return(o=e.onPaste)==null?void 0:o.call(e,a)},placeholder:e.placeholder,error:e.error,warning:e.warning,disabled:e.disabled,isInTable:!0,maxTooltipWidth:e.maxTooltipWidth,right:t===h.RIGHT,testId:r,tabIndex:e.disabled?-1:0,tooltip:e.tooltip,type:i});te.__docgenInfo={description:"",methods:[],displayName:"InputCell",props:{cell:{required:!0,tsType:{name:"IInputCell"},description:""},columnAlignment:{required:!1,tsType:{name:"union",raw:"Align.LEFT | Align.RIGHT | string",elements:[{name:"Align.LEFT"},{name:"Align.RIGHT"},{name:"string"}]},description:""},testId:{required:!1,tsType:{name:"string"},description:""},type:{required:!1,tsType:{name:"union",raw:"'text' | 'date'",elements:[{name:"literal",value:"'text'"},{name:"literal",value:"'date'"}]},description:""}}};const _e=({cell:e,testId:t})=>n.jsx(Me,{name:e.name,value:e.value,onChange:r=>{var i;return(i=e.onChange)==null?void 0:i.call(e,r)},onFocus:e.onFocus,onBlur:e.onBlur,placeholder:e.placeholder,error:e.error,warning:e.warning,disabled:e.disabled,isInTable:!0,left:e.left,tabIndex:e.disabled?-1:0,testId:t,tooltip:e.tooltip,validationCallback:e.validationCallback,allowEmpty:e.allowEmpty,enableCosmeticRounding:e.enableCosmeticRounding,enableDisplayRounding:e.enableDisplayRounding,roundDisplayValue:e.roundDisplayValue});_e.__docgenInfo={description:"",methods:[],displayName:"NumberInputCell",props:{cell:{required:!0,tsType:{name:"INumberInputCell"},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};const we=({cell:e,columnAlignment:t,testId:r})=>n.jsx(Ge,{name:e.name,borderRadius:0,options:e.options,onChange:i=>{var a;return(a=e.onChange)==null?void 0:a.call(e,i)},onCreate:e.onCreate?i=>e.onCreate&&e.onCreate(i):void 0,error:e.error,warning:e.warning,disabled:e.disabled,placeholder:e.placeholder,isInTable:!0,value:e.value,native:e.native,clearable:e.clearable,searchable:e.searchable,deprecatedEventHandler:e.deprecatedEventHandler,maxTooltipWidth:e.maxTooltipWidth,width:"100%",autoLayerWidth:e.autoLayerWidth,multi:e.multi,right:t===h.RIGHT,testId:r,tabIndex:e.disabled?-1:0});we.__docgenInfo={description:"",methods:[],displayName:"SelectCell",props:{cell:{required:!0,tsType:{name:"ISelectCell"},description:""},columnAlignment:{required:!1,tsType:{name:"union",raw:"Align.LEFT | Align.RIGHT | string",elements:[{name:"Align.LEFT"},{name:"Align.RIGHT"},{name:"string"}]},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};const xe=({cell:e,columnAlignment:t,testId:r})=>n.jsx("div",{className:T(l.inputWrapper,e.type==="NumberInput"?l.numberInputWrapper:""),children:e.type==="Input"?n.jsx(te,{cell:e,columnAlignment:t,testId:r}):e.type==="NumberInput"?n.jsx(_e,{cell:e,testId:r}):e.type==="DateInput"?n.jsx(te,{cell:e,testId:r,type:"date"}):e.type==="Select"?n.jsx(we,{cell:e,columnAlignment:t,testId:r}):null});xe.__docgenInfo={description:"",methods:[],displayName:"InputCellWrapper",props:{cell:{required:!0,tsType:{name:"any"},description:""},columnAlignment:{required:!0,tsType:{name:"union",raw:"Align.LEFT | Align.RIGHT | string",elements:[{name:"Align.LEFT"},{name:"Align.RIGHT"},{name:"string"}]},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};const Te=({cell:e,testId:t})=>{const r=S.useContext(Ve),{error:i,warning:a,tooltip:o,maxTooltipWidth:s}=e,c=d=>M(d);return n.jsx("div",{className:l.inputWrapper,children:n.jsx(ie,{error:!!i,warning:!!a,text:o||i||a,enabled:c(o)||c(i)||c(a)||!1,maxWidth:s,placement:"bottom-center",children:n.jsx("div",{className:l.staticCellContent,"data-error":i||null,"data-warning":a||null,children:n.jsx("a",{className:T((e.disabled||r)&&l.disabledLink),onClick:e.disabled||r?void 0:d=>{var p;d.stopPropagation(),(p=e.onClick)==null||p.call(e,d)},"data-testid":t,children:e.value})})})})};Te.__docgenInfo={description:"",methods:[],displayName:"LinkCell",props:{cell:{required:!0,tsType:{name:"ILinkCell"},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};const ve=({cell:e,testId:t})=>n.jsx(Ue,{label:e.label,checked:e.checked,isInTable:!0,disabled:e.disabled,onChange:r=>e.onChange(r),testId:t,tabIndex:e.disabled?-1:0});ve.__docgenInfo={description:"",methods:[],displayName:"CheckBoxCell",props:{cell:{required:!0,tsType:{name:"ICheckBoxCell"},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};const Ae=({cell:e})=>n.jsx("div",{className:l.inputWrapper,children:n.jsx(ze,{label:e.label,value:e.value,min:e.min,max:e.max,step:e.step,marks:e.marks,onChange:t=>e.onChange(t),showArrows:e.showArrows,showTooltip:e.showTooltip,tooltipFormatter:e.tooltipFormatter,disabled:e.disabled})});Ae.__docgenInfo={description:"",methods:[],displayName:"SliderCell",props:{cell:{required:!0,tsType:{name:"ISliderCell"},description:""}}};const Re=({cell:e})=>{const{tooltip:t,icon:r}=e;return n.jsx("div",{className:l.iconCellWrapper,children:n.jsx(ie,{text:t,enabled:!!t&&M(t),display:"flex",placement:"top-center",children:n.jsx(G,{icon:r})})})};Re.__docgenInfo={description:"",methods:[],displayName:"IconCell",props:{cell:{required:!0,tsType:{name:"IIconCell"},description:""}}};const je=({cell:e})=>n.jsx(ae,{actions:e.actions});je.__docgenInfo={description:"",methods:[],displayName:"ActionsCell",props:{cell:{required:!0,tsType:{name:"IActionCell"},description:""}}};const ke=({cell:e})=>{const{helpIcon:t}=e;return t?n.jsx("div",{className:l.icon,children:n.jsx(fe,{onClick:t.onClick,text:t.tooltip})}):null};ke.__docgenInfo={description:"",methods:[],displayName:"CellHelpIcon",props:{cell:{required:!0,tsType:{name:"IHelpIconCell"},description:""}}};const qe=({cell:e})=>{const{libraryIcon:t}=e;return t?n.jsx("div",{className:l.icon,children:n.jsx(fe,{onClick:t.onClick,text:t.tooltip,icon:$.LIBRARY})}):null};qe.__docgenInfo={description:"",methods:[],displayName:"CellLibraryIcon",props:{cell:{required:!0,tsType:{name:"ILibraryIconCell"},description:""}}};const Ne=({cell:e})=>{const{hasSort:t,sort:r,sortPriority:i}=e;return t?n.jsxs("span",{className:l.sortingCellIcon,children:[r==="down"?n.jsx(Y,{link:!0,children:n.jsx(G,{icon:$.SORT_ASCENDING})}):r==="up"?n.jsx(Y,{link:!0,children:n.jsx(G,{icon:$.SORT_DESCENDING})}):n.jsx(Y,{faint:!0,children:n.jsx(G,{icon:$.SORT_DESCENDING})}),i&&r?n.jsx("sup",{children:i}):null]}):null};Ne.__docgenInfo={description:"",methods:[],displayName:"Sort",props:{cell:{required:!0,tsType:{name:"ISortCell"},description:""}}};const oe=({cell:e,isHeader:t,testId:r})=>{const{error:i,warning:a,tooltip:o,maxTooltipWidth:s,hasSort:c,onSort:d,type:p}=e,u=n.jsxs("div",{className:T(l.staticCellContent,p==="Unit"?l.unit:""),onClick:c?y=>d&&d(y):()=>{},"data-error":i||null,"data-warning":a||null,"data-testid":r,children:[e.value,t?n.jsxs(n.Fragment,{children:[n.jsx(ke,{cell:e}),n.jsx(qe,{cell:e}),n.jsx(Ne,{cell:e})]}):null]});return n.jsx("div",{className:l.inputWrapper,children:n.jsx(ie,{error:!!i,warning:!!a,text:o||i||a,enabled:o&&M(o)||i&&M(i)||a&&M(a)||!1,maxWidth:s,display:"block",placement:"bottom-center",children:u})})};oe.__docgenInfo={description:"",methods:[],displayName:"StaticCell",props:{cell:{required:!0,tsType:{name:"IStaticCell"},description:""},isHeader:{required:!1,tsType:{name:"boolean"},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};const Se=({cell:e,testId:t})=>{const{content:r,fullWidth:i,closeOnOutsideClick:a,disabled:o}=e;return n.jsx(Ke,{content:r,fullWidth:i,closeOnOutsideClick:a,disabled:o,children:n.jsx("div",{className:l.popover,children:n.jsx(oe,{cell:e,testId:t})})})};Se.__docgenInfo={description:"",methods:[],displayName:"PopoverCell",props:{cell:{required:!0,tsType:{name:"IPopoverCell"},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};const Ee=({cell:e,isHeader:t,columnAlignment:r,testId:i})=>{if(!e)return null;switch(e.type){case"Input":case"NumberInput":case"DateInput":case"Select":return n.jsx(xe,{cell:e,columnAlignment:r,testId:i});case"Link":return n.jsx(Te,{cell:e,testId:i});case"CheckBox":return n.jsx(ve,{cell:e,testId:i});case"Slider":return n.jsx(Ae,{cell:e});case"Icon":return n.jsx(Re,{cell:e});case"Actions":return n.jsx(je,{cell:e});case"Popover":return n.jsx(Se,{cell:e});default:return n.jsx(oe,{cell:e,isHeader:t,testId:i})}};Ee.__docgenInfo={description:"",methods:[],displayName:"CellWrapper",props:{cell:{required:!0,tsType:{name:"any"},description:""},isHeader:{required:!0,tsType:{name:"boolean"},description:""},columnAlignment:{required:!0,tsType:{name:"union",raw:"Align.LEFT | Align.RIGHT | string",elements:[{name:"Align.LEFT"},{name:"Align.RIGHT"},{name:"string"}]},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};var j=(e=>(e.INPUT="Input",e.NUMBER_INPUT="NumberInput",e.SELECT="Select",e.POPOVER="Popover",e.SLIDER="Slider",e.CHECKBOX="CheckBox",e.ACTIONS="Actions",e.AUTO_UNIT="AutoUnit",e))(j||{});const re=({cell:e,isHeader:t,columnHeaderAlignment:r,columnAlignment:i=h.LEFT,width:a,snapshot:o,testId:s})=>{if(!e)return null;const{style:c,colSpan:d,rowSpan:p,width:u}=e,y=S.useRef(null),I={bodyAlignment:i,headerAlignment:r,isHeader:t},W=he(I,l),f=he(I,l,!0),F=e.type===j.INPUT||e.type===j.NUMBER_INPUT||e.type===j.SELECT||e.type===j.POPOVER?l.inputCell:e.type===j.SLIDER?l.sliderCell:e.type===j.CHECKBOX?l.checkBoxCell:e.type===j.ACTIONS?l.actionsCell:l.staticCell,v=T(l.cell,F,e.hasSort?l.sortingCell:null,W,e.breakWord?l.breakWord:""),E=u??a??((o==null?void 0:o.isDragging)&&y.current&&y.current.offsetWidth)??void 0,_={width:E,minWidth:E,...c},A=t?"th":"td";return n.jsx(A,{ref:y,className:v,style:_,colSpan:d,rowSpan:p,children:n.jsx(Ee,{cell:e,columnAlignment:f??h.RIGHT,isHeader:t,testId:s})})};re.__docgenInfo={description:"",methods:[],displayName:"Cell",props:{cell:{required:!1,tsType:{name:"union",raw:`| IPopoverCell
|
|
1
|
+
import{j as n}from"./jsx-runtime-eps93zm2.js";import{r as S}from"./index-DhsZuJvc.js";import{c as T}from"./index-Bk2sglWO.js";import{I as Le,D as We,C as Fe,P as Pe}from"./index.es-DazXb-ul.js";import{l as De}from"./lodash-c4VUpsOs.js";import{A as ae}from"./actions-Bax0KeqM.js";import{H as Oe}from"./heading-CRNoBc7q.js";import{P as Be}from"./pagination-CR1nxnnq.js";import{A as h,I as $}from"./common-types-Sih75Sav.js";import{I as $e}from"./input-Db9WkmPP.js";import{N as Me}from"./number-input-B3_gmeWr.js";import{S as Ge}from"./select-Cwks-WA0.js";import{D as Ve}from"./disabled-context-rmpd7YJS.js";import{i as M}from"./types-Dx2TtIG9.js";import{T as ie}from"./tooltip-1V7clEnw.js";import{C as Ue}from"./check-box-DPLaOkRR.js";import{S as ze}from"./slider-CcpE4BLD.js";import{I as G}from"./icon-BSFY3vDO.js";import{P as Ke}from"./popover-C_2P8LFJ.js";import{H as fe}from"./help-icon-Buhx5nl6.js";import{T as Y}from"./text-B3-TSWok.js";const Xe="_inputInTable_1dg3w_1",Ye="_inputHover_1dg3w_13",Je="_inputFocus_1dg3w_18",Qe="_inputError_1dg3w_25",Ze="_inputWarning_1dg3w_26",en="_inputDisabled_1dg3w_61",nn="_hideScrollbars_1dg3w_67",tn="_wrapper_1dg3w_85",rn="_bordered_1dg3w_93",an="_scroll_1dg3w_98",on="_table_1dg3w_108",sn="_striped_1dg3w_188",L={inputInTable:Xe,inputHover:Ye,inputFocus:Je,inputError:Qe,inputWarning:Ze,inputDisabled:en,hideScrollbars:nn,wrapper:tn,bordered:rn,scroll:an,table:on,striped:sn},ln="_title_zn5s7_1",dn={title:ln},Q=({name:e=null,actions:t=null,actionsRight:r=!1,testId:i})=>{const a=e!==null,o=t!==null;if(!a&&!o)return null;const s=()=>{if(!o)return null;const c=n.jsx(ae,{actions:t});return r?c:n.jsx("div",{children:c})};return n.jsxs("div",{className:dn.title,children:[a?n.jsx(Oe,{children:n.jsx("span",{"data-testid":i,children:e})}):null,s()]})};Q.__docgenInfo={description:"",methods:[],displayName:"Title",props:{name:{required:!1,tsType:{name:"union",raw:"TStringOrNumber | ReactNode",elements:[{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},{name:"ReactNode"}]},description:"",defaultValue:{value:"null",computed:!1}},actions:{required:!1,tsType:{name:"any"},description:"",defaultValue:{value:"null",computed:!1}},actionsRight:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},testId:{required:!1,tsType:{name:"string"},description:""}}};const un="_footer_4sumy_1",cn="_section_4sumy_7",J={footer:un,section:cn},Z=({colSpan:e,pagination:t,actions:r,content:i})=>{const a=r&&r.length,o=i!=null,s=()=>{var d,p;if(t){const{rowCount:u,rowsPerPage:y}=t,I=Number((p=(d=y==null?void 0:y.options)==null?void 0:d[0])==null?void 0:p.value);return u>I}return!1};return a||o||s()?n.jsxs("div",{className:J.footer,children:[o?n.jsx("div",{className:J.section,children:n.jsx("div",{children:i})}):null,a||s()?n.jsxs("div",{className:J.section,children:[s()?n.jsx(Be,{pagination:t}):n.jsx("div",{}),a&&n.jsx("div",{children:n.jsx(ae,{actions:r})})]}):null]}):null};Z.__docgenInfo={description:"",methods:[],displayName:"Footer",props:{colSpan:{required:!1,tsType:{name:"number"},description:""},pagination:{required:!0,tsType:{name:"IPagination"},description:""},actions:{required:!1,tsType:{name:"Array",elements:[{name:"IAction"}],raw:"IAction[]"},description:""},content:{required:!1,tsType:{name:"ReactNode"},description:""}}};const Ce=e=>{const t=Math.max(...e.reduce((r,i)=>{const a=i.cells.map(o=>o.colSpan?o.colSpan:1).reduce((o,s)=>o+s,0);return r.concat(a)},[]));return isNaN(t)?0:t},pn=(e,t)=>{const r=[Ce(t),Ce(e)];return Math.max(...r)},be=e=>e.reduce((t,r)=>r.actions&&r.actions.length>0?1:t,0),mn=(e,t)=>be(t)>0||be(e)>0,ee=({table:e,children:t})=>{const{rows:r,infiniteScroll:i}=e,a=Math.ceil(window.innerHeight/30),[o,s]=i?S.useState(a):[r.length,null],[c,d]=i?S.useState(o<r.length):[!1,null],p=()=>{if(o>=r.length&&d){d(!1);return}s&&s(o+a)};return n.jsx("div",{id:"scrollWrapper",className:L.scroll,children:i?n.jsx(Le,{dataLength:Math.min(r.length,o+a),next:p,hasMore:c,scrollableTarget:"scrollWrapper",style:{overflow:"initial"},loader:null,children:t({visibleRows:o})}):t({visibleRows:o})})};ee.__docgenInfo={description:"",methods:[],displayName:"TableScrollWrapper",props:{table:{required:!0,tsType:{name:"ITableProps"},description:""},children:{required:!0,tsType:{name:"signature",type:"function",raw:"(props: { visibleRows: number }) => ReactNode",signature:{arguments:[{type:{name:"signature",type:"object",raw:"{ visibleRows: number }",signature:{properties:[{key:"visibleRows",value:{name:"number",required:!0}}]}},name:"props"}],return:{name:"ReactNode"}}},description:""}}};const gn="_clickableRow_m64j5_1",In="_hoverableRow_m64j5_4",yn="_rowActive_m64j5_4",Cn="_expandableRow_m64j5_8",bn="_flush_m64j5_8",hn="_dragIconCell_m64j5_34",fn="_dragIcon_m64j5_34",R={clickableRow:gn,hoverableRow:In,rowActive:yn,expandableRow:Cn,flush:bn,dragIconCell:hn,dragIcon:fn},ne=({colSpan:e,children:t,flush:r})=>n.jsx("tr",{children:n.jsx("td",{colSpan:e,className:T(R.expandableRow,r?R.flush:""),children:t})});ne.__docgenInfo={description:"",methods:[],displayName:"ExpandedContentRow",props:{colSpan:{required:!0,tsType:{name:"number"},description:""},children:{required:!0,tsType:{name:"ReactNode"},description:""},flush:{required:!1,tsType:{name:"boolean"},description:""}}};const he=(e,t={leftAligned:"",rightAligned:"",centerAligned:""},r=!1)=>{if(!e)return null;const{bodyAlignment:i,headerAlignment:a,isHeader:o}=e;switch(o&&a?a:i){case h.LEFT:return r?h.LEFT:t.leftAligned;case h.RIGHT:return r?h.RIGHT:t.rightAligned;case h.CENTER:return r?h.CENTER:t.centerAligned;default:return r?h.LEFT:t.leftAligned}},_n=(e,t=!1,r=0)=>{if(!e||e.length===0)return[];const i=e.every(o=>Array.isArray(o)),a=e.every(o=>typeof o=="string");return i&&t?e[r]||[]:a?e:(console.warn("getHeaderAlignment: alignments array contains a mix of strings and arrays, returning an empty array."),[])},wn="_inputInTable_ie6ng_1",xn="_inputHover_ie6ng_13",Tn="_inputFocus_ie6ng_18",vn="_inputError_ie6ng_25",An="_inputWarning_ie6ng_26",Rn="_inputDisabled_ie6ng_61",jn="_hideScrollbars_ie6ng_67",kn="_cell_ie6ng_77",qn="_disabledLink_ie6ng_87",Nn="_inputWrapper_ie6ng_91",Sn="_numberInputWrapper_ie6ng_106",En="_breakWord_ie6ng_113",Hn="_inputCell_ie6ng_116",Ln="_sliderCell_ie6ng_119",Wn="_staticCell_ie6ng_123",Fn="_staticCellContent_ie6ng_126",Pn="_unit_ie6ng_148",Dn="_sortingCell_ie6ng_151",On="_sortingCellIcon_ie6ng_162",Bn="_icon_ie6ng_173",$n="_checkBoxCell_ie6ng_177",Mn="_iconCellWrapper_ie6ng_181",Gn="_actionsCell_ie6ng_185",Vn="_rightAligned_ie6ng_193",Un="_centerAligned_ie6ng_199",zn="_leftAligned_ie6ng_205",Kn="_popover_ie6ng_208",Xn="_disabledPointerEvents_ie6ng_211",l={inputInTable:wn,inputHover:xn,inputFocus:Tn,inputError:vn,inputWarning:An,inputDisabled:Rn,hideScrollbars:jn,cell:kn,disabledLink:qn,inputWrapper:Nn,numberInputWrapper:Sn,breakWord:En,inputCell:Hn,sliderCell:Ln,staticCell:Wn,staticCellContent:Fn,unit:Pn,sortingCell:Dn,sortingCellIcon:On,icon:Bn,checkBoxCell:$n,iconCellWrapper:Mn,actionsCell:Gn,rightAligned:Vn,centerAligned:Un,leftAligned:zn,popover:Kn,disabledPointerEvents:Xn},te=({cell:e,columnAlignment:t,testId:r,type:i})=>n.jsx($e,{name:e.name,value:e.value,onChange:a=>{var o;return(o=e.onChange)==null?void 0:o.call(e,a)},onFocus:e.onFocus,onBlur:e.onBlur,onPaste:a=>{var o;return(o=e.onPaste)==null?void 0:o.call(e,a)},placeholder:e.placeholder,error:e.error,warning:e.warning,disabled:e.disabled,isInTable:!0,maxTooltipWidth:e.maxTooltipWidth,right:t===h.RIGHT,testId:r,tabIndex:e.disabled?-1:0,tooltip:e.tooltip,type:i});te.__docgenInfo={description:"",methods:[],displayName:"InputCell",props:{cell:{required:!0,tsType:{name:"IInputCell"},description:""},columnAlignment:{required:!1,tsType:{name:"union",raw:"Align.LEFT | Align.RIGHT | string",elements:[{name:"Align.LEFT"},{name:"Align.RIGHT"},{name:"string"}]},description:""},testId:{required:!1,tsType:{name:"string"},description:""},type:{required:!1,tsType:{name:"union",raw:"'text' | 'date'",elements:[{name:"literal",value:"'text'"},{name:"literal",value:"'date'"}]},description:""}}};const _e=({cell:e,testId:t})=>n.jsx(Me,{name:e.name,value:e.value,onChange:r=>{var i;return(i=e.onChange)==null?void 0:i.call(e,r)},onFocus:e.onFocus,onBlur:e.onBlur,placeholder:e.placeholder,error:e.error,warning:e.warning,disabled:e.disabled,isInTable:!0,left:e.left,tabIndex:e.disabled?-1:0,testId:t,tooltip:e.tooltip,validationCallback:e.validationCallback,allowEmpty:e.allowEmpty,enableCosmeticRounding:e.enableCosmeticRounding,enableDisplayRounding:e.enableDisplayRounding,roundDisplayValue:e.roundDisplayValue});_e.__docgenInfo={description:"",methods:[],displayName:"NumberInputCell",props:{cell:{required:!0,tsType:{name:"INumberInputCell"},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};const we=({cell:e,columnAlignment:t,testId:r})=>n.jsx(Ge,{name:e.name,borderRadius:0,options:e.options,onChange:i=>{var a;return(a=e.onChange)==null?void 0:a.call(e,i)},onCreate:e.onCreate?i=>e.onCreate&&e.onCreate(i):void 0,error:e.error,warning:e.warning,disabled:e.disabled,placeholder:e.placeholder,isInTable:!0,value:e.value,native:e.native,clearable:e.clearable,searchable:e.searchable,deprecatedEventHandler:e.deprecatedEventHandler,maxTooltipWidth:e.maxTooltipWidth,width:"100%",autoLayerWidth:e.autoLayerWidth,multi:e.multi,right:t===h.RIGHT,testId:r,tabIndex:e.disabled?-1:0});we.__docgenInfo={description:"",methods:[],displayName:"SelectCell",props:{cell:{required:!0,tsType:{name:"ISelectCell"},description:""},columnAlignment:{required:!1,tsType:{name:"union",raw:"Align.LEFT | Align.RIGHT | string",elements:[{name:"Align.LEFT"},{name:"Align.RIGHT"},{name:"string"}]},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};const xe=({cell:e,columnAlignment:t,testId:r})=>n.jsx("div",{className:T(l.inputWrapper,e.type==="NumberInput"?l.numberInputWrapper:""),children:e.type==="Input"?n.jsx(te,{cell:e,columnAlignment:t,testId:r}):e.type==="NumberInput"?n.jsx(_e,{cell:e,testId:r}):e.type==="DateInput"?n.jsx(te,{cell:e,testId:r,type:"date"}):e.type==="Select"?n.jsx(we,{cell:e,columnAlignment:t,testId:r}):null});xe.__docgenInfo={description:"",methods:[],displayName:"InputCellWrapper",props:{cell:{required:!0,tsType:{name:"any"},description:""},columnAlignment:{required:!0,tsType:{name:"union",raw:"Align.LEFT | Align.RIGHT | string",elements:[{name:"Align.LEFT"},{name:"Align.RIGHT"},{name:"string"}]},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};const Te=({cell:e,testId:t})=>{const r=S.useContext(Ve),{error:i,warning:a,tooltip:o,maxTooltipWidth:s}=e,c=d=>M(d);return n.jsx("div",{className:l.inputWrapper,children:n.jsx(ie,{error:!!i,warning:!!a,text:o||i||a,enabled:c(o)||c(i)||c(a)||!1,maxWidth:s,placement:"bottom-center",children:n.jsx("div",{className:l.staticCellContent,"data-error":i||null,"data-warning":a||null,children:n.jsx("a",{className:T((e.disabled||r)&&l.disabledLink),onClick:e.disabled||r?void 0:d=>{var p;d.stopPropagation(),(p=e.onClick)==null||p.call(e,d)},"data-testid":t,children:e.value})})})})};Te.__docgenInfo={description:"",methods:[],displayName:"LinkCell",props:{cell:{required:!0,tsType:{name:"ILinkCell"},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};const ve=({cell:e,testId:t})=>n.jsx(Ue,{label:e.label,checked:e.checked,isInTable:!0,disabled:e.disabled,onChange:r=>e.onChange(r),testId:t,tabIndex:e.disabled?-1:0});ve.__docgenInfo={description:"",methods:[],displayName:"CheckBoxCell",props:{cell:{required:!0,tsType:{name:"ICheckBoxCell"},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};const Ae=({cell:e})=>n.jsx("div",{className:l.inputWrapper,children:n.jsx(ze,{label:e.label,value:e.value,min:e.min,max:e.max,step:e.step,marks:e.marks,onChange:t=>e.onChange(t),showArrows:e.showArrows,showTooltip:e.showTooltip,tooltipFormatter:e.tooltipFormatter,disabled:e.disabled})});Ae.__docgenInfo={description:"",methods:[],displayName:"SliderCell",props:{cell:{required:!0,tsType:{name:"ISliderCell"},description:""}}};const Re=({cell:e})=>{const{tooltip:t,icon:r}=e;return n.jsx("div",{className:l.iconCellWrapper,children:n.jsx(ie,{text:t,enabled:!!t&&M(t),display:"flex",placement:"top-center",children:n.jsx(G,{icon:r})})})};Re.__docgenInfo={description:"",methods:[],displayName:"IconCell",props:{cell:{required:!0,tsType:{name:"IIconCell"},description:""}}};const je=({cell:e})=>n.jsx(ae,{actions:e.actions});je.__docgenInfo={description:"",methods:[],displayName:"ActionsCell",props:{cell:{required:!0,tsType:{name:"IActionCell"},description:""}}};const ke=({cell:e})=>{const{helpIcon:t}=e;return t?n.jsx("div",{className:l.icon,children:n.jsx(fe,{onClick:t.onClick,text:t.tooltip})}):null};ke.__docgenInfo={description:"",methods:[],displayName:"CellHelpIcon",props:{cell:{required:!0,tsType:{name:"IHelpIconCell"},description:""}}};const qe=({cell:e})=>{const{libraryIcon:t}=e;return t?n.jsx("div",{className:l.icon,children:n.jsx(fe,{onClick:t.onClick,text:t.tooltip,icon:$.LIBRARY})}):null};qe.__docgenInfo={description:"",methods:[],displayName:"CellLibraryIcon",props:{cell:{required:!0,tsType:{name:"ILibraryIconCell"},description:""}}};const Ne=({cell:e})=>{const{hasSort:t,sort:r,sortPriority:i}=e;return t?n.jsxs("span",{className:l.sortingCellIcon,children:[r==="down"?n.jsx(Y,{link:!0,children:n.jsx(G,{icon:$.SORT_ASCENDING})}):r==="up"?n.jsx(Y,{link:!0,children:n.jsx(G,{icon:$.SORT_DESCENDING})}):n.jsx(Y,{faint:!0,children:n.jsx(G,{icon:$.SORT_DESCENDING})}),i&&r?n.jsx("sup",{children:i}):null]}):null};Ne.__docgenInfo={description:"",methods:[],displayName:"Sort",props:{cell:{required:!0,tsType:{name:"ISortCell"},description:""}}};const oe=({cell:e,isHeader:t,testId:r})=>{const{error:i,warning:a,tooltip:o,maxTooltipWidth:s,hasSort:c,onSort:d,type:p}=e,u=n.jsxs("div",{className:T(l.staticCellContent,p==="Unit"?l.unit:""),onClick:c?y=>d&&d(y):()=>{},"data-error":i||null,"data-warning":a||null,"data-testid":r,children:[e.value,t?n.jsxs(n.Fragment,{children:[n.jsx(ke,{cell:e}),n.jsx(qe,{cell:e}),n.jsx(Ne,{cell:e})]}):null]});return n.jsx("div",{className:l.inputWrapper,children:n.jsx(ie,{error:!!i,warning:!!a,text:o||i||a,enabled:o&&M(o)||i&&M(i)||a&&M(a)||!1,maxWidth:s,display:"block",placement:"bottom-center",children:u})})};oe.__docgenInfo={description:"",methods:[],displayName:"StaticCell",props:{cell:{required:!0,tsType:{name:"IStaticCell"},description:""},isHeader:{required:!1,tsType:{name:"boolean"},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};const Se=({cell:e,testId:t})=>{const{content:r,fullWidth:i,closeOnOutsideClick:a,disabled:o}=e;return n.jsx(Ke,{content:r,fullWidth:i,closeOnOutsideClick:a,disabled:o,children:n.jsx("div",{className:l.popover,children:n.jsx(oe,{cell:e,testId:t})})})};Se.__docgenInfo={description:"",methods:[],displayName:"PopoverCell",props:{cell:{required:!0,tsType:{name:"IPopoverCell"},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};const Ee=({cell:e,isHeader:t,columnAlignment:r,testId:i})=>{if(!e)return null;switch(e.type){case"Input":case"NumberInput":case"DateInput":case"Select":return n.jsx(xe,{cell:e,columnAlignment:r,testId:i});case"Link":return n.jsx(Te,{cell:e,testId:i});case"CheckBox":return n.jsx(ve,{cell:e,testId:i});case"Slider":return n.jsx(Ae,{cell:e});case"Icon":return n.jsx(Re,{cell:e});case"Actions":return n.jsx(je,{cell:e});case"Popover":return n.jsx(Se,{cell:e});default:return n.jsx(oe,{cell:e,isHeader:t,testId:i})}};Ee.__docgenInfo={description:"",methods:[],displayName:"CellWrapper",props:{cell:{required:!0,tsType:{name:"any"},description:""},isHeader:{required:!0,tsType:{name:"boolean"},description:""},columnAlignment:{required:!0,tsType:{name:"union",raw:"Align.LEFT | Align.RIGHT | string",elements:[{name:"Align.LEFT"},{name:"Align.RIGHT"},{name:"string"}]},description:""},testId:{required:!1,tsType:{name:"string"},description:""}}};var j=(e=>(e.INPUT="Input",e.NUMBER_INPUT="NumberInput",e.SELECT="Select",e.POPOVER="Popover",e.SLIDER="Slider",e.CHECKBOX="CheckBox",e.ACTIONS="Actions",e.AUTO_UNIT="AutoUnit",e))(j||{});const re=({cell:e,isHeader:t,columnHeaderAlignment:r,columnAlignment:i=h.LEFT,width:a,snapshot:o,testId:s})=>{if(!e)return null;const{style:c,colSpan:d,rowSpan:p,width:u}=e,y=S.useRef(null),I={bodyAlignment:i,headerAlignment:r,isHeader:t},W=he(I,l),f=he(I,l,!0),F=e.type===j.INPUT||e.type===j.NUMBER_INPUT||e.type===j.SELECT||e.type===j.POPOVER?l.inputCell:e.type===j.SLIDER?l.sliderCell:e.type===j.CHECKBOX?l.checkBoxCell:e.type===j.ACTIONS?l.actionsCell:l.staticCell,v=T(l.cell,F,e.hasSort?l.sortingCell:null,W,e.breakWord?l.breakWord:""),E=u??a??((o==null?void 0:o.isDragging)&&y.current&&y.current.offsetWidth)??void 0,_={width:E,minWidth:E,...c},A=t?"th":"td";return n.jsx(A,{ref:y,className:v,style:_,colSpan:d,rowSpan:p,children:n.jsx(Ee,{cell:e,columnAlignment:f??h.RIGHT,isHeader:t,testId:s})})};re.__docgenInfo={description:"",methods:[],displayName:"Cell",props:{cell:{required:!1,tsType:{name:"union",raw:`| IPopoverCell
|
|
2
2
|
| IStaticCell
|
|
3
3
|
| ISelectCell
|
|
4
4
|
| IHelpIconCell
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as n}from"./jsx-runtime-eps93zm2.js";import{r as S}from"./index-DhsZuJvc.js";import{f as ne}from"./immer.esm-BwVl9PS2.js";import{l as Z}from"./lodash-c4VUpsOs.js";import{G as le}from"./grid-DRkC-bt8.js";import{T as W}from"./text-B3-TSWok.js";import{T as D}from"./table-DPbEkZqw.js";import{C as dn}from"./card-EcjmryU9.js";import{I as se}from"./input-Db9WkmPP.js";import{F as oe}from"./field-HrLaMLbx.js";import{H as un}from"./heading-CRNoBc7q.js";import{t as ae,x as pn,y as mn,z as gn,A as bn,B as hn,C as wn,D as yn}from"./table.stories-data-C7mC5R8Q.js";import"./styled-components.browser.esm-BQ9GQzDc.js";import"./index-Bk2sglWO.js";import"./index.es-DazXb-ul.js";import"./inheritsLoose-DP0QEDDI.js";import"./redux-tRgGMjwY.js";import"./objectSpread2-DW4nTBoq.js";import"./tiny-invariant-DqLgxztJ.js";import"./index-CUZDtIZe.js";import"./memoize-one.esm-CcMeOnPo.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./actions-Bax0KeqM.js";import"./common-types-Sih75Sav.js";import"./disabled-context-rmpd7YJS.js";import"./button-Cbv7WK6k.js";import"./spinner-AWUe4xwQ.js";import"./icon-BSFY3vDO.js";import"./index-CEuq6vkz.js";import"./tooltip-1V7clEnw.js";import"./types-BmbYqTX_.js";import"./types-Dx2TtIG9.js";import"./badge-CLQ59MDF.js";import"./pagination-CoyQUC4R.js";import"./select-BQzJMnK1.js";import"./enum-Bnn40S8Q.js";import"./assertThisInitialized-B9jnkVVz.js";import"./select.input-CJed_LLR.js";import"./helpers-JJxzGegQ.js";import"./input-group-BaRSJAEN.js";import"./input-group-addon-D68iUKV2.js";import"./number-input-CNnU6gOF.js";import"./index-C0x1JmaP.js";import"./index-DRSy5Ssd.js";import"./check-box-DPLaOkRR.js";import"./help-icon-Buhx5nl6.js";import"./slider-CcpE4BLD.js";import"./index-BI4_Bp97.js";import"./popover-C_2P8LFJ.js";import"./label-CqmyC9he.js";import"./flex-EllkLxgO.js";const ht={title:"Basic/Table",component:D,args:{table:{...ae}}},A=h=>n.jsx(D,{...h}),te=A.bind({}),E=A.bind({});E.args={table:{...ae,fixedWidth:"400px"}};const L=A.bind({});L.args={table:{...ae,fixedWidth:"auto"}};const _=A.bind({});_.args={table:pn};_.parameters={docs:{description:{story:"Use sparingly when certain columns cannot be below a certain width. Unless the Table is auto width, set one column to `auto` to use remaining space."}}};const Q=A.bind({});Q.args={table:mn};const O=A.bind({});O.args={table:gn};O.parameters={docs:{description:{story:"This is only required when you need to override `columnAlignment` in header cells (i.e. they have different alignment)"}}};const G=A.bind({});G.args={table:bn};const N=A.bind({});N.args={table:hn};N.decorators=[h=>n.jsx("div",{style:{position:"absolute",inset:0,padding:"var(--padding)"},children:n.jsx(h,{})})];const U=A.bind({});U.args={table:wn};U.parameters={docs:{description:{story:"If a `maxHeight` is set, the table should only fill that height if it needs to."}}};const $=A.bind({});$.args={table:yn};const M=()=>n.jsx(dn,{heading:n.jsx(un,{children:"Card heading"}),padding:!1,children:n.jsx(D,{table:{...ae,bordered:!1}})});M.parameters={docs:{source:{type:"dynamic"}}};const q=()=>{const h=["Section","Width","Height"];let g=["","m","m"],o=[...Array(175).keys()].map((l,t)=>[t,t*2,t*2]);const x=(l,t,r)=>l==="m"&&t==="ft"?r*3.28084:l==="ft"&&t==="m"?r/3.28084:r,i=(l,t,r,c)=>{o[t][r]=l.target.value,c()},R=l=>{o=o.concat([["","",""]]),l()},k=(l,t)=>{o=o.filter((r,c)=>c!==l),t()},p=(l,t,r)=>{const c=g[t],b=l.target.value;g=g.map((y,s)=>s===t?b:y),o=o.map(y=>y.map((s,u)=>u===t?x(c,b,s):s)),r()},w=()=>{const l=[{label:"10 / page",value:10},{label:"20 / page",value:20},{label:"50 / page",value:50},{label:"Show all",value:0}],[t,r]=S.useState(10),[c,b]=S.useState(1),[y,s]=S.useState(!1),u=()=>{s(!y)},j=()=>{const e=Math.ceil(o.length/t);b(e)},T=(c-1)*t,a=t===0?o.length-1:T+t,m={headers:[{cells:h.map(e=>({value:e})),actions:[{primary:!0,label:"Add",icon:"add",onClick:()=>{R(u),j()}}]},{cells:[{},{options:[{label:"m",value:"m"},{label:"ft",value:"ft"}],value:g[1],type:"Select",native:!0,onChange:e=>p(e,1,u)},{options:[{label:"m",value:"m"},{label:"ft",value:"ft"}],value:g[2],type:"Select",native:!0,onChange:e=>p(e,2,u)}]}],rows:o.slice(T,a).map((e,d)=>{const I=T+d;return{cells:[...Array(3).keys()].map((P,v)=>({value:e[v],type:"Input",onChange:C=>i(C,I,v,u)})),actions:[{label:"Delete",icon:"minus",onClick:()=>k(I,u)}]}}),footer:{pagination:{rowCount:o.length,selectedPage:c,rowsPerPage:{onChange:e=>{const{value:d}=e.target;r(Number(d))},options:l,value:t},onSelectPage:e=>b(e),small:!0}}};return n.jsx(D,{table:m})};return n.jsx(w,{})},K=()=>{const h=["Section","Width","Height"];let g=[...Array(20).keys()].map((x,i)=>({Section:Z.random(0,100),Width:Z.random(0,100),Height:Z.random(0,100)}));const o=()=>{const[x,i]=S.useState({Section:"up"}),R=(r,c)=>r.sort((b,y)=>Object.entries(c).map(([s,u])=>{switch(u){case"up":return b[s]-y[s];case"down":return y[s]-b[s];default:return 0}}).reduce((s,u)=>s||u,0)),k=(r,c,b)=>({dataSortCells:r.map(s=>{const u=Object.keys(c).includes(s)?c[s]:"",j=`${s[0].toUpperCase()}${s.slice(1)}`;return{key:s,value:j,hasSort:!0,sort:u,onSort:()=>{const T=u==="up"?"down":"up";b({[s]:T})}}})}),{dataSortCells:p}=k(h,x,i),l=[...R(g,x).map(r=>({cells:Object.entries(r).map(([b,y])=>({key:b,value:y,type:"Input",disabled:!0}))}))],t={headers:[{cells:p}],rows:l};return n.jsx(D,{table:t})};return n.jsx(o,{})},B=()=>{const h=["Section","Width","Height"];let g=[...Array(175).keys()].map((x,i)=>({Section:i,Width:i*2,Height:i*2}));const o=()=>{const x=[{label:"10 / page",value:10},{label:"20 / page",value:20},{label:"50 / page",value:50},{label:"Show all",value:0}],[i,R]=S.useState(10),[k,p]=S.useState(1),[w,l]=S.useState({}),[t,r]=S.useState({});S.useEffect(()=>{p(1)},[w,t]);const c=(k-1)*i,b=i===0?g.length-1:c+i,y=(e,d,I)=>e.filter(P=>Object.keys(d).every(v=>d[v]===""?!0:P[v].toString().includes(d[v]))).sort((P,v)=>Object.entries(I).map(([C,H])=>{switch(H){case"up":return P[C]-v[C];case"down":return v[C]-P[C];default:return 0}}).reduce((C,H)=>C||H,0)),s=(e,d,I,P,v)=>{const C=e.map(f=>{const V=Object.keys(P).includes(f)?P[f]:"",F=`${f[0].toUpperCase()}${f.slice(1)}`;return{key:f,value:F,hasSort:!0,sort:V,onSort:()=>{const ee=V===""?"up":V==="up"?"down":"";v({...P,[f]:ee})}}}),H=e.map(f=>{const V=Object.keys(d).includes(f)?d[f]:"";return{key:f,value:V,type:"Input",placeholder:"Filter",onChange:F=>I({...d,[f]:F.target.value})}});return{dataSortCells:C,dataFilterCells:H}},{dataSortCells:u,dataFilterCells:j}=s(h,w,l,t,r),T=y(g,w,t),a=[...T.slice(c,b).map(e=>({cells:Object.entries(e).map(([I,P])=>({key:I,value:P,type:"Input",disabled:!0}))}))],m={headers:[{cells:u},{cells:j}],rows:a,footer:{pagination:{rowCount:T.length,selectedPage:k,rowsPerPage:{onChange:e=>{const{value:d}=e.target;R(Number(d))},options:x,value:i},onSelectPage:e=>p(e),small:!0}}};return n.jsx(D,{table:m})};return n.jsx(o,{})},z=()=>{const h={tea:3.6,coffee:3.2,orange:4.1},g=[{label:"Tea",value:"tea"},{label:"Coffee",value:"coffee"},{label:"Orange juice",value:"orange"}],o={cells:[{type:"Select",options:g,value:{value:"tea"}},{type:"Input"},{type:"Static"}]},x=[...Array(15).keys()].map((a,m)=>({cells:[{type:"Select",options:g,value:{value:"tea"}},{type:"Input",value:m+1},{type:"Static"}]})),[i,R]=S.useState(x),k=[{label:"10 / page",value:10},{label:"20 / page",value:20},{label:"50 / page",value:50},{label:"Show all",value:0}],[p,w]=S.useState(10),[l,t]=S.useState(1),r=(l-1)*p,c=p===0?i.length-1:r+p,b=({newRow:a}={})=>{const m=ne(i,e=>{e.push(a??o)});R(m)},y=({rowIndex:a})=>{const m=ne(i,e=>{delete e[a]}).filter(e=>e);R(m)},s=({rowIndex:a,value:m})=>{const e=ne(i,d=>{d[a].cells[0].value.value=m});R(e)},u=({rowIndex:a,value:m})=>{const e=ne(i,d=>{d[a].cells[1].value=m});R(e)},j=({value:a})=>{const m=Number(a);return!Z.isNaN(m)&&Z.isInteger(m)&&m>0},T=i.slice(r,c).map((a,m)=>{const e=r+m;return i.length-1,{...a,cells:a==null?void 0:a.cells.map((d,I)=>{var f,V,F,ee,ie;const P=(F=(V=(f=a==null?void 0:a.cells)==null?void 0:f[0])==null?void 0:V.value)==null?void 0:F.value,v=Number((ie=(ee=a==null?void 0:a.cells)==null?void 0:ee[1])==null?void 0:ie.value),C=h==null?void 0:h[P],H=C&&j({value:v})?(C*v).toFixed(2):null;if(I===0)return{...d,onChange:re=>s({rowIndex:e,value:re.target.value})};if(I===1)return{...d,onChange:re=>u({rowIndex:e,value:re.target.value}),error:j({value:d.value})?null:"Must be valid whole number"};if(I===2)return{...d,value:H}}),actions:[{label:"Delete",icon:"minus",onClick:()=>y({rowIndex:e})}]}});return n.jsx(D,{table:{defaultEmptyRow:o,onAddRow:b,columnAlignment:["left","right","right"],headers:[{cells:[{value:"Drink"},{value:"Quantity"},{value:"Total Price (£)"}],actions:[{primary:!0,icon:"plus",label:"Add",onClick:()=>b()}]}],rows:T,footer:{pagination:{rowCount:i.length,selectedPage:l,rowsPerPage:{onChange:a=>{const{value:m}=a.target;w(Number(m))},options:k,value:p},onSelectPage:a=>t(a),small:!0}}}})},J=()=>{const h=["Section","Width","Height"];let g=Array.from(Array(10),(p,w)=>[w,w*2,w*2]);const[o,x]=S.useState({pastedValues:"",rowIndex:0,cellIndex:0}),i=(p,w,l,t)=>{g[w][l]=Number(p.target.value),t()},R=(p,w,l,t)=>{var c;let r=((c=p==null?void 0:p.clipboardData)==null?void 0:c.getData("text"))??"";return x({rowIndex:w,cellIndex:l,pastedValues:r}),t(),{pastedData:o}},k=()=>{const[p,w]=S.useState(!1),l=()=>{w(!p)},t={headers:[{cells:h.map(r=>({value:r}))}],rows:g.map((r,c)=>{const b=c;return{cells:[...Array(3).keys()].map((y,s)=>({value:r[s],type:"Input",onChange:u=>i(u,b,s,l),onPaste:u=>R(u,b,s,l)}))}})};return n.jsxs(n.Fragment,{children:[n.jsx(D,{table:t}),n.jsx(oe,{label:"Pasted Data",children:n.jsx(se,{value:o.pastedValues})}),n.jsx(oe,{label:"At Row",children:n.jsx(se,{value:o.rowIndex})}),n.jsx(oe,{label:"At Cell Index",children:n.jsx(se,{value:o.cellIndex})})]})};return n.jsx(k,{})},X=()=>{const h={fixedWidth:"auto",name:"Table title",actions:[{icon:"download",tooltip:"Download"}],columnAlignment:[...Array(10)].map((g,o)=>"right"),headers:[{cells:[...Array(10)].map((g,o)=>({value:"Heading"}))},{cells:[...Array(10)].map((g,o)=>({options:[{label:"m",value:"m"},{label:"ft",value:"ft"}],type:"Select",searchable:!1,value:{label:"m",value:"m"},autoLayerWidth:!0}))}],rows:[...Array(10)].map((g,o)=>({cells:[...Array(10)].map((x,i)=>({value:123.45})),actions:[{icon:"help",tooltip:n.jsxs(le,{children:[n.jsx(W,{bold:!0,children:"Title goes here lorem ipsum"}),n.jsx(W,{children:"Label: 123.45m"}),n.jsx(W,{children:"Another label: 123.45m"}),n.jsx(W,{children:"Label: 123.45m"})]})}]}))};return n.jsx(D,{table:h})},Y=()=>{const h={fixedWidth:"auto",name:"Table title",actions:[{icon:"download",tooltip:"Download"}],headers:[{cells:[{value:"Label"},{value:"Value",colSpan:2}]}],rows:[{cells:[{value:"Country",style:{fontWeight:"bold"},width:"120px"},{value:"Norway",colSpan:2}],actions:[{icon:"help",tooltip:n.jsxs(le,{children:[n.jsx(W,{bold:!0,children:"Title goes here"}),n.jsx(W,{children:"Details go here"})]})}]},{cells:[{value:"Depth",style:{fontWeight:"bold"}},{value:123,width:"80px"},{options:[{label:"m",value:"m"},{label:"ft",value:"ft"}],value:{label:"m",value:"m"},type:"Select",width:"80px"}],actions:[{icon:"help",tooltip:n.jsxs(le,{children:[n.jsx(W,{bold:!0,children:"Title goes here"}),n.jsx(W,{children:"Details go here"})]})}]}]};return n.jsx(D,{table:h})};M.__docgenInfo={description:"",methods:[],displayName:"InCard"};q.__docgenInfo={description:"",methods:[],displayName:"Managed"};K.__docgenInfo={description:"",methods:[],displayName:"ManagedWithSort"};B.__docgenInfo={description:"",methods:[],displayName:"ManagedWithFilterAndMultipleSort"};z.__docgenInfo={description:"",methods:[],displayName:"AutoAddNewRow"};J.__docgenInfo={description:"",methods:[],displayName:"OnPasteCallback"};X.__docgenInfo={description:"",methods:[],displayName:"ExampleTableWithInfoTooltips"};Y.__docgenInfo={description:"",methods:[],displayName:"ExampleTableWithInlineUnits"};var ce,de,ue;te.parameters={...te.parameters,docs:{...(ce=te.parameters)==null?void 0:ce.docs,source:{originalSource:`args => {
|
|
1
|
+
import{j as n}from"./jsx-runtime-eps93zm2.js";import{r as S}from"./index-DhsZuJvc.js";import{f as ne}from"./immer.esm-BwVl9PS2.js";import{l as Z}from"./lodash-c4VUpsOs.js";import{G as le}from"./grid-DRkC-bt8.js";import{T as W}from"./text-B3-TSWok.js";import{T as D}from"./table-DoyDBG6l.js";import{C as dn}from"./card-EcjmryU9.js";import{I as se}from"./input-Db9WkmPP.js";import{F as oe}from"./field-HrLaMLbx.js";import{H as un}from"./heading-CRNoBc7q.js";import{t as ae,x as pn,y as mn,z as gn,A as bn,B as hn,C as wn,D as yn}from"./table.stories-data-C7mC5R8Q.js";import"./styled-components.browser.esm-BQ9GQzDc.js";import"./index-Bk2sglWO.js";import"./index.es-DazXb-ul.js";import"./inheritsLoose-DP0QEDDI.js";import"./redux-tRgGMjwY.js";import"./objectSpread2-DW4nTBoq.js";import"./tiny-invariant-DqLgxztJ.js";import"./index-CUZDtIZe.js";import"./memoize-one.esm-CcMeOnPo.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./actions-Bax0KeqM.js";import"./common-types-Sih75Sav.js";import"./disabled-context-rmpd7YJS.js";import"./button-Cbv7WK6k.js";import"./spinner-AWUe4xwQ.js";import"./icon-BSFY3vDO.js";import"./index-CEuq6vkz.js";import"./tooltip-1V7clEnw.js";import"./types-BmbYqTX_.js";import"./types-Dx2TtIG9.js";import"./badge-CLQ59MDF.js";import"./pagination-CR1nxnnq.js";import"./select-Cwks-WA0.js";import"./enum-Bnn40S8Q.js";import"./assertThisInitialized-B9jnkVVz.js";import"./select.input-CJed_LLR.js";import"./helpers-JJxzGegQ.js";import"./input-group-BaRSJAEN.js";import"./input-group-addon-D68iUKV2.js";import"./number-input-B3_gmeWr.js";import"./index-C0x1JmaP.js";import"./index-DRSy5Ssd.js";import"./check-box-DPLaOkRR.js";import"./help-icon-Buhx5nl6.js";import"./slider-CcpE4BLD.js";import"./index-BI4_Bp97.js";import"./popover-C_2P8LFJ.js";import"./label-CqmyC9he.js";import"./flex-EllkLxgO.js";const ht={title:"Basic/Table",component:D,args:{table:{...ae}}},A=h=>n.jsx(D,{...h}),te=A.bind({}),E=A.bind({});E.args={table:{...ae,fixedWidth:"400px"}};const L=A.bind({});L.args={table:{...ae,fixedWidth:"auto"}};const _=A.bind({});_.args={table:pn};_.parameters={docs:{description:{story:"Use sparingly when certain columns cannot be below a certain width. Unless the Table is auto width, set one column to `auto` to use remaining space."}}};const Q=A.bind({});Q.args={table:mn};const O=A.bind({});O.args={table:gn};O.parameters={docs:{description:{story:"This is only required when you need to override `columnAlignment` in header cells (i.e. they have different alignment)"}}};const G=A.bind({});G.args={table:bn};const N=A.bind({});N.args={table:hn};N.decorators=[h=>n.jsx("div",{style:{position:"absolute",inset:0,padding:"var(--padding)"},children:n.jsx(h,{})})];const U=A.bind({});U.args={table:wn};U.parameters={docs:{description:{story:"If a `maxHeight` is set, the table should only fill that height if it needs to."}}};const $=A.bind({});$.args={table:yn};const M=()=>n.jsx(dn,{heading:n.jsx(un,{children:"Card heading"}),padding:!1,children:n.jsx(D,{table:{...ae,bordered:!1}})});M.parameters={docs:{source:{type:"dynamic"}}};const q=()=>{const h=["Section","Width","Height"];let g=["","m","m"],o=[...Array(175).keys()].map((l,t)=>[t,t*2,t*2]);const x=(l,t,r)=>l==="m"&&t==="ft"?r*3.28084:l==="ft"&&t==="m"?r/3.28084:r,i=(l,t,r,c)=>{o[t][r]=l.target.value,c()},R=l=>{o=o.concat([["","",""]]),l()},k=(l,t)=>{o=o.filter((r,c)=>c!==l),t()},p=(l,t,r)=>{const c=g[t],b=l.target.value;g=g.map((y,s)=>s===t?b:y),o=o.map(y=>y.map((s,u)=>u===t?x(c,b,s):s)),r()},w=()=>{const l=[{label:"10 / page",value:10},{label:"20 / page",value:20},{label:"50 / page",value:50},{label:"Show all",value:0}],[t,r]=S.useState(10),[c,b]=S.useState(1),[y,s]=S.useState(!1),u=()=>{s(!y)},j=()=>{const e=Math.ceil(o.length/t);b(e)},T=(c-1)*t,a=t===0?o.length-1:T+t,m={headers:[{cells:h.map(e=>({value:e})),actions:[{primary:!0,label:"Add",icon:"add",onClick:()=>{R(u),j()}}]},{cells:[{},{options:[{label:"m",value:"m"},{label:"ft",value:"ft"}],value:g[1],type:"Select",native:!0,onChange:e=>p(e,1,u)},{options:[{label:"m",value:"m"},{label:"ft",value:"ft"}],value:g[2],type:"Select",native:!0,onChange:e=>p(e,2,u)}]}],rows:o.slice(T,a).map((e,d)=>{const I=T+d;return{cells:[...Array(3).keys()].map((P,v)=>({value:e[v],type:"Input",onChange:C=>i(C,I,v,u)})),actions:[{label:"Delete",icon:"minus",onClick:()=>k(I,u)}]}}),footer:{pagination:{rowCount:o.length,selectedPage:c,rowsPerPage:{onChange:e=>{const{value:d}=e.target;r(Number(d))},options:l,value:t},onSelectPage:e=>b(e),small:!0}}};return n.jsx(D,{table:m})};return n.jsx(w,{})},K=()=>{const h=["Section","Width","Height"];let g=[...Array(20).keys()].map((x,i)=>({Section:Z.random(0,100),Width:Z.random(0,100),Height:Z.random(0,100)}));const o=()=>{const[x,i]=S.useState({Section:"up"}),R=(r,c)=>r.sort((b,y)=>Object.entries(c).map(([s,u])=>{switch(u){case"up":return b[s]-y[s];case"down":return y[s]-b[s];default:return 0}}).reduce((s,u)=>s||u,0)),k=(r,c,b)=>({dataSortCells:r.map(s=>{const u=Object.keys(c).includes(s)?c[s]:"",j=`${s[0].toUpperCase()}${s.slice(1)}`;return{key:s,value:j,hasSort:!0,sort:u,onSort:()=>{const T=u==="up"?"down":"up";b({[s]:T})}}})}),{dataSortCells:p}=k(h,x,i),l=[...R(g,x).map(r=>({cells:Object.entries(r).map(([b,y])=>({key:b,value:y,type:"Input",disabled:!0}))}))],t={headers:[{cells:p}],rows:l};return n.jsx(D,{table:t})};return n.jsx(o,{})},B=()=>{const h=["Section","Width","Height"];let g=[...Array(175).keys()].map((x,i)=>({Section:i,Width:i*2,Height:i*2}));const o=()=>{const x=[{label:"10 / page",value:10},{label:"20 / page",value:20},{label:"50 / page",value:50},{label:"Show all",value:0}],[i,R]=S.useState(10),[k,p]=S.useState(1),[w,l]=S.useState({}),[t,r]=S.useState({});S.useEffect(()=>{p(1)},[w,t]);const c=(k-1)*i,b=i===0?g.length-1:c+i,y=(e,d,I)=>e.filter(P=>Object.keys(d).every(v=>d[v]===""?!0:P[v].toString().includes(d[v]))).sort((P,v)=>Object.entries(I).map(([C,H])=>{switch(H){case"up":return P[C]-v[C];case"down":return v[C]-P[C];default:return 0}}).reduce((C,H)=>C||H,0)),s=(e,d,I,P,v)=>{const C=e.map(f=>{const V=Object.keys(P).includes(f)?P[f]:"",F=`${f[0].toUpperCase()}${f.slice(1)}`;return{key:f,value:F,hasSort:!0,sort:V,onSort:()=>{const ee=V===""?"up":V==="up"?"down":"";v({...P,[f]:ee})}}}),H=e.map(f=>{const V=Object.keys(d).includes(f)?d[f]:"";return{key:f,value:V,type:"Input",placeholder:"Filter",onChange:F=>I({...d,[f]:F.target.value})}});return{dataSortCells:C,dataFilterCells:H}},{dataSortCells:u,dataFilterCells:j}=s(h,w,l,t,r),T=y(g,w,t),a=[...T.slice(c,b).map(e=>({cells:Object.entries(e).map(([I,P])=>({key:I,value:P,type:"Input",disabled:!0}))}))],m={headers:[{cells:u},{cells:j}],rows:a,footer:{pagination:{rowCount:T.length,selectedPage:k,rowsPerPage:{onChange:e=>{const{value:d}=e.target;R(Number(d))},options:x,value:i},onSelectPage:e=>p(e),small:!0}}};return n.jsx(D,{table:m})};return n.jsx(o,{})},z=()=>{const h={tea:3.6,coffee:3.2,orange:4.1},g=[{label:"Tea",value:"tea"},{label:"Coffee",value:"coffee"},{label:"Orange juice",value:"orange"}],o={cells:[{type:"Select",options:g,value:{value:"tea"}},{type:"Input"},{type:"Static"}]},x=[...Array(15).keys()].map((a,m)=>({cells:[{type:"Select",options:g,value:{value:"tea"}},{type:"Input",value:m+1},{type:"Static"}]})),[i,R]=S.useState(x),k=[{label:"10 / page",value:10},{label:"20 / page",value:20},{label:"50 / page",value:50},{label:"Show all",value:0}],[p,w]=S.useState(10),[l,t]=S.useState(1),r=(l-1)*p,c=p===0?i.length-1:r+p,b=({newRow:a}={})=>{const m=ne(i,e=>{e.push(a??o)});R(m)},y=({rowIndex:a})=>{const m=ne(i,e=>{delete e[a]}).filter(e=>e);R(m)},s=({rowIndex:a,value:m})=>{const e=ne(i,d=>{d[a].cells[0].value.value=m});R(e)},u=({rowIndex:a,value:m})=>{const e=ne(i,d=>{d[a].cells[1].value=m});R(e)},j=({value:a})=>{const m=Number(a);return!Z.isNaN(m)&&Z.isInteger(m)&&m>0},T=i.slice(r,c).map((a,m)=>{const e=r+m;return i.length-1,{...a,cells:a==null?void 0:a.cells.map((d,I)=>{var f,V,F,ee,ie;const P=(F=(V=(f=a==null?void 0:a.cells)==null?void 0:f[0])==null?void 0:V.value)==null?void 0:F.value,v=Number((ie=(ee=a==null?void 0:a.cells)==null?void 0:ee[1])==null?void 0:ie.value),C=h==null?void 0:h[P],H=C&&j({value:v})?(C*v).toFixed(2):null;if(I===0)return{...d,onChange:re=>s({rowIndex:e,value:re.target.value})};if(I===1)return{...d,onChange:re=>u({rowIndex:e,value:re.target.value}),error:j({value:d.value})?null:"Must be valid whole number"};if(I===2)return{...d,value:H}}),actions:[{label:"Delete",icon:"minus",onClick:()=>y({rowIndex:e})}]}});return n.jsx(D,{table:{defaultEmptyRow:o,onAddRow:b,columnAlignment:["left","right","right"],headers:[{cells:[{value:"Drink"},{value:"Quantity"},{value:"Total Price (£)"}],actions:[{primary:!0,icon:"plus",label:"Add",onClick:()=>b()}]}],rows:T,footer:{pagination:{rowCount:i.length,selectedPage:l,rowsPerPage:{onChange:a=>{const{value:m}=a.target;w(Number(m))},options:k,value:p},onSelectPage:a=>t(a),small:!0}}}})},J=()=>{const h=["Section","Width","Height"];let g=Array.from(Array(10),(p,w)=>[w,w*2,w*2]);const[o,x]=S.useState({pastedValues:"",rowIndex:0,cellIndex:0}),i=(p,w,l,t)=>{g[w][l]=Number(p.target.value),t()},R=(p,w,l,t)=>{var c;let r=((c=p==null?void 0:p.clipboardData)==null?void 0:c.getData("text"))??"";return x({rowIndex:w,cellIndex:l,pastedValues:r}),t(),{pastedData:o}},k=()=>{const[p,w]=S.useState(!1),l=()=>{w(!p)},t={headers:[{cells:h.map(r=>({value:r}))}],rows:g.map((r,c)=>{const b=c;return{cells:[...Array(3).keys()].map((y,s)=>({value:r[s],type:"Input",onChange:u=>i(u,b,s,l),onPaste:u=>R(u,b,s,l)}))}})};return n.jsxs(n.Fragment,{children:[n.jsx(D,{table:t}),n.jsx(oe,{label:"Pasted Data",children:n.jsx(se,{value:o.pastedValues})}),n.jsx(oe,{label:"At Row",children:n.jsx(se,{value:o.rowIndex})}),n.jsx(oe,{label:"At Cell Index",children:n.jsx(se,{value:o.cellIndex})})]})};return n.jsx(k,{})},X=()=>{const h={fixedWidth:"auto",name:"Table title",actions:[{icon:"download",tooltip:"Download"}],columnAlignment:[...Array(10)].map((g,o)=>"right"),headers:[{cells:[...Array(10)].map((g,o)=>({value:"Heading"}))},{cells:[...Array(10)].map((g,o)=>({options:[{label:"m",value:"m"},{label:"ft",value:"ft"}],type:"Select",searchable:!1,value:{label:"m",value:"m"},autoLayerWidth:!0}))}],rows:[...Array(10)].map((g,o)=>({cells:[...Array(10)].map((x,i)=>({value:123.45})),actions:[{icon:"help",tooltip:n.jsxs(le,{children:[n.jsx(W,{bold:!0,children:"Title goes here lorem ipsum"}),n.jsx(W,{children:"Label: 123.45m"}),n.jsx(W,{children:"Another label: 123.45m"}),n.jsx(W,{children:"Label: 123.45m"})]})}]}))};return n.jsx(D,{table:h})},Y=()=>{const h={fixedWidth:"auto",name:"Table title",actions:[{icon:"download",tooltip:"Download"}],headers:[{cells:[{value:"Label"},{value:"Value",colSpan:2}]}],rows:[{cells:[{value:"Country",style:{fontWeight:"bold"},width:"120px"},{value:"Norway",colSpan:2}],actions:[{icon:"help",tooltip:n.jsxs(le,{children:[n.jsx(W,{bold:!0,children:"Title goes here"}),n.jsx(W,{children:"Details go here"})]})}]},{cells:[{value:"Depth",style:{fontWeight:"bold"}},{value:123,width:"80px"},{options:[{label:"m",value:"m"},{label:"ft",value:"ft"}],value:{label:"m",value:"m"},type:"Select",width:"80px"}],actions:[{icon:"help",tooltip:n.jsxs(le,{children:[n.jsx(W,{bold:!0,children:"Title goes here"}),n.jsx(W,{children:"Details go here"})]})}]}]};return n.jsx(D,{table:h})};M.__docgenInfo={description:"",methods:[],displayName:"InCard"};q.__docgenInfo={description:"",methods:[],displayName:"Managed"};K.__docgenInfo={description:"",methods:[],displayName:"ManagedWithSort"};B.__docgenInfo={description:"",methods:[],displayName:"ManagedWithFilterAndMultipleSort"};z.__docgenInfo={description:"",methods:[],displayName:"AutoAddNewRow"};J.__docgenInfo={description:"",methods:[],displayName:"OnPasteCallback"};X.__docgenInfo={description:"",methods:[],displayName:"ExampleTableWithInfoTooltips"};Y.__docgenInfo={description:"",methods:[],displayName:"ExampleTableWithInlineUnits"};var ce,de,ue;te.parameters={...te.parameters,docs:{...(ce=te.parameters)==null?void 0:ce.docs,source:{originalSource:`args => {
|
|
2
2
|
return <Table
|
|
3
3
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
4
4
|
{...args} />;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as G}from"./jsx-runtime-eps93zm2.js";import{T as X}from"./table-
|
|
1
|
+
import{j as G}from"./jsx-runtime-eps93zm2.js";import{T as X}from"./table-DoyDBG6l.js";import{t as K,E as O,s as W,F as k,G as q,H as z,I as D,J as M,K as P,L as Q}from"./table.stories-data-C7mC5R8Q.js";import"./index-DhsZuJvc.js";import"./index-Bk2sglWO.js";import"./index.es-DazXb-ul.js";import"./inheritsLoose-DP0QEDDI.js";import"./redux-tRgGMjwY.js";import"./objectSpread2-DW4nTBoq.js";import"./tiny-invariant-DqLgxztJ.js";import"./index-CUZDtIZe.js";import"./memoize-one.esm-CcMeOnPo.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./lodash-c4VUpsOs.js";import"./actions-Bax0KeqM.js";import"./common-types-Sih75Sav.js";import"./disabled-context-rmpd7YJS.js";import"./button-Cbv7WK6k.js";import"./spinner-AWUe4xwQ.js";import"./icon-BSFY3vDO.js";import"./index-CEuq6vkz.js";import"./tooltip-1V7clEnw.js";import"./types-BmbYqTX_.js";import"./types-Dx2TtIG9.js";import"./badge-CLQ59MDF.js";import"./heading-CRNoBc7q.js";import"./help-icon-Buhx5nl6.js";import"./pagination-CR1nxnnq.js";import"./select-Cwks-WA0.js";import"./enum-Bnn40S8Q.js";import"./assertThisInitialized-B9jnkVVz.js";import"./text-B3-TSWok.js";import"./select.input-CJed_LLR.js";import"./helpers-JJxzGegQ.js";import"./input-Db9WkmPP.js";import"./input-group-BaRSJAEN.js";import"./input-group-addon-D68iUKV2.js";import"./number-input-B3_gmeWr.js";import"./index-C0x1JmaP.js";import"./index-DRSy5Ssd.js";import"./check-box-DPLaOkRR.js";import"./slider-CcpE4BLD.js";import"./index-BI4_Bp97.js";import"./popover-C_2P8LFJ.js";import"./flex-EllkLxgO.js";const Or={title:"Basic/Table/Title & Header",component:X,args:{table:{...K}}},r=B=>G.jsx(X,{...B}),e=r.bind({});e.args={table:O};const s=r.bind({});s.args={table:W};const a=r.bind({});a.args={table:k};const t=r.bind({});t.args={table:q};const o=r.bind({});o.args={table:z};const n=r.bind({});n.args={table:D};const i=r.bind({});i.args={table:M};const p=r.bind({});p.args={table:P};const m=r.bind({});m.args={table:Q};var l,c,d;e.parameters={...e.parameters,docs:{...(l=e.parameters)==null?void 0:l.docs,source:{originalSource:`args => {
|
|
2
2
|
return <Table
|
|
3
3
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
4
4
|
{...args} />;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as o}from"./jsx-runtime-eps93zm2.js";import{r as q}from"./index-DhsZuJvc.js";import{d as a}from"./index-C0x1JmaP.js";import{c as Ce}from"./index-Bk2sglWO.js";import{c as ae,i as Ne,a as Fe,g as De,u as Me,b as Pe}from"./initialize-context-
|
|
1
|
+
import{j as o}from"./jsx-runtime-eps93zm2.js";import{r as q}from"./index-DhsZuJvc.js";import{d as a}from"./index-C0x1JmaP.js";import{c as Ce}from"./index-Bk2sglWO.js";import{c as ae,i as Ne,a as Fe,g as De,u as Me,b as Pe}from"./initialize-context-Y03pJPr5.js";import{M as Y}from"./actions-Bax0KeqM.js";import{I as xe}from"./input-group-addon-D68iUKV2.js";import{B as je}from"./button-Cbv7WK6k.js";import{T as Ae}from"./tooltip-1V7clEnw.js";import{I as Se}from"./input-group-BaRSJAEN.js";import{S as Oe}from"./spacer-BWoNR27H.js";import{T as Le}from"./text-B3-TSWok.js";import{M as Z}from"./types-BmbYqTX_.js";import{l as v}from"./lodash-c4VUpsOs.js";import{N as We,r as Re}from"./number-input-B3_gmeWr.js";const He=()=>{const e=q.useRef(null);return q.useLayoutEffect(()=>{e.current&&(e.current(),e.current=null)}),m=>{e.current=m}};var d=(e=>(e.CUSTOM="custom",e.PREDEFINED="predefined",e))(d||{});const _e=e=>e?!!a.getUnit(e):!1,w=({value:e="",toUnit:f,unitkey:m,defaultFromUnit:P,doNotConvertValue:I})=>{const x=_e(e)||a.isValueWithUnit(e),y=a.getValue(e);return Ne(y)?{value:y}:x?ae({value:e,unitkey:m,toUnit:f,fromUnit:P,doNotConvertValue:I,exactPrecision:!0}):{value:e}},ee=e=>v.isObject(e)&&!v.isArray(e)&&!v.isFunction(e)?v.get(e,"fieldName",""):typeof e=="string"?e:"",te=(e="")=>{var f;return(f=a.KNOWN_UNITS)==null?void 0:f.includes(e)},ke=(e,f)=>{const m=a.getUnit(e||"");return te(f)&&te(m)},$e="_predefinedMenuActive_ye9w9_1",Be="_inputWrapper_ye9w9_4",ne={predefinedMenuActive:$e,inputWrapper:Be},Ke=({name:e,placeholder:f="",disabled:m=!1,disabledUnit:P=!1,error:I=null,left:x=!1,small:y=!1,width:R="100%",value:l,unitkey:u="",initUnit:ie,noConversion:re=!1,onChange:j=v.noop,onClick:Ge=v.noop,onFocus:se=v.noop,onSwitchUnit:H=v.noop,unitTemplate:_,doNotConvertValue:b=!1,testId:V,warning:k=null,predefinedOptions:g,initialPredefinedOption:le=!1,shouldLinkAutomaticly:$=!0,selectedPredefinedOptionKey:B,validationCallback:ue=()=>({name:"",error:null}),disabledValidation:oe=!1,allowEmpty:de=!1,autoValue:U,convertBackToStorageUnit:pe=!1,enableCosmeticRounding:K=!0,enableDisplayRounding:me=!1})=>{const h=Fe(),ce=He();typeof l=="number"&&(l=`${l}`);const[G="",T=""]=l!==void 0?a.split(l):[],Q=U?a.getUnit(U):"",z=q.useMemo(()=>De(u,_||(h==null?void 0:h.unitTemplate)),[u,_,h==null?void 0:h.unitTemplate]),fe=ke(l,z),c=ie||z||T,ge=Me(c),{value:J}=w({value:l,toUnit:c,unitkey:u,defaultFromUnit:T,doNotConvertValue:b}),{value:X}=w({value:U,toUnit:c,unitkey:u,defaultFromUnit:Q,doNotConvertValue:b}),ve=J!==""?{value:J,unit:c}:X!==""?{value:X,unit:c}:{value:G,unit:T},[i,A]=q.useState(ve),ye=de||(i==null?void 0:i.value)===void 0,[E,S]=q.useState(le?d.PREDEFINED:d.CUSTOM),O=G===""&&U,Ue=!!(oe||U),C=g&&g.find(t=>{if(!(t!=null&&t.value))return;if(B)return B===t.valueKey;const n=a.isValueWithUnit(t.value)?a.getUnit(t.value):"",{value:r=l}=ae({value:String(l),unitkey:u,toUnit:n});return a.withUnit(r,n)===t.value}),Te=()=>{const t=O?U:l??"",n=i.unit;if(Pe({value:t,unitkey:u,toUnit:n})){if(u)try{let s=a.altUnitsList(t,u);return a.getValue(t)===""?s.map(p=>["",p[1]]):s}catch{return null}}else{let s=a.getAltUnitsListByQuantity(u);return s==null?void 0:s.map(p=>["",p==null?void 0:p.unit])}},Ee=t=>{const n=ee(e),r=t.target,{value:s,selectionStart:p}=r,M=a.withUnit(s,(i==null?void 0:i.unit)||""),W=pe?a.withUnit(a.convertAndGetValue(M,T),T):M;j({target:{value:W,name:n}});const[qe,Ie]=a.split(M);A({value:qe,unit:Ie}),ce(()=>{r.selectionStart=p,r.selectionEnd=p})},be=(t,n)=>{n===i.unit||isNaN(Number(t))||(A({value:t,unit:n}),H&&H(n))};q.useEffect(()=>{if(c){let t,n="";if(ge!==c){const{value:r}=w({value:l,toUnit:c,unitkey:u,defaultFromUnit:T,doNotConvertValue:b});t=r,n=c}else if(a.withUnit(i.value,i.unit)!==l){const{value:r}=w({value:l,toUnit:i.unit,unitkey:u,defaultFromUnit:T,doNotConvertValue:b});t=r,n=i.unit}t!==void 0&&A({value:t,unit:n}),g&&S(C&&$?d.PREDEFINED:d.CUSTOM)}},[c,l,I,$]);const N=Te(),F=a.label(i.unit)||i.unit||"",Ve=re||!N||N&&N.length===1,L=ee(e);let D;const he=t=>{const n=t!=null&&t.value?t.value:"",[r="",s=""]=a.isValueWithUnit(n)?a.split(n):[n];return{type:Z.OPTION,inline:!0,onClick:()=>{a.validateNumber(r).valid&&!m&&(S(d.PREDEFINED),j({target:{value:n,name:typeof e=="string"?e:(e==null?void 0:e.fieldName)||"",predefinedSelected:!0,predefinedOption:t}}))},label:o.jsxs(o.Fragment,{children:[o.jsx(Le,{children:t.label}),o.jsx(Oe,{width:"20px",height:"0"})]}),description:a.isValueWithUnit(n)?`${r} ${s}`:n,selected:C===t&&E===d.PREDEFINED}};if(D=[{type:Z.OPTION,inline:!0,onClick:()=>{E!==d.CUSTOM&&!m&&j({target:{value:a.withUnit(i.value,i.unit),name:typeof e=="string"?e:(e==null?void 0:e.fieldName)||""}})},label:"Custom",selected:E===d.CUSTOM}],g!=null&&g.length){const t=g.map(he);D=[...D,...t]}const we=t=>{if(O){const{value:n}=w({value:U,toUnit:i.unit,unitkey:u,defaultFromUnit:Q,doNotConvertValue:b});return n}else if(a.isValueWithUnit(t)){const n=a.getUnit(t),{value:r}=w({value:t,toUnit:i.unit,unitkey:u,defaultFromUnit:n,doNotConvertValue:b});return r}return t};return o.jsx("div",{className:E===d.PREDEFINED?Ce(ne.predefinedMenuActive):"",children:o.jsxs(Se,{small:y,width:R,children:[g&&o.jsx(Ae,{text:E===d.PREDEFINED?C==null?void 0:C.label:"",children:o.jsx(Y,{maxHeight:380,groupOrder:"first",testId:V&&`${V}-predefined-menu`,disabled:m,menu:{colored:!0,trigger:"Component",component:o.jsx(je,{groupOrder:"first",active:E===d.PREDEFINED,icon:E===d.PREDEFINED?"link":"unlink"}),small:y,sections:D}})}),o.jsx("div",{className:ne.inputWrapper,children:o.jsx(We,{name:L,testId:V,disabled:m,placeholder:we(f),value:i.value,onChange:Ee,onFocus:se,error:I===null?void 0:I,warning:k===null?void 0:k,left:x,allowEmpty:ye,validationCallback:(t,n)=>ue(L,n),enableCosmeticRounding:K,enableDisplayRounding:me,groupOrder:g?"middle":"first",disableInternalErrorValidationMessages:Ue,small:y},L)}),F&&(Ve||!fe?o.jsx(xe,{groupOrder:"last",children:F}):o.jsx(Y,{maxHeight:380,groupOrder:"last",disabled:P,testId:V&&`${V}-menu`,menu:{label:F,trigger:"DropDownButton",small:y,sections:N.map(([t,n,r])=>{const s=r||n||"",p=a.isValidNum(t)?t:"";return{type:"Option",label:K?Re(p):p,inline:!0,onClick:W=>{W.stopPropagation(),be(O?"":t,n)},description:s,selected:s===F,testId:`${V}-unit-${s}`}})}}))]})})};Ke.__docgenInfo={description:"",methods:[],displayName:"UnitInput",props:{name:{required:!0,tsType:{name:"union",raw:"string | { fieldName?: string }",elements:[{name:"string"},{name:"signature",type:"object",raw:"{ fieldName?: string }",signature:{properties:[{key:"fieldName",value:{name:"string",required:!1}}]}}]},description:""},placeholder:{required:!1,tsType:{name:"string"},description:"",defaultValue:{value:"''",computed:!1}},disabled:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},disabledUnit:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},error:{required:!1,tsType:{name:"union",raw:"string | null | boolean",elements:[{name:"string"},{name:"null"},{name:"boolean"}]},description:"",defaultValue:{value:"null",computed:!1}},left:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},small:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},width:{required:!1,tsType:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},description:"",defaultValue:{value:"'100%'",computed:!1}},value:{required:!1,tsType:{name:"string"},description:""},unitkey:{required:!1,tsType:{name:"string"},description:"",defaultValue:{value:"''",computed:!1}},initUnit:{required:!1,tsType:{name:"string"},description:""},noConversion:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},doNotConvertValue:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},testId:{required:!1,tsType:{name:"string"},description:""},warning:{required:!1,tsType:{name:"union",raw:"string | boolean | null",elements:[{name:"string"},{name:"boolean"},{name:"null"}]},description:"",defaultValue:{value:"null",computed:!1}},predefinedOptions:{required:!1,tsType:{name:"union",raw:"IPredefinedOption[] | null",elements:[{name:"Array",elements:[{name:"IPredefinedOption"}],raw:"IPredefinedOption[]"},{name:"null"}]},description:""},initialPredefinedOption:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},shouldLinkAutomaticly:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},selectedPredefinedOptionKey:{required:!1,tsType:{name:"string"},description:""},validationCallback:{required:!1,tsType:{name:"signature",type:"function",raw:"(name: string, error: string | null) => any",signature:{arguments:[{type:{name:"string"},name:"name"},{type:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}]},name:"error"}],return:{name:"any"}}},description:"",defaultValue:{value:"() => ({ name: '', error: null })",computed:!1}},disabledValidation:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},allowEmpty:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},autoValue:{required:!1,tsType:{name:"string"},description:""},onChange:{required:!1,tsType:{name:"signature",type:"function",raw:"(event: TChangeEvent | ICustomChangeEvent) => void",signature:{arguments:[{type:{name:"union",raw:"TChangeEvent | ICustomChangeEvent",elements:[{name:"intersection",raw:`ChangeEvent<T> & {
|
|
2
2
|
target:
|
|
3
3
|
| T
|
|
4
4
|
| { name: string; value: any; label?: string; files?: FileList | null };
|
package/dist/storybook/assets/{unit-input.stories-CChVbxmI.js → unit-input.stories-Btz2M_TP.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as e}from"./jsx-runtime-eps93zm2.js";import{r as u}from"./index-DhsZuJvc.js";import{U as o}from"./unit-input-
|
|
1
|
+
import{j as e}from"./jsx-runtime-eps93zm2.js";import{r as u}from"./index-DhsZuJvc.js";import{U as o}from"./unit-input-BXg4VphV.js";import{B as p}from"./button-Cbv7WK6k.js";import{S as E}from"./spacer-BWoNR27H.js";import{R as Fe,C as De}from"./row-Bmiy2Lh0.js";import{F as g}from"./field-HrLaMLbx.js";import{M as Ne}from"./message-BRyKdRaX.js";import"./index-C0x1JmaP.js";import"./index-DRSy5Ssd.js";import"./index-Bk2sglWO.js";import"./initialize-context-Y03pJPr5.js";import"./number-input-B3_gmeWr.js";import"./enum-Bnn40S8Q.js";import"./index-CEuq6vkz.js";import"./lodash-c4VUpsOs.js";import"./helpers-JJxzGegQ.js";import"./input-Db9WkmPP.js";import"./disabled-context-rmpd7YJS.js";import"./types-Dx2TtIG9.js";import"./tooltip-1V7clEnw.js";import"./index-CUZDtIZe.js";import"./actions-Bax0KeqM.js";import"./common-types-Sih75Sav.js";import"./icon-BSFY3vDO.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./inheritsLoose-DP0QEDDI.js";import"./types-BmbYqTX_.js";import"./badge-CLQ59MDF.js";import"./input-group-addon-D68iUKV2.js";import"./input-group-BaRSJAEN.js";import"./text-B3-TSWok.js";import"./spinner-AWUe4xwQ.js";import"./styled-components.browser.esm-BQ9GQzDc.js";import"./label-CqmyC9he.js";import"./help-icon-Buhx5nl6.js";const{useArgs:Be}=__STORYBOOK_MODULE_PREVIEW_API__,Ua={title:"Forms/UnitInput",component:o,args:{name:"example",unitkey:"length",value:"123|m"}},s=n=>{const[r,a]=Be(),i=l=>{a({value:l.target.value})};return e.jsx(o,{...n,onChange:i})},P=s.bind({}),m=s.bind({});m.args={initUnit:"ft",unitTemplate:{length:"ft"}};const h=s.bind({});h.args={value:'123|"',unitkey:'"'};const v=s.bind({});v.args={width:"180px"};const C=s.bind({});C.args={noConversion:!0};const b=s.bind({});b.args={small:!0};const U=s.bind({});U.args={error:"Error message goes here"};const x=s.bind({});x.args={value:"asas123asd|%"};const c=s.bind({});c.args={disabled:!0,disabledUnit:!0};c.parameters={docs:{description:{story:"Each part of UnitInput can be disabled separately. `disabled` disables only the main text input, `disabledUnit` disables only the unit menu. **Needs review (comes from Reservoir input requirements)**"}}};const y=s.bind({});y.args={disabled:!0,disabledUnit:!0,noConversion:!0};const I=s.bind({});I.args={disabledUnit:!0,unitkey:void 0};const V=s.bind({});V.args={disabledUnit:!0,unitkey:"length"};const A=s.bind({});A.args={disabledUnit:!1,disabled:!0};const S=s.bind({});S.args={predefinedOptions:[{label:"bottom of casing",value:"12|km"},{label:"mud weight at shoe depth",value:"8|mm"}]};const w=()=>{const n="500px",[r,a]=u.useState("1|m"),[i,l]=u.useState("|m"),d="123|km";return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different cases for automatic (placeholder) values:"}),e.jsx(Fe,{children:e.jsxs(De,{width:"25%",children:[e.jsx(p,{label:"Change value to ''",onClick:()=>a("")}),e.jsx("br",{}),e.jsx(p,{label:"Change value to 1",onClick:()=>a("1")}),e.jsx("br",{}),e.jsx(p,{label:"Change value to 1|m",onClick:()=>a("1|m")}),e.jsx("br",{}),e.jsx(p,{label:"Change value to |m - empty value",onClick:()=>a("|m")})]})}),e.jsx("br",{}),e.jsx(g,{label:"Normal PUI (placeholder + auto)",children:e.jsx(o,{name:"example1",onChange:t=>a(t.target.value),value:r,unitkey:"length",width:n,placeholder:"value|unit",autoValue:d})}),e.jsx(g,{label:"Normal PUI (only auto)",children:e.jsx(o,{name:"example1",onChange:t=>a(t.target.value),value:r,unitkey:"length",width:n,autoValue:d})}),e.jsx(g,{label:"Empty PUI with autoValue",children:e.jsx(o,{name:"example1",onChange:t=>l(t.target.value),value:i,unitkey:"length",width:n,autoValue:d})}),e.jsx(g,{label:"Normal PUI (only placeholder)",children:e.jsx(o,{name:"example1",onChange:t=>a(t.target.value),value:r,unitkey:"length",width:n,placeholder:"Placeholder test"})}),e.jsx(g,{label:"Normal PUI (placeholder + allowEmpty)",children:e.jsx(o,{name:"example1",onChange:t=>a(t.target.value),value:r,unitkey:"length",width:n,placeholder:"Placeholder test",allowEmpty:!0})}),e.jsx(Ne,{message:{heading:"Current value inside PUI: "+r,visible:!0}})]})},j=()=>{const[n,r]=u.useState("123|%"),[a,i]=u.useState(null),l="This should be visible when an error appears",d=(t,_)=>(i(_),{name:t,error:_});return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"3rd party validation message when inputting invalid value:"}),e.jsx(o,{name:"example",onChange:t=>r(t.target.value),error:!a||l,validationCallback:d,value:n}),e.jsx("br",{}),e.jsx(E,{}),e.jsx("h4",{children:"Original validation message: "}),e.jsx(Ne,{message:{heading:a,visible:!0}})]})},k=()=>{const[n,r]=u.useState("123|m"),[a,i]=u.useState(""),[l,d]=u.useState("km"),t=()=>{d("ft"),i("placeholder"),r("|m")};return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Empty value case:"}),e.jsx(o,{name:"example",onChange:_=>r(_.target.value),value:n,allowEmpty:!0,placeholder:a,initUnit:l,unitkey:"length"}),e.jsx("br",{}),e.jsx(E,{}),e.jsx(p,{label:"Change value |m and unit ft",onClick:()=>t()})]})},f=()=>{const[n,r]=u.useState("123|m"),[a,i]=u.useState("m");return e.jsxs(e.Fragment,{children:[e.jsx(o,{name:"example",onChange:l=>r(l.target.value),value:n,initUnit:a,unitkey:"length",onSwitchUnit:i}),e.jsx(E,{}),e.jsx(o,{name:"example",onChange:l=>r(l.target.value),value:n,initUnit:a,unitkey:"length",onSwitchUnit:i})]})};w.__docgenInfo={description:"",methods:[],displayName:"AutomaticValues"};j.__docgenInfo={description:"",methods:[],displayName:"ValidationCallback"};k.__docgenInfo={description:"",methods:[],displayName:"AllowEmptyPUI"};f.__docgenInfo={description:"",methods:[],displayName:"OnSwitchUnit"};var N,F,D;P.parameters={...P.parameters,docs:{...(N=P.parameters)==null?void 0:N.docs,source:{originalSource:`args => {
|
|
2
2
|
const [_, updateArgs] = useArgs();
|
|
3
3
|
const handleChange = (evt: any) => {
|
|
4
4
|
updateArgs({
|