@oliasoft-open-source/react-ui-library 4.7.8 → 4.7.9-beta-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/dist/index.d.ts +35 -30
  2. package/dist/index.js +80 -62
  3. package/dist/index.js.map +1 -1
  4. package/dist/storybook/assets/Color-KGDBMAHA-DcdC9v0p.js +1 -0
  5. package/dist/storybook/assets/DocsRenderer-PKQXORMH-CT4GlLnv.js +1 -0
  6. package/dist/storybook/assets/{accordion-BiuI_LCA.js → accordion-6ouB0WTt.js} +1 -1
  7. package/dist/storybook/assets/{accordion.stories-Cs2ubF5q.js → accordion.stories-CH0BX_os.js} +2 -2
  8. package/dist/storybook/assets/actions-Tr0wIZve.js +39 -0
  9. package/dist/storybook/assets/{actions.stories-CUAkvJjE.js → actions.stories-CQK6PyBH.js} +1 -1
  10. package/dist/storybook/assets/afe.stories-CSYzQy-o.js +88 -0
  11. package/dist/storybook/assets/{badge.stories-Dkq_XgEW.js → badge.stories-Blb5k20_.js} +1 -1
  12. package/dist/storybook/assets/{blowout.stories-CF976Bad.js → blowout.stories-hdxkqScp.js} +1 -1
  13. package/dist/storybook/assets/{button-DHevvVBE.js → button-CzvLc2io.js} +1 -1
  14. package/dist/storybook/assets/{button-group-DCx4Z6vk.js → button-group-C1PqMW-H.js} +1 -1
  15. package/dist/storybook/assets/{button-group.stories-DvSsGv_D.js → button-group.stories-QlYbfeJS.js} +1 -1
  16. package/dist/storybook/assets/{button.stories-DA9DGYD2.js → button.stories-tM18j4A3.js} +2 -2
  17. package/dist/storybook/assets/{buttons-and-links-CtQdvmxW.js → buttons-and-links-CA4QaD8G.js} +2 -2
  18. package/dist/storybook/assets/{card.stories-CsTB0DuM.js → card.stories-Bn6LpucB.js} +1 -1
  19. package/dist/storybook/assets/{casing-loads.stories-DYLqR3q4.js → casing-loads.stories-C-GU3_LZ.js} +2 -2
  20. package/dist/storybook/assets/{cell.stories-lHzrZ3g_.js → cell.stories-CmBZ9hQL.js} +2 -2
  21. package/dist/storybook/assets/check-box-wCvXxtCz.js +13 -0
  22. package/dist/storybook/assets/{check-box.stories-C_7Z7Ss6.js → check-box.stories-Q_WICJ_2.js} +1 -1
  23. package/dist/storybook/assets/{chunk-HLWAVYOI-GiKqAqKE.js → chunk-HLWAVYOI-CEGCXOH9.js} +1 -1
  24. package/dist/storybook/assets/color-BtyLQXx1.js +25 -0
  25. package/dist/storybook/assets/{column.stories-DDTHFELF.js → column.stories-DATtbLrP.js} +1 -1
  26. package/dist/storybook/assets/{dialog-BtnEK12u.js → dialog-B55T_62Q.js} +1 -1
  27. package/dist/storybook/assets/{drawer-BqojbwAS.js → drawer-CNKfMbq9.js} +1 -1
  28. package/dist/storybook/assets/drawer.stories-BzVj2VTf.js +113 -0
  29. package/dist/storybook/assets/{empty.stories-DcwF0pkK.js → empty.stories-CVaJlnv1.js} +1 -1
  30. package/dist/storybook/assets/extends-CF3RwP-h.js +1 -0
  31. package/dist/storybook/assets/{field-HrLaMLbx.js → field-C5_fLDpy.js} +1 -1
  32. package/dist/storybook/assets/{field.stories-BBqJzdkf.js → field.stories-DhiTcelS.js} +1 -1
  33. package/dist/storybook/assets/file-button.stories-oe6HKMH2.js +22 -0
  34. package/dist/storybook/assets/file-input-CMP44wlr.js +13 -0
  35. package/dist/storybook/assets/{file-input.stories-BW--e4ZG.js → file-input.stories-DTRWZyqS.js} +1 -1
  36. package/dist/storybook/assets/{flex.stories-BhvJpHpN.js → flex.stories-DtDxXdHB.js} +1 -1
  37. package/dist/storybook/assets/footer.stories-M5swlcht.js +3 -0
  38. package/dist/storybook/assets/form.stories-BCg9rFVI.js +49 -0
  39. package/dist/storybook/assets/formation.stories-CgBhz3-o.js +74 -0
  40. package/dist/storybook/assets/{heading-CRNoBc7q.js → heading-NkLgQYoP.js} +1 -1
  41. package/dist/storybook/assets/{heading.stories-DahFxeiX.js → heading.stories-nI_cFnAN.js} +1 -1
  42. package/dist/storybook/assets/{help-icon-Buhx5nl6.js → help-icon-41R-Z9N1.js} +1 -1
  43. package/dist/storybook/assets/{help-icon.stories-DbmZ1fgP.js → help-icon.stories-DBYh0YX7.js} +1 -1
  44. package/dist/storybook/assets/helpers-JJxzGegQ.js +1 -0
  45. package/dist/storybook/assets/icon-BP4BO6-k.js +8 -0
  46. package/dist/storybook/assets/{icon.stories-fnZUR-LK.js → icon.stories-C4pR7xky.js} +1 -1
  47. package/dist/storybook/assets/iframe-BZTJ8TMF.js +2 -0
  48. package/dist/storybook/assets/{index-BAoS3bLT.js → index-D0Yp3qUF.js} +88 -88
  49. package/dist/storybook/assets/index-qsNwq0s-.js +1 -0
  50. package/dist/storybook/assets/{index.es-DazXb-ul.js → index.es-D2piFfFj.js} +4 -4
  51. package/dist/storybook/assets/inheritsLoose-DR8r8Ogv.js +1 -0
  52. package/dist/storybook/assets/input-DTXbDJaL.js +1 -0
  53. package/dist/storybook/assets/{input-group.stories-CFpFac6W.js → input-group.stories-M4a8AYtB.js} +3 -3
  54. package/dist/storybook/assets/{input-validation-X_m8WekI.js → input-validation-CPjdS76B.js} +2 -2
  55. package/dist/storybook/assets/{input.stories-EZ7qJt4K.js → input.stories-FKl0qVhm.js} +1 -1
  56. package/dist/storybook/assets/{inputs-D80uNhPY.js → inputs-vBIiN7wa.js} +2 -2
  57. package/dist/storybook/assets/{label-CqmyC9he.js → label-hiSz3I8H.js} +1 -1
  58. package/dist/storybook/assets/{label.stories-C0AO5F1a.js → label.stories-Cyv5jBAO.js} +1 -1
  59. package/dist/storybook/assets/layout-forms-CJdRAvRT.js +16 -0
  60. package/dist/storybook/assets/{layout-general-E6Gt2dIZ.js → layout-general-CrYxsfxK.js} +2 -2
  61. package/dist/storybook/assets/{list-DhcQLzoC.js → list-DhjHm8bz.js} +1 -1
  62. package/dist/storybook/assets/{list.stories-IFLT_P7d.js → list.stories-2F-UkS1E.js} +2 -2
  63. package/dist/storybook/assets/{list.stories-data-tIuoGcNV.js → list.stories-data-DqFECKJF.js} +1 -1
  64. package/dist/storybook/assets/{loader.stories-pS8zRM4u.js → loader.stories-BMe1zhEL.js} +1 -1
  65. package/dist/storybook/assets/{lodash-BHd_uQHh.js → lodash-c4VUpsOs.js} +2 -2
  66. package/dist/storybook/assets/{menu.stories-CXq2Fiuq.js → menu.stories-B_1YsebS.js} +2 -2
  67. package/dist/storybook/assets/menu.stories-data-CQ59XhzU.js +1 -0
  68. package/dist/storybook/assets/{message-Y48EomV-.js → message-DQ3q8XF9.js} +1 -1
  69. package/dist/storybook/assets/{message.stories-r_UlbshI.js → message.stories-QYFwbrO0.js} +1 -1
  70. package/dist/storybook/assets/{meta-content-CvnoQB7n.js → meta-content-DCllGQX6.js} +1 -1
  71. package/dist/storybook/assets/{modal.stories-CyMCZp33.js → modal.stories-PZXXHpu9.js} +2 -2
  72. package/dist/storybook/assets/number-input-Ct8VwJX0.js +16 -0
  73. package/dist/storybook/assets/number-input.stories-CK-pmDN5.js +110 -0
  74. package/dist/storybook/assets/option-dropdown.stories-ntKLWycS.js +52 -0
  75. package/dist/storybook/assets/{padding-and-spacing-yWT70QJX.js → padding-and-spacing-B-93CHYn.js} +2 -2
  76. package/dist/storybook/assets/{page.stories-B_x_6shq.js → page.stories-Dp_z8s1a.js} +1 -1
  77. package/dist/storybook/assets/{pagination-BcGXyU5V.js → pagination-T__Mixkr.js} +1 -1
  78. package/dist/storybook/assets/pagination.stories-C_oRnFX_.js +59 -0
  79. package/dist/storybook/assets/{pop-confirm.stories-DCpooB2O.js → pop-confirm.stories-D-iQo6s7.js} +1 -1
  80. package/dist/storybook/assets/{popover-rq33c1W2.js → popover-9ZnEm5Hy.js} +1 -1
  81. package/dist/storybook/assets/popover.stories-B9slHpqQ.js +10 -0
  82. package/dist/storybook/assets/{preview-BTEgxsm7.js → preview-3lxfqOkZ.js} +2 -2
  83. package/dist/storybook/assets/preview-D0xsXs52.js +2 -0
  84. package/dist/storybook/assets/projects.stories-CdvyNFKw.js +47 -0
  85. package/dist/storybook/assets/radio-button-C3RuBqEf.js +13 -0
  86. package/dist/storybook/assets/{radio-button.stories-CGJnfCk-.js → radio-button.stories-CAHs1mr6.js} +2 -2
  87. package/dist/storybook/assets/react-router-dom-CMITYWBH.js +8 -0
  88. package/dist/storybook/assets/{reservoirs.stories-CIUf8Stc.js → reservoirs.stories-zzDr9Zir.js} +2 -2
  89. package/dist/storybook/assets/{rich-text-input.stories-BxwJD_An.js → rich-text-input.stories-DDnRLaZw.js} +3 -3
  90. package/dist/storybook/assets/{row.stories-BqhC3_2k.js → row.stories-DVq_splx.js} +2 -2
  91. package/dist/storybook/assets/select-BW0IihoR.js +61 -0
  92. package/dist/storybook/assets/select.input-CJed_LLR.js +1 -0
  93. package/dist/storybook/assets/{select.stories-5JpxALAP.js → select.stories-CtbKVF6A.js} +2 -2
  94. package/dist/storybook/assets/{side-bar-BhPNjZba.js → side-bar-BApSkmiM.js} +1 -1
  95. package/dist/storybook/assets/{side-bar.stories-BsFhqiB3.js → side-bar.stories-BuAIJ8NV.js} +1 -1
  96. package/dist/storybook/assets/{site.stories-zUoOcZmf.js → site.stories-lIyAWOdt.js} +2 -2
  97. package/dist/storybook/assets/slider-CBE03NwD.js +27 -0
  98. package/dist/storybook/assets/{slider.stories-BJOTup9W.js → slider.stories-7oMw2PCp.js} +2 -2
  99. package/dist/storybook/assets/{smart-upload-modal.stories-CwsrLvhg.js → smart-upload-modal.stories-n4bjMFhq.js} +1 -1
  100. package/dist/storybook/assets/{spacer.stories-BBTt2LdE.js → spacer.stories-BC7lirqi.js} +1 -1
  101. package/dist/storybook/assets/{table-5QX-8wvq.js → table-Ci7MC96P.js} +1 -1
  102. package/dist/storybook/assets/{table.stories-lL4Wjd7C.js → table.stories-LALh_tT_.js} +2 -2
  103. package/dist/storybook/assets/{table.stories-data-CG4FwGG3.js → table.stories-data-CYppbCAy.js} +1 -1
  104. package/dist/storybook/assets/tabs-BoToLVEP.js +13 -0
  105. package/dist/storybook/assets/tabs.stories-B52iEaHf.js +30 -0
  106. package/dist/storybook/assets/text-link.stories-BsuVBOWo.js +14 -0
  107. package/dist/storybook/assets/textarea-D6ltcKhz.js +13 -0
  108. package/dist/storybook/assets/{textarea.stories-CrZgmMxl.js → textarea.stories-CJ-Oqytp.js} +1 -1
  109. package/dist/storybook/assets/{title.stories-klSBDiXt.js → title.stories-CmYtRWA7.js} +3 -3
  110. package/dist/storybook/assets/{toaster-BoBcvmf9.js → toaster-CDSt-Toh.js} +1 -1
  111. package/dist/storybook/assets/{toaster.stories-HO4VBTy-.js → toaster.stories-D1XTcQR_.js} +1 -1
  112. package/dist/storybook/assets/toggle-C0zvrIOF.js +13 -0
  113. package/dist/storybook/assets/{toggle.stories-mjk0JIle.js → toggle.stories-DOc7uN93.js} +1 -1
  114. package/dist/storybook/assets/{tooltip.test-case.stories-joo9YReN.js → tooltip.test-case.stories-D2SX9mkM.js} +1 -1
  115. package/dist/storybook/assets/{top-bar-BlwEXx7O.js → top-bar-BQzmL0IU.js} +1 -1
  116. package/dist/storybook/assets/top-bar.stories-Czza1RvB.js +21 -0
  117. package/dist/storybook/assets/{top-bar.testcase.stories-BUBXpPJs.js → top-bar.testcase.stories-DpV-QqfZ.js} +1 -1
  118. package/dist/storybook/assets/{tree.stories-CTPqyCKs.js → tree.stories-CsmZwDmr.js} +1 -1
  119. package/dist/storybook/assets/{types-UmZ4Y_CR.js → types-Dx2TtIG9.js} +1 -1
  120. package/dist/storybook/assets/unit-input.stories-ODKyfhaE.js +318 -0
  121. package/dist/storybook/assets/unit-table.stories-BLfZcK7Z.js +152 -0
  122. package/dist/storybook/iframe.html +1 -1
  123. package/dist/storybook/index.json +1 -1
  124. package/dist/storybook/project.json +1 -1
  125. package/package.json +1 -1
  126. package/dist/404.html +0 -1
  127. package/dist/storybook/assets/Color-KGDBMAHA-CQlondIs.js +0 -1
  128. package/dist/storybook/assets/DocsRenderer-PKQXORMH-CMePffZo.js +0 -1
  129. package/dist/storybook/assets/actions-BhPnDYmS.js +0 -27
  130. package/dist/storybook/assets/afe.stories-BejQRTzS.js +0 -88
  131. package/dist/storybook/assets/check-box-BtCGePRy.js +0 -1
  132. package/dist/storybook/assets/color-DsEwQuSe.js +0 -25
  133. package/dist/storybook/assets/drawer.stories-fxIBm3g1.js +0 -113
  134. package/dist/storybook/assets/file-button.stories-DQxp1MPV.js +0 -10
  135. package/dist/storybook/assets/file-input-DlOuEoMf.js +0 -1
  136. package/dist/storybook/assets/footer.stories-C2YHanQl.js +0 -3
  137. package/dist/storybook/assets/form.stories-DVcTzOpM.js +0 -49
  138. package/dist/storybook/assets/formation.stories-D4U2fgj6.js +0 -74
  139. package/dist/storybook/assets/icon-BSFY3vDO.js +0 -8
  140. package/dist/storybook/assets/iframe-B1EjAYJz.js +0 -2
  141. package/dist/storybook/assets/index-CrEVlQ_6.js +0 -1
  142. package/dist/storybook/assets/inheritsLoose-DP0QEDDI.js +0 -1
  143. package/dist/storybook/assets/input-DFNY9YDm.js +0 -1
  144. package/dist/storybook/assets/layout-forms-0_2iXsYr.js +0 -16
  145. package/dist/storybook/assets/menu.stories-data-DeDnsKpk.js +0 -1
  146. package/dist/storybook/assets/number-input-B6I6KkcP.js +0 -4
  147. package/dist/storybook/assets/number-input.stories-BCEHti8m.js +0 -107
  148. package/dist/storybook/assets/option-dropdown.stories-DVA8-yqU.js +0 -34
  149. package/dist/storybook/assets/pagination.stories-DH-XbCfQ.js +0 -59
  150. package/dist/storybook/assets/popover.stories-Ulut7imO.js +0 -10
  151. package/dist/storybook/assets/preview-DPs6y1HU.js +0 -2
  152. package/dist/storybook/assets/projects.stories-Clez6c2x.js +0 -47
  153. package/dist/storybook/assets/radio-button-YBwYcMaM.js +0 -1
  154. package/dist/storybook/assets/react-router-dom-Ck2Y_Fzc.js +0 -8
  155. package/dist/storybook/assets/select-C1_gWJ7I.js +0 -40
  156. package/dist/storybook/assets/select.input-DIKP56UZ.js +0 -1
  157. package/dist/storybook/assets/slider-DckvIvC7.js +0 -31
  158. package/dist/storybook/assets/tabs-CAZ_dHGK.js +0 -1
  159. package/dist/storybook/assets/tabs.stories-DXcDAqB2.js +0 -30
  160. package/dist/storybook/assets/text-link.stories-BQAkVO-W.js +0 -14
  161. package/dist/storybook/assets/textarea-D-R3vavM.js +0 -1
  162. package/dist/storybook/assets/toggle-CBpNgTrm.js +0 -1
  163. package/dist/storybook/assets/top-bar.stories-Bxk6q5go.js +0 -21
  164. package/dist/storybook/assets/unit-input.stories-D_hhvilo.js +0 -295
  165. package/dist/storybook/assets/unit-table.stories-Co3OB0Hd.js +0 -152
