@oliasoft-open-source/react-ui-library 4.7.6 → 4.7.7

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 (138) hide show
  1. package/dist/404.html +1 -1
  2. package/dist/assets/{index-CbZ_B_tn.js → index-DCeIsyRy.js} +1 -0
  3. package/dist/global.css +576 -576
  4. package/dist/index.html +1 -1
  5. package/dist/index.js +1259 -1165
  6. package/dist/index.js.map +1 -1
  7. package/dist/storybook/assets/Color-KGDBMAHA-B09ajdpG.js +1 -0
  8. package/dist/storybook/assets/DocsRenderer-PKQXORMH-B1FePHEE.js +1 -0
  9. package/dist/storybook/assets/{accordion-6ouB0WTt.js → accordion-BiuI_LCA.js} +1 -1
  10. package/dist/storybook/assets/{accordion.stories-YuQaNHcr.js → accordion.stories-wRr6K6oi.js} +2 -2
  11. package/dist/storybook/assets/{actions-CZK3mphC.js → actions-CHgr8eL8.js} +1 -1
  12. package/dist/storybook/assets/{actions.stories-FOK1cLb3.js → actions.stories-CCDxFKFk.js} +1 -1
  13. package/dist/storybook/assets/{afe.stories-CT81gs6M.js → afe.stories-80-X2oCf.js} +2 -2
  14. package/dist/storybook/assets/{badge.stories-D30jHm96.js → badge.stories-D5DA-vxC.js} +1 -1
  15. package/dist/storybook/assets/{blowout.stories-CJrNKpKP.js → blowout.stories-ES-Fuaqn.js} +1 -1
  16. package/dist/storybook/assets/{button-C1sV-0mR.js → button-VxhoNhrV.js} +1 -1
  17. package/dist/storybook/assets/{button-group-Ai4DXqNr.js → button-group-CwJdFo2z.js} +1 -1
  18. package/dist/storybook/assets/{button-group.stories-incmyYJ-.js → button-group.stories-DU5k5qCY.js} +1 -1
  19. package/dist/storybook/assets/{button.stories-Bcy7mnLs.js → button.stories-DVtec2Eo.js} +2 -2
  20. package/dist/storybook/assets/{buttons-and-links-CtOaPZlv.js → buttons-and-links-DrDYbdOk.js} +2 -2
  21. package/dist/storybook/assets/{card.stories-Bn6LpucB.js → card.stories-CsTB0DuM.js} +1 -1
  22. package/dist/storybook/assets/{casing-loads.stories-DQy8gjj6.js → casing-loads.stories-BXcv0FiI.js} +2 -2
  23. package/dist/storybook/assets/{cell.stories-ChfAWqCt.js → cell.stories-MhANINNu.js} +2 -2
  24. package/dist/storybook/assets/{check-box-CaSrhzev.js → check-box-BtCGePRy.js} +1 -1
  25. package/dist/storybook/assets/{check-box.stories-BAH78tMZ.js → check-box.stories-C_7Z7Ss6.js} +1 -1
  26. package/dist/storybook/assets/{chunk-HLWAVYOI-CkQdzq8g.js → chunk-HLWAVYOI-3IbBqp3W.js} +1 -1
  27. package/dist/storybook/assets/color-DqVXeBjc.js +25 -0
  28. package/dist/storybook/assets/{column.stories-JMvj3_fr.js → column.stories-BxfR9Tla.js} +1 -1
  29. package/dist/storybook/assets/{dialog-vClt2ahZ.js → dialog-Di8hNunM.js} +1 -1
  30. package/dist/storybook/assets/{drawer-DSS8yvvp.js → drawer-BhuWxI7V.js} +1 -1
  31. package/dist/storybook/assets/drawer.stories-B-PsNJJ6.js +113 -0
  32. package/dist/storybook/assets/{empty.stories-G8jeIfLL.js → empty.stories-BVYXwvpa.js} +1 -1
  33. package/dist/storybook/assets/{field-C5_fLDpy.js → field-HrLaMLbx.js} +1 -1
  34. package/dist/storybook/assets/{field.stories-D5Mej0Bt.js → field.stories-B9p9nBgY.js} +1 -1
  35. package/dist/storybook/assets/{file-button.stories-DePr8MKB.js → file-button.stories-FOaiNPt-.js} +1 -1
  36. package/dist/storybook/assets/{file-input-BZecnRBy.js → file-input-BpMtsZ2S.js} +1 -1
  37. package/dist/storybook/assets/{file-input.stories-Br89AkVv.js → file-input.stories-Jrdw5k-s.js} +1 -1
  38. package/dist/storybook/assets/{flex.stories-sSdg0ChR.js → flex.stories-BEXf0VqI.js} +1 -1
  39. package/dist/storybook/assets/footer.stories-CGHFDUfT.js +3 -0
  40. package/dist/storybook/assets/form.stories-C1Qx3M_1.js +49 -0
  41. package/dist/storybook/assets/formation.stories-BEowxQZ-.js +74 -0
  42. package/dist/storybook/assets/{heading-NkLgQYoP.js → heading-CRNoBc7q.js} +1 -1
  43. package/dist/storybook/assets/{heading.stories-nI_cFnAN.js → heading.stories-DahFxeiX.js} +1 -1
  44. package/dist/storybook/assets/{help-icon-41R-Z9N1.js → help-icon-Buhx5nl6.js} +1 -1
  45. package/dist/storybook/assets/{help-icon.stories-DBYh0YX7.js → help-icon.stories-DbmZ1fgP.js} +1 -1
  46. package/dist/storybook/assets/icon-BSFY3vDO.js +8 -0
  47. package/dist/storybook/assets/{icon.stories-B-tKaIKA.js → icon.stories-C1hZXIMX.js} +1 -1
  48. package/dist/storybook/assets/iframe-0oHxQxyh.js +2 -0
  49. package/dist/storybook/assets/{index-Be0hXiyp.js → index-DMAnyMX5.js} +1 -1
  50. package/dist/storybook/assets/{index-Cf2IDQZ4.js → index-Dx_aqqZM.js} +8 -8
  51. package/dist/storybook/assets/index-iPmJVpyV.js +1 -0
  52. package/dist/storybook/assets/{index.es-D2piFfFj.js → index.es-DazXb-ul.js} +4 -4
  53. package/dist/storybook/assets/inheritsLoose-DP0QEDDI.js +1 -0
  54. package/dist/storybook/assets/{input-group.stories-BmeUtBOK.js → input-group.stories-44quIZTV.js} +2 -2
  55. package/dist/storybook/assets/{input-validation-U3o9_8IY.js → input-validation-CregAhZZ.js} +2 -2
  56. package/dist/storybook/assets/{inputs-gP7hGRtM.js → inputs-DZn0C_9Y.js} +2 -2
  57. package/dist/storybook/assets/{label-hiSz3I8H.js → label-CqmyC9he.js} +1 -1
  58. package/dist/storybook/assets/{label.stories-Cyv5jBAO.js → label.stories-C0AO5F1a.js} +1 -1
  59. package/dist/storybook/assets/layout-forms-zjNDNCOQ.js +16 -0
  60. package/dist/storybook/assets/{layout-general-Bw291PmI.js → layout-general-_85zGG_p.js} +2 -2
  61. package/dist/storybook/assets/{list-DYNKqvUR.js → list-yVTOdmpX.js} +1 -1
  62. package/dist/storybook/assets/{list.stories-BX67BegD.js → list.stories-ChqQXY5M.js} +2 -2
  63. package/dist/storybook/assets/{list.stories-data-D_ZfzaxE.js → list.stories-data-Iq66w9oH.js} +1 -1
  64. package/dist/storybook/assets/{loader.stories-DjrwwZ15.js → loader.stories-DM7ZJBgz.js} +1 -1
  65. package/dist/storybook/assets/{menu.stories-QTzp0Z7C.js → menu.stories-mt3LwVCk.js} +2 -2
  66. package/dist/storybook/assets/{message-B7G1ESkC.js → message-BYzRg8Ae.js} +1 -1
  67. package/dist/storybook/assets/{message.stories-Czui5Ym7.js → message.stories-K3bQ-5bJ.js} +1 -1
  68. package/dist/storybook/assets/{meta-content-BE7pulye.js → meta-content-cbHGvPJ7.js} +1 -1
  69. package/dist/storybook/assets/{modal.stories-DAxDpo0A.js → modal.stories-Cct1SMOP.js} +2 -2
  70. package/dist/storybook/assets/number-input.stories-C2QTTzzN.js +110 -0
  71. package/dist/storybook/assets/{option-dropdown.stories-ByLG631x.js → option-dropdown.stories-CoLsSS95.js} +1 -1
  72. package/dist/storybook/assets/{padding-and-spacing-DLeCWmND.js → padding-and-spacing-CPgb4ZMT.js} +2 -2
  73. package/dist/storybook/assets/{page.stories-br9ia4zp.js → page.stories-Cse3cMsO.js} +1 -1
  74. package/dist/storybook/assets/{pagination-BtguPxeR.js → pagination-iSMIbR33.js} +1 -1
  75. package/dist/storybook/assets/{pagination.stories-CgG4wp8P.js → pagination.stories-BUPaZD5R.js} +2 -2
  76. package/dist/storybook/assets/{pop-confirm.stories-CZpYmUBz.js → pop-confirm.stories-Dhid1FK8.js} +1 -1
  77. package/dist/storybook/assets/{popover-DgUpTRMk.js → popover-CzZdWNnB.js} +1 -1
  78. package/dist/storybook/assets/popover.stories-Duemqiqp.js +10 -0
  79. package/dist/storybook/assets/{preview-Dml2wSQG.js → preview-Bay6IiqP.js} +2 -2
  80. package/dist/storybook/assets/preview-DrVrew0c.js +2 -0
  81. package/dist/storybook/assets/projects.stories-DU-QlBa6.js +47 -0
  82. package/dist/storybook/assets/{radio-button-C_cV5TWA.js → radio-button-YBwYcMaM.js} +1 -1
  83. package/dist/storybook/assets/{radio-button.stories-BNE-U9db.js → radio-button.stories-CGJnfCk-.js} +1 -1
  84. package/dist/storybook/assets/react-router-dom-Ck2Y_Fzc.js +8 -0
  85. package/dist/storybook/assets/{reservoirs.stories-ux3hZbkX.js → reservoirs.stories-aSZ9r1Pu.js} +2 -2
  86. package/dist/storybook/assets/{rich-text-input.stories-savcIJ5B.js → rich-text-input.stories-CsFyrKRA.js} +3 -3
  87. package/dist/storybook/assets/{row.stories-CG6Eipay.js → row.stories-DL2h5FzP.js} +2 -2
  88. package/dist/storybook/assets/{select-Z-GCZ-pY.js → select-C8iu4-uz.js} +2 -2
  89. package/dist/storybook/assets/{select.stories-CX_B6BvR.js → select.stories-BZFdXGPs.js} +2 -2
  90. package/dist/storybook/assets/{side-bar-ChOjPNLR.js → side-bar-CKbHPgIV.js} +1 -1
  91. package/dist/storybook/assets/{side-bar.stories-BupidZk5.js → side-bar.stories-MUj_dj1F.js} +1 -1
  92. package/dist/storybook/assets/{site.stories-C1GnbK5P.js → site.stories-Ci4g5W2A.js} +2 -2
  93. package/dist/storybook/assets/{slider-gZmYlxxz.js → slider-DAramr8j.js} +4 -4
  94. package/dist/storybook/assets/{slider.stories-CY4GxD4Y.js → slider.stories-Cd0rLfHP.js} +2 -2
  95. package/dist/storybook/assets/{smart-upload-modal.stories-BrsVuS4a.js → smart-upload-modal.stories-BmrhOtOG.js} +1 -1
  96. package/dist/storybook/assets/{spacer.stories-D7Q45uBk.js → spacer.stories-CHEZdgDM.js} +1 -1
  97. package/dist/storybook/assets/{table-CaaSoHex.js → table-BNMxYhsu.js} +1 -1
  98. package/dist/storybook/assets/{table.stories-BiBivAvh.js → table.stories-YV04PKkU.js} +2 -2
  99. package/dist/storybook/assets/{table.stories-data-DwfKQW7P.js → table.stories-data-CR9VpXHs.js} +1 -1
  100. package/dist/storybook/assets/text-link.stories-BQAkVO-W.js +14 -0
  101. package/dist/storybook/assets/{title.stories-CfdJbgvT.js → title.stories-CuiMnOil.js} +2 -2
  102. package/dist/storybook/assets/{toaster-DJeREs3e.js → toaster-BNO0suPv.js} +1 -1
  103. package/dist/storybook/assets/{toaster.stories-QjvljKdT.js → toaster.stories-zcWIPp_X.js} +1 -1
  104. package/dist/storybook/assets/{toggle-Bo-JPbUP.js → toggle-CBpNgTrm.js} +1 -1
  105. package/dist/storybook/assets/{toggle.stories-BYrikgrA.js → toggle.stories-mjk0JIle.js} +1 -1
  106. package/dist/storybook/assets/{tooltip.test-case.stories-C74mKGrI.js → tooltip.test-case.stories-i9YQqba1.js} +1 -1
  107. package/dist/storybook/assets/{top-bar-DG4ok0uF.js → top-bar-C_tn2Pc5.js} +1 -1
  108. package/dist/storybook/assets/top-bar.stories-B2a-RgK-.js +21 -0
  109. package/dist/storybook/assets/{top-bar.testcase.stories-DzsYUZIx.js → top-bar.testcase.stories-DoPEAMYc.js} +1 -1
  110. package/dist/storybook/assets/{tree.stories-RtuZpYXn.js → tree.stories-6UHASEZu.js} +1 -1
  111. package/dist/storybook/assets/unit-input.stories-B3VwXCO8.js +295 -0
  112. package/dist/storybook/assets/unit-table.stories-DQrTQd6a.js +152 -0
  113. package/dist/storybook/iframe.html +1 -1
  114. package/dist/storybook/index.json +1 -1
  115. package/dist/storybook/project.json +1 -1
  116. package/package.json +1 -1
  117. package/dist/storybook/assets/Color-KGDBMAHA-C0EpwEFf.js +0 -1
  118. package/dist/storybook/assets/DocsRenderer-PKQXORMH-CWe5JIRI.js +0 -1
  119. package/dist/storybook/assets/color-eaylxLAo.js +0 -25
  120. package/dist/storybook/assets/drawer.stories-D6FBs1_r.js +0 -113
  121. package/dist/storybook/assets/extends-CF3RwP-h.js +0 -1
  122. package/dist/storybook/assets/footer.stories-BM5UBN62.js +0 -3
  123. package/dist/storybook/assets/form.stories-CYcggA-f.js +0 -49
  124. package/dist/storybook/assets/formation.stories-NDB_Sbor.js +0 -74
  125. package/dist/storybook/assets/icon-BP4BO6-k.js +0 -8
  126. package/dist/storybook/assets/iframe-WLuE3PcW.js +0 -2
  127. package/dist/storybook/assets/index-CXmS_Aty.js +0 -1
  128. package/dist/storybook/assets/inheritsLoose-DR8r8Ogv.js +0 -1
  129. package/dist/storybook/assets/layout-forms-r2wYyx-8.js +0 -16
  130. package/dist/storybook/assets/number-input.stories-CFTNLnHw.js +0 -105
  131. package/dist/storybook/assets/popover.stories-CtaFGXR_.js +0 -10
  132. package/dist/storybook/assets/preview-BjyexbB3.js +0 -2
  133. package/dist/storybook/assets/projects.stories-BSAMs8RG.js +0 -47
  134. package/dist/storybook/assets/react-router-dom-CMITYWBH.js +0 -8
  135. package/dist/storybook/assets/text-link.stories-BsuVBOWo.js +0 -14
  136. package/dist/storybook/assets/top-bar.stories-BI4a_ekv.js +0 -21
  137. package/dist/storybook/assets/unit-input.stories-BSWm9641.js +0 -290
  138. package/dist/storybook/assets/unit-table.stories-CgF-UOP3.js +0 -150
