@oliasoft-open-source/react-ui-library 4.12.1 → 4.12.2-beta-1

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.
Files changed (43) hide show
  1. package/dist/global.css +12 -14
  2. package/dist/index.js +23 -16
  3. package/dist/index.js.map +1 -1
  4. package/dist/storybook/assets/{Color-KGDBMAHA-cuFJBfra.js → Color-KGDBMAHA-DR5riISF.js} +1 -1
  5. package/dist/storybook/assets/{DocsRenderer-PKQXORMH-CaQNyPjs.js → DocsRenderer-PKQXORMH-DoLMzUGK.js} +1 -1
  6. package/dist/storybook/assets/{accordion.stories-BlHfHegj.js → accordion.stories-CrmHu75y.js} +1 -1
  7. package/dist/storybook/assets/{buttons-and-links-CIalsKBg.js → buttons-and-links-D9QYAqXc.js} +1 -1
  8. package/dist/storybook/assets/{casing-loads.stories-Cl2tJipP.js → casing-loads.stories-Buy0-e_n.js} +1 -1
  9. package/dist/storybook/assets/{cell.stories-rzJE_qJC.js → cell.stories-CPNfDo9l.js} +1 -1
  10. package/dist/storybook/assets/{chunk-HLWAVYOI-B6tKmVAb.js → chunk-HLWAVYOI-B19gizy0.js} +1 -1
  11. package/dist/storybook/assets/{color-Db0d-sIL.js → color-DOGODpJM.js} +1 -1
  12. package/dist/storybook/assets/{footer.stories-C6M5S0UZ.js → footer.stories-DniqHrTZ.js} +1 -1
  13. package/dist/storybook/assets/{form.stories-BNORsn6Z.js → form.stories-Cr5Pz40F.js} +1 -1
  14. package/dist/storybook/assets/{formation.stories-1WX1Nu1P.js → formation.stories-C4Kugh7C.js} +1 -1
  15. package/dist/storybook/assets/{iframe-CiH1oRY9.js → iframe-DkdT7E6u.js} +2 -2
  16. package/dist/storybook/assets/{index-CFQAbfkz.js → index-BAPxTrKt.js} +1 -1
  17. package/dist/storybook/assets/{index-DxVfXBUu.js → index-CwR8VCbF.js} +88 -88
  18. package/dist/storybook/assets/{input-validation-2jw3AErr.js → input-validation-llrgZ0aw.js} +1 -1
  19. package/dist/storybook/assets/{inputs-vz_lls3e.js → inputs-D95idzfz.js} +1 -1
  20. package/dist/storybook/assets/{layout-forms-C57CCgYO.js → layout-forms-Bmc6a73a.js} +1 -1
  21. package/dist/storybook/assets/{layout-general-BrPYeT71.js → layout-general-DwimaZpH.js} +1 -1
  22. package/dist/storybook/assets/{padding-and-spacing-frCiIWTJ.js → padding-and-spacing-DX1RBvZY.js} +1 -1
  23. package/dist/storybook/assets/{preview-BtOO2cWa.js → preview-IQ_AMOjJ.js} +2 -2
  24. package/dist/storybook/assets/{preview-zxbSrXtO.js → preview-lF2OP7nL.js} +1 -1
  25. package/dist/storybook/assets/{row.stories-DRvH8Grn.js → row.stories-jKh8Ms1e.js} +1 -1
  26. package/dist/storybook/assets/{slider-DnRddBCy.css → slider-DPdTVMP0.css} +1 -1
  27. package/dist/storybook/assets/{slider-CcpE4BLD.js → slider-DxaD8LU4.js} +4 -4
  28. package/dist/storybook/assets/slider.stories-DuGie_AX.js +134 -0
  29. package/dist/storybook/assets/{table-DoyDBG6l.js → table-BSABGfWm.js} +1 -1
  30. package/dist/storybook/assets/{table.stories-BgWKzIob.js → table.stories-CHwzAdud.js} +1 -1
  31. package/dist/storybook/assets/{title.stories-Rv6ZO_Wl.js → title.stories-D0VjujmM.js} +1 -1
  32. package/dist/storybook/assets/unit-input-DTOrVqdm.js +5 -0
  33. package/dist/storybook/assets/{unit-input.stories-BP03WTYV.js → unit-input.stories-BhSBzB95.js} +1 -1
  34. package/dist/storybook/assets/{unit-input.test-case.stories-D9PyN8YI.js → unit-input.test-case.stories-Dk5SRvMt.js} +7 -12
  35. package/dist/storybook/assets/{unit-table.stories-CISvZMxX.js → unit-table.stories-DwZVHcZo.js} +1 -1
  36. package/dist/storybook/assets/{unit-table.test-case.stories-tEype9om.js → unit-table.test-case.stories-C9Swzooe.js} +1 -1
  37. package/dist/storybook/iframe.html +1 -1
  38. package/dist/storybook/index.json +1 -1
  39. package/dist/storybook/project.json +1 -1
  40. package/package.json +1 -1
  41. package/dist/404.html +0 -1
  42. package/dist/storybook/assets/slider.stories-BqlRLY_C.js +0 -171
  43. package/dist/storybook/assets/unit-input-C07ZKMj5.js +0 -10