@@ -0,0 +1,318 @@
1
+ import{j as e}from"./jsx-runtime-eps93zm2.js";import{r as c}from"./index-DhsZuJvc.js";import{d as i,r as Tn}from"./index-DaLCDjg_.js";import{c as Vn}from"./index-Bk2sglWO.js";import{u as kn}from"./use-previous-D775JrO6.js";import{M as Pe}from"./actions-Tr0wIZve.js";import{I as jn}from"./input-group-addon-D68iUKV2.js";import{B as g}from"./button-CzvLc2io.js";import{T as Sn}from"./tooltip-1V7clEnw.js";import{I as En}from"./input-group-BaRSJAEN.js";import{S as j}from"./spacer-BWoNR27H.js";import{T as tn}from"./text-B3-TSWok.js";import{I as Nn}from"./input-DTXbDJaL.js";import{M as Be}from"./types-BmbYqTX_.js";import{l as x}from"./lodash-c4VUpsOs.js";import{i as qn}from"./helpers-JJxzGegQ.js";import{D as An}from"./divider-DY9nJ_7N.js";import{R as nn,C as Ce}from"./row-Bmiy2Lh0.js";import{F as k}from"./field-C5_fLDpy.js";import{M as Ue}from"./message-DQ3q8XF9.js";import{w as ce,u as o,e as I,f as an,a as rn}from"./index-DMAnyMX5.js";import"./index-DRSy5Ssd.js";import"./common-types-Sih75Sav.js";import"./disabled-context-rmpd7YJS.js";import"./icon-BP4BO6-k.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./inheritsLoose-DR8r8Ogv.js";import"./index-CEuq6vkz.js";import"./types-Dx2TtIG9.js";import"./badge-CLQ59MDF.js";import"./spinner-AWUe4xwQ.js";import"./index-CUZDtIZe.js";import"./styled-components.browser.esm-BQ9GQzDc.js";import"./label-hiSz3I8H.js";import"./help-icon-41R-Z9N1.js";import"./index-CF7H4eMJ.js";const Dn=()=>{const t=c.useRef(null);return c.useLayoutEffect(()=>{t.current&&(t.current(),t.current=null)}),n=>{t.current=n}},Pn=(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.`),i.unitFromQuantity(t)??"")};var C=(t=>(t.CUSTOM="custom",t.PREDEFINED="predefined",t))(C||{});const sn=t=>t==="undefined"||t===void 0||t===""||t==="null"||t===null||t==="NaN"||isNaN(t),ln=(t="",a,n="",s=!1)=>{if(s)return t;if(a&&!sn(t))try{const r=i.isValueWithUnit(t)?t:i.withUnit(t,n),m=i.convertSamePrecision(r,a);return i.getValue(m)}catch{}return t},Bn=t=>t?!!i.getUnit(t):!1,R=(t="",a,n,s)=>{if(s)return t;const r=Bn(t)||i.isValueWithUnit(t),m=i.getValue(t);return sn(m)?m:r?ln(m,a,n,s):t},Fe=t=>x.isObject(t)&&!x.isArray(t)&&!x.isFunction(t)?x.get(t,"fieldName",""):typeof t=="string"?t:"",Fn=t=>x.isObjectLike(t)&&x.has(t,"message"),_n=t=>typeof t=="string"?t:Fn(t)?t.message:null;var Mn=Tn();const On=t=>t.search(RegExp(/(^0{2}\.)|(^0+[1-9])/g))===0,_e=(t,a)=>{var S;const{allowEmpty:n=!1,autoValue:s,placeholder:r,disabledValidation:m=!1}=a||{},u=String(t);if(m||s||r&&qn(t))return null;const h=Mn.isValueWithUnit(u)?i.getValue(u):u;if(n&&h==="")return null;if(On(h))return"Invalid number format due to leading zeroes";const v=i.validateNumber(h);if(!v.valid){const me=((S=v==null?void 0:v.errors)==null?void 0:S[0])??null;return _n(me)}return null},Me=(t="")=>{var a;return(a=i.KNOWN_UNITS)==null?void 0:a.includes(t)},Wn=(t,a)=>{const n=i.getUnit(t||"");return Me(a)&&Me(n)};let Rn=c.createContext(null);const Ln=()=>c.useContext(Rn),Hn="_predefinedMenuActive_1yvt4_1",Kn={predefinedMenuActive:Hn},p=({name:t,placeholder:a="",disabled:n=!1,disabledUnit:s=!1,error:r=null,left:m=!1,small:u=!1,width:h="100%",value:v,unitkey:S="",initUnit:me,noConversion:un=!1,onChange:pe=x.noop,onClick:zn=x.noop,onFocus:on=x.noop,onSwitchUnit:we=x.noop,unitTemplate:Ie,doNotConvertValue:_=!1,testId:N,warning:dn=null,predefinedOptions:T,initialPredefinedOption:cn=!1,shouldLinkAutomaticly:xe=!0,selectedPredefinedOptionKey:Te,validationCallback:Ve=()=>({name:"",error:null}),disabledValidation:ke=!1,allowEmpty:je=!1,autoValue:V})=>{const q=Ln(),mn=Dn();typeof v=="number"&&(v=`${v}`);const[ge="",M=""]=v!==void 0?i.split(v):[],Se=V?i.getUnit(V):"",Ee=c.useMemo(()=>Pn(S,Ie||(q==null?void 0:q.unitTemplate)),[S,Ie,q==null?void 0:q.unitTemplate]),pn=Wn(v,Ee),w=me||Ee||M,gn=kn(w),Ne=R(v,w,M,_),qe=R(V,w,Se,_),hn=Ne!==""?{value:Ne,unit:w}:qe!==""?{value:qe,unit:w}:{value:ge,unit:M},[f,ie]=c.useState(hn),[vn,he]=c.useState(null),[E,ve]=c.useState(cn?C.PREDEFINED:C.CUSTOM),fe=ge===""&&V,O=T&&T.find(l=>{if(!(l!=null&&l.value))return;if(Te)return Te===l.valueKey;const d=i.isValueWithUnit(l.value)?i.getUnit(l.value):"";return i.withUnit(ln(v,d),d)===l.value}),fn=()=>{if(S)try{const l=fe?V:v??"";let d=i.altUnitsList(l,S);return i.getValue(l)===""?d.map(y=>["",y[1]]):d}catch{return null}},yn=l=>{const d=Fe(t),y=l.target,{value:U,selectionStart:W}=y,De=i.cleanNumStr(U.replaceAll(" ","").replaceAll("|","")),ye=i.withUnit(De,(f==null?void 0:f.unit)||""),wn=i.getValue(ye),be=_e(wn,{allowEmpty:je,autoValue:V,placeholder:a,disabledValidation:ke});if(be===null){pe({target:{value:ye,name:d}});const[In,xn]=i.split(ye);ie({value:In,unit:xn}),he(null),Ve(d,null)}else ie({value:De,unit:f.unit}),he(be),Ve(d,be);mn(()=>{y.selectionStart=W,y.selectionEnd=W})},bn=(l,d)=>{d===f.unit||isNaN(Number(l))||(ie({value:l,unit:d}),we&&we(d))};c.useEffect(()=>{if(w){let y,U="";gn!==w?(y=R(v,w,M,_),U=w):i.withUnit(f.value,f.unit)!==v&&(y=R(v,f.unit,M,_),U=f.unit),y!==void 0&&ie({value:y,unit:U}),T&&ve(O&&xe?C.PREDEFINED:C.CUSTOM)}const l=i.checkAndCleanDecimalComma(ge),d=_e(l,{allowEmpty:je,autoValue:V,placeholder:a,disabledValidation:ke});he(d)},[w,v,r,xe]);const le=fn(),ue=i.label(f.unit)||f.unit||"",Cn=un||!le||le&&le.length===1,Ae=Fe(t);let oe;const Un=l=>{const d=l!=null&&l.value?l.value:"",[y="",U=""]=i.isValueWithUnit(d)?i.split(d):[d];return{type:Be.OPTION,inline:!0,onClick:()=>{i.validateNumber(y).valid&&!n&&(ve(C.PREDEFINED),pe({target:{value:d,name:typeof t=="string"?t:(t==null?void 0:t.fieldName)||"",predefinedSelected:!0,predefinedOption:l}}))},label:e.jsxs(e.Fragment,{children:[e.jsx(tn,{children:l.label}),e.jsx(j,{width:"20px",height:"0"})]}),description:i.isValueWithUnit(d)?`${y} ${U}`:d,selected:O===l&&E===C.PREDEFINED}};if(oe=[{type:Be.OPTION,inline:!0,onClick:()=>{E!==C.CUSTOM&&!n&&pe({target:{value:i.withUnit(f.value,f.unit),name:typeof t=="string"?t:(t==null?void 0:t.fieldName)||""}})},label:"Custom",selected:E===C.CUSTOM}],T!=null&&T.length){const l=T.map(Un);oe=[...oe,...l]}return e.jsx("div",{className:E===C.PREDEFINED?Vn(Kn.predefinedMenuActive):"",children:e.jsxs(En,{small:u,width:h,children:[T&&e.jsx(Sn,{text:E===C.PREDEFINED?O==null?void 0:O.label:"",children:e.jsx(Pe,{maxHeight:380,groupOrder:"first",testId:N&&`${N}-predefined-menu`,disabled:n,menu:{colored:!0,trigger:"Component",component:e.jsx(g,{groupOrder:"first",active:E===C.PREDEFINED,icon:E===C.PREDEFINED?"link":"unlink"}),small:u,sections:oe}})}),e.jsx(Nn,{type:"text",name:Ae,testId:N,disabled:n,placeholder:fe?R(V,f.unit,Se,_):a,value:f.value,onChange:yn,onFocus:on,error:r||vn,warning:dn,right:!m},Ae),ue&&(Cn||!pn?e.jsx(jn,{groupOrder:"last",children:ue}):e.jsx(Pe,{maxHeight:380,groupOrder:"last",disabled:s,testId:N&&`${N}-menu`,menu:{label:ue,trigger:"DropDownButton",small:u,sections:le.map(([l,d,y])=>{const U=y||d||"";return{type:"Option",label:isNaN(Number(l))?"":l,inline:!0,onClick:W=>{W.stopPropagation(),bn(fe?"":l,d)},description:U,selected:U===ue,testId:`${N}-unit-${U}`}})}}))]})})};p.__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: TChangeEvent | ICustomChangeEvent) => void",signature:{arguments:[{type:{name:"union",raw:"TChangeEvent | ICustomChangeEvent",elements:[{name:"intersection",raw:`ChangeEvent<T> & {
5
+ target:
6
+ | T
7
+ | { name: string; value: any; label?: string; files?: FileList | null };
8
+ }`,elements:[{name:"ChangeEvent",elements:[{name:"T"}],raw:"ChangeEvent<T>"},{name:"signature",type:"object",raw:`{
9
+ target:
10
+ | T
11
+ | { name: string; value: any; label?: string; files?: FileList | null };
12
+ }`,signature:{properties:[{key:"target",value:{name:"union",raw:`| T
13
+ | { name: string; value: any; label?: string; files?: FileList | null }`,elements:[{name:"T"},{name:"signature",type:"object",raw:"{ name: string; value: any; label?: string; files?: FileList | null }",signature:{properties:[{key:"name",value:{name:"string",required:!0}},{key:"value",value:{name:"any",required:!0}},{key:"label",value:{name:"string",required:!1}},{key:"files",value:{name:"union",raw:"FileList | null",elements:[{name:"FileList"},{name:"null"}],required:!1}}]}}],required:!0}}]}}]},{name:"ICustomChangeEvent"}]},name:"event"}],return:{name:"void"}}},description:"",defaultValue:{value:"noop",computed:!0}},onSwitchUnit:{required:!1,tsType:{name:"signature",type:"function",raw:"(unit: string) => void",signature:{arguments:[{type:{name:"string"},name:"unit"}],return:{name:"void"}}},description:"",defaultValue:{value:"noop",computed:!0}},onClick:{required:!1,tsType:{name:"MouseEventHandler",elements:[{name:"HTMLInputElement"}],raw:"MouseEventHandler<HTMLInputElement>"},description:"",defaultValue:{value:"noop",computed:!0}},onFocus:{required:!1,tsType:{name:"FocusEventHandler",elements:[{name:"HTMLInputElement"}],raw:"FocusEventHandler<HTMLInputElement>"},description:"",defaultValue:{value:"noop",computed:!0}},unitTemplate:{required:!1,tsType:{name:"Record",elements:[{name:"string"},{name:"any"}],raw:"Record<string, any>"},description:""}}};const{useArgs:$n}=__STORYBOOK_MODULE_PREVIEW_API__,Ea={title:"Basic/UnitInput",component:p,args:{name:"example",unitkey:"length",value:"123|m"}},b=t=>{const[a,n]=$n(),s=r=>{n({value:r.target.value})};return e.jsx(p,{...t,onChange:s})},de=b.bind({}),L=b.bind({});L.args={initUnit:"ft",unitTemplate:{length:"ft"}};const H=b.bind({});H.args={value:'123|"',unitkey:'"'};const K=b.bind({});K.args={width:"180px"};const $=b.bind({});$.args={noConversion:!0};const z=b.bind({});z.args={small:!0};const A=()=>{const[t,a]=c.useState("123|m");return e.jsx(p,{name:"example",onChange:n=>a(n.target.value),placeholder:"Type a value...",value:t,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"},testId:"testId"})};A.play=async({canvasElement:t,step:a})=>{const n=ce(t),s=ce(t.ownerDocument.body);await a("Shows validation error for non-numeric input",async()=>{const r=n.getByTestId("testId");await o.clear(r),await o.type(r,"123x45s6"),await o.click(t),await I(n.getByDisplayValue("123x45s6")).toBeInTheDocument(),await an.mouseOver(r),await rn(()=>{I(s.getByText("Must be a numerical value")).toBeInTheDocument()})})};const G=b.bind({});G.args={error:"Error message goes here"};const J=b.bind({});J.args={value:"asas123asd|%"};const D=b.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 Y=b.bind({});Y.args={disabled:!0,disabledUnit:!0,noConversion:!0};const Z=b.bind({});Z.args={disabledUnit:!0,unitkey:void 0};const Q=b.bind({});Q.args={disabledUnit:!0,unitkey:"length"};const X=b.bind({});X.args={disabledUnit:!1,disabled:!0};const P=t=>{const[a,n]=c.useState("123|m"),[s,r]=c.useState("223|m"),[m,u]=c.useState("ft");return e.jsxs(e.Fragment,{children:[e.jsx(g,{label:"Change initUnit",onClick:()=>u(m==="m"?"ft":"m")}),e.jsx(j,{}),e.jsx(g,{label:"Change value",onClick:()=>n(a==="123|m"?"456|m":"123|m")}),e.jsx(j,{}),e.jsx(p,{name:"example",onChange:h=>{n(h.target.value)},unitkey:"length",value:a,initUnit:m,onSwitchUnit:u}),e.jsx(j,{}),e.jsx(p,{name:"example2",onChange:h=>{r(h.target.value)},unitkey:"length",value:s,initUnit:m,onSwitchUnit:u}),e.jsx(An,{}),e.jsx("h4",{children:"Without initUnit property (taken from the redux store)"}),e.jsx(p,{name:"example",onChange:h=>{n(h.target.value)},unitkey:"length",value:a,onSwitchUnit:u}),e.jsx(p,{name:"example2",onChange:h=>{r(h.target.value)},unitkey:"length",value:s,onSwitchUnit:u})]})};P.parameters={docs:{description:{story:"[OW-4380](https://oliasoft.atlassian.net/browse/OW-4380?atlOrigin=eyJpIjoiMmM1N2RkNWU3Mjk5NDYxY2E0YzhkMzk5ZTVmZTJhMjciLCJwIjoiaiJ9)"}}};const ee=b.bind({});ee.args={predefinedOptions:[{label:"bottom of casing",value:"12|km"},{label:"mud weight at shoe depth",value:"8|mm"}]};const B=()=>{const t="500px",[a,n]=c.useState(void 0);return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different edge cases such as +/- infinity, undefined, NaN, null:"}),e.jsxs(nn,{children:[e.jsxs(Ce,{width:"25%",children:[e.jsx(g,{label:"Change value infinity",onClick:()=>n(1/0)}),e.jsx("br",{}),e.jsx(g,{label:"Change value -infinity",onClick:()=>n(-1/0)}),e.jsx("br",{}),e.jsx(g,{label:"Change value null",onClick:()=>n(null)}),e.jsx("br",{}),e.jsx(g,{label:"Change value - undefined",onClick:()=>n(void 0)}),e.jsx("br",{}),e.jsx(g,{label:"Change value - NaN",onClick:()=>n(NaN)}),e.jsx("br",{}),e.jsx(g,{label:"Change value - nothing (empty)",onClick:()=>n(void 0)}),e.jsx("br",{}),e.jsx(g,{label:"Change value - empty string",onClick:()=>n("")})]}),e.jsxs(Ce,{width:"25%",children:[e.jsx(g,{label:"Change value infinity|m",onClick:()=>n("Infinity|m")}),e.jsx("br",{}),e.jsx(g,{label:"Change value -infinity|m",onClick:()=>n("-Infinity|m")}),e.jsx("br",{}),e.jsx(g,{label:"Change value null|m",onClick:()=>n("null|m")}),e.jsx("br",{}),e.jsx(g,{label:"Change value - undefined|m",onClick:()=>n("undefined|m")}),e.jsx("br",{}),e.jsx(g,{label:"Change value - NaN|m",onClick:()=>n("NaN|m")}),e.jsx("br",{}),e.jsx(g,{label:"Change value - nothing (empty)|m",onClick:()=>n("|m")})]})]}),e.jsx("br",{}),e.jsx(k,{label:"Normal PUI",children:e.jsx(p,{name:"example1",onChange:s=>n(s.target.value),value:a,unitkey:"length",width:t,placeholder:"value|unit"})}),e.jsx(k,{label:"Disabled validation",children:e.jsx(p,{name:"example2",onChange:s=>n(s.target.value),value:a,unitkey:"length",disabledValidation:!0,width:t})}),e.jsx(k,{label:"Disabled validation and manual error",children:e.jsx(p,{name:"example3",onChange:s=>n(s.target.value),value:a,unitkey:"length",error:"test",disabledValidation:!0,width:t})}),e.jsx(Ue,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})},te=()=>{const t="500px",[a,n]=c.useState("1|m"),[s,r]=c.useState("|m"),m="123|km";return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different cases for automatic (placeholder) values:"}),e.jsx(nn,{children:e.jsxs(Ce,{width:"25%",children:[e.jsx(g,{label:"Change value to ''",onClick:()=>n("")}),e.jsx("br",{}),e.jsx(g,{label:"Change value to 1",onClick:()=>n("1")}),e.jsx("br",{}),e.jsx(g,{label:"Change value to 1|m",onClick:()=>n("1|m")}),e.jsx("br",{}),e.jsx(g,{label:"Change value to |m - empty value",onClick:()=>n("|m")})]})}),e.jsx("br",{}),e.jsx(k,{label:"Normal PUI (placeholder + auto)",children:e.jsx(p,{name:"example1",onChange:u=>n(u.target.value),value:a,unitkey:"length",width:t,placeholder:"value|unit",autoValue:m})}),e.jsx(k,{label:"Normal PUI (only auto)",children:e.jsx(p,{name:"example1",onChange:u=>n(u.target.value),value:a,unitkey:"length",width:t,autoValue:m})}),e.jsx(k,{label:"Empty PUI with autoValue",children:e.jsx(p,{name:"example1",onChange:u=>r(u.target.value),value:s,unitkey:"length",width:t,autoValue:m})}),e.jsx(k,{label:"Normal PUI (only placeholder)",children:e.jsx(p,{name:"example1",onChange:u=>n(u.target.value),value:a,unitkey:"length",width:t,placeholder:"Placeholder test"})}),e.jsx(k,{label:"Normal PUI (placeholder + allowEmpty)",children:e.jsx(p,{name:"example1",onChange:u=>n(u.target.value),value:a,unitkey:"length",width:t,placeholder:"Placeholder test",allowEmpty:!0})}),e.jsx(Ue,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})};B.parameters={docs:{description:{story:"[OW-8884](https://oliasoft.atlassian.net/browse/OW-8884)"}}};const ne=()=>{const[t,a]=c.useState("123|%"),[n,s]=c.useState(null),r="This should be visible when an error appears",m=(u,h)=>(s(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(p,{name:"example",onChange:u=>a(u.target.value),error:!n||r,validationCallback:m,value:t}),e.jsx("br",{}),e.jsx(j,{}),e.jsx("h4",{children:"Original validation message: "}),e.jsx(Ue,{message:{heading:n,visible:!0}})]})},ae=()=>{const[t,a]=c.useState("123|m"),[n,s]=c.useState(""),[r,m]=c.useState("km"),u=()=>{m("ft"),s("placeholder"),a("|m")};return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Empty value case:"}),e.jsx(p,{name:"example",onChange:h=>a(h.target.value),value:t,allowEmpty:!0,placeholder:n,initUnit:r,unitkey:"length"}),e.jsx("br",{}),e.jsx(j,{}),e.jsx(g,{label:"Change value |m and unit ft",onClick:()=>u()})]})},re=()=>{const[t,a]=c.useState("123|m"),[n,s]=c.useState("m");return e.jsxs(e.Fragment,{children:[e.jsx(p,{name:"example",onChange:r=>a(r.target.value),value:t,initUnit:n,unitkey:"length",onSwitchUnit:s}),e.jsx(j,{}),e.jsx(p,{name:"example",onChange:r=>a(r.target.value),value:t,initUnit:n,unitkey:"length",onSwitchUnit:s})]})},se=()=>e.jsxs(e.Fragment,{children:[e.jsx(tn,{faint:!0,children:"Reproduce OW-10614 rounding noise bug when storing values in a different unit to the display unit"}),e.jsx(j,{}),e.jsx(p,{name:"example",onChange:()=>{},value:i.withUnit(i.convertAndGetValue("9750|psi","bar"),"bar"),initUnit:"psi",unitkey:"pressure",unitTemplate:{pressure:"psi"}})]}),F=()=>{const[t,a]=c.useState("123|m");return e.jsx(p,{name:"example",onChange:n=>a(n.target.value),value:t,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"},testId:"testId"})};F.play=async({canvasElement:t,step:a})=>{const n=ce(t),s=ce(t.ownerDocument.body);await a("Can enter decimal values",async()=>{const r=n.getByTestId("testId");await o.clear(r),await o.type(r,"123.123456789"),await o.click(t),await I(n.getByDisplayValue("123.123456789")).toBeInTheDocument()}),await a("Can enter scientific notation",async()=>{const r=n.getByTestId("testId");await o.clear(r),await o.type(r,"-1.12e3"),await o.click(t),await I(n.getByDisplayValue("-1.12e3")).toBeInTheDocument()}),await a("Can enter comma decimals (converts to dot)",async()=>{const r=n.getByTestId("testId");await o.clear(r),await o.type(r,"123,456"),await o.click(t),await I(n.getByDisplayValue("123.456")).toBeInTheDocument()}),await a("Can enter small numbers",async()=>{const r=n.getByTestId("testId");await o.clear(r),await o.type(r,"0.0000000023"),await o.click(t),await I(n.getByDisplayValue("0.0000000023")).toBeInTheDocument()}),await a("Can enter large numbers",async()=>{const r=n.getByTestId("testId");await o.clear(r),await o.type(r,"999999999999"),await o.click(t),await I(n.getByDisplayValue("999999999999")).toBeInTheDocument()}),await a("Can convert units",async()=>{const r=n.getByTestId("testId"),m=n.getByTestId("testId-menu");await o.clear(r),await o.type(r,"456.1"),await o.click(t),await o.click(m),await o.click(s.getByTestId("testId-unit-ft")),await I(n.getByDisplayValue("1496")).toBeInTheDocument()}),await a("Shows validation error for non-numeric input",async()=>{const r=n.getByTestId("testId");await o.clear(r),await o.type(r,"123x45s6"),await o.click(t),await I(n.getByDisplayValue("123x45s6")).toBeInTheDocument(),await an.mouseOver(r),await rn(()=>{I(s.getByText("Must be a numerical value")).toBeInTheDocument()})})};A.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"Placeholder"};P.__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:`(
14
+ name: string,
15
+ message: string | null,
16
+ ) => { 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:!1,tsType:{name:"signature",type:"function",raw:"(event: TChangeEvent | ICustomChangeEvent) => void",signature:{arguments:[{type:{name:"union",raw:"TChangeEvent | ICustomChangeEvent",elements:[{name:"intersection",raw:`ChangeEvent<T> & {
17
+ target:
18
+ | T
19
+ | { name: string; value: any; label?: string; files?: FileList | null };
20
+ }`,elements:[{name:"ChangeEvent",elements:[{name:"T"}],raw:"ChangeEvent<T>"},{name:"signature",type:"object",raw:`{
21
+ target:
22
+ | T
23
+ | { name: string; value: any; label?: string; files?: FileList | null };
24
+ }`,signature:{properties:[{key:"target",value:{name:"union",raw:`| T
25
+ | { name: string; value: any; label?: string; files?: FileList | null }`,elements:[{name:"T"},{name:"signature",type:"object",raw:"{ name: string; value: any; label?: string; files?: FileList | null }",signature:{properties:[{key:"name",value:{name:"string",required:!0}},{key:"value",value:{name:"any",required:!0}},{key:"label",value:{name:"string",required:!1}},{key:"files",value:{name:"union",raw:"FileList | null",elements:[{name:"FileList"},{name:"null"}],required:!1}}]}}],required:!0}}]}}]},{name:"ICustomChangeEvent"}]},name:"event"}],return:{name:"void"}}},description:""},onSwitchUnit:{required:!1,tsType:{name:"signature",type:"function",raw:"(unit: string) => void",signature:{arguments:[{type:{name:"string"},name:"unit"}],return:{name:"void"}}},description:""},onClick:{required:!1,tsType:{name:"MouseEventHandler",elements:[{name:"HTMLInputElement"}],raw:"MouseEventHandler<HTMLInputElement>"},description:""},onFocus:{required:!1,tsType:{name:"FocusEventHandler",elements:[{name:"HTMLInputElement"}],raw:"FocusEventHandler<HTMLInputElement>"},description:""},unitTemplate:{required:!1,tsType:{name:"Record",elements:[{name:"string"},{name:"any"}],raw:"Record<string, any>"},description:""}}};B.__docgenInfo={description:"",methods:[],displayName:"TestEdgeCases"};te.__docgenInfo={description:"",methods:[],displayName:"AutomaticValues"};ne.__docgenInfo={description:"",methods:[],displayName:"ValidationCallback"};ae.__docgenInfo={description:"",methods:[],displayName:"AllowEmptyPUI"};re.__docgenInfo={description:"",methods:[],displayName:"onSwitchUnit"};se.__docgenInfo={description:"",methods:[],displayName:"OW_10614TestCase"};F.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"TestUserInput"};var Oe,We,Re;de.parameters={...de.parameters,docs:{...(Oe=de.parameters)==null?void 0:Oe.docs,source:{originalSource:`args => {
26
+ const [_, updateArgs] = useArgs();
27
+ const handleChange = (evt: any) => {
28
+ updateArgs({
29
+ value: evt.target.value
30
+ });
31
+ };
32
+ return <UnitInput {...args} onChange={handleChange} />;
33
+ }`,...(Re=(We=de.parameters)==null?void 0:We.docs)==null?void 0:Re.source}}};var Le,He,Ke;L.parameters={...L.parameters,docs:{...(Le=L.parameters)==null?void 0:Le.docs,source:{originalSource:`args => {
34
+ const [_, updateArgs] = useArgs();
35
+ const handleChange = (evt: any) => {
36
+ updateArgs({
37
+ value: evt.target.value
38
+ });
39
+ };
40
+ return <UnitInput {...args} onChange={handleChange} />;
41
+ }`,...(Ke=(He=L.parameters)==null?void 0:He.docs)==null?void 0:Ke.source}}};var $e,ze,Ge;H.parameters={...H.parameters,docs:{...($e=H.parameters)==null?void 0:$e.docs,source:{originalSource:`args => {
42
+ const [_, updateArgs] = useArgs();
43
+ const handleChange = (evt: any) => {
44
+ updateArgs({
45
+ value: evt.target.value
46
+ });
47
+ };
48
+ return <UnitInput {...args} onChange={handleChange} />;
49
+ }`,...(Ge=(ze=H.parameters)==null?void 0:ze.docs)==null?void 0:Ge.source}}};var Je,Ye,Ze;K.parameters={...K.parameters,docs:{...(Je=K.parameters)==null?void 0:Je.docs,source:{originalSource:`args => {
50
+ const [_, updateArgs] = useArgs();
51
+ const handleChange = (evt: any) => {
52
+ updateArgs({
53
+ value: evt.target.value
54
+ });
55
+ };
56
+ return <UnitInput {...args} onChange={handleChange} />;
57
+ }`,...(Ze=(Ye=K.parameters)==null?void 0:Ye.docs)==null?void 0:Ze.source}}};var Qe,Xe,et;$.parameters={...$.parameters,docs:{...(Qe=$.parameters)==null?void 0:Qe.docs,source:{originalSource:`args => {
58
+ const [_, updateArgs] = useArgs();
59
+ const handleChange = (evt: any) => {
60
+ updateArgs({
61
+ value: evt.target.value
62
+ });
63
+ };
64
+ return <UnitInput {...args} onChange={handleChange} />;
65
+ }`,...(et=(Xe=$.parameters)==null?void 0:Xe.docs)==null?void 0:et.source}}};var tt,nt,at;z.parameters={...z.parameters,docs:{...(tt=z.parameters)==null?void 0:tt.docs,source:{originalSource:`args => {
66
+ const [_, updateArgs] = useArgs();
67
+ const handleChange = (evt: any) => {
68
+ updateArgs({
69
+ value: evt.target.value
70
+ });
71
+ };
72
+ return <UnitInput {...args} onChange={handleChange} />;
73
+ }`,...(at=(nt=z.parameters)==null?void 0:nt.docs)==null?void 0:at.source}}};var rt,st,it;A.parameters={...A.parameters,docs:{...(rt=A.parameters)==null?void 0:rt.docs,source:{originalSource:`() => {
74
+ const [value, setValue] = useState('123|m');
75
+ return <UnitInput name="example" onChange={evt => setValue(evt.target.value)} placeholder="Type a value..." value={value} initUnit="m" unitkey="depth" unitTemplate={{
76
+ depth: 'm'
77
+ }} testId="testId" />;
78
+ }`,...(it=(st=A.parameters)==null?void 0:st.docs)==null?void 0:it.source}}};var lt,ut,ot;G.parameters={...G.parameters,docs:{...(lt=G.parameters)==null?void 0:lt.docs,source:{originalSource:`args => {
79
+ const [_, updateArgs] = useArgs();
80
+ const handleChange = (evt: any) => {
81
+ updateArgs({
82
+ value: evt.target.value
83
+ });
84
+ };
85
+ return <UnitInput {...args} onChange={handleChange} />;
86
+ }`,...(ot=(ut=G.parameters)==null?void 0:ut.docs)==null?void 0:ot.source}}};var dt,ct,mt;J.parameters={...J.parameters,docs:{...(dt=J.parameters)==null?void 0:dt.docs,source:{originalSource:`args => {
87
+ const [_, updateArgs] = useArgs();
88
+ const handleChange = (evt: any) => {
89
+ updateArgs({
90
+ value: evt.target.value
91
+ });
92
+ };
93
+ return <UnitInput {...args} onChange={handleChange} />;
94
+ }`,...(mt=(ct=J.parameters)==null?void 0:ct.docs)==null?void 0:mt.source}}};var pt,gt,ht;D.parameters={...D.parameters,docs:{...(pt=D.parameters)==null?void 0:pt.docs,source:{originalSource:`args => {
95
+ const [_, updateArgs] = useArgs();
96
+ const handleChange = (evt: any) => {
97
+ updateArgs({
98
+ value: evt.target.value
99
+ });
100
+ };
101
+ return <UnitInput {...args} onChange={handleChange} />;
102
+ }`,...(ht=(gt=D.parameters)==null?void 0:gt.docs)==null?void 0:ht.source}}};var vt,ft,yt;Y.parameters={...Y.parameters,docs:{...(vt=Y.parameters)==null?void 0:vt.docs,source:{originalSource:`args => {
103
+ const [_, updateArgs] = useArgs();
104
+ const handleChange = (evt: any) => {
105
+ updateArgs({
106
+ value: evt.target.value
107
+ });
108
+ };
109
+ return <UnitInput {...args} onChange={handleChange} />;
110
+ }`,...(yt=(ft=Y.parameters)==null?void 0:ft.docs)==null?void 0:yt.source}}};var bt,Ct,Ut;Z.parameters={...Z.parameters,docs:{...(bt=Z.parameters)==null?void 0:bt.docs,source:{originalSource:`args => {
111
+ const [_, updateArgs] = useArgs();
112
+ const handleChange = (evt: any) => {
113
+ updateArgs({
114
+ value: evt.target.value
115
+ });
116
+ };
117
+ return <UnitInput {...args} onChange={handleChange} />;
118
+ }`,...(Ut=(Ct=Z.parameters)==null?void 0:Ct.docs)==null?void 0:Ut.source}}};var wt,It,xt;Q.parameters={...Q.parameters,docs:{...(wt=Q.parameters)==null?void 0:wt.docs,source:{originalSource:`args => {
119
+ const [_, updateArgs] = useArgs();
120
+ const handleChange = (evt: any) => {
121
+ updateArgs({
122
+ value: evt.target.value
123
+ });
124
+ };
125
+ return <UnitInput {...args} onChange={handleChange} />;
126
+ }`,...(xt=(It=Q.parameters)==null?void 0:It.docs)==null?void 0:xt.source}}};var Tt,Vt,kt;X.parameters={...X.parameters,docs:{...(Tt=X.parameters)==null?void 0:Tt.docs,source:{originalSource:`args => {
127
+ const [_, updateArgs] = useArgs();
128
+ const handleChange = (evt: any) => {
129
+ updateArgs({
130
+ value: evt.target.value
131
+ });
132
+ };
133
+ return <UnitInput {...args} onChange={handleChange} />;
134
+ }`,...(kt=(Vt=X.parameters)==null?void 0:Vt.docs)==null?void 0:kt.source}}};var jt,St,Et;P.parameters={...P.parameters,docs:{...(jt=P.parameters)==null?void 0:jt.docs,source:{originalSource:`(args: IUnitInputProps) => {
135
+ const [value, setValue] = useState('123|m');
136
+ const [value2, setValue2] = useState('223|m');
137
+ const [initUnit, setInitUnit] = useState('ft');
138
+ return <>
139
+ <Button label="Change initUnit" onClick={() => setInitUnit(initUnit === 'm' ? 'ft' : 'm')} />
140
+ <Spacer />
141
+ <Button label="Change value" onClick={() => setValue(value === '123|m' ? '456|m' : '123|m')} />
142
+ <Spacer />
143
+ <UnitInput name="example" onChange={evt => {
144
+ setValue(evt.target.value);
145
+ }} unitkey="length" value={value} initUnit={initUnit} onSwitchUnit={setInitUnit} />
146
+ <Spacer />
147
+ <UnitInput name="example2" onChange={evt => {
148
+ setValue2(evt.target.value);
149
+ }} unitkey="length" value={value2} initUnit={initUnit} onSwitchUnit={setInitUnit} />
150
+ <Divider />
151
+ <h4>Without initUnit property (taken from the redux store)</h4>
152
+ <UnitInput name="example" onChange={evt => {
153
+ setValue(evt.target.value);
154
+ }} unitkey="length" value={value} onSwitchUnit={setInitUnit} />
155
+ <UnitInput name="example2" onChange={evt => {
156
+ setValue2(evt.target.value);
157
+ }} unitkey="length" value={value2} onSwitchUnit={setInitUnit} />
158
+ </>;
159
+ }`,...(Et=(St=P.parameters)==null?void 0:St.docs)==null?void 0:Et.source}}};var Nt,qt,At;ee.parameters={...ee.parameters,docs:{...(Nt=ee.parameters)==null?void 0:Nt.docs,source:{originalSource:`args => {
160
+ const [_, updateArgs] = useArgs();
161
+ const handleChange = (evt: any) => {
162
+ updateArgs({
163
+ value: evt.target.value
164
+ });
165
+ };
166
+ return <UnitInput {...args} onChange={handleChange} />;
167
+ }`,...(At=(qt=ee.parameters)==null?void 0:qt.docs)==null?void 0:At.source}}};var Dt,Pt,Bt;B.parameters={...B.parameters,docs:{...(Dt=B.parameters)==null?void 0:Dt.docs,source:{originalSource:`() => {
168
+ const width = '500px';
169
+ const [value, setValue] = useState<any>(undefined);
170
+ return <>
171
+ <h4>Different edge cases such as +/- infinity, undefined, NaN, null:</h4>
172
+ <Row>
173
+ <Column width="25%">
174
+ <Button label="Change value infinity" onClick={() => setValue(Infinity)} />
175
+ <br />
176
+ <Button label="Change value -infinity" onClick={() => setValue(-Infinity)} />
177
+ <br />
178
+ <Button label="Change value null" onClick={() => setValue(null)} />
179
+ <br />
180
+ <Button label="Change value - undefined" onClick={() => setValue(undefined)} />
181
+ <br />
182
+ <Button label="Change value - NaN" onClick={() => setValue(NaN)} />
183
+ <br />
184
+ <Button label="Change value - nothing (empty)" onClick={() => setValue(undefined)} />
185
+ <br />
186
+ <Button label="Change value - empty string" onClick={() => setValue('')} />
187
+ </Column>
188
+ <Column width="25%">
189
+ <Button label="Change value infinity|m" onClick={() => setValue(Infinity + '|m')} />
190
+ <br />
191
+ <Button label="Change value -infinity|m" onClick={() => setValue(-Infinity + '|m')} />
192
+ <br />
193
+ <Button label="Change value null|m" onClick={() => setValue(null + '|m')} />
194
+ <br />
195
+ <Button label="Change value - undefined|m" onClick={() => setValue(undefined + '|m')} />
196
+ <br />
197
+ <Button label="Change value - NaN|m" onClick={() => setValue(NaN + '|m')} />
198
+ <br />
199
+ <Button label="Change value - nothing (empty)|m" onClick={() => setValue('|m')} />
200
+ </Column>
201
+ </Row>
202
+ <br />
203
+ <Field label="Normal PUI">
204
+ <UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="value|unit" />
205
+ </Field>
206
+ <Field label="Disabled validation">
207
+ <UnitInput name="example2" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" disabledValidation width={width} />
208
+ </Field>
209
+ <Field label="Disabled validation and manual error">
210
+ <UnitInput name="example3" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" error="test" disabledValidation width={width} />
211
+ </Field>
212
+ <Message message={{
213
+ heading: 'Current value inside PUI: ' + value,
214
+ visible: true
215
+ }} />
216
+ </>;
217
+ }`,...(Bt=(Pt=B.parameters)==null?void 0:Pt.docs)==null?void 0:Bt.source}}};var Ft,_t,Mt;te.parameters={...te.parameters,docs:{...(Ft=te.parameters)==null?void 0:Ft.docs,source:{originalSource:`() => {
218
+ const width = '500px';
219
+ const [value, setValue] = useState<string>('1|m');
220
+ const [valueB, setValueB] = useState('|m');
221
+ const automaticValue = '123|km';
222
+ return <>
223
+ <h4>Different cases for automatic (placeholder) values:</h4>
224
+ <Row>
225
+ <Column width="25%">
226
+ <Button label="Change value to ''" onClick={() => setValue('')} />
227
+ <br />
228
+ <Button label="Change value to 1" onClick={() => setValue('1')} />
229
+ <br />
230
+ <Button label="Change value to 1|m" onClick={() => setValue('1|m')} />
231
+ <br />
232
+ <Button label="Change value to |m - empty value" onClick={() => setValue('|m')} />
233
+ </Column>
234
+ </Row>
235
+ <br />
236
+ <Field label="Normal PUI (placeholder + auto)">
237
+ <UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="value|unit" autoValue={automaticValue} />
238
+ </Field>
239
+ <Field label="Normal PUI (only auto)">
240
+ <UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} autoValue={automaticValue} />
241
+ </Field>
242
+ <Field label="Empty PUI with autoValue">
243
+ <UnitInput name="example1" onChange={evt => setValueB(evt.target.value)} value={valueB} unitkey="length" width={width} autoValue={automaticValue} />
244
+ </Field>
245
+ <Field label="Normal PUI (only placeholder)">
246
+ <UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="Placeholder test" />
247
+ </Field>
248
+ <Field label="Normal PUI (placeholder + allowEmpty)">
249
+ <UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="Placeholder test" allowEmpty />
250
+ </Field>
251
+ <Message message={{
252
+ heading: 'Current value inside PUI: ' + value,
253
+ visible: true
254
+ }} />
255
+ </>;
256
+ }`,...(Mt=(_t=te.parameters)==null?void 0:_t.docs)==null?void 0:Mt.source}}};var Ot,Wt,Rt;ne.parameters={...ne.parameters,docs:{...(Ot=ne.parameters)==null?void 0:Ot.docs,source:{originalSource:`() => {
257
+ const [value, setValue] = useState('123|%');
258
+ const [validation, setValidation] = useState<string | null>(null);
259
+ const predictedMessage = 'This should be visible when an error appears';
260
+ const handleValidation = (name: string, message: string | null) => {
261
+ setValidation(message);
262
+ return {
263
+ name,
264
+ error: message
265
+ };
266
+ };
267
+ return <>
268
+ <h4>3rd party validation message when inputting invalid value:</h4>
269
+ <UnitInput name="example" onChange={evt => setValue(evt.target.value)} error={!validation || predictedMessage} validationCallback={handleValidation} value={value} />
270
+ <br />
271
+ <Spacer />
272
+ <h4>Original validation message: </h4>
273
+ <Message message={{
274
+ heading: validation,
275
+ visible: true
276
+ }} />
277
+ </>;
278
+ }`,...(Rt=(Wt=ne.parameters)==null?void 0:Wt.docs)==null?void 0:Rt.source}}};var Lt,Ht,Kt;ae.parameters={...ae.parameters,docs:{...(Lt=ae.parameters)==null?void 0:Lt.docs,source:{originalSource:`() => {
279
+ const [value, setValue] = useState('123|m');
280
+ const [placeholder, setPlaceholder] = useState('');
281
+ const [initUnit, setInitUnit] = useState('km');
282
+ const setPlaceholderValue = () => {
283
+ setInitUnit('ft');
284
+ setPlaceholder('placeholder');
285
+ setValue('|m');
286
+ };
287
+ return <>
288
+ <h4>Empty value case:</h4>
289
+ <UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} allowEmpty placeholder={placeholder} initUnit={initUnit} unitkey="length" />
290
+ <br />
291
+ <Spacer />
292
+ <Button label="Change value |m and unit ft" onClick={() => setPlaceholderValue()} />
293
+ </>;
294
+ }`,...(Kt=(Ht=ae.parameters)==null?void 0:Ht.docs)==null?void 0:Kt.source}}};var $t,zt,Gt;re.parameters={...re.parameters,docs:{...($t=re.parameters)==null?void 0:$t.docs,source:{originalSource:`() => {
295
+ const [value, setValue] = useState('123|m');
296
+ const [unit, setUnit] = useState('m');
297
+ return <>
298
+ <UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} initUnit={unit} unitkey="length" onSwitchUnit={setUnit} />
299
+ <Spacer />
300
+ <UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} initUnit={unit} unitkey="length" onSwitchUnit={setUnit} />
301
+ </>;
302
+ }`,...(Gt=(zt=re.parameters)==null?void 0:zt.docs)==null?void 0:Gt.source}}};var Jt,Yt,Zt;se.parameters={...se.parameters,docs:{...(Jt=se.parameters)==null?void 0:Jt.docs,source:{originalSource:`() => {
303
+ return <>
304
+ <Text faint>
305
+ Reproduce OW-10614 rounding noise bug when storing values in a different
306
+ unit to the display unit
307
+ </Text>
308
+ <Spacer />
309
+ <UnitInput name="example" onChange={() => {}} value={withUnit(convertAndGetValue('9750|psi', 'bar'), 'bar')} initUnit="psi" unitkey="pressure" unitTemplate={{
310
+ pressure: 'psi'
311
+ }} />
312
+ </>;
313
+ }`,...(Zt=(Yt=se.parameters)==null?void 0:Yt.docs)==null?void 0:Zt.source}}};var Qt,Xt,en;F.parameters={...F.parameters,docs:{...(Qt=F.parameters)==null?void 0:Qt.docs,source:{originalSource:`() => {
314
+ const [value, setValue] = useState('123|m');
315
+ return <UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} initUnit="m" unitkey="depth" unitTemplate={{
316
+ depth: 'm'
317
+ }} testId="testId" />;
318
+ }`,...(en=(Xt=F.parameters)==null?void 0:Xt.docs)==null?void 0:en.source}}};const Na=["Default","InitUnit","notKnownUnit","Width","NoConversion","Small","Placeholder","Error","InternalValidationError","Disabled","DisabledNoConversion","DisabledUnitWithoutUnitKey","DisabledUnitWithUnitKey","DisabledWithEnabledUnitMenu","TestExternalStateChangeWithSynchronizedUnits","PredefinedOptionsMenu","TestEdgeCases","AutomaticValues","ValidationCallback","AllowEmptyPUI","onSwitchUnit","OW_10614TestCase","TestUserInput"];export{ae as AllowEmptyPUI,te as AutomaticValues,de as Default,D as Disabled,Y as DisabledNoConversion,Q as DisabledUnitWithUnitKey,Z as DisabledUnitWithoutUnitKey,X as DisabledWithEnabledUnitMenu,G as Error,L as InitUnit,J as InternalValidationError,$ as NoConversion,se as OW_10614TestCase,A as Placeholder,ee as PredefinedOptionsMenu,z as Small,B as TestEdgeCases,P as TestExternalStateChangeWithSynchronizedUnits,F as TestUserInput,ne as ValidationCallback,K as Width,Na as __namedExportsOrder,Ea as default,H as notKnownUnit,re 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-DaLCDjg_.js";import{G as ne}from"./grid-DRkC-bt8.js";import{S as ae}from"./spacer-BWoNR27H.js";import{w as O,u as d,e as B,f as ie,a as re}from"./index-DMAnyMX5.js";import{C as F}from"./card-EcjmryU9.js";import{F as R}from"./field-C5_fLDpy.js";import{H as _}from"./heading-NkLgQYoP.js";import{S as P}from"./select-BW0IihoR.js";import{T as W}from"./toggle-C0zvrIOF.js";import{l as oe}from"./lodash-c4VUpsOs.js";import{u as le}from"./use-previous-D775JrO6.js";import{T as se,C as G}from"./table-Ci7MC96P.js";import"./index-DRSy5Ssd.js";import"./styled-components.browser.esm-BQ9GQzDc.js";import"./index-CF7H4eMJ.js";import"./index-Bk2sglWO.js";import"./label-hiSz3I8H.js";import"./common-types-Sih75Sav.js";import"./help-icon-41R-Z9N1.js";import"./tooltip-1V7clEnw.js";import"./index-CUZDtIZe.js";import"./icon-BP4BO6-k.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./inheritsLoose-DR8r8Ogv.js";import"./index-CEuq6vkz.js";import"./disabled-context-rmpd7YJS.js";import"./types-Dx2TtIG9.js";import"./extends-CF3RwP-h.js";import"./assertThisInitialized-B9jnkVVz.js";import"./memoize-one.esm-CcMeOnPo.js";import"./types-BmbYqTX_.js";import"./text-B3-TSWok.js";import"./actions-Tr0wIZve.js";import"./button-CzvLc2io.js";import"./spinner-AWUe4xwQ.js";import"./badge-CLQ59MDF.js";import"./select.input-CJed_LLR.js";import"./helpers-JJxzGegQ.js";import"./index.es-D2piFfFj.js";import"./redux-tRgGMjwY.js";import"./objectSpread2-DW4nTBoq.js";import"./tiny-invariant-DqLgxztJ.js";import"./pagination-T__Mixkr.js";import"./input-DTXbDJaL.js";import"./input-group-BaRSJAEN.js";import"./input-group-addon-D68iUKV2.js";import"./number-input-Ct8VwJX0.js";import"./check-box-wCvXxtCz.js";import"./slider-CBE03NwD.js";import"./index-BI4_Bp97.js";import"./popover-9ZnEm5Hy.js";const ue=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:{}}),ce=({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}=ue(o),c=le(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=>ce({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(()=>{!oe.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(se,{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 Tt={title:"Basic/UnitTable",args:{}},de=!0,pe=!0,ge=!0,me=!1,N="m",Y="C",he=3,be=(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]},ye=be(he,N,Y),fe=({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}),ve=({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(ye),[m,C]=v.useState(de),[u,s]=v.useState(ge),[c,p]=v.useState(pe),[n,x]=v.useState(me),[g,U]=v.useState(N),I=t=>{const{rowIndex:f,cellIndex:w,value:k,unit:S}=t.target,D=n?fe({reduxTable:e,value:k,unit:S,rowIndex:f,cellIndex:w}):ve({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(F,{heading:i.jsx(_,{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(F,{heading:i.jsx(_,{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(F,{heading:i.jsx(_,{children:"Storage State (Redux)"}),children:i.jsx("pre",{children:i.jsx("code",{children:JSON.stringify(e,null,2)})})}),i.jsxs(F,{heading:i.jsx(_,{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 re(()=>{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 Ut=["UnitTableExample"];export{L as UnitTableExample,Ut as __namedExportsOrder,Tt as default};
@@ -509,7 +509,7 @@
509
509
  }
510
510
  </script>
511
511
 
512
- <script type="module" crossorigin src="./assets/iframe-B1EjAYJz.js"></script>
512
+ <script type="module" crossorigin src="./assets/iframe-BZTJ8TMF.js"></script>
513
513
  </head>
514
514
 
515
515
  <body>