@oliasoft-open-source/react-ui-library 4.6.16 → 4.6.18

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 (145) hide show
  1. package/dist/404.html +1 -1
  2. package/dist/assets/{index-noRhVNRn.js → index-3CeHq3uM.js} +14 -4
  3. package/dist/assets/{index-UHom3TOS.css → index-DdTheZoQ.css} +11 -8
  4. package/dist/global.css +11 -8
  5. package/dist/index.d.ts +10 -0
  6. package/dist/index.html +1 -1
  7. package/dist/index.js +65 -14
  8. package/dist/index.js.map +1 -1
  9. package/dist/storybook/assets/Color-6VNJS4EI-xbGhw5Tj.js +1 -0
  10. package/dist/storybook/assets/DocsRenderer-NNNQARDV-sAPbui3t.js +1 -0
  11. package/dist/storybook/assets/WithTooltip-V3YHNWJZ-gwFLosBp.js +1 -0
  12. package/dist/storybook/assets/{accordion-M-sY23Hd.js → accordion-MRdNs3mQ.js} +1 -1
  13. package/dist/storybook/assets/{accordion.stories-lXs4IRds.js → accordion.stories-488HeY9k.js} +2 -2
  14. package/dist/storybook/assets/actions-Z1pyUd57.js +1 -0
  15. package/dist/storybook/assets/actions-_FIB7bOt.css +1 -0
  16. package/dist/storybook/assets/{actions.stories-sQK7SAX5.js → actions.stories-JWaU0QAA.js} +1 -1
  17. package/dist/storybook/assets/{afe.stories-ODEPBi0c.js → afe.stories-Rsl77dCu.js} +2 -2
  18. package/dist/storybook/assets/{badge.stories-fpUlm73g.js → badge.stories-2BykvoFl.js} +1 -1
  19. package/dist/storybook/assets/{blowout.stories-4nLIosc7.js → blowout.stories--vPM-KpE.js} +1 -1
  20. package/dist/storybook/assets/{button-BiJw0fB3.js → button-UQO14biP.js} +1 -1
  21. package/dist/storybook/assets/{button-group-uKCjEKYR.js → button-group-g7HxxHTn.js} +1 -1
  22. package/dist/storybook/assets/{button-group.stories-mynaBhDz.js → button-group.stories-hJ9V_va5.js} +1 -1
  23. package/dist/storybook/assets/{button.stories-7N3AZjiw.js → button.stories-ihIU7iUf.js} +6 -6
  24. package/dist/storybook/assets/{buttons-and-links-2FBaBkFc.js → buttons-and-links-kUTQnA6P.js} +2 -2
  25. package/dist/storybook/assets/{card.stories-N8mLrD63.js → card.stories-5YbTAbLy.js} +1 -1
  26. package/dist/storybook/assets/{casing-loads.stories-g4yBGv5b.js → casing-loads.stories-LogF6TT6.js} +2 -2
  27. package/dist/storybook/assets/{cell.stories-sVyam_bx.js → cell.stories-BF9fKK_5.js} +2 -2
  28. package/dist/storybook/assets/{check-box-KynSyTaY.js → check-box-Q2GsbR79.js} +1 -1
  29. package/dist/storybook/assets/{check-box.stories-yE82OQod.js → check-box.stories-iQby_Dan.js} +1 -1
  30. package/dist/storybook/assets/{chunk-HLWAVYOI-tHzaOxem.js → chunk-HLWAVYOI-IUW2ushY.js} +1 -1
  31. package/dist/storybook/assets/color-T7GIoOH6.js +25 -0
  32. package/dist/storybook/assets/{column.stories-cX-u-DHI.js → column.stories-NnQNzY18.js} +1 -1
  33. package/dist/storybook/assets/{dialog-Au78k7wS.js → dialog-hHTtMGls.js} +1 -1
  34. package/dist/storybook/assets/{drawer-Vhj7CUNA.js → drawer-ChY55ghN.js} +1 -1
  35. package/dist/storybook/assets/{drawer.stories-gbeto4wq.js → drawer.stories-xv50_UKt.js} +2 -2
  36. package/dist/storybook/assets/{empty.stories-oRmjEU7P.js → empty.stories-dFjUCZln.js} +1 -1
  37. package/dist/storybook/assets/extends-dGVwEr9R.js +1 -0
  38. package/dist/storybook/assets/{field-m7XXDdEG.js → field-jD6TclDQ.js} +1 -1
  39. package/dist/storybook/assets/{field.stories-6xmZA-uD.js → field.stories-CeHr9rXs.js} +1 -1
  40. package/dist/storybook/assets/file-button.stories-z0vvWcvN.js +10 -0
  41. package/dist/storybook/assets/{file-input-AwnqYeJy.js → file-input-H1V5DMV-.js} +1 -1
  42. package/dist/storybook/assets/{file-input.stories-5kyAKS_C.js → file-input.stories-2-2uTWvd.js} +1 -1
  43. package/dist/storybook/assets/{flex.stories-xAOrglx5.js → flex.stories-6qFQFEL7.js} +1 -1
  44. package/dist/storybook/assets/footer.stories-nvn3DsNw.js +3 -0
  45. package/dist/storybook/assets/form.stories-TIQoYJwC.js +49 -0
  46. package/dist/storybook/assets/formation.stories-m_rHJhHE.js +74 -0
  47. package/dist/storybook/assets/{formatter-SWP5E3XI-_Igw7BUr.js → formatter-SWP5E3XI-GzRPFG7m.js} +2 -2
  48. package/dist/storybook/assets/{heading-4tVgoT7O.js → heading-FcNTpGhR.js} +1 -1
  49. package/dist/storybook/assets/{heading.stories-7Bqlw14c.js → heading.stories-0MJHBHcQ.js} +1 -1
  50. package/dist/storybook/assets/{help-icon-eelulTML.js → help-icon-D6ZGAbgL.js} +1 -1
  51. package/dist/storybook/assets/{help-icon.stories-CptgOV2E.js → help-icon.stories-YZw5pFQt.js} +1 -1
  52. package/dist/storybook/assets/icon-_m67DAr0.js +8 -0
  53. package/dist/storybook/assets/{icon.stories-j-b_Exev.js → icon.stories-2aZia1VV.js} +1 -1
  54. package/dist/storybook/assets/iframe-NjfSsybe.js +7 -0
  55. package/dist/storybook/assets/{index-K-0S6d15.js → index-wKW2GPrE.js} +5 -5
  56. package/dist/storybook/assets/{index.es-VXFRDikp.js → index.es-HG2GUH9i.js} +4 -4
  57. package/dist/storybook/assets/inheritsLoose-Y9jOMJLd.js +1 -0
  58. package/dist/storybook/assets/{input-group.stories-BJcLpgsm.js → input-group.stories-yF-PiFm1.js} +2 -2
  59. package/dist/storybook/assets/{input-validation-gD2VptJq.js → input-validation-U4HJ5Ucw.js} +2 -2
  60. package/dist/storybook/assets/{inputs-xtYro1Lt.js → inputs-S04nRGW2.js} +2 -2
  61. package/dist/storybook/assets/{label-bLcoUwtK.js → label-dla_bzHj.js} +1 -1
  62. package/dist/storybook/assets/{label.stories-KbJuUVw3.js → label.stories-t-e2pWHW.js} +1 -1
  63. package/dist/storybook/assets/layout-forms-a8CnPDfT.js +16 -0
  64. package/dist/storybook/assets/{layout-general-wuAEAmS1.js → layout-general-Khl-lgRH.js} +2 -2
  65. package/dist/storybook/assets/{list-F9uDwsrH.js → list-Nr0UfaUw.js} +1 -1
  66. package/dist/storybook/assets/{list.stories-GyWvG8gC.js → list.stories-K1nFEsjX.js} +2 -2
  67. package/dist/storybook/assets/{list.stories-data-Ijj3YnfK.js → list.stories-data-WlepbhE1.js} +1 -1
  68. package/dist/storybook/assets/{loader.stories-B5lK8-XB.js → loader.stories-eEBGjVSN.js} +1 -1
  69. package/dist/storybook/assets/{menu.stories-YY0ZhdqW.js → menu.stories-nx6w59Nv.js} +6 -6
  70. package/dist/storybook/assets/{message-CRKuTfOl.js → message-bbAE2zjv.js} +1 -1
  71. package/dist/storybook/assets/{message.stories-aLAQs_iU.js → message.stories-RJI8haIH.js} +1 -1
  72. package/dist/storybook/assets/{meta-content-h1NJ9ypR.js → meta-content-073TGkSN.js} +1 -1
  73. package/dist/storybook/assets/{modal.stories-aZGhb1Cl.js → modal.stories-HOB4HNE4.js} +2 -2
  74. package/dist/storybook/assets/{number-input.stories-QU9Llt5Z.js → number-input.stories-0-jDCroI.js} +5 -5
  75. package/dist/storybook/assets/{option-dropdown.stories-f_5X-NT4.js → option-dropdown.stories-M9-IYc-K.js} +1 -1
  76. package/dist/storybook/assets/{padding-and-spacing-h7UETkPK.js → padding-and-spacing-ckWSgL0y.js} +2 -2
  77. package/dist/storybook/assets/{page.stories-_evmOXW2.js → page.stories-x7QRBnZm.js} +1 -1
  78. package/dist/storybook/assets/{pagination-DtJdggbI.js → pagination-lFdPlLPJ.js} +1 -1
  79. package/dist/storybook/assets/{pagination.stories-M2RqRdRc.js → pagination.stories-etfovhze.js} +2 -2
  80. package/dist/storybook/assets/{pop-confirm.stories-6V_XrhKa.js → pop-confirm.stories-QyBm5ZAb.js} +1 -1
  81. package/dist/storybook/assets/{popover-N9B8JT3G.js → popover-rJn7kxkX.js} +1 -1
  82. package/dist/storybook/assets/popover.stories-eItcO8iz.js +10 -0
  83. package/dist/storybook/assets/preview-YmO-dFt7.js +7 -0
  84. package/dist/storybook/assets/{preview-T-saggOw.js → preview-eOJx8ySI.js} +3 -3
  85. package/dist/storybook/assets/projects.stories-wnXCxuJE.js +47 -0
  86. package/dist/storybook/assets/{radio-button-HPU-KHv4.js → radio-button-7TJh5k-h.js} +1 -1
  87. package/dist/storybook/assets/{radio-button.stories-ZyjCpReq.js → radio-button.stories-9mvBu2BH.js} +1 -1
  88. package/dist/storybook/assets/react-router-dom-4Z66xYqZ.js +8 -0
  89. package/dist/storybook/assets/{reservoirs.stories-dvGcJAh0.js → reservoirs.stories-6dilTPJE.js} +2 -2
  90. package/dist/storybook/assets/{rich-text-input.stories-BroJS4L0.js → rich-text-input.stories-Vu2wd1uh.js} +3 -3
  91. package/dist/storybook/assets/{row.stories-ZibxnXR9.js → row.stories-6wXvgyio.js} +2 -2
  92. package/dist/storybook/assets/select-IxUsW-Xm.js +1 -0
  93. package/dist/storybook/assets/{select.stories-pZ8RM3fJ.js → select.stories-Kbzpw3od.js} +2 -2
  94. package/dist/storybook/assets/{side-bar-evBxuVzm.js → side-bar-kr46QLwI.js} +1 -1
  95. package/dist/storybook/assets/{side-bar.stories-mtQSbRi1.js → side-bar.stories-bJoVvzG5.js} +1 -1
  96. package/dist/storybook/assets/{site.stories--LjoKnDF.js → site.stories-VpsCjYty.js} +2 -2
  97. package/dist/storybook/assets/slider-jx0z5OyT.js +7 -0
  98. package/dist/storybook/assets/{slider.stories-ZZQVWjaY.js → slider.stories-CpY4L01U.js} +2 -2
  99. package/dist/storybook/assets/{smart-upload-modal.stories-RRF2yq4B.js → smart-upload-modal.stories-VCP3yghQ.js} +1 -1
  100. package/dist/storybook/assets/{spacer.stories-oFV2pFb8.js → spacer.stories-FpDFoVWE.js} +1 -1
  101. package/dist/storybook/assets/syntaxhighlighter-B5GMVT5T-J83QFJ3_.js +1 -0
  102. package/dist/storybook/assets/{table-kSTipYE0.js → table-fdcNapB-.js} +1 -1
  103. package/dist/storybook/assets/{table.stories-zdRM5AV8.js → table.stories-a5LZLQDT.js} +2 -2
  104. package/dist/storybook/assets/{table.stories-data-tjY9V0bM.js → table.stories-data-UqqhbXjA.js} +1 -1
  105. package/dist/storybook/assets/text-link.stories-Plmiu8NV.js +14 -0
  106. package/dist/storybook/assets/{title.stories-tcfNoA6z.js → title.stories-zxDbEh-U.js} +3 -3
  107. package/dist/storybook/assets/{toaster-yPcd4ELJ.js → toaster-IL_npIpU.js} +1 -1
  108. package/dist/storybook/assets/{toaster.stories-Cu8HbPc6.js → toaster.stories-QL3_PKZL.js} +1 -1
  109. package/dist/storybook/assets/{toggle-R__kwKym.js → toggle-vKuY4G3w.js} +1 -1
  110. package/dist/storybook/assets/{toggle.stories-ViKd2aK_.js → toggle.stories-fJ5QYzcQ.js} +1 -1
  111. package/dist/storybook/assets/{tooltip.test-case.stories-_THFk3Hb.js → tooltip.test-case.stories-0HiezXaS.js} +1 -1
  112. package/dist/storybook/assets/{top-bar-0Ownj3Bx.js → top-bar-pptAo2LU.js} +1 -1
  113. package/dist/storybook/assets/top-bar.stories-H1OeyQS_.js +21 -0
  114. package/dist/storybook/assets/{top-bar.testcase.stories-3XlaHVAQ.js → top-bar.testcase.stories-uJCoeG_m.js} +1 -1
  115. package/dist/storybook/assets/{tree.stories-Uh4XKQdz.js → tree.stories-a-UG4OFf.js} +1 -1
  116. package/dist/storybook/assets/{unit-input.stories-R93nVPV4.js → unit-input.stories-QoJkzTRA.js} +1 -1
  117. package/dist/storybook/assets/unit-table.stories-rHU8wR7Z.js +150 -0
  118. package/dist/storybook/iframe.html +1 -1
  119. package/dist/storybook/index.json +1 -1
  120. package/dist/storybook/project.json +1 -1
  121. package/dist/storybook/stories.json +1 -1
  122. package/package.json +1 -1
  123. package/dist/storybook/assets/Color-6VNJS4EI-YEDm9gbz.js +0 -1
  124. package/dist/storybook/assets/DocsRenderer-NNNQARDV-NmCW-oyQ.js +0 -1
  125. package/dist/storybook/assets/WithTooltip-V3YHNWJZ-3DZ-8kE7.js +0 -1
  126. package/dist/storybook/assets/actions-7PO9r8zE.js +0 -1
  127. package/dist/storybook/assets/actions-ZOs51LZe.css +0 -1
  128. package/dist/storybook/assets/color-7OzxGyA_.js +0 -25
  129. package/dist/storybook/assets/footer.stories-ZEZ_We0f.js +0 -3
  130. package/dist/storybook/assets/form.stories-rXc4fhX5.js +0 -49
  131. package/dist/storybook/assets/formation.stories-062BdtdZ.js +0 -74
  132. package/dist/storybook/assets/icon-8EQazuuW.js +0 -8
  133. package/dist/storybook/assets/iframe-CpYMK6kb.js +0 -7
  134. package/dist/storybook/assets/inheritsLoose-8sb_A2v4.js +0 -1
  135. package/dist/storybook/assets/layout-forms-NhJIOV9y.js +0 -16
  136. package/dist/storybook/assets/popover.stories-goIrT_jy.js +0 -10
  137. package/dist/storybook/assets/preview-f-BBQod4.js +0 -7
  138. package/dist/storybook/assets/projects.stories-H8sLyz8n.js +0 -47
  139. package/dist/storybook/assets/react-router-dom-EZH1n7K1.js +0 -8
  140. package/dist/storybook/assets/select-AcJYUY86.js +0 -1
  141. package/dist/storybook/assets/slider-n3IxC2iq.js +0 -7
  142. package/dist/storybook/assets/syntaxhighlighter-B5GMVT5T-d9li6xQn.js +0 -1
  143. package/dist/storybook/assets/text-link.stories-Mx9ojcOC.js +0 -14
  144. package/dist/storybook/assets/top-bar.stories-Z8pUGVuU.js +0 -21
  145. package/dist/storybook/assets/unit-table.stories-9k8rllRh.js +0 -142