@@ -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-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
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-DxaD8LU4.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-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 => {
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-BSABGfWm.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-DxaD8LU4.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-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 => {
1
+ import{j as G}from"./jsx-runtime-eps93zm2.js";import{T as X}from"./table-BSABGfWm.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-DxaD8LU4.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} />;
@@ -0,0 +1,5 @@
1
+ import{j as o}from"./jsx-runtime-eps93zm2.js";import{r as q}from"./index-DhsZuJvc.js";import{d as r}from"./index-C0x1JmaP.js";import{c as Ne}from"./index-Bk2sglWO.js";import{c as ne,i as Ce,a as De,g as Pe,u as Me,b as Oe}from"./initialize-context-Y03pJPr5.js";import{M as X}from"./actions-Bax0KeqM.js";import{I as Fe}from"./input-group-addon-D68iUKV2.js";import{B as Se}from"./button-Cbv7WK6k.js";import{T as xe}from"./tooltip-1V7clEnw.js";import{I as je}from"./input-group-BaRSJAEN.js";import{S as Ae}from"./spacer-BWoNR27H.js";import{T as We}from"./text-B3-TSWok.js";import{M as Y}from"./types-BmbYqTX_.js";import{l as v}from"./lodash-c4VUpsOs.js";import{N as Re,r as _e}from"./number-input-B3_gmeWr.js";const He=()=>{const e=q.useRef(null);return q.useLayoutEffect(()=>{e.current&&(e.current(),e.current=null)}),f=>{e.current=f}};var d=(e=>(e.CUSTOM="custom",e.PREDEFINED="predefined",e))(d||{});const ke=e=>{if(!e)return!1;const c=r.getUnit(e);return!r.KNOWN_UNITS.includes(c)},w=({value:e="",toUnit:c,unitkey:f,defaultFromUnit:F,doNotConvertValue:I})=>{const N=r.getValue(e),E=Ce(N);return ke(e)?{value:N}:E?{value:N}:r.isValueWithUnit(e)?ne({value:e,unitkey:f,toUnit:c,fromUnit:F,doNotConvertValue:I,exactPrecision:!0}):{value:e}},Z=e=>v.isObject(e)&&!v.isArray(e)&&!v.isFunction(e)?v.get(e,"fieldName",""):typeof e=="string"?e:"",ee=(e="")=>{var c;return(c=r.KNOWN_UNITS)==null?void 0:c.includes(e)},Le=(e,c)=>{const f=r.getUnit(e||"");return ee(c)&&ee(f)},Be="_predefinedMenuActive_ye9w9_1",$e="_inputWrapper_ye9w9_4",te={predefinedMenuActive:Be,inputWrapper:$e},Ke=({name:e,placeholder:c="",disabled:f=!1,disabledUnit:F=!1,error:I=null,left:N=!1,small:E=!1,width:re="100%",value:l,unitkey:u="",initUnit:ae,noConversion:ie=!1,onChange:S=v.noop,onClick:Ge=v.noop,onFocus:se=v.noop,onSwitchUnit:_=v.noop,unitTemplate:H,doNotConvertValue:V=!1,testId:b,warning:k=null,predefinedOptions:g,initialPredefinedOption:le=!1,shouldLinkAutomaticly:L=!0,selectedPredefinedOptionKey:B,validationCallback:ue=()=>({name:"",error:null}),disabledValidation:oe=!1,allowEmpty:de=!1,autoValue:U,convertBackToStorageUnit:pe=!1,enableCosmeticRounding:$=!0,enableDisplayRounding:ce=!1})=>{const h=De(),fe=He();typeof l=="number"&&(l=`${l}`);const[K="",y=""]=l!==void 0?r.split(l):[],G=U?r.getUnit(U):"",Q=q.useMemo(()=>Pe(u,H||(h==null?void 0:h.unitTemplate)),[u,H,h==null?void 0:h.unitTemplate]),me=Le(l,Q),m=ae||Q||y,ge=Me(m),{value:z}=w({value:l,toUnit:m,unitkey:u,defaultFromUnit:y,doNotConvertValue:V}),{value:J}=w({value:U,toUnit:m,unitkey:u,defaultFromUnit:G,doNotConvertValue:V}),ve=z!==""?{value:z,unit:m}:J!==""?{value:J,unit:m}:{value:K,unit:y},[a,x]=q.useState(ve),Ue=de||(a==null?void 0:a.value)===void 0,[T,j]=q.useState(le?d.PREDEFINED:d.CUSTOM),A=K===""&&U,ye=!!(oe||U),C=g&&g.find(t=>{if(!(t!=null&&t.value))return;if(B)return B===t.valueKey;const n=r.isValueWithUnit(t.value)?r.getUnit(t.value):"",{value:i=l}=ne({value:String(l),unitkey:u,toUnit:n});return r.withUnit(i,n)===t.value}),Te=()=>{const t=A?U:l??"",n=a.unit;if(Oe({value:t,unitkey:u,toUnit:n})){if(u)try{let s=r.altUnitsList(t,u);return r.getValue(t)===""?s.map(p=>["",p[1]]):s}catch{return null}}else{let s=r.getAltUnitsListByQuantity(u);return s==null?void 0:s.map(p=>["",p==null?void 0:p.unit])}},Ee=t=>{const n=Z(e),i=t.target,{value:s,selectionStart:p}=i,O=r.withUnit(s,(a==null?void 0:a.unit)||""),R=pe?r.withUnit(r.convertAndGetValue(O,y),y):O;S({target:{value:R,name:n}});const[qe,Ie]=r.split(O);x({value:qe,unit:Ie}),fe(()=>{i.selectionStart=p,i.selectionEnd=p})},Ve=(t,n)=>{n===a.unit||isNaN(Number(t))||(x({value:t,unit:n}),_&&_(n))};q.useEffect(()=>{if(m){let t,n="";if(ge!==m){const{value:i}=w({value:l,toUnit:m,unitkey:u,defaultFromUnit:y,doNotConvertValue:V});t=i,n=m}else if(r.withUnit(a.value,a.unit)!==l){const{value:i}=w({value:l,toUnit:a.unit,unitkey:u,defaultFromUnit:y,doNotConvertValue:V});t=i,n=a.unit}t!==void 0&&x({value:t,unit:n}),g&&j(C&&L?d.PREDEFINED:d.CUSTOM)}},[m,l,I,L]);const D=Te(),P=r.label(a.unit)||a.unit||"",be=ie||!D||D&&D.length===1,W=Z(e);let M;const he=t=>{const n=t!=null&&t.value?t.value:"",[i="",s=""]=r.isValueWithUnit(n)?r.split(n):[n];return{type:Y.OPTION,inline:!0,onClick:()=>{r.validateNumber(i).valid&&!f&&(j(d.PREDEFINED),S({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(We,{children:t.label}),o.jsx(Ae,{width:"20px",height:"0"})]}),description:r.isValueWithUnit(n)?`${i} ${s}`:n,selected:C===t&&T===d.PREDEFINED}};if(M=[{type:Y.OPTION,inline:!0,onClick:()=>{T!==d.CUSTOM&&!f&&S({target:{value:r.withUnit(a.value,a.unit),name:typeof e=="string"?e:(e==null?void 0:e.fieldName)||""}})},label:"Custom",selected:T===d.CUSTOM}],g!=null&&g.length){const t=g.map(he);M=[...M,...t]}const we=t=>{if(A){const{value:n}=w({value:U,toUnit:a.unit,unitkey:u,defaultFromUnit:G,doNotConvertValue:V});return n}else if(r.isValueWithUnit(t)){const n=r.getUnit(t),{value:i}=w({value:t,toUnit:a.unit,unitkey:u,defaultFromUnit:n,doNotConvertValue:V});return i}return t};return o.jsx("div",{className:T===d.PREDEFINED?Ne(te.predefinedMenuActive):"",children:o.jsxs(je,{small:E,width:re,children:[g&&o.jsx(xe,{text:T===d.PREDEFINED?C==null?void 0:C.label:"",children:o.jsx(X,{maxHeight:380,groupOrder:"first",testId:b&&`${b}-predefined-menu`,disabled:f,menu:{colored:!0,trigger:"Component",component:o.jsx(Se,{groupOrder:"first",active:T===d.PREDEFINED,icon:T===d.PREDEFINED?"link":"unlink"}),small:E,sections:M}})}),o.jsx("div",{className:te.inputWrapper,children:o.jsx(Re,{name:W,testId:b,disabled:f,placeholder:we(c),value:a.value,onChange:Ee,onFocus:se,error:I===null?void 0:I,warning:k===null?void 0:k,left:N,allowEmpty:Ue,validationCallback:(t,n)=>ue(W,n),enableCosmeticRounding:$,enableDisplayRounding:ce,groupOrder:g?"middle":"first",disableInternalErrorValidationMessages:ye,small:E},W)}),P&&(be||!me?o.jsx(Fe,{groupOrder:"last",children:P}):o.jsx(X,{maxHeight:380,groupOrder:"last",disabled:F,testId:b&&`${b}-menu`,menu:{label:P,trigger:"DropDownButton",small:E,sections:D.map(([t,n,i])=>{const s=i||n||"",p=r.isValidNum(t)?t:"";return{type:"Option",label:$?_e(p):p,inline:!0,onClick:R=>{R.stopPropagation(),Ve(A?"":t,n)},description:s,selected:s===P,testId:`${b}-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:"(evt: TOnChangeEvent) => void",signature:{arguments:[{type:{name:"signature",type:"object",raw:"{ target: TOnChangeEventTarget }",signature:{properties:[{key:"target",value:{name:"union",raw:`| TOnChangeEventBaseTarget
2
+ | (TOnChangeEventBaseTarget & {
3
+ predefinedSelected: boolean;
4
+ predefinedOption: IPredefinedOption;
5
+ })`,elements:[{name:"signature",type:"object",raw:"{ name: string; value: string }",signature:{properties:[{key:"name",value:{name:"string",required:!0}},{key:"value",value:{name:"string",required:!0}}]}},{name:"unknown"}],required:!0}}]}},name:"evt"}],return:{name:"void"}}},description:"",defaultValue:{value:"noop",computed:!0}},onSwitchUnit:{required:!1,tsType:{name:"signature",type:"function",raw:"(unit: string) => void",signature:{arguments:[{type:{name:"string"},name:"unit"}],return:{name:"void"}}},description:"",defaultValue:{value:"noop",computed:!0}},onClick:{required:!1,tsType:{name:"MouseEventHandler",elements:[{name:"HTMLInputElement"}],raw:"MouseEventHandler<HTMLInputElement>"},description:"",defaultValue:{value:"noop",computed:!0}},onFocus:{required:!1,tsType:{name:"FocusEventHandler",elements:[{name:"HTMLInputElement"}],raw:"FocusEventHandler<HTMLInputElement>"},description:"",defaultValue:{value:"noop",computed:!0}},unitTemplate:{required:!1,tsType:{name:"Record",elements:[{name:"string"},{name:"any"}],raw:"Record<string, any>"},description:""},convertBackToStorageUnit:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},enableCosmeticRounding:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},enableDisplayRounding:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}}}};export{Ke as U};
@@ -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-C07ZKMj5.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 => {
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-DTOrVqdm.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({
@@ -1,23 +1,18 @@
1
- import{j as e}from"./jsx-runtime-eps93zm2.js";import{r as d}from"./index-DhsZuJvc.js";import{d as b}from"./index-C0x1JmaP.js";import{w as f,u as l,e as r,f as V,a as D}from"./index-DMAnyMX5.js";import{U as u}from"./unit-input-C07ZKMj5.js";import{B as o}from"./button-Cbv7WK6k.js";import{S as g}from"./spacer-BWoNR27H.js";import{D as fe}from"./divider-DY9nJ_7N.js";import{R as Ce,C as _}from"./row-Bmiy2Lh0.js";import{F as U}from"./field-HrLaMLbx.js";import{M as pe}from"./message-BRyKdRaX.js";import{G as ge}from"./grid-DRkC-bt8.js";import{C as v}from"./card-EcjmryU9.js";import{H as y}from"./heading-CRNoBc7q.js";import{T as N}from"./toggle-BbFVf61v.js";import{T as q}from"./text-B3-TSWok.js";import{S as xe}from"./select-Cwks-WA0.js";import{I as he}from"./icon-BSFY3vDO.js";import"./index-DRSy5Ssd.js";import"./index-CF7H4eMJ.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"./types-BmbYqTX_.js";import"./badge-CLQ59MDF.js";import"./input-group-addon-D68iUKV2.js";import"./input-group-BaRSJAEN.js";import"./spinner-AWUe4xwQ.js";import"./styled-components.browser.esm-BQ9GQzDc.js";import"./label-CqmyC9he.js";import"./help-icon-Buhx5nl6.js";import"./inheritsLoose-DP0QEDDI.js";import"./assertThisInitialized-B9jnkVVz.js";import"./memoize-one.esm-CcMeOnPo.js";import"./select.input-CJed_LLR.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";const ht={title:"Forms/UnitInput/Test Cases",component:u,tags:["!autodocs"]},C=()=>{const[i,a]=d.useState("123|m");return e.jsx(u,{name:"example",onChange:t=>a(t.target.value),placeholder:"Type a value...",value:i,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"},testId:"testId"})};C.play=async({canvasElement:i,step:a})=>{const t=f(i),s=f(i.ownerDocument.body);await a("Shows validation error for non-numeric input",async()=>{const n=t.getByTestId("testId");await l.clear(n),await l.type(n,"123x45s6"),await r(t.getByDisplayValue("123x45s6")).toBeInTheDocument(),await r(n.getAttribute("data-error")).toEqual("Must be a numerical value"),await V.mouseOver(n),await D(()=>{r(s.getByText("Must be a numerical value")).toBeInTheDocument()})})};const x=()=>{const[i,a]=d.useState("|m");return e.jsx(u,{name:"example-ft",onChange:t=>a(t.target.value),placeholder:"7|ft",value:i,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"},testId:"testId-ft"})};x.play=async({canvasElement:i,step:a})=>{const t=f(i),s=f(i.ownerDocument.body);await a("Handle input with unit only",async()=>{const n=t.getByTestId("testId-ft");await r(t.getByDisplayValue("")).toBeInTheDocument(),await r(n.getAttribute("data-error")).toBeNull(),await V.mouseOver(n),await D(()=>{r(s.queryByText("Must be a numerical value")).not.toBeInTheDocument()})}),await a("Clear input and check placeholder",async()=>{const n=t.getByTestId("testId-ft");await l.clear(n),await r(n).toHaveAttribute("placeholder","2.13")}),await a("Type a correct numeric value and ensure no error",async()=>{const n=t.getByTestId("testId-ft");await l.type(n,"123"),await r(t.getByDisplayValue("123")).toBeInTheDocument(),await r(n.getAttribute("data-error")).toBeNull(),await V.mouseOver(n),await D(()=>{r(s.queryByText("Must be a numerical value")).not.toBeInTheDocument()})}),await a("Remove value, type incorrect value and check for error",async()=>{const n=t.getByTestId("testId-ft");await l.clear(n),await l.type(n,"123abc"),await r(t.getByDisplayValue("123abc")).toBeInTheDocument(),await r(n.getAttribute("data-error")).toEqual("Must be a numerical value"),await V.mouseOver(n),await D(()=>{r(s.getByText("Must be a numerical value")).toBeInTheDocument()})})};const T=i=>{const[a,t]=d.useState("123|m"),[s,n]=d.useState("223|m"),[c,h]=d.useState("ft");return e.jsxs(e.Fragment,{children:[e.jsx(o,{label:"Change initUnit",onClick:()=>h(c==="m"?"ft":"m")}),e.jsx(g,{}),e.jsx(o,{label:"Change value",onClick:()=>t(a==="123|m"?"456|m":"123|m")}),e.jsx(g,{}),e.jsx(u,{name:"example",onChange:m=>{t(m.target.value)},unitkey:"length",value:a,initUnit:c,onSwitchUnit:h}),e.jsx(g,{}),e.jsx(u,{name:"example2",onChange:m=>{n(m.target.value)},unitkey:"length",value:s,initUnit:c,onSwitchUnit:h}),e.jsx(fe,{}),e.jsx("h4",{children:"Without initUnit property (taken from the redux store)"}),e.jsx(u,{name:"example",onChange:m=>{t(m.target.value)},unitkey:"length",value:a,onSwitchUnit:h}),e.jsx(u,{name:"example2",onChange:m=>{n(m.target.value)},unitkey:"length",value:s,onSwitchUnit:h})]})};T.parameters={docs:{description:{story:"[OW-4380](https://oliasoft.atlassian.net/browse/OW-4380?atlOrigin=eyJpIjoiMmM1N2RkNWU3Mjk5NDYxY2E0YzhkMzk5ZTVmZTJhMjciLCJwIjoiaiJ9)"}}};const I=()=>{const i="500px",[a,t]=d.useState(void 0);return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different edge cases such as +/- infinity, undefined, NaN, null:"}),e.jsxs(Ce,{children:[e.jsxs(_,{width:"25%",children:[e.jsx(o,{label:"Change value infinity",onClick:()=>t(1/0)}),e.jsx("br",{}),e.jsx(o,{label:"Change value -infinity",onClick:()=>t(-1/0)}),e.jsx("br",{}),e.jsx(o,{label:"Change value null",onClick:()=>t(null)}),e.jsx("br",{}),e.jsx(o,{label:"Change value - undefined",onClick:()=>t(void 0)}),e.jsx("br",{}),e.jsx(o,{label:"Change value - NaN",onClick:()=>t(NaN)}),e.jsx("br",{}),e.jsx(o,{label:"Change value - nothing (empty)",onClick:()=>t(void 0)}),e.jsx("br",{}),e.jsx(o,{label:"Change value - empty string",onClick:()=>t("")})]}),e.jsxs(_,{width:"25%",children:[e.jsx(o,{label:"Change value infinity|m",onClick:()=>t("Infinity|m")}),e.jsx("br",{}),e.jsx(o,{label:"Change value -infinity|m",onClick:()=>t("-Infinity|m")}),e.jsx("br",{}),e.jsx(o,{label:"Change value null|m",onClick:()=>t("null|m")}),e.jsx("br",{}),e.jsx(o,{label:"Change value - undefined|m",onClick:()=>t("undefined|m")}),e.jsx("br",{}),e.jsx(o,{label:"Change value - NaN|m",onClick:()=>t("NaN|m")}),e.jsx("br",{}),e.jsx(o,{label:"Change value - nothing (empty)|m",onClick:()=>t("|m")})]})]}),e.jsx("br",{}),e.jsx(U,{label:"Normal PUI",children:e.jsx(u,{name:"example1",onChange:s=>t(s.target.value),value:a,unitkey:"length",width:i,placeholder:"value|unit"})}),e.jsx(U,{label:"Disabled validation",children:e.jsx(u,{name:"example2",onChange:s=>t(s.target.value),value:a,unitkey:"length",disabledValidation:!0,width:i})}),e.jsx(U,{label:"Disabled validation and manual error",children:e.jsx(u,{name:"example3",onChange:s=>t(s.target.value),value:a,unitkey:"length",error:"test",disabledValidation:!0,width:i})}),e.jsx(pe,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})};I.parameters={docs:{description:{story:"[OW-8884](https://oliasoft.atlassian.net/browse/OW-8884)"}}};const j=()=>{const[i,a]=d.useState(!0),t=()=>{a(!1),setTimeout(()=>a(!0),0)},[s,n]=d.useState("123|ft");return e.jsxs(ge,{columns:"1fr 1fr",gap:!0,children:[e.jsxs(v,{heading:e.jsx(y,{children:"Storage State (Redux)"}),children:[s,e.jsx(g,{}),e.jsx(o,{label:"Change value",onClick:()=>n(b.withUnit(String(Math.floor(Math.random()*100)),"ft"))})]}),e.jsx(v,{heading:e.jsx(y,{icon:e.jsx(he,{icon:"refresh",testId:"triggerRerenderTestId"}),onIconClick:t,children:"UnitInput"}),children:i&&e.jsx(u,{name:"example",onChange:c=>n(c.target.value),value:s,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"}})})]})},S=()=>e.jsxs(e.Fragment,{children:[e.jsx(q,{faint:!0,children:"Reproduce OW-10614 rounding noise bug when storing values in a different unit to the display unit"}),e.jsx(g,{}),e.jsx(u,{name:"example",onChange:()=>{},value:b.withUnit(b.convertAndGetValue("9750|psi","bar"),"bar"),initUnit:"psi",unitkey:"pressure",unitTemplate:{pressure:"psi"}}),e.jsx(g,{}),e.jsx(u,{name:"example2",onChange:()=>{},value:b.withUnit(b.convertAndGetValue("8642|lbf","tonneForce"),"tonneForce"),initUnit:"lbf",unitkey:"force",unitTemplate:{force:"tonneForce"}})]}),w=()=>e.jsxs(e.Fragment,{children:[e.jsx(u,{name:"example",unitkey:"moleWeight",initUnit:"g/mol",doNotConvertValue:!0,value:"170|g/mol",unitTemplate:{moleWeight:"g/mol"},testId:"case1"}),e.jsx(g,{}),e.jsx(u,{name:"gor",unitkey:"moleWeight",initUnit:"gor",value:"Infinity|SCF/STB",testId:"case2"})]});w.play=async({canvasElement:i,step:a})=>{const t=f(i);await a("Can enter decimal values",async()=>{await r(t.getByDisplayValue("170")).toBeInTheDocument(),await r(t.getByDisplayValue("")).toBeInTheDocument()})};const B=()=>{const[i,a]=d.useState(!0),t=()=>{a(!1),setTimeout(()=>a(!0),0)},[s,n]=d.useState("psi"),[c,h]=d.useState(!1),[m,ve]=d.useState(!0),[F,ye]=d.useState(!0),[R,M]=d.useState("672.2388357750001|bar"),[W,be]=d.useState("");return e.jsxs(ge,{columns:"1fr 1fr",gap:!0,children:[e.jsxs(v,{heading:e.jsx(y,{children:"Settings"}),children:[e.jsx(U,{label:"Enable display rounding:",labelLeft:!0,labelWidth:200,children:e.jsx(N,{checked:c,onChange:p=>h(p.target.checked)})}),e.jsx(U,{label:"Enable cosmetic rounding:",labelLeft:!0,labelWidth:200,children:e.jsx(N,{checked:m,onChange:p=>ve(p.target.checked)})}),e.jsx(U,{label:"Convert back to storage unit (onChange):",labelLeft:!0,labelWidth:200,children:e.jsx(N,{checked:F,onChange:p=>ye(p.target.checked)})})]}),e.jsxs(v,{heading:e.jsx(y,{icon:e.jsx(he,{icon:"refresh",testId:"triggerRerenderTestId"}),onIconClick:t,children:"UnitInput"}),children:[e.jsx(q,{faint:!0,children:"Cosmetic Rounding Test Case: type 9750 then return (compare with enableCosmeticRounding on and off)"}),e.jsx(g,{}),e.jsx(q,{warning:!0,children:"Note: UnitInput uses convertSamePrecision internally (decision prior to cosmetic value implementation). This means not all rounding noise occurrences seen in NumberInput will be reproducible in UnitInput, because they get rounded off by other logic."}),e.jsx(g,{}),i&&e.jsx(u,{name:"Example",unitkey:"pressure",initUnit:s,unitTemplate:{pressure:"psi"},value:R,onChange:p=>{const{value:E}=p.target;E&&M(E)},enableDisplayRounding:c,enableCosmeticRounding:m,error:b.convertAndGetValue(R,"bar")>=0?"":"Value must be positive",validationCallback:(p,E)=>{be(E??"")},convertBackToStorageUnit:F})]}),e.jsx(v,{heading:e.jsx(y,{children:"Unit Template"}),children:e.jsx(xe,{options:[{label:"Bar",value:"bar"},{label:"psi",value:"psi"}],value:s,width:70,onChange:p=>n(p.target.value)})}),e.jsx(v,{heading:e.jsx(y,{children:"Test Validation Callback"}),children:W&&e.jsx(pe,{message:{content:W,icon:!0,type:"Error",visible:!0}})}),e.jsxs(v,{heading:e.jsx(y,{children:"Storage State / Redux"}),children:[R,e.jsx(g,{}),e.jsx(o,{label:"Change value",onClick:()=>M(b.withUnit(String(Math.floor(Math.random()*100)),"bar"))})]})]})},k=()=>{const[i,a]=d.useState("123|m");return e.jsx(u,{name:"example",onChange:t=>a(t.target.value),value:i,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"},testId:"testId"})};k.play=async({canvasElement:i,step:a})=>{const t=f(i),s=f(i.ownerDocument.body);await a("Can enter decimal values",async()=>{const n=t.getByTestId("testId");await l.clear(n),await l.type(n,"123.123456789"),await r(t.getByDisplayValue("123.123456789")).toBeInTheDocument()}),await a("Can enter scientific notation",async()=>{const n=t.getByTestId("testId");await l.clear(n),await l.type(n,"-1.12e3"),await r(t.getByDisplayValue("-1.12e3")).toBeInTheDocument()}),await a("Can enter comma decimals (converts to dot)",async()=>{const n=t.getByTestId("testId");await l.clear(n),await l.type(n,"123,456"),await r(t.getByDisplayValue("123.456")).toBeInTheDocument()}),await a("Can enter small numbers",async()=>{const n=t.getByTestId("testId");await l.clear(n),await l.type(n,"0.0000000023"),await r(t.getByDisplayValue("0.0000000023")).toBeInTheDocument()}),await a("Can enter large numbers",async()=>{const n=t.getByTestId("testId");await l.clear(n),await l.type(n,"999999999999"),await r(t.getByDisplayValue("999999999999")).toBeInTheDocument()}),await a("Can convert units",async()=>{const n=t.getByTestId("testId"),c=t.getByTestId("testId-menu");await l.clear(n),await l.type(n,"456.1"),await l.click(c),await l.click(s.getByTestId("testId-unit-ft")),await r(t.getByDisplayValue("1496")).toBeInTheDocument()}),await a("Shows validation error for non-numeric input",async()=>{const n=t.getByTestId("testId");await l.clear(n),await l.type(n,"123x45s6"),await r(t.getByDisplayValue("123x45s6")).toBeInTheDocument(),await r(n.getAttribute("data-error")).toEqual("Must be a numerical value"),await V.mouseOver(n),await D(()=>{r(s.getByText("Must be a numerical value")).toBeInTheDocument()})})};C.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"Placeholder"};x.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"PlaceholderWithUnit"};T.__docgenInfo={description:"",methods:[],displayName:"TestExternalStateChangeWithSynchronizedUnits",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:""},disabled:{required:!1,tsType:{name:"boolean"},description:""},disabledUnit:{required:!1,tsType:{name:"boolean"},description:""},error:{required:!1,tsType:{name:"union",raw:"string | null | boolean",elements:[{name:"string"},{name:"null"},{name:"boolean"}]},description:""},left:{required:!1,tsType:{name:"boolean"},description:""},small:{required:!1,tsType:{name:"boolean"},description:""},width:{required:!1,tsType:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},description:""},value:{required:!1,tsType:{name:"string"},description:""},unitkey:{required:!1,tsType:{name:"string"},description:""},initUnit:{required:!1,tsType:{name:"string"},description:""},noConversion:{required:!1,tsType:{name:"boolean"},description:""},doNotConvertValue:{required:!1,tsType:{name:"boolean"},description:""},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:""},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:""},shouldLinkAutomaticly:{required:!1,tsType:{name:"boolean"},description:""},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:""},disabledValidation:{required:!1,tsType:{name:"boolean"},description:""},allowEmpty:{required:!1,tsType:{name:"boolean"},description:""},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
- target:
3
- | T
4
- | { name: string; value: any; label?: string; files?: FileList | null };
5
- }`,elements:[{name:"ChangeEvent",elements:[{name:"T"}],raw:"ChangeEvent<T>"},{name:"signature",type:"object",raw:`{
6
- target:
7
- | T
8
- | { name: string; value: any; label?: string; files?: FileList | null };
9
- }`,signature:{properties:[{key:"target",value:{name:"union",raw:`| T
10
- | { 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:"ICustomChangeEvent"}]},name:"event"}],return:{name:"void"}}},description:""},onSwitchUnit:{required:!1,tsType:{name:"signature",type:"function",raw:"(unit: string) => void",signature:{arguments:[{type:{name:"string"},name:"unit"}],return:{name:"void"}}},description:""},onClick:{required:!1,tsType:{name:"MouseEventHandler",elements:[{name:"HTMLInputElement"}],raw:"MouseEventHandler<HTMLInputElement>"},description:""},onFocus:{required:!1,tsType:{name:"FocusEventHandler",elements:[{name:"HTMLInputElement"}],raw:"FocusEventHandler<HTMLInputElement>"},description:""},unitTemplate:{required:!1,tsType:{name:"Record",elements:[{name:"string"},{name:"any"}],raw:"Record<string, any>"},description:""},convertBackToStorageUnit:{required:!1,tsType:{name:"boolean"},description:""},enableCosmeticRounding:{required:!1,tsType:{name:"boolean"},description:""},enableDisplayRounding:{required:!1,tsType:{name:"boolean"},description:""}}};I.__docgenInfo={description:"",methods:[],displayName:"TestEdgeCases"};j.__docgenInfo={description:"",methods:[],displayName:"ManagedTestCase"};S.__docgenInfo={description:"",methods:[],displayName:"OW_10614TestCase"};w.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"OW_17784TestCase"};B.__docgenInfo={description:"",methods:[],displayName:"DemoCosmeticRounding"};k.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"TestUserInput"};var H,O,P;C.parameters={...C.parameters,docs:{...(H=C.parameters)==null?void 0:H.docs,source:{originalSource:`() => {
1
+ import{j as e}from"./jsx-runtime-eps93zm2.js";import{r as d}from"./index-DhsZuJvc.js";import{d as b}from"./index-C0x1JmaP.js";import{w as f,u as l,e as r,f as V,a as D}from"./index-DMAnyMX5.js";import{U as u}from"./unit-input-DTOrVqdm.js";import{B as o}from"./button-Cbv7WK6k.js";import{S as g}from"./spacer-BWoNR27H.js";import{D as fe}from"./divider-DY9nJ_7N.js";import{R as Ce,C as F}from"./row-Bmiy2Lh0.js";import{F as U}from"./field-HrLaMLbx.js";import{M as pe}from"./message-BRyKdRaX.js";import{G as ge}from"./grid-DRkC-bt8.js";import{C as v}from"./card-EcjmryU9.js";import{H as y}from"./heading-CRNoBc7q.js";import{T as N}from"./toggle-BbFVf61v.js";import{T as q}from"./text-B3-TSWok.js";import{S as xe}from"./select-Cwks-WA0.js";import{I as he}from"./icon-BSFY3vDO.js";import"./index-DRSy5Ssd.js";import"./index-CF7H4eMJ.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"./types-BmbYqTX_.js";import"./badge-CLQ59MDF.js";import"./input-group-addon-D68iUKV2.js";import"./input-group-BaRSJAEN.js";import"./spinner-AWUe4xwQ.js";import"./styled-components.browser.esm-BQ9GQzDc.js";import"./label-CqmyC9he.js";import"./help-icon-Buhx5nl6.js";import"./inheritsLoose-DP0QEDDI.js";import"./assertThisInitialized-B9jnkVVz.js";import"./memoize-one.esm-CcMeOnPo.js";import"./select.input-CJed_LLR.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";const ht={title:"Forms/UnitInput/Test Cases",component:u,tags:["!autodocs"]},C=()=>{const[i,a]=d.useState("123|m");return e.jsx(u,{name:"example",onChange:t=>a(t.target.value),placeholder:"Type a value...",value:i,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"},testId:"testId"})};C.play=async({canvasElement:i,step:a})=>{const t=f(i),s=f(i.ownerDocument.body);await a("Shows validation error for non-numeric input",async()=>{const n=t.getByTestId("testId");await l.clear(n),await l.type(n,"123x45s6"),await r(t.getByDisplayValue("123x45s6")).toBeInTheDocument(),await r(n.getAttribute("data-error")).toEqual("Must be a numerical value"),await V.mouseOver(n),await D(()=>{r(s.getByText("Must be a numerical value")).toBeInTheDocument()})})};const x=()=>{const[i,a]=d.useState("|m");return e.jsx(u,{name:"example-ft",onChange:t=>a(t.target.value),placeholder:"7|ft",value:i,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"},testId:"testId-ft"})};x.play=async({canvasElement:i,step:a})=>{const t=f(i),s=f(i.ownerDocument.body);await a("Handle input with unit only",async()=>{const n=t.getByTestId("testId-ft");await r(t.getByDisplayValue("")).toBeInTheDocument(),await r(n.getAttribute("data-error")).toBeNull(),await V.mouseOver(n),await D(()=>{r(s.queryByText("Must be a numerical value")).not.toBeInTheDocument()})}),await a("Clear input and check placeholder",async()=>{const n=t.getByTestId("testId-ft");await l.clear(n),await r(n).toHaveAttribute("placeholder","2.13")}),await a("Type a correct numeric value and ensure no error",async()=>{const n=t.getByTestId("testId-ft");await l.type(n,"123"),await r(t.getByDisplayValue("123")).toBeInTheDocument(),await r(n.getAttribute("data-error")).toBeNull(),await V.mouseOver(n),await D(()=>{r(s.queryByText("Must be a numerical value")).not.toBeInTheDocument()})}),await a("Remove value, type incorrect value and check for error",async()=>{const n=t.getByTestId("testId-ft");await l.clear(n),await l.type(n,"123abc"),await r(t.getByDisplayValue("123abc")).toBeInTheDocument(),await r(n.getAttribute("data-error")).toEqual("Must be a numerical value"),await V.mouseOver(n),await D(()=>{r(s.getByText("Must be a numerical value")).toBeInTheDocument()})})};const T=i=>{const[a,t]=d.useState("123|m"),[s,n]=d.useState("223|m"),[c,h]=d.useState("ft");return e.jsxs(e.Fragment,{children:[e.jsx(o,{label:"Change initUnit",onClick:()=>h(c==="m"?"ft":"m")}),e.jsx(g,{}),e.jsx(o,{label:"Change value",onClick:()=>t(a==="123|m"?"456|m":"123|m")}),e.jsx(g,{}),e.jsx(u,{name:"example",onChange:m=>{t(m.target.value)},unitkey:"length",value:a,initUnit:c,onSwitchUnit:h}),e.jsx(g,{}),e.jsx(u,{name:"example2",onChange:m=>{n(m.target.value)},unitkey:"length",value:s,initUnit:c,onSwitchUnit:h}),e.jsx(fe,{}),e.jsx("h4",{children:"Without initUnit property (taken from the redux store)"}),e.jsx(u,{name:"example",onChange:m=>{t(m.target.value)},unitkey:"length",value:a,onSwitchUnit:h}),e.jsx(u,{name:"example2",onChange:m=>{n(m.target.value)},unitkey:"length",value:s,onSwitchUnit:h})]})};T.parameters={docs:{description:{story:"[OW-4380](https://oliasoft.atlassian.net/browse/OW-4380?atlOrigin=eyJpIjoiMmM1N2RkNWU3Mjk5NDYxY2E0YzhkMzk5ZTVmZTJhMjciLCJwIjoiaiJ9)"}}};const I=()=>{const i="500px",[a,t]=d.useState(void 0);return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different edge cases such as +/- infinity, undefined, NaN, null:"}),e.jsxs(Ce,{children:[e.jsxs(F,{width:"25%",children:[e.jsx(o,{label:"Change value infinity",onClick:()=>t(1/0)}),e.jsx("br",{}),e.jsx(o,{label:"Change value -infinity",onClick:()=>t(-1/0)}),e.jsx("br",{}),e.jsx(o,{label:"Change value null",onClick:()=>t(null)}),e.jsx("br",{}),e.jsx(o,{label:"Change value - undefined",onClick:()=>t(void 0)}),e.jsx("br",{}),e.jsx(o,{label:"Change value - NaN",onClick:()=>t(NaN)}),e.jsx("br",{}),e.jsx(o,{label:"Change value - nothing (empty)",onClick:()=>t(void 0)}),e.jsx("br",{}),e.jsx(o,{label:"Change value - empty string",onClick:()=>t("")})]}),e.jsxs(F,{width:"25%",children:[e.jsx(o,{label:"Change value infinity|m",onClick:()=>t("Infinity|m")}),e.jsx("br",{}),e.jsx(o,{label:"Change value -infinity|m",onClick:()=>t("-Infinity|m")}),e.jsx("br",{}),e.jsx(o,{label:"Change value null|m",onClick:()=>t("null|m")}),e.jsx("br",{}),e.jsx(o,{label:"Change value - undefined|m",onClick:()=>t("undefined|m")}),e.jsx("br",{}),e.jsx(o,{label:"Change value - NaN|m",onClick:()=>t("NaN|m")}),e.jsx("br",{}),e.jsx(o,{label:"Change value - nothing (empty)|m",onClick:()=>t("|m")})]})]}),e.jsx("br",{}),e.jsx(U,{label:"Normal PUI",children:e.jsx(u,{name:"example1",onChange:s=>t(s.target.value),value:a,unitkey:"length",width:i,placeholder:"value|unit"})}),e.jsx(U,{label:"Disabled validation",children:e.jsx(u,{name:"example2",onChange:s=>t(s.target.value),value:a,unitkey:"length",disabledValidation:!0,width:i})}),e.jsx(U,{label:"Disabled validation and manual error",children:e.jsx(u,{name:"example3",onChange:s=>t(s.target.value),value:a,unitkey:"length",error:"test",disabledValidation:!0,width:i})}),e.jsx(pe,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})};I.parameters={docs:{description:{story:"[OW-8884](https://oliasoft.atlassian.net/browse/OW-8884)"}}};const j=()=>{const[i,a]=d.useState(!0),t=()=>{a(!1),setTimeout(()=>a(!0),0)},[s,n]=d.useState("123|ft");return e.jsxs(ge,{columns:"1fr 1fr",gap:!0,children:[e.jsxs(v,{heading:e.jsx(y,{children:"Storage State (Redux)"}),children:[s,e.jsx(g,{}),e.jsx(o,{label:"Change value",onClick:()=>n(b.withUnit(String(Math.floor(Math.random()*100)),"ft"))})]}),e.jsx(v,{heading:e.jsx(y,{icon:e.jsx(he,{icon:"refresh",testId:"triggerRerenderTestId"}),onIconClick:t,children:"UnitInput"}),children:i&&e.jsx(u,{name:"example",onChange:c=>n(c.target.value),value:s,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"}})})]})},S=()=>e.jsxs(e.Fragment,{children:[e.jsx(q,{faint:!0,children:"Reproduce OW-10614 rounding noise bug when storing values in a different unit to the display unit"}),e.jsx(g,{}),e.jsx(u,{name:"example",onChange:()=>{},value:b.withUnit(b.convertAndGetValue("9750|psi","bar"),"bar"),initUnit:"psi",unitkey:"pressure",unitTemplate:{pressure:"psi"}}),e.jsx(g,{}),e.jsx(u,{name:"example2",onChange:()=>{},value:b.withUnit(b.convertAndGetValue("8642|lbf","tonneForce"),"tonneForce"),initUnit:"lbf",unitkey:"force",unitTemplate:{force:"tonneForce"}})]}),w=()=>e.jsxs(e.Fragment,{children:[e.jsx(u,{name:"example",unitkey:"moleWeight",initUnit:"g/mol",doNotConvertValue:!0,value:"170|g/mol",unitTemplate:{moleWeight:"g/mol"},testId:"case1"}),e.jsx(g,{}),e.jsx(u,{name:"gor",unitkey:"moleWeight",initUnit:"gor",value:"Infinity|SCF/STB",testId:"case2"})]});w.play=async({canvasElement:i,step:a})=>{const t=f(i);await a("Can enter decimal values",async()=>{await r(t.getByDisplayValue("170")).toBeInTheDocument(),await r(t.getByDisplayValue("")).toBeInTheDocument()})};const B=()=>{const[i,a]=d.useState(!0),t=()=>{a(!1),setTimeout(()=>a(!0),0)},[s,n]=d.useState("psi"),[c,h]=d.useState(!1),[m,ve]=d.useState(!0),[M,ye]=d.useState(!0),[R,W]=d.useState("672.2388357750001|bar"),[O,be]=d.useState("");return e.jsxs(ge,{columns:"1fr 1fr",gap:!0,children:[e.jsxs(v,{heading:e.jsx(y,{children:"Settings"}),children:[e.jsx(U,{label:"Enable display rounding:",labelLeft:!0,labelWidth:200,children:e.jsx(N,{checked:c,onChange:p=>h(p.target.checked)})}),e.jsx(U,{label:"Enable cosmetic rounding:",labelLeft:!0,labelWidth:200,children:e.jsx(N,{checked:m,onChange:p=>ve(p.target.checked)})}),e.jsx(U,{label:"Convert back to storage unit (onChange):",labelLeft:!0,labelWidth:200,children:e.jsx(N,{checked:M,onChange:p=>ye(p.target.checked)})})]}),e.jsxs(v,{heading:e.jsx(y,{icon:e.jsx(he,{icon:"refresh",testId:"triggerRerenderTestId"}),onIconClick:t,children:"UnitInput"}),children:[e.jsx(q,{faint:!0,children:"Cosmetic Rounding Test Case: type 9750 then return (compare with enableCosmeticRounding on and off)"}),e.jsx(g,{}),e.jsx(q,{warning:!0,children:"Note: UnitInput uses convertSamePrecision internally (decision prior to cosmetic value implementation). This means not all rounding noise occurrences seen in NumberInput will be reproducible in UnitInput, because they get rounded off by other logic."}),e.jsx(g,{}),i&&e.jsx(u,{name:"Example",unitkey:"pressure",initUnit:s,unitTemplate:{pressure:"psi"},value:R,onChange:p=>{const{value:E}=p.target;E&&W(E)},enableDisplayRounding:c,enableCosmeticRounding:m,error:b.convertAndGetValue(R,"bar")>=0?"":"Value must be positive",validationCallback:(p,E)=>{be(E??"")},convertBackToStorageUnit:M})]}),e.jsx(v,{heading:e.jsx(y,{children:"Unit Template"}),children:e.jsx(xe,{options:[{label:"Bar",value:"bar"},{label:"psi",value:"psi"}],value:s,width:70,onChange:p=>n(p.target.value)})}),e.jsx(v,{heading:e.jsx(y,{children:"Test Validation Callback"}),children:O&&e.jsx(pe,{message:{content:O,icon:!0,type:"Error",visible:!0}})}),e.jsxs(v,{heading:e.jsx(y,{children:"Storage State / Redux"}),children:[R,e.jsx(g,{}),e.jsx(o,{label:"Change value",onClick:()=>W(b.withUnit(String(Math.floor(Math.random()*100)),"bar"))})]})]})},k=()=>{const[i,a]=d.useState("123|m");return e.jsx(u,{name:"example",onChange:t=>a(t.target.value),value:i,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"},testId:"testId"})};k.play=async({canvasElement:i,step:a})=>{const t=f(i),s=f(i.ownerDocument.body);await a("Can enter decimal values",async()=>{const n=t.getByTestId("testId");await l.clear(n),await l.type(n,"123.123456789"),await r(t.getByDisplayValue("123.123456789")).toBeInTheDocument()}),await a("Can enter scientific notation",async()=>{const n=t.getByTestId("testId");await l.clear(n),await l.type(n,"-1.12e3"),await r(t.getByDisplayValue("-1.12e3")).toBeInTheDocument()}),await a("Can enter comma decimals (converts to dot)",async()=>{const n=t.getByTestId("testId");await l.clear(n),await l.type(n,"123,456"),await r(t.getByDisplayValue("123.456")).toBeInTheDocument()}),await a("Can enter small numbers",async()=>{const n=t.getByTestId("testId");await l.clear(n),await l.type(n,"0.0000000023"),await r(t.getByDisplayValue("0.0000000023")).toBeInTheDocument()}),await a("Can enter large numbers",async()=>{const n=t.getByTestId("testId");await l.clear(n),await l.type(n,"999999999999"),await r(t.getByDisplayValue("999999999999")).toBeInTheDocument()}),await a("Can convert units",async()=>{const n=t.getByTestId("testId"),c=t.getByTestId("testId-menu");await l.clear(n),await l.type(n,"456.1"),await l.click(c),await l.click(s.getByTestId("testId-unit-ft")),await r(t.getByDisplayValue("1496")).toBeInTheDocument()}),await a("Shows validation error for non-numeric input",async()=>{const n=t.getByTestId("testId");await l.clear(n),await l.type(n,"123x45s6"),await r(t.getByDisplayValue("123x45s6")).toBeInTheDocument(),await r(n.getAttribute("data-error")).toEqual("Must be a numerical value"),await V.mouseOver(n),await D(()=>{r(s.getByText("Must be a numerical value")).toBeInTheDocument()})})};C.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"Placeholder"};x.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"PlaceholderWithUnit"};T.__docgenInfo={description:"",methods:[],displayName:"TestExternalStateChangeWithSynchronizedUnits",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:""},disabled:{required:!1,tsType:{name:"boolean"},description:""},disabledUnit:{required:!1,tsType:{name:"boolean"},description:""},error:{required:!1,tsType:{name:"union",raw:"string | null | boolean",elements:[{name:"string"},{name:"null"},{name:"boolean"}]},description:""},left:{required:!1,tsType:{name:"boolean"},description:""},small:{required:!1,tsType:{name:"boolean"},description:""},width:{required:!1,tsType:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},description:""},value:{required:!1,tsType:{name:"string"},description:""},unitkey:{required:!1,tsType:{name:"string"},description:""},initUnit:{required:!1,tsType:{name:"string"},description:""},noConversion:{required:!1,tsType:{name:"boolean"},description:""},doNotConvertValue:{required:!1,tsType:{name:"boolean"},description:""},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:""},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:""},shouldLinkAutomaticly:{required:!1,tsType:{name:"boolean"},description:""},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:""},disabledValidation:{required:!1,tsType:{name:"boolean"},description:""},allowEmpty:{required:!1,tsType:{name:"boolean"},description:""},autoValue:{required:!1,tsType:{name:"string"},description:""},onChange:{required:!1,tsType:{name:"signature",type:"function",raw:"(evt: TOnChangeEvent) => void",signature:{arguments:[{type:{name:"signature",type:"object",raw:"{ target: TOnChangeEventTarget }",signature:{properties:[{key:"target",value:{name:"union",raw:`| TOnChangeEventBaseTarget
2
+ | (TOnChangeEventBaseTarget & {
3
+ predefinedSelected: boolean;
4
+ predefinedOption: IPredefinedOption;
5
+ })`,elements:[{name:"signature",type:"object",raw:"{ name: string; value: string }",signature:{properties:[{key:"name",value:{name:"string",required:!0}},{key:"value",value:{name:"string",required:!0}}]}},{name:"unknown"}],required:!0}}]}},name:"evt"}],return:{name:"void"}}},description:""},onSwitchUnit:{required:!1,tsType:{name:"signature",type:"function",raw:"(unit: string) => void",signature:{arguments:[{type:{name:"string"},name:"unit"}],return:{name:"void"}}},description:""},onClick:{required:!1,tsType:{name:"MouseEventHandler",elements:[{name:"HTMLInputElement"}],raw:"MouseEventHandler<HTMLInputElement>"},description:""},onFocus:{required:!1,tsType:{name:"FocusEventHandler",elements:[{name:"HTMLInputElement"}],raw:"FocusEventHandler<HTMLInputElement>"},description:""},unitTemplate:{required:!1,tsType:{name:"Record",elements:[{name:"string"},{name:"any"}],raw:"Record<string, any>"},description:""},convertBackToStorageUnit:{required:!1,tsType:{name:"boolean"},description:""},enableCosmeticRounding:{required:!1,tsType:{name:"boolean"},description:""},enableDisplayRounding:{required:!1,tsType:{name:"boolean"},description:""}}};I.__docgenInfo={description:"",methods:[],displayName:"TestEdgeCases"};j.__docgenInfo={description:"",methods:[],displayName:"ManagedTestCase"};S.__docgenInfo={description:"",methods:[],displayName:"OW_10614TestCase"};w.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"OW_17784TestCase"};B.__docgenInfo={description:"",methods:[],displayName:"DemoCosmeticRounding"};k.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"TestUserInput"};var _,H,P;C.parameters={...C.parameters,docs:{...(_=C.parameters)==null?void 0:_.docs,source:{originalSource:`() => {
11
6
  const [value, setValue] = useState('123|m');
12
7
  return <UnitInput name="example" onChange={evt => setValue(evt.target.value)} placeholder="Type a value..." value={value} initUnit="m" unitkey="depth" unitTemplate={{
13
8
  depth: 'm'
14
9
  }} testId="testId" />;
15
- }`,...(P=(O=C.parameters)==null?void 0:O.docs)==null?void 0:P.source}}};var L,A,G;x.parameters={...x.parameters,docs:{...(L=x.parameters)==null?void 0:L.docs,source:{originalSource:`() => {
10
+ }`,...(P=(H=C.parameters)==null?void 0:H.docs)==null?void 0:P.source}}};var A,G,L;x.parameters={...x.parameters,docs:{...(A=x.parameters)==null?void 0:A.docs,source:{originalSource:`() => {
16
11
  const [value, setValue] = useState('|m');
17
12
  return <UnitInput name="example-ft" onChange={evt => setValue(evt.target.value)} placeholder="7|ft" value={value} initUnit="m" unitkey="depth" unitTemplate={{
18
13
  depth: 'm'
19
14
  }} testId="testId-ft" />;
20
- }`,...(G=(A=x.parameters)==null?void 0:A.docs)==null?void 0:G.source}}};var z,J,Y;T.parameters={...T.parameters,docs:{...(z=T.parameters)==null?void 0:z.docs,source:{originalSource:`(args: IUnitInputProps) => {
15
+ }`,...(L=(G=x.parameters)==null?void 0:G.docs)==null?void 0:L.source}}};var z,J,Y;T.parameters={...T.parameters,docs:{...(z=T.parameters)==null?void 0:z.docs,source:{originalSource:`(args: IUnitInputProps) => {
21
16
  const [value, setValue] = useState('123|m');
22
17
  const [value2, setValue2] = useState('223|m');
23
18
  const [initUnit, setInitUnit] = useState('ft');
@@ -1,4 +1,4 @@
1
- import{j as n}from"./jsx-runtime-eps93zm2.js";import{r as f}from"./index-DhsZuJvc.js";import{f as z}from"./immer.esm-BwVl9PS2.js";import{d as w}from"./index-C0x1JmaP.js";import{G as ee}from"./grid-DRkC-bt8.js";import{S as te}from"./spacer-BWoNR27H.js";import{C as V}from"./card-EcjmryU9.js";import{F as R}from"./field-HrLaMLbx.js";import{H as F}from"./heading-CRNoBc7q.js";import{S as N}from"./select-Cwks-WA0.js";import{T as W}from"./toggle-BbFVf61v.js";import{l as ne}from"./lodash-c4VUpsOs.js";import{u as ae,a as ie,g as re,c as K}from"./initialize-context-Y03pJPr5.js";import{T as oe,C as P}from"./table-DoyDBG6l.js";import{s as le}from"./number-input-B3_gmeWr.js";import"./index-DRSy5Ssd.js";import"./styled-components.browser.esm-BQ9GQzDc.js";import"./index-Bk2sglWO.js";import"./label-CqmyC9he.js";import"./common-types-Sih75Sav.js";import"./help-icon-Buhx5nl6.js";import"./tooltip-1V7clEnw.js";import"./index-CUZDtIZe.js";import"./icon-BSFY3vDO.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./inheritsLoose-DP0QEDDI.js";import"./index-CEuq6vkz.js";import"./disabled-context-rmpd7YJS.js";import"./types-Dx2TtIG9.js";import"./enum-Bnn40S8Q.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"./badge-CLQ59MDF.js";import"./select.input-CJed_LLR.js";import"./helpers-JJxzGegQ.js";import"./index.es-DazXb-ul.js";import"./redux-tRgGMjwY.js";import"./objectSpread2-DW4nTBoq.js";import"./tiny-invariant-DqLgxztJ.js";import"./pagination-CR1nxnnq.js";import"./input-Db9WkmPP.js";import"./input-group-BaRSJAEN.js";import"./input-group-addon-D68iUKV2.js";import"./check-box-DPLaOkRR.js";import"./slider-CcpE4BLD.js";import"./index-BI4_Bp97.js";import"./popover-C_2P8LFJ.js";const se=l=>l.reduce(({preferredUnits:i,storageUnits:r},{unitKey:s,preferredUnit:a,storageUnit:h})=>{const{unitTemplate:p=null}=ie()??{};return i[s]=a??re(s,p),r[s]=h,{preferredUnits:i,storageUnits:r}},{preferredUnits:{},storageUnits:{}}),ue=({headers:l,rows:i,selectedUnits:r,storageUnits:s,onChangeUnit:a,convertBackToStorageUnit:h,enableCosmeticRounding:p,enableDisplayRounding:T})=>{const d=l?l.map(c=>({...c,cells:c.cells.map(g=>{var t;if(g.type===P.AUTO_UNIT){const{testId:x,unitKey:u}=g;return{value:r[u],type:P.SELECT,searchable:!1,options:(t=w.getUnitsForQuantity(u))==null?void 0:t.map(v=>({label:w.label(v),value:v})),native:g.native,onChange:v=>a({unitKey:u,value:v.target.value}),testId:x}}return g})})):[],o=i?i.map((c,g)=>({...c,cells:c.cells.map((t,x)=>{if("autoUnit"in t&&(t!=null&&t.autoUnit)&&(typeof(t==null?void 0:t.value)=="string"||typeof(t==null?void 0:t.value)=="number")){const{unitKey:u,value:v,formatDisplayValue:D}=t,L=T&&"roundDisplayValue"in t?t==null?void 0:t.roundDisplayValue:null,m=r[u],b=s[u],e=m!==b,{value:U=v}=K({value:le(v),unitkey:u,toUnit:m,fromUnit:b}),y=e?U:t.value,k=D?D(y):y;return{...t,value:k,enableCosmeticRounding:p&&e,enableDisplayRounding:T,roundDisplayValue:L,onChange:C=>{const{value:S}=C.target,B=s[u],E=r[u],A=E!==B,_=h?B:E,{value:I=S}=K({value:String(S),unitkey:u,toUnit:_,fromUnit:E}),X=A?I:S;if("onChange"in t){const{onChange:Y}=t,Z={...C,target:{...C.target,value:String(X),rowIndex:g,cellIndex:x,unit:_}};Y(Z)}}}}return t})})):[];return{convertedHeaders:d,convertedRows:o}},M=({table:l,unitConfig:i,convertBackToStorageUnit:r=!0,enableCosmeticRounding:s=!0,enableDisplayRounding:a=!0})=>{const{rows:h,headers:p,...T}=l,{storageUnits:d,preferredUnits:o}=se(i),c=ae(o),[g,t]=f.useState(o),x=({unitKey:m,value:b})=>{t({...g,[m]:b});const e=i.find(U=>U.unitKey===m);e&&typeof e.onChange=="function"&&e.onChange({oldUnit:g[m],newUnit:b,unitKey:m})},u=m=>ue({headers:p,rows:h,selectedUnits:m,storageUnits:d,onChangeUnit:x,convertBackToStorageUnit:r,enableCosmeticRounding:s,enableDisplayRounding:a}),v=u(g),[D,L]=f.useState(v);return f.useEffect(()=>{!ne.isEqual(o,c)&&(Object.keys(o).forEach(b=>{const e=c==null?void 0:c[b],U=o[b];e!==U&&x({unitKey:b,value:U})}),L(u(o)))},[i]),f.useEffect(()=>{L(u(g))},[l,g]),n.jsx(oe,{table:{...T,headers:D.convertedHeaders,rows:D.convertedRows}})};M.__docgenInfo={description:"",methods:[],displayName:"UnitTable",props:{table:{required:!0,tsType:{name:"IUnitTable"},description:""},unitConfig:{required:!0,tsType:{name:"Array",elements:[{name:"IUnitConfigItem"}],raw:"IUnitConfigItem[]"},description:""},convertBackToStorageUnit:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},enableCosmeticRounding:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},enableDisplayRounding:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}}},composes:["Omit"]};const ft={title:"Basic/UnitTable",args:{}},de=!0,ce=!0,pe=!0,ge=!1,H="ft",J="C",me=3,he=(l,i,r)=>{const s=[i,i,r],a=[...Array(l)].map((h,p)=>{const T=p,d=p+1.25,o=4+p*.25;return[String(T),String(d),String(o)]});return[s,...a]},be=he(me,H,J),fe=({reduxTable:l,value:i,unit:r,rowIndex:s,cellIndex:a})=>z(l,h=>{const p=h[0][a],T=(d,o)=>o===0;return h.forEach((d,o)=>{if(T(d,o)){d[a]=r;return}if(o===s+1){d[a]=String(i);return}const c=w.convertAndGetValue(d[a],r,p);d[a]=String(c)}),h}),ve=({reduxTable:l,value:i,rowIndex:r,cellIndex:s})=>z(l,a=>{a[r+1][s]=i}),j=()=>{var m,b;const[l,i]=f.useState(H),[r,s]=f.useState(J),[a,h]=f.useState(be),[p,T]=f.useState(de),[d,o]=f.useState(pe),[c,g]=f.useState(ce),[t,x]=f.useState(ge),[u,v]=f.useState(H),D=e=>{const{rowIndex:U,cellIndex:y,value:k,unit:C}=e.target,S=t?fe({reduxTable:a,value:k,unit:C,rowIndex:U,cellIndex:y}):ve({reduxTable:a,value:k,rowIndex:U,cellIndex:y});h(S)},L=a.reduce((e,U,y)=>(y===0?e.headers=[{cells:[{value:"From"},{value:"To"},{value:"Temperature"}]},{cells:[{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"temperature",testId:"table-unit-selector-3"}]}]:e.rows=e.rows.concat({cells:U.map((k,C)=>{const S=y===1&&C===1;return{value:k,type:S?"Text":"NumberInput",unitKey:C===2?"temperature":"length",onChange:D,roundDisplayValue:y===3&&C===2?I=>w.roundByMagnitude(I,2):null,formatDisplayValue:S?I=>`T* ${I}`:null,autoUnit:!0,testId:`testId_${y}_${C}`}})}),e),{testId:"testId",headers:[],rows:[]});return n.jsxs(ee,{columns:"1fr 1fr",gap:!0,children:[n.jsxs(V,{heading:n.jsx(F,{children:"Settings"}),children:[n.jsx(R,{label:"Convert back to storage unit:",labelLeft:!0,labelWidth:200,children:n.jsx(W,{checked:p,onChange:e=>T(e.target.checked)})}),n.jsx(R,{label:"Enable display rounding:",labelLeft:!0,labelWidth:200,children:n.jsx(W,{checked:d,onChange:e=>o(e.target.checked)})}),n.jsx(R,{label:"Enable cosmetic rounding:",labelLeft:!0,labelWidth:200,children:n.jsx(W,{checked:c,onChange:e=>g(e.target.checked)})}),n.jsx(R,{label:"Convert whole table:",labelLeft:!0,labelWidth:200,children:n.jsx(W,{checked:t,onChange:e=>x(e.target.checked)})})]}),n.jsxs(V,{heading:n.jsx(F,{children:"Unit template"}),children:[n.jsx(R,{label:"Length unit:",labelLeft:!0,labelWidth:120,children:n.jsx(N,{options:(m=w.getUnitsForQuantity("length"))==null?void 0:m.map(e=>({value:e,label:w.label(e)})),value:{value:l},onChange:e=>i(e.target.value),width:"100px"})}),n.jsx(R,{label:"Temperature unit:",labelLeft:!0,labelWidth:120,children:n.jsx(N,{options:(b=w.getUnitsForQuantity("temperature"))==null?void 0:b.map(e=>({value:e,label:w.label(e)})),value:{value:r},onChange:e=>s(e.target.value),width:"100px"})})]}),n.jsx(V,{heading:n.jsx(F,{children:"Storage State (Redux)"}),children:n.jsx("pre",{children:n.jsx("code",{children:JSON.stringify(a,null,2)})})}),n.jsxs(V,{heading:n.jsx(F,{children:"UnitTable"}),children:[n.jsx(M,{table:L,unitConfig:[{unitKey:"length",storageUnit:a[0][0],preferredUnit:l,onChange:({newUnit:e})=>v(e)},{unitKey:"temperature",storageUnit:a[0][2],preferredUnit:r}],convertBackToStorageUnit:p,enableDisplayRounding:d,enableCosmeticRounding:c}),n.jsx(te,{height:20}),n.jsx(R,{label:"Displayed length unit:",labelLeft:!0,labelWidth:150,children:u})]})]})};j.__docgenInfo={description:"",methods:[],displayName:"UnitTableExample"};var O,q,$,G,Q;j.parameters={...j.parameters,docs:{...(O=j.parameters)==null?void 0:O.docs,source:{originalSource:`() => {
1
+ import{j as n}from"./jsx-runtime-eps93zm2.js";import{r as f}from"./index-DhsZuJvc.js";import{f as z}from"./immer.esm-BwVl9PS2.js";import{d as w}from"./index-C0x1JmaP.js";import{G as ee}from"./grid-DRkC-bt8.js";import{S as te}from"./spacer-BWoNR27H.js";import{C as V}from"./card-EcjmryU9.js";import{F as R}from"./field-HrLaMLbx.js";import{H as F}from"./heading-CRNoBc7q.js";import{S as N}from"./select-Cwks-WA0.js";import{T as W}from"./toggle-BbFVf61v.js";import{l as ne}from"./lodash-c4VUpsOs.js";import{u as ae,a as ie,g as re,c as K}from"./initialize-context-Y03pJPr5.js";import{T as oe,C as P}from"./table-BSABGfWm.js";import{s as le}from"./number-input-B3_gmeWr.js";import"./index-DRSy5Ssd.js";import"./styled-components.browser.esm-BQ9GQzDc.js";import"./index-Bk2sglWO.js";import"./label-CqmyC9he.js";import"./common-types-Sih75Sav.js";import"./help-icon-Buhx5nl6.js";import"./tooltip-1V7clEnw.js";import"./index-CUZDtIZe.js";import"./icon-BSFY3vDO.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./inheritsLoose-DP0QEDDI.js";import"./index-CEuq6vkz.js";import"./disabled-context-rmpd7YJS.js";import"./types-Dx2TtIG9.js";import"./enum-Bnn40S8Q.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"./badge-CLQ59MDF.js";import"./select.input-CJed_LLR.js";import"./helpers-JJxzGegQ.js";import"./index.es-DazXb-ul.js";import"./redux-tRgGMjwY.js";import"./objectSpread2-DW4nTBoq.js";import"./tiny-invariant-DqLgxztJ.js";import"./pagination-CR1nxnnq.js";import"./input-Db9WkmPP.js";import"./input-group-BaRSJAEN.js";import"./input-group-addon-D68iUKV2.js";import"./check-box-DPLaOkRR.js";import"./slider-DxaD8LU4.js";import"./index-BI4_Bp97.js";import"./popover-C_2P8LFJ.js";const se=l=>l.reduce(({preferredUnits:i,storageUnits:r},{unitKey:s,preferredUnit:a,storageUnit:h})=>{const{unitTemplate:p=null}=ie()??{};return i[s]=a??re(s,p),r[s]=h,{preferredUnits:i,storageUnits:r}},{preferredUnits:{},storageUnits:{}}),ue=({headers:l,rows:i,selectedUnits:r,storageUnits:s,onChangeUnit:a,convertBackToStorageUnit:h,enableCosmeticRounding:p,enableDisplayRounding:T})=>{const d=l?l.map(c=>({...c,cells:c.cells.map(g=>{var t;if(g.type===P.AUTO_UNIT){const{testId:x,unitKey:u}=g;return{value:r[u],type:P.SELECT,searchable:!1,options:(t=w.getUnitsForQuantity(u))==null?void 0:t.map(v=>({label:w.label(v),value:v})),native:g.native,onChange:v=>a({unitKey:u,value:v.target.value}),testId:x}}return g})})):[],o=i?i.map((c,g)=>({...c,cells:c.cells.map((t,x)=>{if("autoUnit"in t&&(t!=null&&t.autoUnit)&&(typeof(t==null?void 0:t.value)=="string"||typeof(t==null?void 0:t.value)=="number")){const{unitKey:u,value:v,formatDisplayValue:D}=t,L=T&&"roundDisplayValue"in t?t==null?void 0:t.roundDisplayValue:null,m=r[u],b=s[u],e=m!==b,{value:U=v}=K({value:le(v),unitkey:u,toUnit:m,fromUnit:b}),y=e?U:t.value,k=D?D(y):y;return{...t,value:k,enableCosmeticRounding:p&&e,enableDisplayRounding:T,roundDisplayValue:L,onChange:C=>{const{value:S}=C.target,B=s[u],E=r[u],A=E!==B,_=h?B:E,{value:I=S}=K({value:String(S),unitkey:u,toUnit:_,fromUnit:E}),X=A?I:S;if("onChange"in t){const{onChange:Y}=t,Z={...C,target:{...C.target,value:String(X),rowIndex:g,cellIndex:x,unit:_}};Y(Z)}}}}return t})})):[];return{convertedHeaders:d,convertedRows:o}},M=({table:l,unitConfig:i,convertBackToStorageUnit:r=!0,enableCosmeticRounding:s=!0,enableDisplayRounding:a=!0})=>{const{rows:h,headers:p,...T}=l,{storageUnits:d,preferredUnits:o}=se(i),c=ae(o),[g,t]=f.useState(o),x=({unitKey:m,value:b})=>{t({...g,[m]:b});const e=i.find(U=>U.unitKey===m);e&&typeof e.onChange=="function"&&e.onChange({oldUnit:g[m],newUnit:b,unitKey:m})},u=m=>ue({headers:p,rows:h,selectedUnits:m,storageUnits:d,onChangeUnit:x,convertBackToStorageUnit:r,enableCosmeticRounding:s,enableDisplayRounding:a}),v=u(g),[D,L]=f.useState(v);return f.useEffect(()=>{!ne.isEqual(o,c)&&(Object.keys(o).forEach(b=>{const e=c==null?void 0:c[b],U=o[b];e!==U&&x({unitKey:b,value:U})}),L(u(o)))},[i]),f.useEffect(()=>{L(u(g))},[l,g]),n.jsx(oe,{table:{...T,headers:D.convertedHeaders,rows:D.convertedRows}})};M.__docgenInfo={description:"",methods:[],displayName:"UnitTable",props:{table:{required:!0,tsType:{name:"IUnitTable"},description:""},unitConfig:{required:!0,tsType:{name:"Array",elements:[{name:"IUnitConfigItem"}],raw:"IUnitConfigItem[]"},description:""},convertBackToStorageUnit:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},enableCosmeticRounding:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},enableDisplayRounding:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}}},composes:["Omit"]};const ft={title:"Basic/UnitTable",args:{}},de=!0,ce=!0,pe=!0,ge=!1,H="ft",J="C",me=3,he=(l,i,r)=>{const s=[i,i,r],a=[...Array(l)].map((h,p)=>{const T=p,d=p+1.25,o=4+p*.25;return[String(T),String(d),String(o)]});return[s,...a]},be=he(me,H,J),fe=({reduxTable:l,value:i,unit:r,rowIndex:s,cellIndex:a})=>z(l,h=>{const p=h[0][a],T=(d,o)=>o===0;return h.forEach((d,o)=>{if(T(d,o)){d[a]=r;return}if(o===s+1){d[a]=String(i);return}const c=w.convertAndGetValue(d[a],r,p);d[a]=String(c)}),h}),ve=({reduxTable:l,value:i,rowIndex:r,cellIndex:s})=>z(l,a=>{a[r+1][s]=i}),j=()=>{var m,b;const[l,i]=f.useState(H),[r,s]=f.useState(J),[a,h]=f.useState(be),[p,T]=f.useState(de),[d,o]=f.useState(pe),[c,g]=f.useState(ce),[t,x]=f.useState(ge),[u,v]=f.useState(H),D=e=>{const{rowIndex:U,cellIndex:y,value:k,unit:C}=e.target,S=t?fe({reduxTable:a,value:k,unit:C,rowIndex:U,cellIndex:y}):ve({reduxTable:a,value:k,rowIndex:U,cellIndex:y});h(S)},L=a.reduce((e,U,y)=>(y===0?e.headers=[{cells:[{value:"From"},{value:"To"},{value:"Temperature"}]},{cells:[{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"temperature",testId:"table-unit-selector-3"}]}]:e.rows=e.rows.concat({cells:U.map((k,C)=>{const S=y===1&&C===1;return{value:k,type:S?"Text":"NumberInput",unitKey:C===2?"temperature":"length",onChange:D,roundDisplayValue:y===3&&C===2?I=>w.roundByMagnitude(I,2):null,formatDisplayValue:S?I=>`T* ${I}`:null,autoUnit:!0,testId:`testId_${y}_${C}`}})}),e),{testId:"testId",headers:[],rows:[]});return n.jsxs(ee,{columns:"1fr 1fr",gap:!0,children:[n.jsxs(V,{heading:n.jsx(F,{children:"Settings"}),children:[n.jsx(R,{label:"Convert back to storage unit:",labelLeft:!0,labelWidth:200,children:n.jsx(W,{checked:p,onChange:e=>T(e.target.checked)})}),n.jsx(R,{label:"Enable display rounding:",labelLeft:!0,labelWidth:200,children:n.jsx(W,{checked:d,onChange:e=>o(e.target.checked)})}),n.jsx(R,{label:"Enable cosmetic rounding:",labelLeft:!0,labelWidth:200,children:n.jsx(W,{checked:c,onChange:e=>g(e.target.checked)})}),n.jsx(R,{label:"Convert whole table:",labelLeft:!0,labelWidth:200,children:n.jsx(W,{checked:t,onChange:e=>x(e.target.checked)})})]}),n.jsxs(V,{heading:n.jsx(F,{children:"Unit template"}),children:[n.jsx(R,{label:"Length unit:",labelLeft:!0,labelWidth:120,children:n.jsx(N,{options:(m=w.getUnitsForQuantity("length"))==null?void 0:m.map(e=>({value:e,label:w.label(e)})),value:{value:l},onChange:e=>i(e.target.value),width:"100px"})}),n.jsx(R,{label:"Temperature unit:",labelLeft:!0,labelWidth:120,children:n.jsx(N,{options:(b=w.getUnitsForQuantity("temperature"))==null?void 0:b.map(e=>({value:e,label:w.label(e)})),value:{value:r},onChange:e=>s(e.target.value),width:"100px"})})]}),n.jsx(V,{heading:n.jsx(F,{children:"Storage State (Redux)"}),children:n.jsx("pre",{children:n.jsx("code",{children:JSON.stringify(a,null,2)})})}),n.jsxs(V,{heading:n.jsx(F,{children:"UnitTable"}),children:[n.jsx(M,{table:L,unitConfig:[{unitKey:"length",storageUnit:a[0][0],preferredUnit:l,onChange:({newUnit:e})=>v(e)},{unitKey:"temperature",storageUnit:a[0][2],preferredUnit:r}],convertBackToStorageUnit:p,enableDisplayRounding:d,enableCosmeticRounding:c}),n.jsx(te,{height:20}),n.jsx(R,{label:"Displayed length unit:",labelLeft:!0,labelWidth:150,children:u})]})]})};j.__docgenInfo={description:"",methods:[],displayName:"UnitTableExample"};var O,q,$,G,Q;j.parameters={...j.parameters,docs:{...(O=j.parameters)==null?void 0:O.docs,source:{originalSource:`() => {
2
2
  const [preferredLengthUnit, setPreferredLengthUnit] = useState(initialLengthUnit);
3
3
  const [preferredTemperatureUnit, setPreferredTemperatureUnit] = useState(initialTemperatureUnit);
4
4
  const [reduxTable, setReduxTable] = useState<TTable>(initialTable);
@@ -1 +1 @@
1
- import{w as p,u as i,e as r,f as s,a as n}from"./index-DMAnyMX5.js";import{UnitTableExample as c}from"./unit-table.stories-CISvZMxX.js";import"./index-CF7H4eMJ.js";import"./jsx-runtime-eps93zm2.js";import"./index-DhsZuJvc.js";import"./immer.esm-BwVl9PS2.js";import"./index-C0x1JmaP.js";import"./index-DRSy5Ssd.js";import"./grid-DRkC-bt8.js";import"./styled-components.browser.esm-BQ9GQzDc.js";import"./spacer-BWoNR27H.js";import"./card-EcjmryU9.js";import"./index-Bk2sglWO.js";import"./field-HrLaMLbx.js";import"./label-CqmyC9he.js";import"./common-types-Sih75Sav.js";import"./help-icon-Buhx5nl6.js";import"./tooltip-1V7clEnw.js";import"./index-CUZDtIZe.js";import"./icon-BSFY3vDO.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./inheritsLoose-DP0QEDDI.js";import"./index-CEuq6vkz.js";import"./disabled-context-rmpd7YJS.js";import"./heading-CRNoBc7q.js";import"./select-Cwks-WA0.js";import"./lodash-c4VUpsOs.js";import"./types-Dx2TtIG9.js";import"./enum-Bnn40S8Q.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"./badge-CLQ59MDF.js";import"./select.input-CJed_LLR.js";import"./helpers-JJxzGegQ.js";import"./toggle-BbFVf61v.js";import"./initialize-context-Y03pJPr5.js";import"./number-input-B3_gmeWr.js";import"./input-Db9WkmPP.js";import"./table-DoyDBG6l.js";import"./index.es-DazXb-ul.js";import"./redux-tRgGMjwY.js";import"./objectSpread2-DW4nTBoq.js";import"./tiny-invariant-DqLgxztJ.js";import"./pagination-CR1nxnnq.js";import"./input-group-BaRSJAEN.js";import"./input-group-addon-D68iUKV2.js";import"./check-box-DPLaOkRR.js";import"./slider-CcpE4BLD.js";import"./index-BI4_Bp97.js";import"./popover-C_2P8LFJ.js";const wt={title:"Basic/UnitTable/Test Cases",args:{},tags:["!autodocs"]},u=c.bind({});u.play=async({canvasElement:o,step:e})=>{const a=p(o),m=p(o.ownerDocument.body);await e("Can enter decimal values",async()=>{const t=a.getByTestId("testId_2_1");await i.clear(t),await i.type(t,"123.123456789"),await i.click(o),await r(a.getByDisplayValue("123.12")).toBeInTheDocument()}),await e("Can enter comma decimals (converts to dot)",async()=>{const t=a.getByTestId("testId_2_1");await i.clear(t),await i.type(t,"123,456"),await i.click(o),await r(a.getByDisplayValue("123.46")).toBeInTheDocument()}),await e("Can enter small numbers",async()=>{const t=a.getByTestId("testId_2_1");await i.clear(t),await i.type(t,"0.0000000023"),await i.click(o),await r(t).toHaveDisplayValue("0.00")}),await e("Can enter large numbers",async()=>{const t=a.getByTestId("testId_2_1");await i.clear(t),await i.type(t,"999999999999"),await i.click(o),await r(a.getByDisplayValue("999999999999.00")).toBeInTheDocument()}),await e("Shows validation error for non-numeric input",async()=>{const t=a.getByTestId("testId_2_1");await i.clear(t),await i.type(t,"123x45s6"),await i.click(o),await r(a.getByDisplayValue("123x45s6")).toBeInTheDocument(),await r(t.getAttribute("data-error")).toEqual("Must be a numerical value"),await s.mouseOver(t),await n(()=>{r(m.getByText("Must be a numerical value")).toBeInTheDocument()})})};const yt=["Test"];export{u as Test,yt as __namedExportsOrder,wt as default};
1
+ import{w as p,u as i,e as r,f as s,a as n}from"./index-DMAnyMX5.js";import{UnitTableExample as c}from"./unit-table.stories-DwZVHcZo.js";import"./index-CF7H4eMJ.js";import"./jsx-runtime-eps93zm2.js";import"./index-DhsZuJvc.js";import"./immer.esm-BwVl9PS2.js";import"./index-C0x1JmaP.js";import"./index-DRSy5Ssd.js";import"./grid-DRkC-bt8.js";import"./styled-components.browser.esm-BQ9GQzDc.js";import"./spacer-BWoNR27H.js";import"./card-EcjmryU9.js";import"./index-Bk2sglWO.js";import"./field-HrLaMLbx.js";import"./label-CqmyC9he.js";import"./common-types-Sih75Sav.js";import"./help-icon-Buhx5nl6.js";import"./tooltip-1V7clEnw.js";import"./index-CUZDtIZe.js";import"./icon-BSFY3vDO.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./inheritsLoose-DP0QEDDI.js";import"./index-CEuq6vkz.js";import"./disabled-context-rmpd7YJS.js";import"./heading-CRNoBc7q.js";import"./select-Cwks-WA0.js";import"./lodash-c4VUpsOs.js";import"./types-Dx2TtIG9.js";import"./enum-Bnn40S8Q.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"./badge-CLQ59MDF.js";import"./select.input-CJed_LLR.js";import"./helpers-JJxzGegQ.js";import"./toggle-BbFVf61v.js";import"./initialize-context-Y03pJPr5.js";import"./number-input-B3_gmeWr.js";import"./input-Db9WkmPP.js";import"./table-BSABGfWm.js";import"./index.es-DazXb-ul.js";import"./redux-tRgGMjwY.js";import"./objectSpread2-DW4nTBoq.js";import"./tiny-invariant-DqLgxztJ.js";import"./pagination-CR1nxnnq.js";import"./input-group-BaRSJAEN.js";import"./input-group-addon-D68iUKV2.js";import"./check-box-DPLaOkRR.js";import"./slider-DxaD8LU4.js";import"./index-BI4_Bp97.js";import"./popover-C_2P8LFJ.js";const wt={title:"Basic/UnitTable/Test Cases",args:{},tags:["!autodocs"]},u=c.bind({});u.play=async({canvasElement:o,step:e})=>{const a=p(o),m=p(o.ownerDocument.body);await e("Can enter decimal values",async()=>{const t=a.getByTestId("testId_2_1");await i.clear(t),await i.type(t,"123.123456789"),await i.click(o),await r(a.getByDisplayValue("123.12")).toBeInTheDocument()}),await e("Can enter comma decimals (converts to dot)",async()=>{const t=a.getByTestId("testId_2_1");await i.clear(t),await i.type(t,"123,456"),await i.click(o),await r(a.getByDisplayValue("123.46")).toBeInTheDocument()}),await e("Can enter small numbers",async()=>{const t=a.getByTestId("testId_2_1");await i.clear(t),await i.type(t,"0.0000000023"),await i.click(o),await r(t).toHaveDisplayValue("0.00")}),await e("Can enter large numbers",async()=>{const t=a.getByTestId("testId_2_1");await i.clear(t),await i.type(t,"999999999999"),await i.click(o),await r(a.getByDisplayValue("999999999999.00")).toBeInTheDocument()}),await e("Shows validation error for non-numeric input",async()=>{const t=a.getByTestId("testId_2_1");await i.clear(t),await i.type(t,"123x45s6"),await i.click(o),await r(a.getByDisplayValue("123x45s6")).toBeInTheDocument(),await r(t.getAttribute("data-error")).toEqual("Must be a numerical value"),await s.mouseOver(t),await n(()=>{r(m.getByText("Must be a numerical value")).toBeInTheDocument()})})};const yt=["Test"];export{u as Test,yt as __namedExportsOrder,wt as default};
@@ -509,7 +509,7 @@
509
509
  }
510
510
  </script>
511
511
 
512
- <script type="module" crossorigin src="./assets/iframe-CiH1oRY9.js"></script>
512
+ <script type="module" crossorigin src="./assets/iframe-DkdT7E6u.js"></script>
513
513
  </head>
514
514
 
515
515
  <body>