@@ -0,0 +1,295 @@
1
+ import{j as e}from"./jsx-runtime-eps93zm2.js";import{r as m}from"./index-DhsZuJvc.js";import{d as r,r as Cn}from"./index-CWz-hU-f.js";import{c as bn}from"./index-Bk2sglWO.js";import{u as Un}from"./use-previous-D775JrO6.js";import{M as De}from"./actions-CHgr8eL8.js";import{I as In}from"./input-group-addon-D68iUKV2.js";import{B as p}from"./button-VxhoNhrV.js";import{T as wn}from"./tooltip-1V7clEnw.js";import{I as xn}from"./input-group-BaRSJAEN.js";import{S as k}from"./spacer-BWoNR27H.js";import{T as Zt}from"./text-B3-TSWok.js";import{I as Vn}from"./input-BW9trNAW.js";import{M as qe}from"./types-BmbYqTX_.js";import{l as A}from"./lodash-BHd_uQHh.js";import{D as Tn}from"./divider-DY9nJ_7N.js";import{R as Qt,C as ye}from"./row-4iAGREkV.js";import{F as T}from"./field-HrLaMLbx.js";import{M as Ce}from"./message-BYzRg8Ae.js";import{w as Pe,u as c,e as V,f as kn}from"./index-DMAnyMX5.js";import"./index-DRSy5Ssd.js";import"./common-types-Sih75Sav.js";import"./disabled-context-rmpd7YJS.js";import"./icon-BSFY3vDO.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./inheritsLoose-DP0QEDDI.js";import"./index-CEuq6vkz.js";import"./types-UmZ4Y_CR.js";import"./badge-CLQ59MDF.js";import"./spinner-AWUe4xwQ.js";import"./index-CUZDtIZe.js";import"./styled-components.browser.esm-Bf0q9Yjk.js";import"./label-CqmyC9he.js";import"./help-icon-Buhx5nl6.js";import"./index-CF7H4eMJ.js";const jn=()=>{const t=m.useRef(null);return m.useLayoutEffect(()=>{t.current&&(t.current(),t.current=null)}),n=>{t.current=n}},En=(t,a)=>{const n=a==null?void 0:a[t];return n||(console.log(`Warning: 'unitTemplate' missing for '${t}'. Using initial unit, preferred unit or value unit.`),r.unitFromQuantity(t)??"")};var b=(t=>(t.CUSTOM="custom",t.PREDEFINED="predefined",t))(b||{});const Xt=t=>t==="undefined"||t===void 0||t===""||t==="null"||t===null||t==="NaN"||isNaN(t),en=(t="",a,n="",l=!1)=>{if(l)return t;if(a&&!Xt(t))try{const s=r.isValueWithUnit(t)?t:r.withUnit(t,n),d=r.convertSamePrecision(s,a);return r.getValue(d)}catch{}return t},Sn=t=>t?!!r.getUnit(t):!1,W=(t="",a,n,l)=>{if(l)return t;const s=Sn(t)||r.isValueWithUnit(t),d=r.getValue(t);return Xt(d)?d:s?en(d,a,n,l):t},Be=t=>A.isObject(t)&&!A.isArray(t)&&!A.isFunction(t)?A.get(t,"fieldName",""):typeof t=="string"?t:"",Nn=t=>A.isObjectLike(t)&&A.has(t,"message"),An=t=>typeof t=="string"?t:Nn(t)?t.message:null;var Dn=Cn();const qn=t=>t.search(RegExp(/(^0{2}\.)|(^0+[1-9])/g))===0,Me=(t,a)=>{var j;const{allowEmpty:n=!1,autoValue:l,placeholder:s,disabledValidation:d=!1}=a||{},u=String(t);if(d||l||s)return null;const h=Dn.isValueWithUnit(u)?r.getValue(u):u;if(n&&h==="")return null;if(qn(h))return"Invalid number format due to leading zeroes";const v=r.validateNumber(h);if(!v.valid){const de=((j=v==null?void 0:v.errors)==null?void 0:j[0])??null;return An(de)}return null},_e=(t="")=>{var a;return(a=r.KNOWN_UNITS)==null?void 0:a.includes(t)},Pn=(t,a)=>{const n=r.getUnit(t||"");return _e(a)&&_e(n)};let Bn=m.createContext(null);const Mn=()=>m.useContext(Bn),_n="_predefinedMenuActive_1yvt4_1",Fn={predefinedMenuActive:_n},g=({name:t,placeholder:a="",disabled:n=!1,disabledUnit:l=!1,error:s=null,left:d=!1,small:u=!1,width:h="100%",value:v,unitkey:j="",initUnit:de,noConversion:tn=!1,onChange:ce=()=>{},onClick:Wn=()=>{},onFocus:nn=()=>{},onSwitchUnit:be=()=>{},unitTemplate:Ue,doNotConvertValue:M=!1,testId:S,warning:an=null,predefinedOptions:w,initialPredefinedOption:sn=!1,shouldLinkAutomaticly:Ie=!0,selectedPredefinedOptionKey:we,validationCallback:xe=()=>({name:"",error:null}),disabledValidation:Ve=!1,allowEmpty:Te=!1,autoValue:x})=>{const N=Mn(),rn=jn();typeof v=="number"&&(v=`${v}`);const[me="",_=""]=v!==void 0?r.split(v):[],ke=x?r.getUnit(x):"",je=m.useMemo(()=>En(j,Ue||(N==null?void 0:N.unitTemplate)),[j,Ue,N==null?void 0:N.unitTemplate]),ln=Pn(v,je),I=de||je||_,un=Un(I),Ee=W(v,I,_,M),Se=W(x,I,ke,M),on=Ee!==""?{value:Ee,unit:I}:Se!==""?{value:Se,unit:I}:{value:me,unit:_},[f,re]=m.useState(on),[dn,pe]=m.useState(null),[E,ge]=m.useState(sn?b.PREDEFINED:b.CUSTOM),he=me===""&&x,F=w&&w.find(i=>{if(!(i!=null&&i.value))return;if(we)return we===i.valueKey;const o=r.isValueWithUnit(i.value)?r.getUnit(i.value):"";return r.withUnit(en(v,o),o)===i.value}),cn=()=>{if(j)try{const i=he?x:v??"";let o=r.altUnitsList(i,j);return r.getValue(i)===""?o.map(y=>["",y[1]]):o}catch{return null}},mn=i=>{const o=Be(t),y=i.target,{value:U,selectionStart:O}=y,Ae=r.cleanNumStr(U.replaceAll(" ","").replaceAll("|","")),ve=r.withUnit(Ae,(f==null?void 0:f.unit)||""),vn=r.getValue(ve),fe=Me(vn,{allowEmpty:Te,autoValue:x,placeholder:a,disabledValidation:Ve});if(fe===null){ce({target:{value:ve,name:o}});const[fn,yn]=r.split(ve);re({value:fn,unit:yn}),pe(null),xe(o,null)}else re({value:Ae,unit:f.unit}),pe(fe),xe(o,fe);rn(()=>{y.selectionStart=O,y.selectionEnd=O})},pn=(i,o)=>{o===f.unit||isNaN(Number(i))||(re({value:i,unit:o}),be&&be(o))};m.useEffect(()=>{if(I){let y,U="";un!==I?(y=W(v,I,_,M),U=I):r.withUnit(f.value,f.unit)!==v&&(y=W(v,f.unit,_,M),U=f.unit),y!==void 0&&re({value:y,unit:U}),w&&ge(F&&Ie?b.PREDEFINED:b.CUSTOM)}const i=r.checkAndCleanDecimalComma(me),o=Me(i,{allowEmpty:Te,autoValue:x,placeholder:a,disabledValidation:Ve});pe(o)},[I,v,s,Ie]);const ie=cn(),le=r.label(f.unit)||f.unit||"",gn=tn||!ie||ie&&ie.length===1,Ne=Be(t);let ue;const hn=i=>{const o=i!=null&&i.value?i.value:"",[y="",U=""]=r.isValueWithUnit(o)?r.split(o):[o];return{type:qe.OPTION,inline:!0,onClick:()=>{r.validateNumber(y).valid&&!n&&(ge(b.PREDEFINED),ce({target:{value:o,name:typeof t=="string"?t:(t==null?void 0:t.fieldName)||"",predefinedSelected:!0,predefinedOption:i}}))},label:e.jsxs(e.Fragment,{children:[e.jsx(Zt,{children:i.label}),e.jsx(k,{width:"20px",height:"0"})]}),description:r.isValueWithUnit(o)?`${y} ${U}`:o,selected:F===i&&E===b.PREDEFINED}};if(ue=[{type:qe.OPTION,inline:!0,onClick:()=>{E!==b.CUSTOM&&!n&&ce({target:{value:r.withUnit(f.value,f.unit),name:typeof t=="string"?t:(t==null?void 0:t.fieldName)||""}})},label:"Custom",selected:E===b.CUSTOM}],w!=null&&w.length){const i=w.map(hn);ue=[...ue,...i]}return e.jsx("div",{className:E===b.PREDEFINED?bn(Fn.predefinedMenuActive):"",children:e.jsxs(xn,{small:u,width:h,children:[w&&e.jsx(wn,{text:E===b.PREDEFINED?F==null?void 0:F.label:"",children:e.jsx(De,{maxHeight:380,groupOrder:"first",testId:S&&`${S}-predefined-menu`,disabled:n,menu:{colored:!0,trigger:"Component",component:e.jsx(p,{groupOrder:"first",active:E===b.PREDEFINED,icon:E===b.PREDEFINED?"link":"unlink"}),small:u,sections:ue}})}),e.jsx(Vn,{type:"text",name:Ne,testId:S,disabled:n,placeholder:he?W(x,f.unit,ke,M):a,value:f.value,onChange:mn,onFocus:nn,error:s||dn,warning:an,right:!d},Ne),le&&(gn||!ln?e.jsx(In,{groupOrder:"last",children:le}):e.jsx(De,{maxHeight:380,groupOrder:"last",disabled:l,testId:S&&`${S}-menu`,menu:{label:le,trigger:"DropDownButton",small:u,sections:ie.map(([i,o,y])=>{const U=y||o||"";return{type:"Option",label:isNaN(Number(i))?"":i,inline:!0,onClick:O=>{O.stopPropagation(),pn(he?"":i,o)},description:U,selected:U===le,testId:`${S}-unit-${U}`}})}}))]})})};g.__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:`(
2
+ name: string,
3
+ message: string | null,
4
+ ) => { name: string; error: string | null }`,signature:{arguments:[{type:{name:"string"},name:"name"},{type:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}]},name:"message"}],return:{name:"signature",type:"object",raw:"{ name: string; error: string | null }",signature:{properties:[{key:"name",value:{name:"string",required:!0}},{key:"error",value:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}],required:!0}}]}}}},description:"",defaultValue:{value:"() => ({ name: '', error: null })",computed:!1}},disabledValidation:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},allowEmpty:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},autoValue:{required:!1,tsType:{name:"string"},description:""},onChange:{required:!1,tsType:{name:"signature",type:"function",raw:"(event: ChangeEvent<HTMLInputElement> | ICustomChangeEvent) => void",signature:{arguments:[{type:{name:"union",raw:"ChangeEvent<HTMLInputElement> | ICustomChangeEvent",elements:[{name:"ChangeEvent",elements:[{name:"HTMLInputElement"}],raw:"ChangeEvent<HTMLInputElement>"},{name:"ICustomChangeEvent"}]},name:"event"}],return:{name:"void"}}},description:"",defaultValue:{value:"() => {}",computed:!1}},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:"() => {}",computed:!1}},onClick:{required:!1,tsType:{name:"MouseEventHandler",elements:[{name:"HTMLInputElement"}],raw:"MouseEventHandler<HTMLInputElement>"},description:"",defaultValue:{value:"() => {}",computed:!1}},onFocus:{required:!1,tsType:{name:"FocusEventHandler",elements:[{name:"HTMLInputElement"}],raw:"FocusEventHandler<HTMLInputElement>"},description:"",defaultValue:{value:"() => {}",computed:!1}},unitTemplate:{required:!1,tsType:{name:"Record",elements:[{name:"string"},{name:"any"}],raw:"Record<string, any>"},description:""}}};const{useArgs:On}=__STORYBOOK_MODULE_PREVIEW_API__,wa={title:"Basic/UnitInput",component:g,args:{name:"example",unitkey:"length",value:"123|m"}},C=t=>{const[a,n]=On(),l=s=>{n({value:s.target.value})};return e.jsx(g,{...t,onChange:l})},oe=C.bind({}),R=C.bind({});R.args={initUnit:"ft",unitTemplate:{length:"ft"}};const H=C.bind({});H.args={value:'123|"',unitkey:'"'};const L=C.bind({});L.args={width:"180px"};const K=C.bind({});K.args={noConversion:!0};const $=C.bind({});$.args={small:!0};const z=C.bind({});z.args={error:"Error message goes here"};const G=C.bind({});G.args={value:"asas123asd|%"};const D=C.bind({});D.args={disabled:!0,disabledUnit:!0};D.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 J=C.bind({});J.args={disabled:!0,disabledUnit:!0,noConversion:!0};const Y=C.bind({});Y.args={disabledUnit:!0,unitkey:void 0};const Z=C.bind({});Z.args={disabledUnit:!0,unitkey:"length"};const Q=C.bind({});Q.args={disabledUnit:!1,disabled:!0};const q=t=>{const[a,n]=m.useState("123|m"),[l,s]=m.useState("223|m"),[d,u]=m.useState("ft");return e.jsxs(e.Fragment,{children:[e.jsx(p,{label:"Change initUnit",onClick:()=>u(d==="m"?"ft":"m")}),e.jsx(k,{}),e.jsx(p,{label:"Change value",onClick:()=>n(a==="123|m"?"456|m":"123|m")}),e.jsx(k,{}),e.jsx(g,{name:"example",onChange:h=>{n(h.target.value)},unitkey:"length",value:a,initUnit:d,onSwitchUnit:u}),e.jsx(k,{}),e.jsx(g,{name:"example2",onChange:h=>{s(h.target.value)},unitkey:"length",value:l,initUnit:d,onSwitchUnit:u}),e.jsx(Tn,{}),e.jsx("h4",{children:"Without initUnit property (taken from the redux store)"}),e.jsx(g,{name:"example",onChange:h=>{n(h.target.value)},unitkey:"length",value:a,onSwitchUnit:u}),e.jsx(g,{name:"example2",onChange:h=>{s(h.target.value)},unitkey:"length",value:l,onSwitchUnit:u})]})};q.parameters={docs:{description:{story:"[OW-4380](https://oliasoft.atlassian.net/browse/OW-4380?atlOrigin=eyJpIjoiMmM1N2RkNWU3Mjk5NDYxY2E0YzhkMzk5ZTVmZTJhMjciLCJwIjoiaiJ9)"}}};const X=C.bind({});X.args={predefinedOptions:[{label:"bottom of casing",value:"12|km"},{label:"mud weight at shoe depth",value:"8|mm"}]};const P=()=>{const t="500px",[a,n]=m.useState(void 0);return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different edge cases such as +/- infinity, undefined, NaN, null:"}),e.jsxs(Qt,{children:[e.jsxs(ye,{width:"25%",children:[e.jsx(p,{label:"Change value infinity",onClick:()=>n(1/0)}),e.jsx("br",{}),e.jsx(p,{label:"Change value -infinity",onClick:()=>n(-1/0)}),e.jsx("br",{}),e.jsx(p,{label:"Change value null",onClick:()=>n(null)}),e.jsx("br",{}),e.jsx(p,{label:"Change value - undefined",onClick:()=>n(void 0)}),e.jsx("br",{}),e.jsx(p,{label:"Change value - NaN",onClick:()=>n(NaN)}),e.jsx("br",{}),e.jsx(p,{label:"Change value - nothing (empty)",onClick:()=>n(void 0)}),e.jsx("br",{}),e.jsx(p,{label:"Change value - empty string",onClick:()=>n("")})]}),e.jsxs(ye,{width:"25%",children:[e.jsx(p,{label:"Change value infinity|m",onClick:()=>n("Infinity|m")}),e.jsx("br",{}),e.jsx(p,{label:"Change value -infinity|m",onClick:()=>n("-Infinity|m")}),e.jsx("br",{}),e.jsx(p,{label:"Change value null|m",onClick:()=>n("null|m")}),e.jsx("br",{}),e.jsx(p,{label:"Change value - undefined|m",onClick:()=>n("undefined|m")}),e.jsx("br",{}),e.jsx(p,{label:"Change value - NaN|m",onClick:()=>n("NaN|m")}),e.jsx("br",{}),e.jsx(p,{label:"Change value - nothing (empty)|m",onClick:()=>n("|m")})]})]}),e.jsx("br",{}),e.jsx(T,{label:"Normal PUI",children:e.jsx(g,{name:"example1",onChange:l=>n(l.target.value),value:a,unitkey:"length",width:t,placeholder:"value|unit"})}),e.jsx(T,{label:"Disabled validation",children:e.jsx(g,{name:"example2",onChange:l=>n(l.target.value),value:a,unitkey:"length",disabledValidation:!0,width:t})}),e.jsx(T,{label:"Disabled validation and manual error",children:e.jsx(g,{name:"example3",onChange:l=>n(l.target.value),value:a,unitkey:"length",error:"test",disabledValidation:!0,width:t})}),e.jsx(Ce,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})},ee=()=>{const t="500px",[a,n]=m.useState("1|m"),[l,s]=m.useState("|m"),d="123|km";return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different cases for automatic (placeholder) values:"}),e.jsx(Qt,{children:e.jsxs(ye,{width:"25%",children:[e.jsx(p,{label:"Change value to ''",onClick:()=>n("")}),e.jsx("br",{}),e.jsx(p,{label:"Change value to 1",onClick:()=>n("1")}),e.jsx("br",{}),e.jsx(p,{label:"Change value to 1|m",onClick:()=>n("1|m")}),e.jsx("br",{}),e.jsx(p,{label:"Change value to |m - empty value",onClick:()=>n("|m")})]})}),e.jsx("br",{}),e.jsx(T,{label:"Normal PUI (placeholder + auto)",children:e.jsx(g,{name:"example1",onChange:u=>n(u.target.value),value:a,unitkey:"length",width:t,placeholder:"value|unit",autoValue:d})}),e.jsx(T,{label:"Normal PUI (only auto)",children:e.jsx(g,{name:"example1",onChange:u=>n(u.target.value),value:a,unitkey:"length",width:t,autoValue:d})}),e.jsx(T,{label:"Empty PUI with autoValue",children:e.jsx(g,{name:"example1",onChange:u=>s(u.target.value),value:l,unitkey:"length",width:t,autoValue:d})}),e.jsx(T,{label:"Normal PUI (only placeholder)",children:e.jsx(g,{name:"example1",onChange:u=>n(u.target.value),value:a,unitkey:"length",width:t,placeholder:"Placeholder test"})}),e.jsx(T,{label:"Normal PUI (placeholder + allowEmpty)",children:e.jsx(g,{name:"example1",onChange:u=>n(u.target.value),value:a,unitkey:"length",width:t,placeholder:"Placeholder test",allowEmpty:!0})}),e.jsx(Ce,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})};P.parameters={docs:{description:{story:"[OW-8884](https://oliasoft.atlassian.net/browse/OW-8884)"}}};const te=()=>{const[t,a]=m.useState("123|%"),[n,l]=m.useState(null),s="This should be visible when an error appears",d=(u,h)=>(l(h),{name:u,error:h});return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"3rd party validation message when inputting invalid value:"}),e.jsx(g,{name:"example",onChange:u=>a(u.target.value),error:!n||s,validationCallback:d,value:t}),e.jsx("br",{}),e.jsx(k,{}),e.jsx("h4",{children:"Original validation message: "}),e.jsx(Ce,{message:{heading:n,visible:!0}})]})},ne=()=>{const[t,a]=m.useState("123|m"),[n,l]=m.useState(""),[s,d]=m.useState("km"),u=()=>{d("ft"),l("placeholder"),a("|m")};return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Empty value case:"}),e.jsx(g,{name:"example",onChange:h=>a(h.target.value),value:t,allowEmpty:!0,placeholder:n,initUnit:s,unitkey:"length"}),e.jsx("br",{}),e.jsx(k,{}),e.jsx(p,{label:"Change value |m and unit ft",onClick:()=>u()})]})},ae=()=>{const[t,a]=m.useState("123|m"),[n,l]=m.useState("m");return e.jsxs(e.Fragment,{children:[e.jsx(g,{name:"example",onChange:s=>a(s.target.value),value:t,initUnit:n,unitkey:"length",onSwitchUnit:l}),e.jsx(k,{}),e.jsx(g,{name:"example",onChange:s=>a(s.target.value),value:t,initUnit:n,unitkey:"length",onSwitchUnit:l})]})},se=()=>e.jsxs(e.Fragment,{children:[e.jsx(Zt,{faint:!0,children:"Reproduce OW-10614 rounding noise bug when storing values in a different unit to the display unit"}),e.jsx(k,{}),e.jsx(g,{name:"example",onChange:()=>{},value:r.withUnit(r.convertAndGetValue("9750|psi","bar"),"bar"),initUnit:"psi",unitkey:"pressure",unitTemplate:{pressure:"psi"}})]}),B=()=>{const[t,a]=m.useState("123|m");return e.jsx(g,{name:"example",onChange:n=>a(n.target.value),value:t,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"},testId:"testId"})};B.play=async({canvasElement:t,step:a})=>{const n=Pe(t),l=Pe(t.ownerDocument.body);await a("Can enter decimal values",async()=>{const s=n.getByTestId("testId");await c.clear(s),await c.type(s,"123.123456789"),await c.click(t),await V(n.getByDisplayValue("123.123456789")).toBeInTheDocument()}),await a("Can enter scientific notation",async()=>{const s=n.getByTestId("testId");await c.clear(s),await c.type(s,"-1.12e3"),await c.click(t),await V(n.getByDisplayValue("-1.12e3")).toBeInTheDocument()}),await a("Can enter comma decimals (converts to dot)",async()=>{const s=n.getByTestId("testId");await c.clear(s),await c.type(s,"123,456"),await c.click(t),await V(n.getByDisplayValue("123.456")).toBeInTheDocument()}),await a("Can enter small numbers",async()=>{const s=n.getByTestId("testId");await c.clear(s),await c.type(s,"0.0000000023"),await c.click(t),await V(n.getByDisplayValue("0.0000000023")).toBeInTheDocument()}),await a("Can enter large numbers",async()=>{const s=n.getByTestId("testId");await c.clear(s),await c.type(s,"999999999999"),await c.click(t),await V(n.getByDisplayValue("999999999999")).toBeInTheDocument()}),await a("Can convert units",async()=>{const s=n.getByTestId("testId"),d=n.getByTestId("testId-menu");await c.clear(s),await c.type(s,"456.1"),await c.click(t),await c.click(d),await c.click(l.getByTestId("testId-unit-ft")),await V(n.getByDisplayValue("1496")).toBeInTheDocument()}),await a("Shows validation error for non-numeric input",async()=>{const s=n.getByTestId("testId");await c.clear(s),await c.type(s,"123x45s6"),await c.click(t),await V(n.getByDisplayValue("123x45s6")).toBeInTheDocument(),await kn.mouseOver(s),await V(l.getByText("Must be a numerical value")).toBeInTheDocument()})};q.__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:`(
5
+ name: string,
6
+ message: string | null,
7
+ ) => { name: string; error: string | null }`,signature:{arguments:[{type:{name:"string"},name:"name"},{type:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}]},name:"message"}],return:{name:"signature",type:"object",raw:"{ name: string; error: string | null }",signature:{properties:[{key:"name",value:{name:"string",required:!0}},{key:"error",value:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}],required:!0}}]}}}},description:""},disabledValidation:{required:!1,tsType:{name:"boolean"},description:""},allowEmpty:{required:!1,tsType:{name:"boolean"},description:""},autoValue:{required:!1,tsType:{name:"string"},description:""},onChange:{required:!0,tsType:{name:"signature",type:"function",raw:"(event: ChangeEvent<HTMLInputElement> | ICustomChangeEvent) => void",signature:{arguments:[{type:{name:"union",raw:"ChangeEvent<HTMLInputElement> | ICustomChangeEvent",elements:[{name:"ChangeEvent",elements:[{name:"HTMLInputElement"}],raw:"ChangeEvent<HTMLInputElement>"},{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:""}}};P.__docgenInfo={description:"",methods:[],displayName:"TestEdgeCases"};ee.__docgenInfo={description:"",methods:[],displayName:"AutomaticValues"};te.__docgenInfo={description:"",methods:[],displayName:"ValidationCallback"};ne.__docgenInfo={description:"",methods:[],displayName:"AllowEmptyPUI"};ae.__docgenInfo={description:"",methods:[],displayName:"onSwitchUnit"};se.__docgenInfo={description:"",methods:[],displayName:"OW_10614TestCase"};B.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"TestUserInput"};var Fe,Oe,We;oe.parameters={...oe.parameters,docs:{...(Fe=oe.parameters)==null?void 0:Fe.docs,source:{originalSource:`args => {
8
+ const [_, updateArgs] = useArgs();
9
+ const handleChange = (evt: any) => {
10
+ updateArgs({
11
+ value: evt.target.value
12
+ });
13
+ };
14
+ return <UnitInput {...args} onChange={handleChange} />;
15
+ }`,...(We=(Oe=oe.parameters)==null?void 0:Oe.docs)==null?void 0:We.source}}};var Re,He,Le;R.parameters={...R.parameters,docs:{...(Re=R.parameters)==null?void 0:Re.docs,source:{originalSource:`args => {
16
+ const [_, updateArgs] = useArgs();
17
+ const handleChange = (evt: any) => {
18
+ updateArgs({
19
+ value: evt.target.value
20
+ });
21
+ };
22
+ return <UnitInput {...args} onChange={handleChange} />;
23
+ }`,...(Le=(He=R.parameters)==null?void 0:He.docs)==null?void 0:Le.source}}};var Ke,$e,ze;H.parameters={...H.parameters,docs:{...(Ke=H.parameters)==null?void 0:Ke.docs,source:{originalSource:`args => {
24
+ const [_, updateArgs] = useArgs();
25
+ const handleChange = (evt: any) => {
26
+ updateArgs({
27
+ value: evt.target.value
28
+ });
29
+ };
30
+ return <UnitInput {...args} onChange={handleChange} />;
31
+ }`,...(ze=($e=H.parameters)==null?void 0:$e.docs)==null?void 0:ze.source}}};var Ge,Je,Ye;L.parameters={...L.parameters,docs:{...(Ge=L.parameters)==null?void 0:Ge.docs,source:{originalSource:`args => {
32
+ const [_, updateArgs] = useArgs();
33
+ const handleChange = (evt: any) => {
34
+ updateArgs({
35
+ value: evt.target.value
36
+ });
37
+ };
38
+ return <UnitInput {...args} onChange={handleChange} />;
39
+ }`,...(Ye=(Je=L.parameters)==null?void 0:Je.docs)==null?void 0:Ye.source}}};var Ze,Qe,Xe;K.parameters={...K.parameters,docs:{...(Ze=K.parameters)==null?void 0:Ze.docs,source:{originalSource:`args => {
40
+ const [_, updateArgs] = useArgs();
41
+ const handleChange = (evt: any) => {
42
+ updateArgs({
43
+ value: evt.target.value
44
+ });
45
+ };
46
+ return <UnitInput {...args} onChange={handleChange} />;
47
+ }`,...(Xe=(Qe=K.parameters)==null?void 0:Qe.docs)==null?void 0:Xe.source}}};var et,tt,nt;$.parameters={...$.parameters,docs:{...(et=$.parameters)==null?void 0:et.docs,source:{originalSource:`args => {
48
+ const [_, updateArgs] = useArgs();
49
+ const handleChange = (evt: any) => {
50
+ updateArgs({
51
+ value: evt.target.value
52
+ });
53
+ };
54
+ return <UnitInput {...args} onChange={handleChange} />;
55
+ }`,...(nt=(tt=$.parameters)==null?void 0:tt.docs)==null?void 0:nt.source}}};var at,st,rt;z.parameters={...z.parameters,docs:{...(at=z.parameters)==null?void 0:at.docs,source:{originalSource:`args => {
56
+ const [_, updateArgs] = useArgs();
57
+ const handleChange = (evt: any) => {
58
+ updateArgs({
59
+ value: evt.target.value
60
+ });
61
+ };
62
+ return <UnitInput {...args} onChange={handleChange} />;
63
+ }`,...(rt=(st=z.parameters)==null?void 0:st.docs)==null?void 0:rt.source}}};var it,lt,ut;G.parameters={...G.parameters,docs:{...(it=G.parameters)==null?void 0:it.docs,source:{originalSource:`args => {
64
+ const [_, updateArgs] = useArgs();
65
+ const handleChange = (evt: any) => {
66
+ updateArgs({
67
+ value: evt.target.value
68
+ });
69
+ };
70
+ return <UnitInput {...args} onChange={handleChange} />;
71
+ }`,...(ut=(lt=G.parameters)==null?void 0:lt.docs)==null?void 0:ut.source}}};var ot,dt,ct;D.parameters={...D.parameters,docs:{...(ot=D.parameters)==null?void 0:ot.docs,source:{originalSource:`args => {
72
+ const [_, updateArgs] = useArgs();
73
+ const handleChange = (evt: any) => {
74
+ updateArgs({
75
+ value: evt.target.value
76
+ });
77
+ };
78
+ return <UnitInput {...args} onChange={handleChange} />;
79
+ }`,...(ct=(dt=D.parameters)==null?void 0:dt.docs)==null?void 0:ct.source}}};var mt,pt,gt;J.parameters={...J.parameters,docs:{...(mt=J.parameters)==null?void 0:mt.docs,source:{originalSource:`args => {
80
+ const [_, updateArgs] = useArgs();
81
+ const handleChange = (evt: any) => {
82
+ updateArgs({
83
+ value: evt.target.value
84
+ });
85
+ };
86
+ return <UnitInput {...args} onChange={handleChange} />;
87
+ }`,...(gt=(pt=J.parameters)==null?void 0:pt.docs)==null?void 0:gt.source}}};var ht,vt,ft;Y.parameters={...Y.parameters,docs:{...(ht=Y.parameters)==null?void 0:ht.docs,source:{originalSource:`args => {
88
+ const [_, updateArgs] = useArgs();
89
+ const handleChange = (evt: any) => {
90
+ updateArgs({
91
+ value: evt.target.value
92
+ });
93
+ };
94
+ return <UnitInput {...args} onChange={handleChange} />;
95
+ }`,...(ft=(vt=Y.parameters)==null?void 0:vt.docs)==null?void 0:ft.source}}};var yt,Ct,bt;Z.parameters={...Z.parameters,docs:{...(yt=Z.parameters)==null?void 0:yt.docs,source:{originalSource:`args => {
96
+ const [_, updateArgs] = useArgs();
97
+ const handleChange = (evt: any) => {
98
+ updateArgs({
99
+ value: evt.target.value
100
+ });
101
+ };
102
+ return <UnitInput {...args} onChange={handleChange} />;
103
+ }`,...(bt=(Ct=Z.parameters)==null?void 0:Ct.docs)==null?void 0:bt.source}}};var Ut,It,wt;Q.parameters={...Q.parameters,docs:{...(Ut=Q.parameters)==null?void 0:Ut.docs,source:{originalSource:`args => {
104
+ const [_, updateArgs] = useArgs();
105
+ const handleChange = (evt: any) => {
106
+ updateArgs({
107
+ value: evt.target.value
108
+ });
109
+ };
110
+ return <UnitInput {...args} onChange={handleChange} />;
111
+ }`,...(wt=(It=Q.parameters)==null?void 0:It.docs)==null?void 0:wt.source}}};var xt,Vt,Tt;q.parameters={...q.parameters,docs:{...(xt=q.parameters)==null?void 0:xt.docs,source:{originalSource:`(args: IUnitInputProps) => {
112
+ const [value, setValue] = useState('123|m');
113
+ const [value2, setValue2] = useState('223|m');
114
+ const [initUnit, setInitUnit] = useState('ft');
115
+ return <>
116
+ <Button label="Change initUnit" onClick={() => setInitUnit(initUnit === 'm' ? 'ft' : 'm')} />
117
+ <Spacer />
118
+ <Button label="Change value" onClick={() => setValue(value === '123|m' ? '456|m' : '123|m')} />
119
+ <Spacer />
120
+ <UnitInput name="example" onChange={evt => {
121
+ setValue(evt.target.value);
122
+ }} unitkey="length" value={value} initUnit={initUnit} onSwitchUnit={setInitUnit} />
123
+ <Spacer />
124
+ <UnitInput name="example2" onChange={evt => {
125
+ setValue2(evt.target.value);
126
+ }} unitkey="length" value={value2} initUnit={initUnit} onSwitchUnit={setInitUnit} />
127
+ <Divider />
128
+ <h4>Without initUnit property (taken from the redux store)</h4>
129
+ <UnitInput name="example" onChange={evt => {
130
+ setValue(evt.target.value);
131
+ }} unitkey="length" value={value} onSwitchUnit={setInitUnit} />
132
+ <UnitInput name="example2" onChange={evt => {
133
+ setValue2(evt.target.value);
134
+ }} unitkey="length" value={value2} onSwitchUnit={setInitUnit} />
135
+ </>;
136
+ }`,...(Tt=(Vt=q.parameters)==null?void 0:Vt.docs)==null?void 0:Tt.source}}};var kt,jt,Et;X.parameters={...X.parameters,docs:{...(kt=X.parameters)==null?void 0:kt.docs,source:{originalSource:`args => {
137
+ const [_, updateArgs] = useArgs();
138
+ const handleChange = (evt: any) => {
139
+ updateArgs({
140
+ value: evt.target.value
141
+ });
142
+ };
143
+ return <UnitInput {...args} onChange={handleChange} />;
144
+ }`,...(Et=(jt=X.parameters)==null?void 0:jt.docs)==null?void 0:Et.source}}};var St,Nt,At;P.parameters={...P.parameters,docs:{...(St=P.parameters)==null?void 0:St.docs,source:{originalSource:`() => {
145
+ const width = '500px';
146
+ const [value, setValue] = useState<any>(undefined);
147
+ return <>
148
+ <h4>Different edge cases such as +/- infinity, undefined, NaN, null:</h4>
149
+ <Row>
150
+ <Column width="25%">
151
+ <Button label="Change value infinity" onClick={() => setValue(Infinity)} />
152
+ <br />
153
+ <Button label="Change value -infinity" onClick={() => setValue(-Infinity)} />
154
+ <br />
155
+ <Button label="Change value null" onClick={() => setValue(null)} />
156
+ <br />
157
+ <Button label="Change value - undefined" onClick={() => setValue(undefined)} />
158
+ <br />
159
+ <Button label="Change value - NaN" onClick={() => setValue(NaN)} />
160
+ <br />
161
+ <Button label="Change value - nothing (empty)" onClick={() => setValue(undefined)} />
162
+ <br />
163
+ <Button label="Change value - empty string" onClick={() => setValue('')} />
164
+ </Column>
165
+ <Column width="25%">
166
+ <Button label="Change value infinity|m" onClick={() => setValue(Infinity + '|m')} />
167
+ <br />
168
+ <Button label="Change value -infinity|m" onClick={() => setValue(-Infinity + '|m')} />
169
+ <br />
170
+ <Button label="Change value null|m" onClick={() => setValue(null + '|m')} />
171
+ <br />
172
+ <Button label="Change value - undefined|m" onClick={() => setValue(undefined + '|m')} />
173
+ <br />
174
+ <Button label="Change value - NaN|m" onClick={() => setValue(NaN + '|m')} />
175
+ <br />
176
+ <Button label="Change value - nothing (empty)|m" onClick={() => setValue('|m')} />
177
+ </Column>
178
+ </Row>
179
+ <br />
180
+ <Field label="Normal PUI">
181
+ <UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="value|unit" />
182
+ </Field>
183
+ <Field label="Disabled validation">
184
+ <UnitInput name="example2" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" disabledValidation width={width} />
185
+ </Field>
186
+ <Field label="Disabled validation and manual error">
187
+ <UnitInput name="example3" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" error="test" disabledValidation width={width} />
188
+ </Field>
189
+ <Message message={{
190
+ heading: 'Current value inside PUI: ' + value,
191
+ visible: true
192
+ }} />
193
+ </>;
194
+ }`,...(At=(Nt=P.parameters)==null?void 0:Nt.docs)==null?void 0:At.source}}};var Dt,qt,Pt;ee.parameters={...ee.parameters,docs:{...(Dt=ee.parameters)==null?void 0:Dt.docs,source:{originalSource:`() => {
195
+ const width = '500px';
196
+ const [value, setValue] = useState<string>('1|m');
197
+ const [valueB, setValueB] = useState('|m');
198
+ const automaticValue = '123|km';
199
+ return <>
200
+ <h4>Different cases for automatic (placeholder) values:</h4>
201
+ <Row>
202
+ <Column width="25%">
203
+ <Button label="Change value to ''" onClick={() => setValue('')} />
204
+ <br />
205
+ <Button label="Change value to 1" onClick={() => setValue('1')} />
206
+ <br />
207
+ <Button label="Change value to 1|m" onClick={() => setValue('1|m')} />
208
+ <br />
209
+ <Button label="Change value to |m - empty value" onClick={() => setValue('|m')} />
210
+ </Column>
211
+ </Row>
212
+ <br />
213
+ <Field label="Normal PUI (placeholder + auto)">
214
+ <UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="value|unit" autoValue={automaticValue} />
215
+ </Field>
216
+ <Field label="Normal PUI (only auto)">
217
+ <UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} autoValue={automaticValue} />
218
+ </Field>
219
+ <Field label="Empty PUI with autoValue">
220
+ <UnitInput name="example1" onChange={evt => setValueB(evt.target.value)} value={valueB} unitkey="length" width={width} autoValue={automaticValue} />
221
+ </Field>
222
+ <Field label="Normal PUI (only placeholder)">
223
+ <UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="Placeholder test" />
224
+ </Field>
225
+ <Field label="Normal PUI (placeholder + allowEmpty)">
226
+ <UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="Placeholder test" allowEmpty />
227
+ </Field>
228
+ <Message message={{
229
+ heading: 'Current value inside PUI: ' + value,
230
+ visible: true
231
+ }} />
232
+ </>;
233
+ }`,...(Pt=(qt=ee.parameters)==null?void 0:qt.docs)==null?void 0:Pt.source}}};var Bt,Mt,_t;te.parameters={...te.parameters,docs:{...(Bt=te.parameters)==null?void 0:Bt.docs,source:{originalSource:`() => {
234
+ const [value, setValue] = useState('123|%');
235
+ const [validation, setValidation] = useState<string | null>(null);
236
+ const predictedMessage = 'This should be visible when an error appears';
237
+ const handleValidation = (name: string, message: string | null) => {
238
+ setValidation(message);
239
+ return {
240
+ name,
241
+ error: message
242
+ };
243
+ };
244
+ return <>
245
+ <h4>3rd party validation message when inputting invalid value:</h4>
246
+ <UnitInput name="example" onChange={evt => setValue(evt.target.value)} error={!validation || predictedMessage} validationCallback={handleValidation} value={value} />
247
+ <br />
248
+ <Spacer />
249
+ <h4>Original validation message: </h4>
250
+ <Message message={{
251
+ heading: validation,
252
+ visible: true
253
+ }} />
254
+ </>;
255
+ }`,...(_t=(Mt=te.parameters)==null?void 0:Mt.docs)==null?void 0:_t.source}}};var Ft,Ot,Wt;ne.parameters={...ne.parameters,docs:{...(Ft=ne.parameters)==null?void 0:Ft.docs,source:{originalSource:`() => {
256
+ const [value, setValue] = useState('123|m');
257
+ const [placeholder, setPlaceholder] = useState('');
258
+ const [initUnit, setInitUnit] = useState('km');
259
+ const setPlaceholderValue = () => {
260
+ setInitUnit('ft');
261
+ setPlaceholder('placeholder');
262
+ setValue('|m');
263
+ };
264
+ return <>
265
+ <h4>Empty value case:</h4>
266
+ <UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} allowEmpty placeholder={placeholder} initUnit={initUnit} unitkey="length" />
267
+ <br />
268
+ <Spacer />
269
+ <Button label="Change value |m and unit ft" onClick={() => setPlaceholderValue()} />
270
+ </>;
271
+ }`,...(Wt=(Ot=ne.parameters)==null?void 0:Ot.docs)==null?void 0:Wt.source}}};var Rt,Ht,Lt;ae.parameters={...ae.parameters,docs:{...(Rt=ae.parameters)==null?void 0:Rt.docs,source:{originalSource:`() => {
272
+ const [value, setValue] = useState('123|m');
273
+ const [unit, setUnit] = useState('m');
274
+ return <>
275
+ <UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} initUnit={unit} unitkey="length" onSwitchUnit={setUnit} />
276
+ <Spacer />
277
+ <UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} initUnit={unit} unitkey="length" onSwitchUnit={setUnit} />
278
+ </>;
279
+ }`,...(Lt=(Ht=ae.parameters)==null?void 0:Ht.docs)==null?void 0:Lt.source}}};var Kt,$t,zt;se.parameters={...se.parameters,docs:{...(Kt=se.parameters)==null?void 0:Kt.docs,source:{originalSource:`() => {
280
+ return <>
281
+ <Text faint>
282
+ Reproduce OW-10614 rounding noise bug when storing values in a different
283
+ unit to the display unit
284
+ </Text>
285
+ <Spacer />
286
+ <UnitInput name="example" onChange={() => {}} value={withUnit(convertAndGetValue('9750|psi', 'bar'), 'bar')} initUnit="psi" unitkey="pressure" unitTemplate={{
287
+ pressure: 'psi'
288
+ }} />
289
+ </>;
290
+ }`,...(zt=($t=se.parameters)==null?void 0:$t.docs)==null?void 0:zt.source}}};var Gt,Jt,Yt;B.parameters={...B.parameters,docs:{...(Gt=B.parameters)==null?void 0:Gt.docs,source:{originalSource:`() => {
291
+ const [value, setValue] = useState('123|m');
292
+ return <UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} initUnit="m" unitkey="depth" unitTemplate={{
293
+ depth: 'm'
294
+ }} testId="testId" />;
295
+ }`,...(Yt=(Jt=B.parameters)==null?void 0:Jt.docs)==null?void 0:Yt.source}}};const xa=["Default","InitUnit","notKnownUnit","Width","NoConversion","Small","Error","InternalValidationError","Disabled","DisabledNoConversion","DisabledUnitWithoutUnitKey","DisabledUnitWithUnitKey","DisabledWithEnabledUnitMenu","TestExternalStateChangeWithSynchronizedUnits","PredefinedOptionsMenu","TestEdgeCases","AutomaticValues","ValidationCallback","AllowEmptyPUI","onSwitchUnit","OW_10614TestCase","TestUserInput"];export{ne as AllowEmptyPUI,ee as AutomaticValues,oe as Default,D as Disabled,J as DisabledNoConversion,Z as DisabledUnitWithUnitKey,Y as DisabledUnitWithoutUnitKey,Q as DisabledWithEnabledUnitMenu,z as Error,R as InitUnit,G as InternalValidationError,K as NoConversion,se as OW_10614TestCase,X as PredefinedOptionsMenu,$ as Small,P as TestEdgeCases,q as TestExternalStateChangeWithSynchronizedUnits,B as TestUserInput,te as ValidationCallback,L as Width,xa as __namedExportsOrder,wa as default,H as notKnownUnit,ae as onSwitchUnit};
@@ -0,0 +1,152 @@
1
+ import{j as i}from"./jsx-runtime-eps93zm2.js";import{r as v}from"./index-DhsZuJvc.js";import{f as J}from"./immer.esm-BwVl9PS2.js";import{d as T}from"./index-CWz-hU-f.js";import{G as ne}from"./grid-B6LFPf51.js";import{S as ae}from"./spacer-BWoNR27H.js";import{w as O,u as d,e as B,f as ie}from"./index-DMAnyMX5.js";import{C as _}from"./card-EcjmryU9.js";import{F as R}from"./field-HrLaMLbx.js";import{H as F}from"./heading-CRNoBc7q.js";import{S as P}from"./select-C8iu4-uz.js";import{T as W}from"./toggle-CBpNgTrm.js";import{l as re}from"./lodash-BHd_uQHh.js";import{u as oe}from"./use-previous-D775JrO6.js";import{T as le,C as G}from"./table-BNMxYhsu.js";import"./index-DRSy5Ssd.js";import"./styled-components.browser.esm-Bf0q9Yjk.js";import"./index-CF7H4eMJ.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-UmZ4Y_CR.js";import"./assertThisInitialized-B9jnkVVz.js";import"./memoize-one.esm-CcMeOnPo.js";import"./types-BmbYqTX_.js";import"./text-B3-TSWok.js";import"./actions-CHgr8eL8.js";import"./button-VxhoNhrV.js";import"./spinner-AWUe4xwQ.js";import"./badge-CLQ59MDF.js";import"./select.input-DIKP56UZ.js";import"./index.es-DazXb-ul.js";import"./redux-tRgGMjwY.js";import"./objectSpread2-DW4nTBoq.js";import"./tiny-invariant-DqLgxztJ.js";import"./pagination-iSMIbR33.js";import"./input-BW9trNAW.js";import"./input-group-BaRSJAEN.js";import"./input-group-addon-D68iUKV2.js";import"./number-input-uQOVHv2N.js";import"./check-box-BtCGePRy.js";import"./slider-DAramr8j.js";import"./index-BI4_Bp97.js";import"./popover-CzZdWNnB.js";const se=r=>r.reduce(({preferredUnits:o,storageUnits:a},{unitKey:l,preferredUnit:e,storageUnit:b})=>(o[l]=e,a[l]=b,{preferredUnits:o,storageUnits:a}),{preferredUnits:{},storageUnits:{}}),ue=({headers:r,rows:o,selectedUnits:a,storageUnits:l,onChangeUnit:e,convertBackToStorageUnit:b,enableCosmeticRounding:m,enableDisplayRounding:C})=>{const u=r?r.map(c=>({...c,cells:c.cells.map(p=>{var n;if(p.type===G.AUTO_UNIT){const{testId:x,unitKey:g}=p;return{value:a[g],type:G.SELECT,searchable:!1,options:(n=T.getUnitsForQuantity(g))==null?void 0:n.map(U=>({label:T.label(U),value:U})),native:p.native,onChange:U=>e({unitKey:g,value:U.target.value}),testId:x}}return p})})):[],s=o?o.map((c,p)=>({...c,cells:c.cells.map((n,x)=>{if("autoUnit"in n&&(n!=null&&n.autoUnit)&&(typeof(n==null?void 0:n.value)=="string"||typeof(n==null?void 0:n.value)=="number")){const{unitKey:g,value:U,formatDisplayValue:I}=n,V=C&&"roundDisplayValue"in n?n==null?void 0:n.roundDisplayValue:null,h=a[g],y=l[g],t=h!==y,f=t?T.convertAndGetValue(U,h,y):n.value,w=T.isScientificStringNum(U),k=m&&(t||!w)?T.roundToPrecision(f,14):f,S=I?I(k):k;return{...n,value:S,enableCosmeticRounding:m,enableDisplayRounding:C,roundDisplayValue:V,onChange:D=>{const{value:H}=D.target,A=l[g],E=a[g],K=E!==A,j=b?A:E,Z=K?T.convertAndGetValue(H,j,E):H;if("onChange"in n){const{onChange:ee}=n,te={...D,target:{...D.target,value:String(Z),rowIndex:p,cellIndex:x,unit:j}};ee(te)}}}}return n})})):[];return{convertedHeaders:u,convertedRows:s}},X=({table:r,unitConfig:o,convertBackToStorageUnit:a=!0,enableCosmeticRounding:l=!0,enableDisplayRounding:e=!0})=>{const{rows:b,headers:m,...C}=r,{storageUnits:u,preferredUnits:s}=se(o),c=oe(s),[p,n]=v.useState(s),x=({unitKey:h,value:y})=>{n({...p,[h]:y});const t=o.find(f=>f.unitKey===h);t&&typeof t.onChange=="function"&&t.onChange({oldUnit:p[h],newUnit:y,unitKey:h})},g=h=>ue({headers:m,rows:b,selectedUnits:h,storageUnits:u,onChangeUnit:x,convertBackToStorageUnit:a,enableCosmeticRounding:l,enableDisplayRounding:e}),U=g(p),[I,V]=v.useState(U);return v.useEffect(()=>{!re.isEqual(s,c)&&(Object.keys(s).forEach(y=>{const t=c==null?void 0:c[y],f=s[y];t!==f&&x({unitKey:y,value:f})}),V(g(s)))},[o]),v.useEffect(()=>{V(g(p))},[r,p]),i.jsx(le,{table:{...C,headers:I.convertedHeaders,rows:I.convertedRows}})};X.__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 yt={title:"Basic/UnitTable",args:{}},ce=!0,de=!0,pe=!0,ge=!1,N="m",Y="C",me=3,he=(r,o,a)=>{const l=[o,o,a],e=[...Array(r)].map((b,m)=>{const C=m,u=m+1.25,s=4+m*.25;return[String(C),String(u),String(s)]});return[l,...e]},be=he(me,N,Y),ye=({reduxTable:r,value:o,unit:a,rowIndex:l,cellIndex:e})=>J(r,b=>{const m=b[0][e],C=(u,s)=>s===0;return b.forEach((u,s)=>{if(C(u,s)){u[e]=a;return}if(s===l+1){u[e]=String(o);return}const c=T.convertAndGetValue(u[e],a,m);u[e]=String(c)}),b}),fe=({reduxTable:r,value:o,rowIndex:a,cellIndex:l})=>J(r,e=>{e[a+1][l]=o}),L=()=>{var h,y;const[r,o]=v.useState(N),[a,l]=v.useState(Y),[e,b]=v.useState(be),[m,C]=v.useState(ce),[u,s]=v.useState(pe),[c,p]=v.useState(de),[n,x]=v.useState(ge),[g,U]=v.useState(N),I=t=>{const{rowIndex:f,cellIndex:w,value:k,unit:S}=t.target,D=n?ye({reduxTable:e,value:k,unit:S,rowIndex:f,cellIndex:w}):fe({reduxTable:e,value:k,rowIndex:f,cellIndex:w});b(D)},V=e.reduce((t,f,w)=>(w===0?t.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"}]}]:t.rows=t.rows.concat({cells:f.map((k,S)=>{const D=w===1&&S===1;return{value:k,type:D?"Text":"NumberInput",unitKey:S===2?"temperature":"length",onChange:I,roundDisplayValue:w===3&&S===2?j=>T.roundByMagnitude(j,2):null,formatDisplayValue:D?j=>`T* ${j}`:null,autoUnit:!0,testId:`testId_${w}_${S}`}})}),t),{testId:"testId",headers:[],rows:[]});return i.jsxs(ne,{columns:"1fr 1fr",gap:!0,children:[i.jsxs(_,{heading:i.jsx(F,{children:"Settings"}),children:[i.jsx(R,{label:"Convert back to storage unit:",labelLeft:!0,labelWidth:200,children:i.jsx(W,{checked:m,onChange:t=>C(t.target.checked)})}),i.jsx(R,{label:"Enable display rounding:",labelLeft:!0,labelWidth:200,children:i.jsx(W,{checked:u,onChange:t=>s(t.target.checked)})}),i.jsx(R,{label:"Enable cosmetic rounding:",labelLeft:!0,labelWidth:200,children:i.jsx(W,{checked:c,onChange:t=>p(t.target.checked)})}),i.jsx(R,{label:"Convert whole table:",labelLeft:!0,labelWidth:200,children:i.jsx(W,{checked:n,onChange:t=>x(t.target.checked)})})]}),i.jsxs(_,{heading:i.jsx(F,{children:"Unit template"}),children:[i.jsx(R,{label:"Length unit:",labelLeft:!0,labelWidth:120,children:i.jsx(P,{options:(h=T.getUnitsForQuantity("length"))==null?void 0:h.map(t=>({value:t,label:T.label(t)})),value:{value:r},onChange:t=>o(t.target.value),width:"100px"})}),i.jsx(R,{label:"Temperature unit:",labelLeft:!0,labelWidth:120,children:i.jsx(P,{options:(y=T.getUnitsForQuantity("temperature"))==null?void 0:y.map(t=>({value:t,label:T.label(t)})),value:{value:a},onChange:t=>l(t.target.value),width:"100px"})})]}),i.jsx(_,{heading:i.jsx(F,{children:"Storage State (Redux)"}),children:i.jsx("pre",{children:i.jsx("code",{children:JSON.stringify(e,null,2)})})}),i.jsxs(_,{heading:i.jsx(F,{children:"UnitTable"}),children:[i.jsx(X,{table:V,unitConfig:[{unitKey:"length",storageUnit:e[0][0],preferredUnit:r,onChange:({newUnit:t})=>U(t)},{unitKey:"temperature",storageUnit:e[0][2],preferredUnit:a}],convertBackToStorageUnit:m,enableDisplayRounding:u,enableCosmeticRounding:c}),i.jsx(ae,{height:20}),i.jsx(R,{label:"Displayed length unit:",labelLeft:!0,labelWidth:150,children:g})]})]})};L.play=async({canvasElement:r,step:o})=>{const a=O(r),l=O(r.ownerDocument.body);await o("Can enter decimal values",async()=>{const e=a.getByTestId("testId_2_1");await d.clear(e),await d.type(e,"123.123456789"),await d.click(r),await B(a.getByDisplayValue("123.12")).toBeInTheDocument()}),await o("Can enter comma decimals (converts to dot)",async()=>{const e=a.getByTestId("testId_2_1");await d.clear(e),await d.type(e,"123,456"),await d.click(r),await B(a.getByDisplayValue("123.46")).toBeInTheDocument()}),await o("Can enter small numbers",async()=>{const e=a.getByTestId("testId_2_1");await d.clear(e),await d.type(e,"0.0000000023"),await d.click(r),await B(e).toHaveDisplayValue("0.00")}),await o("Can enter large numbers",async()=>{const e=a.getByTestId("testId_2_1");await d.clear(e),await d.type(e,"999999999999"),await d.click(r),await B(a.getByDisplayValue("999999999999.00")).toBeInTheDocument()}),await o("Shows validation error for non-numeric input",async()=>{const e=a.getByTestId("testId_2_1");await d.clear(e),await d.type(e,"123x45s6"),await d.click(r),await ie.mouseOver(e),await B(l.getByText("Must be a numerical value")).toBeInTheDocument()})};L.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"UnitTableExample"};var q,$,Q,M,z;L.parameters={...L.parameters,docs:{...(q=L.parameters)==null?void 0:q.docs,source:{originalSource:`() => {
2
+ const [preferredLengthUnit, setPreferredLengthUnit] = useState(initialLengthUnit);
3
+ const [preferredTemperatureUnit, setPreferredTemperatureUnit] = useState(initialTemperatureUnit);
4
+ const [reduxTable, setReduxTable] = useState<TTable>(initialTable);
5
+ const [convertBackToStorageUnit, setConvertBackToStorageUnit] = useState(initialConvertBackToStorageUnit);
6
+ const [enableDisplayRounding, setEnableDisplayRounding] = useState(initialEnableDisplayRounding);
7
+ const [enableCosmeticRounding, setEnableCosmeticRounding] = useState(initialEnableCosmeticRounding);
8
+ const [convertWholeTable, setConvertWholeTable] = useState(initialConvertWholeTable);
9
+ const [displayedLengthUnit, setDisplayedLengthUnit] = useState(initialLengthUnit);
10
+
11
+ /*********************************************************************************************************************
12
+ Cell onChange handler
13
+ *********************************************************************************************************************/
14
+ const onUpdateCell = (evt: IUnitTableOnChangeEvent) => {
15
+ const {
16
+ rowIndex,
17
+ cellIndex,
18
+ value,
19
+ unit
20
+ } = evt.target;
21
+ const nextTable = convertWholeTable ? convertStorageTable({
22
+ reduxTable,
23
+ value,
24
+ unit,
25
+ rowIndex,
26
+ cellIndex
27
+ }) : updateCell({
28
+ reduxTable,
29
+ value,
30
+ rowIndex,
31
+ cellIndex
32
+ });
33
+ setReduxTable(nextTable);
34
+ };
35
+
36
+ /*********************************************************************************************************************
37
+ Construct table view data (same as old Table component, with a new props)
38
+ *********************************************************************************************************************/
39
+ const tableViewData = reduxTable.reduce((acc, row, rowIndex) => {
40
+ if (rowIndex === 0) {
41
+ acc.headers = [{
42
+ cells: [{
43
+ value: 'From'
44
+ }, {
45
+ value: 'To'
46
+ }, {
47
+ value: 'Temperature'
48
+ }]
49
+ }, {
50
+ cells: [{
51
+ type: 'AutoUnit',
52
+ unitKey: 'length'
53
+ }, {
54
+ type: 'AutoUnit',
55
+ unitKey: 'length'
56
+ }, {
57
+ type: 'AutoUnit',
58
+ unitKey: 'temperature',
59
+ testId: 'table-unit-selector-3'
60
+ }]
61
+ }];
62
+ } else {
63
+ acc.rows = acc.rows.concat({
64
+ cells: row.map((cell, cellIndex) => {
65
+ const specialCell = rowIndex === 1 && cellIndex === 1;
66
+ const type = specialCell ? 'Text' : 'NumberInput';
67
+ const formatDisplayValue = specialCell ? (value: number | string) => \`T* \${value}\` : null;
68
+ const customDisplayRounding = rowIndex === 3 && cellIndex === 2 ? (value: TStringNumberNull) => roundByMagnitude(value, 2) : null;
69
+ const value = cell;
70
+ return {
71
+ value,
72
+ type,
73
+ unitKey: cellIndex === 2 ? 'temperature' : 'length',
74
+ onChange: onUpdateCell,
75
+ roundDisplayValue: customDisplayRounding,
76
+ // optionally customize the display rounding of specific columns/cells
77
+ formatDisplayValue,
78
+ // optionally extend/customize the display formatting of specific columns/cells
79
+ autoUnit: true,
80
+ testId: \`testId_\${rowIndex}_\${cellIndex}\`
81
+ };
82
+ })
83
+ });
84
+ }
85
+ return acc;
86
+ }, {
87
+ testId: 'testId',
88
+ headers: ([] as any[]),
89
+ rows: ([] as IUnitTableRow[])
90
+ });
91
+ return <Grid columns="1fr 1fr" gap>
92
+ <Card heading={<Heading>Settings</Heading>}>
93
+ <Field label="Convert back to storage unit:" labelLeft labelWidth={200}>
94
+ <Toggle checked={convertBackToStorageUnit} onChange={evt => setConvertBackToStorageUnit(evt.target.checked)} />
95
+ </Field>
96
+ <Field label="Enable display rounding:" labelLeft labelWidth={200}>
97
+ <Toggle checked={enableDisplayRounding} onChange={evt => setEnableDisplayRounding(evt.target.checked)} />
98
+ </Field>
99
+ <Field label="Enable cosmetic rounding:" labelLeft labelWidth={200}>
100
+ <Toggle checked={enableCosmeticRounding} onChange={evt => setEnableCosmeticRounding(evt.target.checked)} />
101
+ </Field>
102
+ <Field label="Convert whole table:" labelLeft labelWidth={200}>
103
+ <Toggle checked={convertWholeTable} onChange={evt => setConvertWholeTable(evt.target.checked)} />
104
+ </Field>
105
+ </Card>
106
+ <Card heading={<Heading>Unit template</Heading>}>
107
+ <Field label="Length unit:" labelLeft labelWidth={120}>
108
+ <Select options={getUnitsForQuantity('length')?.map(unit => ({
109
+ value: unit,
110
+ label: label(unit)
111
+ }))} value={{
112
+ value: preferredLengthUnit
113
+ }} onChange={evt => setPreferredLengthUnit(evt.target.value)} width="100px" />
114
+ </Field>
115
+ <Field label="Temperature unit:" labelLeft labelWidth={120}>
116
+ <Select options={getUnitsForQuantity('temperature')?.map(unit => ({
117
+ value: unit,
118
+ label: label(unit)
119
+ }))} value={{
120
+ value: preferredTemperatureUnit
121
+ }} onChange={evt => setPreferredTemperatureUnit(evt.target.value)} width="100px" />
122
+ </Field>
123
+ </Card>
124
+ <Card heading={<Heading>Storage State (Redux)</Heading>}>
125
+ <pre>
126
+ <code>{JSON.stringify(reduxTable, null, 2)}</code>
127
+ </pre>
128
+ </Card>
129
+ <Card heading={<Heading>UnitTable</Heading>}>
130
+ <UnitTable table={tableViewData}
131
+ //New props:
132
+ unitConfig={[{
133
+ unitKey: 'length',
134
+ storageUnit: reduxTable[0][0],
135
+ preferredUnit: preferredLengthUnit,
136
+ onChange: ({
137
+ newUnit
138
+ }) => setDisplayedLengthUnit(newUnit)
139
+ }, {
140
+ unitKey: 'temperature',
141
+ storageUnit: reduxTable[0][2],
142
+ preferredUnit: preferredTemperatureUnit
143
+ }]}
144
+ //Most tables should just use the default values here (true):
145
+ convertBackToStorageUnit={convertBackToStorageUnit} enableDisplayRounding={enableDisplayRounding} enableCosmeticRounding={enableCosmeticRounding} />
146
+ <Spacer height={20} />
147
+ <Field label="Displayed length unit:" labelLeft labelWidth={150}>
148
+ {displayedLengthUnit}
149
+ </Field>
150
+ </Card>
151
+ </Grid>;
152
+ }`,...(Q=($=L.parameters)==null?void 0:$.docs)==null?void 0:Q.source},description:{story:"Story",...(z=(M=L.parameters)==null?void 0:M.docs)==null?void 0:z.description}}};const ft=["UnitTableExample"];export{L as UnitTableExample,ft as __namedExportsOrder,yt as default};
@@ -509,7 +509,7 @@
509
509
  }
510
510
  </script>
511
511
 
512
- <script type="module" crossorigin src="./assets/iframe-WLuE3PcW.js"></script>
512
+ <script type="module" crossorigin src="./assets/iframe-0oHxQxyh.js"></script>
513
513
  </head>
514
514
 
515
515
  <body>