@@ -1,4 +1,4 @@
1
- import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as m}from"./index-RfLt4OUa.js";import{d as r,r as it}from"./index-qZmQ7nA9.js";import{c as st}from"./index-VW3EWkuE.js";import{u as ut}from"./use-previous-VKMmnaK7.js";import{M as we}from"./actions-7PO9r8zE.js";import{I as ot}from"./input-group-addon-BHVsW9mL.js";import{B as c}from"./button-BiJw0fB3.js";import{T as dt}from"./tooltip-dueTLnwA.js";import{I as ct}from"./input-group-R8LoqKRn.js";import{S}from"./spacer-Yji9g2AW.js";import{T as mt}from"./text-6KQ6ntOV.js";import{I as pt}from"./input-fYKvBwPs.js";import{M as Ee}from"./types-VB5zD18b.js";import{l as E}from"./lodash-Bmg8FrMx.js";import{D as gt}from"./divider-RwW2f_N0.js";import{R as Wn,C as pe}from"./row-vFUhHoz5.js";import{F as I}from"./field-m7XXDdEG.js";import{M as ge}from"./message-CRKuTfOl.js";import"./index-cCpkwrS5.js";import"./common-types-U65vzrrz.js";import"./disabled-context-urNQThQz.js";import"./icon-8EQazuuW.js";import"./objectWithoutPropertiesLoose-9Q1jwsKS.js";import"./inheritsLoose-8sb_A2v4.js";import"./tslib.es6-OIsz3r9a.js";import"./index-4QtD-hFu.js";import"./types-5uVBABF4.js";import"./badge-23Ty_zBt.js";import"./spinner-R8Il4aRe.js";import"./index-miLrID2P.js";import"./styled-components.browser.esm-qIipjd6c.js";import"./label-bLcoUwtK.js";import"./help-icon-eelulTML.js";const ht=()=>{const n=m.useRef(null);return m.useLayoutEffect(()=>{n.current&&(n.current(),n.current=null)}),t=>{n.current=t}},vt=(n,a)=>{const t=a==null?void 0:a[n];return t||(console.log(`Warning: 'unitTemplate' does not define a preferred unit for '${n}'. Defaulting to standard unit.`),r.unitFromQuantity(n)??"")};var b=(n=>(n.CUSTOM="custom",n.PREDEFINED="predefined",n))(b||{});const Tn=n=>n==="undefined"||n===void 0||n===""||n==="null"||n===null||n==="NaN"||isNaN(n),Rn=(n="",a,t="",s=!1)=>{if(s)return n;if(a&&!Tn(n))try{const u=r.isValueWithUnit(n)?n:r.withUnit(n,t),o=r.convertSamePrecision(u,a);return r.getValue(o)}catch{}return n},ft=n=>n?!!r.getUnit(n):!1,F=(n="",a,t,s)=>{if(s)return n;const u=ft(n)||r.isValueWithUnit(n),o=r.getValue(n);return Tn(o)?o:u?Rn(o,a,t,s):n},Ne=n=>E.isObject(n)&&!E.isArray(n)&&!E.isFunction(n)?E.get(n,"fieldName",""):typeof n=="string"?n:"",Ct=n=>E.isObjectLike(n)&&E.has(n,"message"),bt=n=>typeof n=="string"?n:Ct(n)?n.message:null;var Ut=it();const yt=n=>n.search(RegExp(/(^0{2}\.)|(^0+[1-9])/g))===0,Ae=(n,a)=>{var j;const{allowEmpty:t=!1,autoValue:s,placeholder:u,disabledValidation:o=!1}=a||{},i=String(n);if(o||s||u)return null;const g=Ut.isValueWithUnit(i)?r.getValue(i):i;if(t&&g==="")return null;if(yt(g))return"Invalid number format due to leading zeroes";const h=r.validateNumber(g);if(!h.valid){const re=((j=h==null?void 0:h.errors)==null?void 0:j[0])??null;return bt(re)}return null},Pe=(n="")=>{var a;return(a=r.KNOWN_UNITS)==null?void 0:a.includes(n)},xt=(n,a)=>{const t=r.getUnit(n||"");return Pe(a)&&Pe(t)},Vt="_predefinedMenuActive_1yvt4_1",It={predefinedMenuActive:Vt},p=({name:n,placeholder:a="",disabled:t=!1,disabledUnit:s=!1,error:u=null,left:o=!1,small:i=!1,width:g="100%",value:h,unitkey:j="",initUnit:re,noConversion:Ln=!1,onChange:ie=()=>{},onClick:kt=()=>{},onFocus:Kn=()=>{},onSwitchUnit:he=()=>{},unitTemplate:ve,doNotConvertValue:A=!1,testId:w,warning:$n=null,predefinedOptions:x,initialPredefinedOption:Hn=!1,shouldLinkAutomaticly:fe=!0,selectedPredefinedOptionKey:Ce,validationCallback:be=()=>({name:"",error:null}),disabledValidation:Ue=!1,allowEmpty:ye=!1,autoValue:V})=>{typeof h=="number"&&(h=`${h}`);const zn=ht(),[se="",P=""]=h!==void 0?r.split(h):[],xe=V?r.getUnit(V):"",Ve=m.useMemo(()=>vt(j,ve),[j,ve]),Jn=xt(h,Ve),U=re||Ve||P,Yn=ut(U),Ie=F(h,U,P,A),je=F(V,U,xe,A),Zn=Ie!==""?{value:Ie,unit:U}:je!==""?{value:je,unit:U}:{value:se,unit:P},[v,Y]=m.useState(Zn),[Gn,ue]=m.useState(null),[k,oe]=m.useState(Hn?b.PREDEFINED:b.CUSTOM),de=se===""&&V,D=x&&x.find(l=>{if(Ce)return Ce===l.valueKey;const d=r.isValueWithUnit(l.value)?r.getUnit(l.value):"";return r.withUnit(Rn(h,d),d)===l.value}),Qn=()=>{if(j)try{const l=de?V:h??"";let d=r.altUnitsList(l,j);return r.getValue(l)===""?d.map(f=>["",f[1]]):d}catch{return null}},Xn=l=>{const d=Ne(n),f=l.target,{value:y,selectionStart:X}=f,Se=r.cleanNumStr(y.replaceAll(" ","").replaceAll("|","")),ce=r.withUnit(Se,(v==null?void 0:v.unit)||""),at=r.getValue(ce),me=Ae(at,{allowEmpty:ye,autoValue:V,placeholder:a,disabledValidation:Ue});if(me===null){ie({target:{value:ce,name:d}});const[lt,rt]=r.split(ce);Y({value:lt,unit:rt}),ue(null),be(d,null)}else Y({value:Se,unit:v.unit}),ue(me),be(d,me);zn(()=>{f.selectionStart=X,f.selectionEnd=X})},et=(l,d)=>{d===v.unit||isNaN(Number(l))||(Y({value:l,unit:d}),he&&he(d))};m.useEffect(()=>{if(U){let f,y="";Yn!==U?(f=F(h,U,P,A),y=U):r.withUnit(v.value,v.unit)!==h&&(f=F(h,v.unit,P,A),y=v.unit),f!==void 0&&Y({value:f,unit:y}),x&&oe(D&&fe?b.PREDEFINED:b.CUSTOM)}const l=r.checkAndCleanDecimalComma(se),d=Ae(l,{allowEmpty:ye,autoValue:V,placeholder:a,disabledValidation:Ue});ue(d)},[U,h,u,fe]);const Z=Qn(),G=r.label(v.unit)||v.unit||"",nt=Ln||!Z||Z&&Z.length===1,ke=Ne(n);let Q;const tt=l=>{const[d,f=""]=r.isValueWithUnit(l.value)?r.split(l.value):[l.value];return{type:Ee.OPTION,inline:!0,onClick:()=>{r.validateNumber(d).valid&&!t&&(oe(b.PREDEFINED),ie({target:{value:l.value,name:typeof n=="string"?n:(n==null?void 0:n.fieldName)||"",predefinedSelected:!0,predefinedOption:l}}))},label:e.jsxs(e.Fragment,{children:[e.jsx(mt,{children:l.label}),e.jsx(S,{width:"20px",height:"0"})]}),description:r.isValueWithUnit(l.value)?`${d} ${f}`:l.value,selected:D===l&&k===b.PREDEFINED}};if(Q=[{type:Ee.OPTION,inline:!0,onClick:()=>{k!==b.CUSTOM&&!t&&ie({target:{value:r.withUnit(v.value,v.unit),name:typeof n=="string"?n:(n==null?void 0:n.fieldName)||""}})},label:"Custom",selected:k===b.CUSTOM}],x!=null&&x.length){const l=x.map(tt);Q=[...Q,...l]}return e.jsx("div",{className:k===b.PREDEFINED?st(It.predefinedMenuActive):"",children:e.jsxs(ct,{small:i,width:g,children:[x&&e.jsx(dt,{text:k===b.PREDEFINED?D==null?void 0:D.label:"",children:e.jsx(we,{maxHeight:380,groupOrder:"first",testId:w&&`${w}-predefined-menu`,disabled:t,menu:{colored:!0,trigger:"Component",component:e.jsx(c,{groupOrder:"first",active:k===b.PREDEFINED,icon:k===b.PREDEFINED?"link":"unlink"}),small:i,sections:Q}})}),e.jsx(pt,{type:"text",name:ke,testId:w,disabled:t,placeholder:de?F(V,v.unit,xe,A):a,value:v.value,onChange:Xn,onFocus:Kn,error:u||Gn,warning:$n,right:!o},ke),G&&(nt||!Jn?e.jsx(ot,{groupOrder:"last",children:G}):e.jsx(we,{maxHeight:380,groupOrder:"last",disabled:s,testId:w&&`${w}-menu`,menu:{label:G,trigger:"DropDownButton",small:i,sections:Z.map(([l,d,f])=>{const y=f||d||"";return{type:"Option",label:isNaN(Number(l))?"":l,inline:!0,onClick:X=>{X.stopPropagation(),et(de?"":l,d)},description:y,selected:y===G,testId:`${w}-unit-${y}`}})}}))]})})};try{p.displayName="UnitInput",p.__docgenInfo={description:"",displayName:"UnitInput",props:{name:{defaultValue:null,description:"",name:"name",required:!0,type:{name:"string | { fieldName?: string | undefined; }"}},placeholder:{defaultValue:{value:""},description:"",name:"placeholder",required:!1,type:{name:"string"}},disabled:{defaultValue:{value:"false"},description:"",name:"disabled",required:!1,type:{name:"boolean"}},disabledUnit:{defaultValue:{value:"false"},description:"",name:"disabledUnit",required:!1,type:{name:"boolean"}},error:{defaultValue:{value:"null"},description:"",name:"error",required:!1,type:{name:"string | boolean | null"}},left:{defaultValue:{value:"false"},description:"",name:"left",required:!1,type:{name:"boolean"}},small:{defaultValue:{value:"false"},description:"",name:"small",required:!1,type:{name:"boolean"}},width:{defaultValue:{value:"100%"},description:"",name:"width",required:!1,type:{name:"string | number"}},value:{defaultValue:null,description:"",name:"value",required:!1,type:{name:"string"}},unitkey:{defaultValue:{value:""},description:"",name:"unitkey",required:!1,type:{name:"string"}},initUnit:{defaultValue:null,description:"",name:"initUnit",required:!1,type:{name:"string"}},noConversion:{defaultValue:{value:"false"},description:"",name:"noConversion",required:!1,type:{name:"boolean"}},doNotConvertValue:{defaultValue:{value:"false"},description:"",name:"doNotConvertValue",required:!1,type:{name:"boolean"}},testId:{defaultValue:null,description:"",name:"testId",required:!1,type:{name:"string"}},warning:{defaultValue:{value:"null"},description:"",name:"warning",required:!1,type:{name:"string | null"}},predefinedOptions:{defaultValue:null,description:"",name:"predefinedOptions",required:!1,type:{name:"IPredefinedOption[]"}},initialPredefinedOption:{defaultValue:{value:"false"},description:"",name:"initialPredefinedOption",required:!1,type:{name:"boolean"}},shouldLinkAutomaticly:{defaultValue:{value:"true"},description:"",name:"shouldLinkAutomaticly",required:!1,type:{name:"boolean"}},selectedPredefinedOptionKey:{defaultValue:null,description:"",name:"selectedPredefinedOptionKey",required:!1,type:{name:"string"}},validationCallback:{defaultValue:{value:"() => ({ name: '', error: null })"},description:"",name:"validationCallback",required:!1,type:{name:"((name: string, message: string | null) => { name: string; error: string | null; })"}},disabledValidation:{defaultValue:{value:"false"},description:"",name:"disabledValidation",required:!1,type:{name:"boolean"}},allowEmpty:{defaultValue:{value:"false"},description:"",name:"allowEmpty",required:!1,type:{name:"boolean"}},autoValue:{defaultValue:null,description:"",name:"autoValue",required:!1,type:{name:"string"}},onChange:{defaultValue:{value:"() => {}"},description:"",name:"onChange",required:!1,type:{name:"(event: ChangeEvent<HTMLInputElement> | ICustomChangeEvent) => void"}},onSwitchUnit:{defaultValue:{value:"() => {}"},description:"",name:"onSwitchUnit",required:!1,type:{name:"((unit: string) => void)"}},onClick:{defaultValue:{value:"() => {}"},description:"",name:"onClick",required:!1,type:{name:"MouseEventHandler<HTMLInputElement>"}},onFocus:{defaultValue:{value:"() => {}"},description:"",name:"onFocus",required:!1,type:{name:"FocusEventHandler<HTMLInputElement>"}},unitTemplate:{defaultValue:null,description:"",name:"unitTemplate",required:!1,type:{name:"Record<string, any>"}}}}}catch{}const{useArgs:jt}=__STORYBOOK_MODULE_ADDONS__,sa={title:"Basic/UnitInput",component:p,args:{name:"example",unitkey:"length",value:"123|m"}},C=n=>{const[a,t]=jt(),s=u=>{t({value:u.target.value})};return e.jsx(p,{...n,onChange:s})},ee=C.bind({}),M=C.bind({});M.args={initUnit:"ft",unitTemplate:{length:"ft"}};const _=C.bind({});_.args={value:'123|"',unitkey:'"'};const O=C.bind({});O.args={width:"180px"};const B=C.bind({});B.args={noConversion:!0};const q=C.bind({});q.args={small:!0};const W=C.bind({});W.args={error:"Error message goes here"};const T=C.bind({});T.args={value:"asas123asd|%"};const N=C.bind({});N.args={disabled:!0,disabledUnit:!0};N.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 R=C.bind({});R.args={disabled:!0,disabledUnit:!0,noConversion:!0};const L=C.bind({});L.args={disabledUnit:!0,unitkey:void 0};const K=C.bind({});K.args={disabledUnit:!0,unitkey:"length"};const $=C.bind({});$.args={disabledUnit:!1,disabled:!0};const H=n=>{const[a,t]=m.useState("123|m"),[s,u]=m.useState("223|m"),[o,i]=m.useState("ft");return e.jsxs(e.Fragment,{children:[e.jsx(c,{label:"Change initUnit",onClick:()=>i(o==="m"?"ft":"m")}),e.jsx(S,{}),e.jsx(c,{label:"Change value",onClick:()=>t(a==="123|m"?"456|m":"123|m")}),e.jsx(S,{}),e.jsx(p,{name:"example",onChange:g=>{t(g.target.value)},unitkey:"length",value:a,initUnit:o,onSwitchUnit:i}),e.jsx(S,{}),e.jsx(p,{name:"example2",onChange:g=>{u(g.target.value)},unitkey:"length",value:s,initUnit:o,onSwitchUnit:i}),e.jsx(gt,{}),e.jsx("h4",{children:"Without initUnit property (taken from the redux store)"}),e.jsx(p,{name:"example",onChange:g=>{t(g.target.value)},unitkey:"length",value:a,onSwitchUnit:i}),e.jsx(p,{name:"example2",onChange:g=>{u(g.target.value)},unitkey:"length",value:s,onSwitchUnit:i})]})};H.parameters={docs:{description:{story:"[OW-4380](https://oliasoft.atlassian.net/browse/OW-4380?atlOrigin=eyJpIjoiMmM1N2RkNWU3Mjk5NDYxY2E0YzhkMzk5ZTVmZTJhMjciLCJwIjoiaiJ9)"}}};const z=C.bind({});z.args={predefinedOptions:[{label:"bottom of casing",value:"12|km"},{label:"mud weight at shoe depth",value:"8|mm"}]};const J=()=>{const n="500px",[a,t]=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(Wn,{children:[e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value infinity",onClick:()=>t(1/0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value -infinity",onClick:()=>t(-1/0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value null",onClick:()=>t(null)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - undefined",onClick:()=>t(void 0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - NaN",onClick:()=>t(NaN)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - nothing (empty)",onClick:()=>t(void 0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - empty string",onClick:()=>t("")})]}),e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value infinity|m",onClick:()=>t("Infinity|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value -infinity|m",onClick:()=>t("-Infinity|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value null|m",onClick:()=>t("null|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - undefined|m",onClick:()=>t("undefined|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - NaN|m",onClick:()=>t("NaN|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - nothing (empty)|m",onClick:()=>t("|m")})]})]}),e.jsx("br",{}),e.jsx(I,{label:"Normal PUI",children:e.jsx(p,{name:"example1",onChange:s=>t(s.target.value),value:a,unitkey:"length",width:n,placeholder:"value|unit"})}),e.jsx(I,{label:"Disabled validation",children:e.jsx(p,{name:"example2",onChange:s=>t(s.target.value),value:a,unitkey:"length",disabledValidation:!0,width:n})}),e.jsx(I,{label:"Disabled validation and manual error",children:e.jsx(p,{name:"example3",onChange:s=>t(s.target.value),value:a,unitkey:"length",error:"test",disabledValidation:!0,width:n})}),e.jsx(ge,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})},ne=()=>{const n="500px",[a,t]=m.useState("1|m"),[s,u]=m.useState("|m"),o="123|km";return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different cases for automatic (placeholder) values:"}),e.jsx(Wn,{children:e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value to ''",onClick:()=>t("")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to 1",onClick:()=>t("1")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to 1|m",onClick:()=>t("1|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to |m - empty value",onClick:()=>t("|m")})]})}),e.jsx("br",{}),e.jsx(I,{label:"Normal PUI (placeholder + auto)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,placeholder:"value|unit",autoValue:o})}),e.jsx(I,{label:"Normal PUI (only auto)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,autoValue:o})}),e.jsx(I,{label:"Empty PUI with autoValue",children:e.jsx(p,{name:"example1",onChange:i=>u(i.target.value),value:s,unitkey:"length",width:n,autoValue:o})}),e.jsx(I,{label:"Normal PUI (only placeholder)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,placeholder:"Placeholder test"})}),e.jsx(I,{label:"Normal PUI (placeholder + allowEmpty)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,placeholder:"Placeholder test",allowEmpty:!0})}),e.jsx(ge,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})};J.parameters={docs:{description:{story:"[OW-8884](https://oliasoft.atlassian.net/browse/OW-8884)"}}};const te=()=>{const[n,a]=m.useState("123|%"),[t,s]=m.useState(null),u="This should be visible when an error appears",o=(i,g)=>(s(g),{name:i,error:g});return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"3rd party validation message when inputting invalid value:"}),e.jsx(p,{name:"example",onChange:i=>a(i.target.value),error:!t||u,validationCallback:o,value:n}),e.jsx("br",{}),e.jsx(S,{}),e.jsx("h4",{children:"Original validation message: "}),e.jsx(ge,{message:{heading:t,visible:!0}})]})},ae=()=>{const[n,a]=m.useState("123|m"),[t,s]=m.useState(""),[u,o]=m.useState("km"),i=()=>{o("ft"),s("placeholder"),a("|m")};return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Empty value case:"}),e.jsx(p,{name:"example",onChange:g=>a(g.target.value),value:n,allowEmpty:!0,placeholder:t,initUnit:u,unitkey:"length"}),e.jsx("br",{}),e.jsx(S,{}),e.jsx(c,{label:"Change value |m and unit ft",onClick:()=>i()})]})},le=()=>{const[n,a]=m.useState("123|m"),[t,s]=m.useState("m");return e.jsxs(e.Fragment,{children:[e.jsx(p,{name:"example",onChange:u=>a(u.target.value),value:n,initUnit:t,unitkey:"length",onSwitchUnit:s}),e.jsx(S,{}),e.jsx(p,{name:"example",onChange:u=>a(u.target.value),value:n,initUnit:t,unitkey:"length",onSwitchUnit:s})]})};var De,Fe,Me;ee.parameters={...ee.parameters,docs:{...(De=ee.parameters)==null?void 0:De.docs,source:{originalSource:`args => {
1
+ import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as m}from"./index-RfLt4OUa.js";import{d as r,r as it}from"./index-qZmQ7nA9.js";import{c as st}from"./index-VW3EWkuE.js";import{u as ut}from"./use-previous-VKMmnaK7.js";import{M as we}from"./actions-Z1pyUd57.js";import{I as ot}from"./input-group-addon-BHVsW9mL.js";import{B as c}from"./button-UQO14biP.js";import{T as dt}from"./tooltip-dueTLnwA.js";import{I as ct}from"./input-group-R8LoqKRn.js";import{S}from"./spacer-Yji9g2AW.js";import{T as mt}from"./text-6KQ6ntOV.js";import{I as pt}from"./input-fYKvBwPs.js";import{M as Ee}from"./types-VB5zD18b.js";import{l as E}from"./lodash-Bmg8FrMx.js";import{D as gt}from"./divider-RwW2f_N0.js";import{R as Wn,C as pe}from"./row-vFUhHoz5.js";import{F as I}from"./field-jD6TclDQ.js";import{M as ge}from"./message-bbAE2zjv.js";import"./index-cCpkwrS5.js";import"./common-types-U65vzrrz.js";import"./disabled-context-urNQThQz.js";import"./icon-_m67DAr0.js";import"./objectWithoutPropertiesLoose-9Q1jwsKS.js";import"./inheritsLoose-Y9jOMJLd.js";import"./tslib.es6-OIsz3r9a.js";import"./index-4QtD-hFu.js";import"./types-5uVBABF4.js";import"./badge-23Ty_zBt.js";import"./spinner-R8Il4aRe.js";import"./index-miLrID2P.js";import"./styled-components.browser.esm-qIipjd6c.js";import"./label-dla_bzHj.js";import"./help-icon-D6ZGAbgL.js";const ht=()=>{const n=m.useRef(null);return m.useLayoutEffect(()=>{n.current&&(n.current(),n.current=null)}),t=>{n.current=t}},vt=(n,a)=>{const t=a==null?void 0:a[n];return t||(console.log(`Warning: 'unitTemplate' does not define a preferred unit for '${n}'. Defaulting to standard unit.`),r.unitFromQuantity(n)??"")};var b=(n=>(n.CUSTOM="custom",n.PREDEFINED="predefined",n))(b||{});const Tn=n=>n==="undefined"||n===void 0||n===""||n==="null"||n===null||n==="NaN"||isNaN(n),Rn=(n="",a,t="",s=!1)=>{if(s)return n;if(a&&!Tn(n))try{const u=r.isValueWithUnit(n)?n:r.withUnit(n,t),o=r.convertSamePrecision(u,a);return r.getValue(o)}catch{}return n},ft=n=>n?!!r.getUnit(n):!1,F=(n="",a,t,s)=>{if(s)return n;const u=ft(n)||r.isValueWithUnit(n),o=r.getValue(n);return Tn(o)?o:u?Rn(o,a,t,s):n},Ne=n=>E.isObject(n)&&!E.isArray(n)&&!E.isFunction(n)?E.get(n,"fieldName",""):typeof n=="string"?n:"",Ct=n=>E.isObjectLike(n)&&E.has(n,"message"),bt=n=>typeof n=="string"?n:Ct(n)?n.message:null;var Ut=it();const yt=n=>n.search(RegExp(/(^0{2}\.)|(^0+[1-9])/g))===0,Ae=(n,a)=>{var j;const{allowEmpty:t=!1,autoValue:s,placeholder:u,disabledValidation:o=!1}=a||{},i=String(n);if(o||s||u)return null;const g=Ut.isValueWithUnit(i)?r.getValue(i):i;if(t&&g==="")return null;if(yt(g))return"Invalid number format due to leading zeroes";const h=r.validateNumber(g);if(!h.valid){const re=((j=h==null?void 0:h.errors)==null?void 0:j[0])??null;return bt(re)}return null},Pe=(n="")=>{var a;return(a=r.KNOWN_UNITS)==null?void 0:a.includes(n)},xt=(n,a)=>{const t=r.getUnit(n||"");return Pe(a)&&Pe(t)},Vt="_predefinedMenuActive_1yvt4_1",It={predefinedMenuActive:Vt},p=({name:n,placeholder:a="",disabled:t=!1,disabledUnit:s=!1,error:u=null,left:o=!1,small:i=!1,width:g="100%",value:h,unitkey:j="",initUnit:re,noConversion:Ln=!1,onChange:ie=()=>{},onClick:kt=()=>{},onFocus:Kn=()=>{},onSwitchUnit:he=()=>{},unitTemplate:ve,doNotConvertValue:A=!1,testId:w,warning:$n=null,predefinedOptions:x,initialPredefinedOption:Hn=!1,shouldLinkAutomaticly:fe=!0,selectedPredefinedOptionKey:Ce,validationCallback:be=()=>({name:"",error:null}),disabledValidation:Ue=!1,allowEmpty:ye=!1,autoValue:V})=>{typeof h=="number"&&(h=`${h}`);const zn=ht(),[se="",P=""]=h!==void 0?r.split(h):[],xe=V?r.getUnit(V):"",Ve=m.useMemo(()=>vt(j,ve),[j,ve]),Jn=xt(h,Ve),U=re||Ve||P,Yn=ut(U),Ie=F(h,U,P,A),je=F(V,U,xe,A),Zn=Ie!==""?{value:Ie,unit:U}:je!==""?{value:je,unit:U}:{value:se,unit:P},[v,Y]=m.useState(Zn),[Gn,ue]=m.useState(null),[k,oe]=m.useState(Hn?b.PREDEFINED:b.CUSTOM),de=se===""&&V,D=x&&x.find(l=>{if(Ce)return Ce===l.valueKey;const d=r.isValueWithUnit(l.value)?r.getUnit(l.value):"";return r.withUnit(Rn(h,d),d)===l.value}),Qn=()=>{if(j)try{const l=de?V:h??"";let d=r.altUnitsList(l,j);return r.getValue(l)===""?d.map(f=>["",f[1]]):d}catch{return null}},Xn=l=>{const d=Ne(n),f=l.target,{value:y,selectionStart:X}=f,Se=r.cleanNumStr(y.replaceAll(" ","").replaceAll("|","")),ce=r.withUnit(Se,(v==null?void 0:v.unit)||""),at=r.getValue(ce),me=Ae(at,{allowEmpty:ye,autoValue:V,placeholder:a,disabledValidation:Ue});if(me===null){ie({target:{value:ce,name:d}});const[lt,rt]=r.split(ce);Y({value:lt,unit:rt}),ue(null),be(d,null)}else Y({value:Se,unit:v.unit}),ue(me),be(d,me);zn(()=>{f.selectionStart=X,f.selectionEnd=X})},et=(l,d)=>{d===v.unit||isNaN(Number(l))||(Y({value:l,unit:d}),he&&he(d))};m.useEffect(()=>{if(U){let f,y="";Yn!==U?(f=F(h,U,P,A),y=U):r.withUnit(v.value,v.unit)!==h&&(f=F(h,v.unit,P,A),y=v.unit),f!==void 0&&Y({value:f,unit:y}),x&&oe(D&&fe?b.PREDEFINED:b.CUSTOM)}const l=r.checkAndCleanDecimalComma(se),d=Ae(l,{allowEmpty:ye,autoValue:V,placeholder:a,disabledValidation:Ue});ue(d)},[U,h,u,fe]);const Z=Qn(),G=r.label(v.unit)||v.unit||"",nt=Ln||!Z||Z&&Z.length===1,ke=Ne(n);let Q;const tt=l=>{const[d,f=""]=r.isValueWithUnit(l.value)?r.split(l.value):[l.value];return{type:Ee.OPTION,inline:!0,onClick:()=>{r.validateNumber(d).valid&&!t&&(oe(b.PREDEFINED),ie({target:{value:l.value,name:typeof n=="string"?n:(n==null?void 0:n.fieldName)||"",predefinedSelected:!0,predefinedOption:l}}))},label:e.jsxs(e.Fragment,{children:[e.jsx(mt,{children:l.label}),e.jsx(S,{width:"20px",height:"0"})]}),description:r.isValueWithUnit(l.value)?`${d} ${f}`:l.value,selected:D===l&&k===b.PREDEFINED}};if(Q=[{type:Ee.OPTION,inline:!0,onClick:()=>{k!==b.CUSTOM&&!t&&ie({target:{value:r.withUnit(v.value,v.unit),name:typeof n=="string"?n:(n==null?void 0:n.fieldName)||""}})},label:"Custom",selected:k===b.CUSTOM}],x!=null&&x.length){const l=x.map(tt);Q=[...Q,...l]}return e.jsx("div",{className:k===b.PREDEFINED?st(It.predefinedMenuActive):"",children:e.jsxs(ct,{small:i,width:g,children:[x&&e.jsx(dt,{text:k===b.PREDEFINED?D==null?void 0:D.label:"",children:e.jsx(we,{maxHeight:380,groupOrder:"first",testId:w&&`${w}-predefined-menu`,disabled:t,menu:{colored:!0,trigger:"Component",component:e.jsx(c,{groupOrder:"first",active:k===b.PREDEFINED,icon:k===b.PREDEFINED?"link":"unlink"}),small:i,sections:Q}})}),e.jsx(pt,{type:"text",name:ke,testId:w,disabled:t,placeholder:de?F(V,v.unit,xe,A):a,value:v.value,onChange:Xn,onFocus:Kn,error:u||Gn,warning:$n,right:!o},ke),G&&(nt||!Jn?e.jsx(ot,{groupOrder:"last",children:G}):e.jsx(we,{maxHeight:380,groupOrder:"last",disabled:s,testId:w&&`${w}-menu`,menu:{label:G,trigger:"DropDownButton",small:i,sections:Z.map(([l,d,f])=>{const y=f||d||"";return{type:"Option",label:isNaN(Number(l))?"":l,inline:!0,onClick:X=>{X.stopPropagation(),et(de?"":l,d)},description:y,selected:y===G,testId:`${w}-unit-${y}`}})}}))]})})};try{p.displayName="UnitInput",p.__docgenInfo={description:"",displayName:"UnitInput",props:{name:{defaultValue:null,description:"",name:"name",required:!0,type:{name:"string | { fieldName?: string | undefined; }"}},placeholder:{defaultValue:{value:""},description:"",name:"placeholder",required:!1,type:{name:"string"}},disabled:{defaultValue:{value:"false"},description:"",name:"disabled",required:!1,type:{name:"boolean"}},disabledUnit:{defaultValue:{value:"false"},description:"",name:"disabledUnit",required:!1,type:{name:"boolean"}},error:{defaultValue:{value:"null"},description:"",name:"error",required:!1,type:{name:"string | boolean | null"}},left:{defaultValue:{value:"false"},description:"",name:"left",required:!1,type:{name:"boolean"}},small:{defaultValue:{value:"false"},description:"",name:"small",required:!1,type:{name:"boolean"}},width:{defaultValue:{value:"100%"},description:"",name:"width",required:!1,type:{name:"string | number"}},value:{defaultValue:null,description:"",name:"value",required:!1,type:{name:"string"}},unitkey:{defaultValue:{value:""},description:"",name:"unitkey",required:!1,type:{name:"string"}},initUnit:{defaultValue:null,description:"",name:"initUnit",required:!1,type:{name:"string"}},noConversion:{defaultValue:{value:"false"},description:"",name:"noConversion",required:!1,type:{name:"boolean"}},doNotConvertValue:{defaultValue:{value:"false"},description:"",name:"doNotConvertValue",required:!1,type:{name:"boolean"}},testId:{defaultValue:null,description:"",name:"testId",required:!1,type:{name:"string"}},warning:{defaultValue:{value:"null"},description:"",name:"warning",required:!1,type:{name:"string | null"}},predefinedOptions:{defaultValue:null,description:"",name:"predefinedOptions",required:!1,type:{name:"IPredefinedOption[]"}},initialPredefinedOption:{defaultValue:{value:"false"},description:"",name:"initialPredefinedOption",required:!1,type:{name:"boolean"}},shouldLinkAutomaticly:{defaultValue:{value:"true"},description:"",name:"shouldLinkAutomaticly",required:!1,type:{name:"boolean"}},selectedPredefinedOptionKey:{defaultValue:null,description:"",name:"selectedPredefinedOptionKey",required:!1,type:{name:"string"}},validationCallback:{defaultValue:{value:"() => ({ name: '', error: null })"},description:"",name:"validationCallback",required:!1,type:{name:"((name: string, message: string | null) => { name: string; error: string | null; })"}},disabledValidation:{defaultValue:{value:"false"},description:"",name:"disabledValidation",required:!1,type:{name:"boolean"}},allowEmpty:{defaultValue:{value:"false"},description:"",name:"allowEmpty",required:!1,type:{name:"boolean"}},autoValue:{defaultValue:null,description:"",name:"autoValue",required:!1,type:{name:"string"}},onChange:{defaultValue:{value:"() => {}"},description:"",name:"onChange",required:!1,type:{name:"(event: ChangeEvent<HTMLInputElement> | ICustomChangeEvent) => void"}},onSwitchUnit:{defaultValue:{value:"() => {}"},description:"",name:"onSwitchUnit",required:!1,type:{name:"((unit: string) => void)"}},onClick:{defaultValue:{value:"() => {}"},description:"",name:"onClick",required:!1,type:{name:"MouseEventHandler<HTMLInputElement>"}},onFocus:{defaultValue:{value:"() => {}"},description:"",name:"onFocus",required:!1,type:{name:"FocusEventHandler<HTMLInputElement>"}},unitTemplate:{defaultValue:null,description:"",name:"unitTemplate",required:!1,type:{name:"Record<string, any>"}}}}}catch{}const{useArgs:jt}=__STORYBOOK_MODULE_ADDONS__,sa={title:"Basic/UnitInput",component:p,args:{name:"example",unitkey:"length",value:"123|m"}},C=n=>{const[a,t]=jt(),s=u=>{t({value:u.target.value})};return e.jsx(p,{...n,onChange:s})},ee=C.bind({}),M=C.bind({});M.args={initUnit:"ft",unitTemplate:{length:"ft"}};const _=C.bind({});_.args={value:'123|"',unitkey:'"'};const O=C.bind({});O.args={width:"180px"};const B=C.bind({});B.args={noConversion:!0};const q=C.bind({});q.args={small:!0};const W=C.bind({});W.args={error:"Error message goes here"};const T=C.bind({});T.args={value:"asas123asd|%"};const N=C.bind({});N.args={disabled:!0,disabledUnit:!0};N.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 R=C.bind({});R.args={disabled:!0,disabledUnit:!0,noConversion:!0};const L=C.bind({});L.args={disabledUnit:!0,unitkey:void 0};const K=C.bind({});K.args={disabledUnit:!0,unitkey:"length"};const $=C.bind({});$.args={disabledUnit:!1,disabled:!0};const H=n=>{const[a,t]=m.useState("123|m"),[s,u]=m.useState("223|m"),[o,i]=m.useState("ft");return e.jsxs(e.Fragment,{children:[e.jsx(c,{label:"Change initUnit",onClick:()=>i(o==="m"?"ft":"m")}),e.jsx(S,{}),e.jsx(c,{label:"Change value",onClick:()=>t(a==="123|m"?"456|m":"123|m")}),e.jsx(S,{}),e.jsx(p,{name:"example",onChange:g=>{t(g.target.value)},unitkey:"length",value:a,initUnit:o,onSwitchUnit:i}),e.jsx(S,{}),e.jsx(p,{name:"example2",onChange:g=>{u(g.target.value)},unitkey:"length",value:s,initUnit:o,onSwitchUnit:i}),e.jsx(gt,{}),e.jsx("h4",{children:"Without initUnit property (taken from the redux store)"}),e.jsx(p,{name:"example",onChange:g=>{t(g.target.value)},unitkey:"length",value:a,onSwitchUnit:i}),e.jsx(p,{name:"example2",onChange:g=>{u(g.target.value)},unitkey:"length",value:s,onSwitchUnit:i})]})};H.parameters={docs:{description:{story:"[OW-4380](https://oliasoft.atlassian.net/browse/OW-4380?atlOrigin=eyJpIjoiMmM1N2RkNWU3Mjk5NDYxY2E0YzhkMzk5ZTVmZTJhMjciLCJwIjoiaiJ9)"}}};const z=C.bind({});z.args={predefinedOptions:[{label:"bottom of casing",value:"12|km"},{label:"mud weight at shoe depth",value:"8|mm"}]};const J=()=>{const n="500px",[a,t]=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(Wn,{children:[e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value infinity",onClick:()=>t(1/0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value -infinity",onClick:()=>t(-1/0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value null",onClick:()=>t(null)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - undefined",onClick:()=>t(void 0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - NaN",onClick:()=>t(NaN)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - nothing (empty)",onClick:()=>t(void 0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - empty string",onClick:()=>t("")})]}),e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value infinity|m",onClick:()=>t("Infinity|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value -infinity|m",onClick:()=>t("-Infinity|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value null|m",onClick:()=>t("null|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - undefined|m",onClick:()=>t("undefined|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - NaN|m",onClick:()=>t("NaN|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - nothing (empty)|m",onClick:()=>t("|m")})]})]}),e.jsx("br",{}),e.jsx(I,{label:"Normal PUI",children:e.jsx(p,{name:"example1",onChange:s=>t(s.target.value),value:a,unitkey:"length",width:n,placeholder:"value|unit"})}),e.jsx(I,{label:"Disabled validation",children:e.jsx(p,{name:"example2",onChange:s=>t(s.target.value),value:a,unitkey:"length",disabledValidation:!0,width:n})}),e.jsx(I,{label:"Disabled validation and manual error",children:e.jsx(p,{name:"example3",onChange:s=>t(s.target.value),value:a,unitkey:"length",error:"test",disabledValidation:!0,width:n})}),e.jsx(ge,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})},ne=()=>{const n="500px",[a,t]=m.useState("1|m"),[s,u]=m.useState("|m"),o="123|km";return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different cases for automatic (placeholder) values:"}),e.jsx(Wn,{children:e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value to ''",onClick:()=>t("")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to 1",onClick:()=>t("1")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to 1|m",onClick:()=>t("1|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to |m - empty value",onClick:()=>t("|m")})]})}),e.jsx("br",{}),e.jsx(I,{label:"Normal PUI (placeholder + auto)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,placeholder:"value|unit",autoValue:o})}),e.jsx(I,{label:"Normal PUI (only auto)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,autoValue:o})}),e.jsx(I,{label:"Empty PUI with autoValue",children:e.jsx(p,{name:"example1",onChange:i=>u(i.target.value),value:s,unitkey:"length",width:n,autoValue:o})}),e.jsx(I,{label:"Normal PUI (only placeholder)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,placeholder:"Placeholder test"})}),e.jsx(I,{label:"Normal PUI (placeholder + allowEmpty)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,placeholder:"Placeholder test",allowEmpty:!0})}),e.jsx(ge,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})};J.parameters={docs:{description:{story:"[OW-8884](https://oliasoft.atlassian.net/browse/OW-8884)"}}};const te=()=>{const[n,a]=m.useState("123|%"),[t,s]=m.useState(null),u="This should be visible when an error appears",o=(i,g)=>(s(g),{name:i,error:g});return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"3rd party validation message when inputting invalid value:"}),e.jsx(p,{name:"example",onChange:i=>a(i.target.value),error:!t||u,validationCallback:o,value:n}),e.jsx("br",{}),e.jsx(S,{}),e.jsx("h4",{children:"Original validation message: "}),e.jsx(ge,{message:{heading:t,visible:!0}})]})},ae=()=>{const[n,a]=m.useState("123|m"),[t,s]=m.useState(""),[u,o]=m.useState("km"),i=()=>{o("ft"),s("placeholder"),a("|m")};return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Empty value case:"}),e.jsx(p,{name:"example",onChange:g=>a(g.target.value),value:n,allowEmpty:!0,placeholder:t,initUnit:u,unitkey:"length"}),e.jsx("br",{}),e.jsx(S,{}),e.jsx(c,{label:"Change value |m and unit ft",onClick:()=>i()})]})},le=()=>{const[n,a]=m.useState("123|m"),[t,s]=m.useState("m");return e.jsxs(e.Fragment,{children:[e.jsx(p,{name:"example",onChange:u=>a(u.target.value),value:n,initUnit:t,unitkey:"length",onSwitchUnit:s}),e.jsx(S,{}),e.jsx(p,{name:"example",onChange:u=>a(u.target.value),value:n,initUnit:t,unitkey:"length",onSwitchUnit:s})]})};var De,Fe,Me;ee.parameters={...ee.parameters,docs:{...(De=ee.parameters)==null?void 0:De.docs,source:{originalSource:`args => {
2
2
  const [_, updateArgs] = useArgs();
3
3
  const handleChange = (evt: any) => {
4
4
  updateArgs({
@@ -0,0 +1,150 @@
1
+ import{j as n}from"./jsx-runtime-FsUICBgo.js";import{r as v}from"./index-RfLt4OUa.js";import{f as M}from"./immer.esm-bD7SSJ7T.js";import{d as U}from"./index-qZmQ7nA9.js";import{G as Z}from"./grid-u1mZpaML.js";import{S as ee}from"./spacer-Yji9g2AW.js";import{C as F}from"./card-0r8RRVk-.js";import{F as L}from"./field-jD6TclDQ.js";import{H as W}from"./heading-FcNTpGhR.js";import{S as P}from"./select-IxUsW-Xm.js";import{T as I}from"./toggle-vKuY4G3w.js";import{l as te}from"./lodash-Bmg8FrMx.js";import{u as ne}from"./use-previous-VKMmnaK7.js";import{T as ae,C as K}from"./table-fdcNapB-.js";import"./index-cCpkwrS5.js";import"./styled-components.browser.esm-qIipjd6c.js";import"./tslib.es6-OIsz3r9a.js";import"./index-VW3EWkuE.js";import"./label-dla_bzHj.js";import"./common-types-U65vzrrz.js";import"./help-icon-D6ZGAbgL.js";import"./tooltip-dueTLnwA.js";import"./index-miLrID2P.js";import"./icon-_m67DAr0.js";import"./objectWithoutPropertiesLoose-9Q1jwsKS.js";import"./inheritsLoose-Y9jOMJLd.js";import"./index-4QtD-hFu.js";import"./disabled-context-urNQThQz.js";import"./types-5uVBABF4.js";import"./extends-dGVwEr9R.js";import"./assertThisInitialized-4q6YPdh3.js";import"./memoize-one.esm-hqe5SRxC.js";import"./types-VB5zD18b.js";import"./text-6KQ6ntOV.js";import"./actions-Z1pyUd57.js";import"./button-UQO14biP.js";import"./spinner-R8Il4aRe.js";import"./badge-23Ty_zBt.js";import"./select.input-zP5tW20f.js";import"./index.es-HG2GUH9i.js";import"./redux-F5dueAP3.js";import"./objectSpread2-93s0nBry.js";import"./tiny-invariant-R4kOKlvx.js";import"./pagination-lFdPlLPJ.js";import"./input-fYKvBwPs.js";import"./input-group-R8LoqKRn.js";import"./input-group-addon-BHVsW9mL.js";import"./number-input-ymd7m-s5.js";import"./check-box-Q2GsbR79.js";import"./slider-jx0z5OyT.js";import"./index-ugi_ZH6T.js";import"./popover-rJn7kxkX.js";const re=o=>o.reduce(({preferredUnits:r,storageUnits:i},{unitKey:s,preferredUnit:a,storageUnit:b})=>(r[s]=a,i[s]=b,{preferredUnits:r,storageUnits:i}),{preferredUnits:{},storageUnits:{}}),ie=({headers:o,rows:r,selectedUnits:i,storageUnits:s,onChangeUnit:a,convertBackToStorageUnit:b,enableCosmeticRounding:g,enableDisplayRounding:T})=>{const u=o?o.map(d=>({...d,cells:d.cells.map(c=>{var t;if(c.type===K.AUTO_UNIT){const{testId:C,unitKey:p}=c;return{value:i[p],type:K.SELECT,searchable:!1,options:(t=U.getUnitsForQuantity(p))==null?void 0:t.map(y=>({label:U.label(y),value:y})),native:c.native,onChange:y=>a({unitKey:p,value:y.target.value}),testId:C}}return c})})):[],l=r?r.map((d,c)=>({...d,cells:d.cells.map((t,C)=>{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:p,value:y,formatDisplayValue:w}=t,j=T&&"roundDisplayValue"in t?t==null?void 0:t.roundDisplayValue:null,m=i[p],h=s[p],e=m!==h,f=e?U.convertAndGetValue(y,m,h):t.value,x=U.isScientificStringNum(y),R=g&&(e||!x)?U.roundToPrecision(f,14):f,D=w?w(R):R;return{...t,value:D,enableCosmeticRounding:g,enableDisplayRounding:T,roundDisplayValue:j,onChange:S=>{const{value:B}=S.target,_=s[p],E=i[p],N=E!==_,k=b?_:E,$=N?U.convertAndGetValue(B,k,E):B;if("onChange"in t){const{onChange:X}=t,Y={...S,target:{...S.target,value:String($),rowIndex:c,cellIndex:C,unit:k}};X(Y)}}}}return t})})):[];return{convertedHeaders:u,convertedRows:l}},H=({table:o,unitConfig:r,convertBackToStorageUnit:i=!0,enableCosmeticRounding:s=!0,enableDisplayRounding:a=!0})=>{const{rows:b,headers:g,...T}=o,{storageUnits:u,preferredUnits:l}=re(r),d=ne(l),[c,t]=v.useState(l),C=({unitKey:m,value:h})=>{t({...c,[m]:h});const e=r.find(f=>f.unitKey===m);e&&typeof e.onChange=="function"&&e.onChange({oldUnit:c[m],newUnit:h,unitKey:m})},p=m=>ie({headers:g,rows:b,selectedUnits:m,storageUnits:u,onChangeUnit:C,convertBackToStorageUnit:i,enableCosmeticRounding:s,enableDisplayRounding:a}),y=p(c),[w,j]=v.useState(y);return v.useEffect(()=>{!te.isEqual(l,d)&&(Object.keys(l).forEach(h=>{const e=d==null?void 0:d[h],f=l[h];e!==f&&C({unitKey:h,value:f})}),j(p(l)))},[r]),v.useEffect(()=>{j(p(c))},[o,c]),n.jsx(ae,{table:{...T,headers:w.convertedHeaders,rows:w.convertedRows}})};try{H.displayName="UnitTable",H.__docgenInfo={description:"",displayName:"UnitTable",props:{table:{defaultValue:null,description:"",name:"table",required:!0,type:{name:"IUnitTable"}},unitConfig:{defaultValue:null,description:"",name:"unitConfig",required:!0,type:{name:"IUnitConfigItem[]"}},convertBackToStorageUnit:{defaultValue:{value:"true"},description:"",name:"convertBackToStorageUnit",required:!1,type:{name:"boolean"}},enableCosmeticRounding:{defaultValue:{value:"true"},description:"",name:"enableCosmeticRounding",required:!1,type:{name:"boolean"}},enableDisplayRounding:{defaultValue:{value:"true"},description:"",name:"enableDisplayRounding",required:!1,type:{name:"boolean"}},onListReorder:{defaultValue:null,description:"",name:"onListReorder",required:!1,type:{name:"((obj: { from: number; to: number; }) => void)"}}}}}catch{}const gt={title:"Basic/UnitTable",args:{}},oe=!0,le=!0,se=!0,ue=!1,A="m",J="C",de=3,ce=(o,r,i)=>{const s=[r,r,i],a=[...Array(o)].map((b,g)=>{const T=g,u=g+1.25,l=4+g*.25;return[String(T),String(u),String(l)]});return[s,...a]},pe=ce(de,A,J),ge=({reduxTable:o,value:r,unit:i,rowIndex:s,cellIndex:a})=>M(o,b=>{const g=b[0][a],T=(u,l)=>l===0;return b.forEach((u,l)=>{if(T(u,l)){u[a]=i;return}if(l===s+1){u[a]=String(r);return}const d=U.convertAndGetValue(u[a],i,g);u[a]=String(d)}),b}),me=({reduxTable:o,value:r,rowIndex:i,cellIndex:s})=>M(o,a=>{a[i+1][s]=r}),V=()=>{var m,h;const[o,r]=v.useState(A),[i,s]=v.useState(J),[a,b]=v.useState(pe),[g,T]=v.useState(oe),[u,l]=v.useState(se),[d,c]=v.useState(le),[t,C]=v.useState(ue),[p,y]=v.useState(A),w=e=>{const{rowIndex:f,cellIndex:x,value:R,unit:D}=e.target,S=t?ge({reduxTable:a,value:R,unit:D,rowIndex:f,cellIndex:x}):me({reduxTable:a,value:R,rowIndex:f,cellIndex:x});b(S)},j=a.reduce((e,f,x)=>(x===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:f.map((R,D)=>{const S=x===1&&D===1;return{value:R,type:S?"Text":"NumberInput",unitKey:D===2?"temperature":"length",onChange:w,roundDisplayValue:x===3&&D===2?k=>U.roundByMagnitude(k,2):null,formatDisplayValue:S?k=>`T* ${k}`:null,autoUnit:!0}})}),e),{headers:[],rows:[]});return n.jsxs(Z,{columns:"1fr 1fr",gap:!0,children:[n.jsxs(F,{heading:n.jsx(W,{children:"Settings"}),children:[n.jsx(L,{label:"Convert back to storage unit:",labelLeft:!0,labelWidth:200,children:n.jsx(I,{checked:g,onChange:e=>T(e.target.checked)})}),n.jsx(L,{label:"Enable display rounding:",labelLeft:!0,labelWidth:200,children:n.jsx(I,{checked:u,onChange:e=>l(e.target.checked)})}),n.jsx(L,{label:"Enable cosmetic rounding:",labelLeft:!0,labelWidth:200,children:n.jsx(I,{checked:d,onChange:e=>c(e.target.checked)})}),n.jsx(L,{label:"Convert whole table:",labelLeft:!0,labelWidth:200,children:n.jsx(I,{checked:t,onChange:e=>C(e.target.checked)})})]}),n.jsxs(F,{heading:n.jsx(W,{children:"Unit template"}),children:[n.jsx(L,{label:"Length unit:",labelLeft:!0,labelWidth:120,children:n.jsx(P,{options:(m=U.getUnitsForQuantity("length"))==null?void 0:m.map(e=>({value:e,label:U.label(e)})),value:{value:o},onChange:e=>r(e.target.value),width:"100px"})}),n.jsx(L,{label:"Temperature unit:",labelLeft:!0,labelWidth:120,children:n.jsx(P,{options:(h=U.getUnitsForQuantity("temperature"))==null?void 0:h.map(e=>({value:e,label:U.label(e)})),value:{value:i},onChange:e=>s(e.target.value),width:"100px"})})]}),n.jsx(F,{heading:n.jsx(W,{children:"Storage State (Redux)"}),children:n.jsx("pre",{children:n.jsx("code",{children:JSON.stringify(a,null,2)})})}),n.jsxs(F,{heading:n.jsx(W,{children:"UnitTable"}),children:[n.jsx(H,{table:j,unitConfig:[{unitKey:"length",storageUnit:a[0][0],preferredUnit:o,onChange:({newUnit:e})=>y(e)},{unitKey:"temperature",storageUnit:a[0][2],preferredUnit:i}],convertBackToStorageUnit:g,enableDisplayRounding:u,enableCosmeticRounding:d}),n.jsx(ee,{height:20}),n.jsx(L,{label:"Displayed length unit:",labelLeft:!0,labelWidth:150,children:p})]})]})};var q,G,O,Q,z;V.parameters={...V.parameters,docs:{...(q=V.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
+ };
81
+ })
82
+ });
83
+ }
84
+ return acc;
85
+ }, {
86
+ headers: ([] as any[]),
87
+ rows: ([] as IUnitTableRow[])
88
+ });
89
+ return <Grid columns="1fr 1fr" gap>
90
+ <Card heading={<Heading>Settings</Heading>}>
91
+ <Field label="Convert back to storage unit:" labelLeft labelWidth={200}>
92
+ <Toggle checked={convertBackToStorageUnit} onChange={evt => setConvertBackToStorageUnit(evt.target.checked)} />
93
+ </Field>
94
+ <Field label="Enable display rounding:" labelLeft labelWidth={200}>
95
+ <Toggle checked={enableDisplayRounding} onChange={evt => setEnableDisplayRounding(evt.target.checked)} />
96
+ </Field>
97
+ <Field label="Enable cosmetic rounding:" labelLeft labelWidth={200}>
98
+ <Toggle checked={enableCosmeticRounding} onChange={evt => setEnableCosmeticRounding(evt.target.checked)} />
99
+ </Field>
100
+ <Field label="Convert whole table:" labelLeft labelWidth={200}>
101
+ <Toggle checked={convertWholeTable} onChange={evt => setConvertWholeTable(evt.target.checked)} />
102
+ </Field>
103
+ </Card>
104
+ <Card heading={<Heading>Unit template</Heading>}>
105
+ <Field label="Length unit:" labelLeft labelWidth={120}>
106
+ <Select options={getUnitsForQuantity('length')?.map(unit => ({
107
+ value: unit,
108
+ label: label(unit)
109
+ }))} value={{
110
+ value: preferredLengthUnit
111
+ }} onChange={evt => setPreferredLengthUnit(evt.target.value)} width="100px" />
112
+ </Field>
113
+ <Field label="Temperature unit:" labelLeft labelWidth={120}>
114
+ <Select options={getUnitsForQuantity('temperature')?.map(unit => ({
115
+ value: unit,
116
+ label: label(unit)
117
+ }))} value={{
118
+ value: preferredTemperatureUnit
119
+ }} onChange={evt => setPreferredTemperatureUnit(evt.target.value)} width="100px" />
120
+ </Field>
121
+ </Card>
122
+ <Card heading={<Heading>Storage State (Redux)</Heading>}>
123
+ <pre>
124
+ <code>{JSON.stringify(reduxTable, null, 2)}</code>
125
+ </pre>
126
+ </Card>
127
+ <Card heading={<Heading>UnitTable</Heading>}>
128
+ <UnitTable table={tableViewData}
129
+ //New props:
130
+ unitConfig={[{
131
+ unitKey: 'length',
132
+ storageUnit: reduxTable[0][0],
133
+ preferredUnit: preferredLengthUnit,
134
+ onChange: ({
135
+ newUnit
136
+ }) => setDisplayedLengthUnit(newUnit)
137
+ }, {
138
+ unitKey: 'temperature',
139
+ storageUnit: reduxTable[0][2],
140
+ preferredUnit: preferredTemperatureUnit
141
+ }]}
142
+ //Most tables should just use the default values here (true):
143
+ convertBackToStorageUnit={convertBackToStorageUnit} enableDisplayRounding={enableDisplayRounding} enableCosmeticRounding={enableCosmeticRounding} />
144
+ <Spacer height={20} />
145
+ <Field label="Displayed length unit:" labelLeft labelWidth={150}>
146
+ {displayedLengthUnit}
147
+ </Field>
148
+ </Card>
149
+ </Grid>;
150
+ }`,...(O=(G=V.parameters)==null?void 0:G.docs)==null?void 0:O.source},description:{story:"Story",...(z=(Q=V.parameters)==null?void 0:Q.docs)==null?void 0:z.description}}};const mt=["UnitTablePrototype"];export{V as UnitTablePrototype,mt as __namedExportsOrder,gt as default};
@@ -359,7 +359,7 @@
359
359
  }
360
360
  </script>
361
361
 
362
- <script type="module" crossorigin src="./assets/iframe-CpYMK6kb.js"></script>
362
+ <script type="module" crossorigin src="./assets/iframe-NjfSsybe.js"></script>
363
363
  </head>
364
364
 
365
365
  <body>