@oliasoft-open-source/react-ui-library 4.6.0-beta-1-beta-1 → 4.7.0-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 (112) hide show
  1. package/dist/index.d.ts +9 -2
  2. package/dist/index.js +136 -63
  3. package/dist/index.js.map +1 -1
  4. package/dist/storybook/assets/{Color-6VNJS4EI-fEFA86eZ.js → Color-6VNJS4EI-NPUHt_3q.js} +1 -1
  5. package/dist/storybook/assets/{DocsRenderer-NNNQARDV-nMqPwG5d.js → DocsRenderer-NNNQARDV-HIEKjKKN.js} +1 -1
  6. package/dist/storybook/assets/{WithTooltip-4HIR6TLV-KkQOzy9q.js → WithTooltip-4HIR6TLV-XVy3Qn7b.js} +1 -1
  7. package/dist/storybook/assets/{accordion.stories-DAmwlTmm.js → accordion.stories-Uipdifbl.js} +1 -1
  8. package/dist/storybook/assets/{actions-SGexXf58.js → actions-Z9jDWreP.js} +1 -1
  9. package/dist/storybook/assets/{actions.stories-dDCC23QK.js → actions.stories-Qrio9EMy.js} +1 -1
  10. package/dist/storybook/assets/{afe.stories-KA-Ul8EG.js → afe.stories-mangk6LB.js} +1 -1
  11. package/dist/storybook/assets/{badge.stories-nzXJ1qip.js → badge.stories-C0MXS15j.js} +1 -1
  12. package/dist/storybook/assets/{blowout.stories-FLPAE9fr.js → blowout.stories-i7Ii3760.js} +1 -1
  13. package/dist/storybook/assets/{button-IoNblLER.js → button-7V8oA22w.js} +1 -1
  14. package/dist/storybook/assets/{button-group-KeeGgC4K.js → button-group-q8QKkLVU.js} +1 -1
  15. package/dist/storybook/assets/{button-group.stories-DG3i2d7K.js → button-group.stories-tLZpLTfD.js} +1 -1
  16. package/dist/storybook/assets/{button.stories-vebimSi_.js → button.stories-PhWmZXOu.js} +1 -1
  17. package/dist/storybook/assets/{buttons-and-links-X1NQO3_1.js → buttons-and-links-gkg6hOs-.js} +1 -1
  18. package/dist/storybook/assets/{card.stories-OtRekExg.js → card.stories-HzHJW6ek.js} +1 -1
  19. package/dist/storybook/assets/{casing-loads.stories--7znBAj-.js → casing-loads.stories-4eIPrrhL.js} +1 -1
  20. package/dist/storybook/assets/{cell.stories-nm3Q_0D8.js → cell.stories-X4sboJCw.js} +1 -1
  21. package/dist/storybook/assets/{check-box-BX5dfQFk.js → check-box-LZdXXKhv.js} +1 -1
  22. package/dist/storybook/assets/{check-box.stories-FNs72smP.js → check-box.stories-0XCykxnz.js} +1 -1
  23. package/dist/storybook/assets/{chunk-HLWAVYOI-u8NfXOtz.js → chunk-HLWAVYOI-YF156CNQ.js} +1 -1
  24. package/dist/storybook/assets/{color-E_qrvl4b.js → color-PIYd2VAw.js} +1 -1
  25. package/dist/storybook/assets/{column.stories-5pd3N4bE.js → column.stories-6OLsjlcP.js} +1 -1
  26. package/dist/storybook/assets/{dialog-dekS0lUR.js → dialog-WKHRZcjc.js} +1 -1
  27. package/dist/storybook/assets/{drawer-TM-jK3WR.js → drawer-WuErQ5Z8.js} +1 -1
  28. package/dist/storybook/assets/{drawer.stories-OE24f2Y4.js → drawer.stories-RFRPs_pQ.js} +1 -1
  29. package/dist/storybook/assets/{empty.stories-KIByp315.js → empty.stories-lva3DbfI.js} +1 -1
  30. package/dist/storybook/assets/{field-kOZPBHf6.js → field-eknsj_Ll.js} +1 -1
  31. package/dist/storybook/assets/{field.stories-aEccauPi.js → field.stories-RmhJ16HT.js} +1 -1
  32. package/dist/storybook/assets/{file-input.stories-I6IPu7wX.js → file-input.stories-SF8BeFpu.js} +1 -1
  33. package/dist/storybook/assets/{flex-KzhjL9yc.js → flex-RYZsoWEN.js} +1 -1
  34. package/dist/storybook/assets/{flex.stories-rDfMJbP6.js → flex.stories-lLz0Xrt_.js} +1 -1
  35. package/dist/storybook/assets/{footer.stories-FmE2JKok.js → footer.stories-L0qQuABW.js} +1 -1
  36. package/dist/storybook/assets/{form.stories-rWTgqDNA.js → form.stories-qQsjBbOk.js} +1 -1
  37. package/dist/storybook/assets/{formation.stories-PmRbjLVy.js → formation.stories-E8DV_cIY.js} +1 -1
  38. package/dist/storybook/assets/{formatter-SWP5E3XI-MyyYQ4w6.js → formatter-SWP5E3XI-uJi-Y6Jy.js} +1 -1
  39. package/dist/storybook/assets/{heading-cUVItwKq.js → heading-Bk0bpNfe.js} +1 -1
  40. package/dist/storybook/assets/{heading.stories-UJlMVVI-.js → heading.stories-HLMPkIPo.js} +1 -1
  41. package/dist/storybook/assets/{help-icon-nI9A506M.js → help-icon--rUDxLUD.js} +1 -1
  42. package/dist/storybook/assets/{help-icon.stories-Qz7MKCnQ.js → help-icon.stories-vifwJgNA.js} +1 -1
  43. package/dist/storybook/assets/{icon.stories-D_XEmSGG.js → icon.stories-W-UgTWyK.js} +1 -1
  44. package/dist/storybook/assets/{iframe-L_X6E7p9.js → iframe-NU_z28D3.js} +2 -2
  45. package/dist/storybook/assets/{index-f3h-H0UN.js → index-_waogfzH.js} +5 -5
  46. package/dist/storybook/assets/{input-group.stories-EouZEW-v.js → input-group.stories-WljyIQ0a.js} +1 -1
  47. package/dist/storybook/assets/{input-iDZqV-2m.js → input-u1He-wWs.js} +1 -1
  48. package/dist/storybook/assets/{input-validation-yy4j_lyO.js → input-validation-XFS-LWhH.js} +1 -1
  49. package/dist/storybook/assets/{input.stories-iopguZKB.js → input.stories-rLdDRxtU.js} +1 -1
  50. package/dist/storybook/assets/{inputs-j3EacUMV.js → inputs-vo_nTpyh.js} +1 -1
  51. package/dist/storybook/assets/{label-RpB4JmHX.js → label-0_Qf6I8t.js} +1 -1
  52. package/dist/storybook/assets/{label.stories-HcdQ1bEB.js → label.stories-aXdU5_Ql.js} +1 -1
  53. package/dist/storybook/assets/{layout-forms-jB2_f1jD.js → layout-forms-w8JJQQqh.js} +1 -1
  54. package/dist/storybook/assets/{layout-general-lM6sWErr.js → layout-general-QgIJDQ4H.js} +1 -1
  55. package/dist/storybook/assets/{list-ciYNlkVM.js → list-8l-RGDgw.js} +1 -1
  56. package/dist/storybook/assets/{list-heading-XbqCJOHh.js → list-heading-Vd3hu5Pf.js} +1 -1
  57. package/dist/storybook/assets/{list.stories-G1n5uCjl.js → list.stories-Vp0Dm7UU.js} +1 -1
  58. package/dist/storybook/assets/{list.stories-data-8eswVWst.js → list.stories-data-IcFu6vvd.js} +1 -1
  59. package/dist/storybook/assets/{loader.stories-G8Q_Fm8u.js → loader.stories-0OwmnNML.js} +1 -1
  60. package/dist/storybook/assets/{menu.stories-GFJs09Wk.js → menu.stories-VwRF_Pbx.js} +1 -1
  61. package/dist/storybook/assets/{menu.stories-data-c8X93fYM.js → menu.stories-data-hEz8P1yK.js} +1 -1
  62. package/dist/storybook/assets/{message.stories-BqM_-mrZ.js → message.stories-CDgUaLZP.js} +1 -1
  63. package/dist/storybook/assets/{modal.stories-K4XxeWTp.js → modal.stories-15sY1c5H.js} +1 -1
  64. package/dist/storybook/assets/{number-input-d7hXQldd.js → number-input-SvjJIGsW.js} +1 -1
  65. package/dist/storybook/assets/{number-input.stories-SOsG2FLJ.js → number-input.stories-BURENIFo.js} +1 -1
  66. package/dist/storybook/assets/{option-dropdown.stories-1Y5JDaBF.js → option-dropdown.stories-Q2zd2AcS.js} +1 -1
  67. package/dist/storybook/assets/{padding-and-spacing-AAcRO_XG.js → padding-and-spacing-J_Zb8SJm.js} +1 -1
  68. package/dist/storybook/assets/{page.stories-eHXLB7iO.js → page.stories-pa-9WU0e.js} +1 -1
  69. package/dist/storybook/assets/{pagination-Eaj_UOBW.js → pagination-5n5spTRo.js} +1 -1
  70. package/dist/storybook/assets/{pagination.stories-sl2a8BMq.js → pagination.stories-g4a-aSxq.js} +1 -1
  71. package/dist/storybook/assets/{pop-confirm.stories-94l3Xg8w.js → pop-confirm.stories-_agvSFJd.js} +1 -1
  72. package/dist/storybook/assets/{popover-uAo1e4-D.js → popover-Y3FpGdUS.js} +1 -1
  73. package/dist/storybook/assets/{popover.stories-JVzzF0Jm.js → popover.stories-b7Tt4S0j.js} +1 -1
  74. package/dist/storybook/assets/{preview-zEeiMorq.js → preview-D7BEK6_6.js} +2 -2
  75. package/dist/storybook/assets/{preview-we9irrbK.js → preview-WIFbPoA-.js} +1 -1
  76. package/dist/storybook/assets/{projects.stories-FkI3WFiR.js → projects.stories-YPlCLdRE.js} +1 -1
  77. package/dist/storybook/assets/{radio-button-QcS9mLYi.js → radio-button-jHcwHUA4.js} +1 -1
  78. package/dist/storybook/assets/{radio-button.stories-KCS981-F.js → radio-button.stories-LkCJsp5P.js} +1 -1
  79. package/dist/storybook/assets/{reservoirs.stories-LdgtGFHD.js → reservoirs.stories-hhPblhmv.js} +1 -1
  80. package/dist/storybook/assets/{rich-text-input.stories-D55Op5Gf.js → rich-text-input.stories-7UzvJ-A1.js} +1 -1
  81. package/dist/storybook/assets/{row.stories-2iigGv-u.js → row.stories-juQv80h3.js} +1 -1
  82. package/dist/storybook/assets/{select-Z1HqJ5aU.js → select-JjEPivho.js} +1 -1
  83. package/dist/storybook/assets/{select.stories-oUxeDUts.js → select.stories-qFDyxRFm.js} +1 -1
  84. package/dist/storybook/assets/{side-bar-GJ2tcZYY.js → side-bar-Fjr2t9MT.js} +1 -1
  85. package/dist/storybook/assets/{side-bar.stories-Ld0zOToQ.js → side-bar.stories-sxBJCVnV.js} +1 -1
  86. package/dist/storybook/assets/{site.stories-l2tDdRBM.js → site.stories-QHCzFOnt.js} +1 -1
  87. package/dist/storybook/assets/{slider-_5NQKbM-.js → slider-nl2rJ9LF.js} +1 -1
  88. package/dist/storybook/assets/{slider.stories-QyyBB_rz.js → slider.stories--aZa8kf-.js} +1 -1
  89. package/dist/storybook/assets/{spacer.stories--ynGgvN4.js → spacer.stories-eCrKj4b3.js} +1 -1
  90. package/dist/storybook/assets/{syntaxhighlighter-NMPM6SWI-o9gHPHbF.js → syntaxhighlighter-NMPM6SWI--OA96ou_.js} +1 -1
  91. package/dist/storybook/assets/{table-_jWgMFOi.js → table-i8WT9qpj.js} +1 -1
  92. package/dist/storybook/assets/{table.stories-data-w897tYMJ.js → table.stories-data-4h6h0P0V.js} +1 -1
  93. package/dist/storybook/assets/{table.stories-QupkMmra.js → table.stories-tEvulp9K.js} +1 -1
  94. package/dist/storybook/assets/{textarea-mYEkEnUR.js → textarea-gxvxVBdC.js} +1 -1
  95. package/dist/storybook/assets/{textarea.stories-ARS3RM31.js → textarea.stories-MZHVAwSx.js} +1 -1
  96. package/dist/storybook/assets/{title.stories-14d2lIxy.js → title.stories-cmteB9lx.js} +1 -1
  97. package/dist/storybook/assets/{toaster.stories-XhUo3pbR.js → toaster.stories-S25S4g_F.js} +1 -1
  98. package/dist/storybook/assets/{toggle-wk0GbVB8.js → toggle-BPI2y-lU.js} +1 -1
  99. package/dist/storybook/assets/{toggle.stories-ItCMhW4M.js → toggle.stories-aVmjpons.js} +1 -1
  100. package/dist/storybook/assets/{tooltip-ZHdi6rl-.js → tooltip-HEHiU__l.js} +1 -1
  101. package/dist/storybook/assets/{tooltip.stories-gTfOeEzv.js → tooltip.stories-tiOgoWHH.js} +1 -1
  102. package/dist/storybook/assets/{tooltip.test-case.stories-L2bW8Ijz.js → tooltip.test-case.stories-kIeZayHw.js} +1 -1
  103. package/dist/storybook/assets/{top-bar-uqbsCAt-.js → top-bar-9iOkm7Gq.js} +1 -1
  104. package/dist/storybook/assets/{top-bar.stories-lt8T4EVJ.js → top-bar.stories-5jcHi3Q_.js} +1 -1
  105. package/dist/storybook/assets/{top-bar.testcase.stories-_Nc_6uY7.js → top-bar.testcase.stories-7acJvLc_.js} +1 -1
  106. package/dist/storybook/assets/{tree.stories-Fsb5fGEv.js → tree.stories-_5t-Rrls.js} +1 -1
  107. package/dist/storybook/assets/{unit-input.stories-0l2v-aF9.js → unit-input.stories-j3Ykteob.js} +1 -1
  108. package/dist/storybook/assets/unit-table.stories-4XYwgJwY.js +100 -0
  109. package/dist/storybook/iframe.html +1 -1
  110. package/dist/storybook/project.json +1 -1
  111. package/package.json +1 -1
  112. package/dist/storybook/assets/unit-table.stories-OTxFddv6.js +0 -84
@@ -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 rn}from"./index-IQMsp8Ab.js";import{c as sn}from"./index-VW3EWkuE.js";import{u as un}from"./use-previous-VKMmnaK7.js";import{M as we}from"./actions-SGexXf58.js";import{I as on}from"./input-group-addon-BHVsW9mL.js";import{B as c}from"./button-IoNblLER.js";import{T as dn}from"./tooltip-ZHdi6rl-.js";import{I as cn}from"./input-group-R8LoqKRn.js";import{S}from"./spacer-Yji9g2AW.js";import{T as mn}from"./text-6KQ6ntOV.js";import{I as pn}from"./input-iDZqV-2m.js";import{M as Ee}from"./types-VB5zD18b.js";import{l as E}from"./lodash-Bmg8FrMx.js";import{D as gn}from"./divider-RwW2f_N0.js";import{R as qt,C as pe}from"./row-vFUhHoz5.js";import{F as I}from"./field-kOZPBHf6.js";import{a as ge}from"./message-uMHaTEXV.js";import"./index-cCpkwrS5.js";import"./common-types-U65vzrrz.js";import"./disabled-context-urNQThQz.js";import"./icon-y1a2N5SZ.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-RpB4JmHX.js";import"./help-icon-nI9A506M.js";const hn=()=>{const t=m.useRef(null);return m.useLayoutEffect(()=>{t.current&&(t.current(),t.current=null)}),n=>{t.current=n}},vn=(t,a)=>{const n=a==null?void 0:a[t];return n||(console.log(`Warning: 'unitTemplate' does not define a preferred unit for '${t}'. Defaulting to standard unit.`),r.unitFromQuantity(t)??"")};var b=(t=>(t.CUSTOM="custom",t.PREDEFINED="predefined",t))(b||{});const Wt=t=>t==="undefined"||t===void 0||t===""||t==="null"||t===null||t==="NaN"||isNaN(t),Tt=(t="",a,n="",s=!1)=>{if(s)return t;if(a&&!Wt(t))try{const u=r.isValueWithUnit(t)?t:r.withUnit(t,n),o=r.convertSamePrecision(u,a);return r.getValue(o)}catch{}return t},fn=t=>t?!!r.getUnit(t):!1,F=(t="",a,n,s)=>{if(s)return t;const u=fn(t)||r.isValueWithUnit(t),o=r.getValue(t);return Wt(o)?o:u?Tt(o,a,n,s):t},Ne=t=>E.isObject(t)&&!E.isArray(t)&&!E.isFunction(t)?E.get(t,"fieldName",""):typeof t=="string"?t:"",Cn=t=>E.isObjectLike(t)&&E.has(t,"message"),bn=t=>typeof t=="string"?t:Cn(t)?t.message:null;var Un=rn();const yn=t=>t.search(RegExp(/(^0{2}\.)|(^0+[1-9])/g))===0,Ae=(t,a)=>{var j;const{allowEmpty:n=!1,autoValue:s,placeholder:u,disabledValidation:o=!1}=a||{},i=String(t);if(o||s||u)return null;const g=Un.isValueWithUnit(i)?r.getValue(i):i;if(n&&g==="")return null;if(yn(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 bn(re)}return null},Pe=(t="")=>{var a;return(a=r.KNOWN_UNITS)==null?void 0:a.includes(t)},xn=(t,a)=>{const n=r.getUnit(t||"");return Pe(a)&&Pe(n)},Vn="_predefinedMenuActive_1yvt4_1",In={predefinedMenuActive:Vn},p=({name:t,placeholder:a="",disabled:n=!1,disabledUnit:s=!1,error:u=null,left:o=!1,small:i=!1,width:g="100%",value:h,unitkey:j="",initUnit:re,noConversion:Rt=!1,onChange:ie=()=>{},onClick:kn=()=>{},onFocus:Lt=()=>{},onSwitchUnit:he=()=>{},unitTemplate:ve,doNotConvertValue:A=!1,testId:w,warning:Kt=null,predefinedOptions:x,initialPredefinedOption:$t=!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 Ht=hn(),[se="",P=""]=h!==void 0?r.split(h):[],xe=V?r.getUnit(V):"",Ve=m.useMemo(()=>vn(j,ve),[j,ve]),zt=xn(h,Ve),U=re||Ve||P,Jt=un(U),Ie=F(h,U,P,A),je=F(V,U,xe,A),Yt=Ie!==""?{value:Ie,unit:U}:je!==""?{value:je,unit:U}:{value:se,unit:P},[v,Y]=m.useState(Yt),[Zt,ue]=m.useState(null),[k,oe]=m.useState($t?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(Tt(h,d),d)===l.value}),Gt=()=>{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}},Qt=l=>{const d=Ne(t),f=l.target,{value:y,selectionStart:X}=f,Se=r.cleanNumStr(y.replaceAll(" ","").replaceAll("|","")),ce=r.withUnit(Se,(v==null?void 0:v.unit)||""),nn=r.getValue(ce),me=Ae(nn,{allowEmpty:ye,autoValue:V,placeholder:a,disabledValidation:Ue});if(me===null){ie({target:{value:ce,name:d}});const[an,ln]=r.split(ce);Y({value:an,unit:ln}),ue(null),be(d,null)}else Y({value:Se,unit:v.unit}),ue(me),be(d,me);Ht(()=>{f.selectionStart=X,f.selectionEnd=X})},Xt=(l,d)=>{d===v.unit||isNaN(Number(l))||(Y({value:l,unit:d}),he&&he(d))};m.useEffect(()=>{if(U){let f,y="";Jt!==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=Gt(),G=r.label(v.unit)||v.unit||"",en=Rt||!Z||Z&&Z.length===1,ke=Ne(t);let Q;const tn=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&&!n&&(oe(b.PREDEFINED),ie({target:{value:l.value,name:typeof t=="string"?t:(t==null?void 0:t.fieldName)||"",predefinedSelected:!0,predefinedOption:l}}))},label:e.jsxs(e.Fragment,{children:[e.jsx(mn,{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&&!n&&ie({target:{value:r.withUnit(v.value,v.unit),name:typeof t=="string"?t:(t==null?void 0:t.fieldName)||""}})},label:"Custom",selected:k===b.CUSTOM}],x!=null&&x.length){const l=x.map(tn);Q=[...Q,...l]}return e.jsx("div",{className:k===b.PREDEFINED?sn(In.predefinedMenuActive):"",children:e.jsxs(cn,{small:i,width:g,children:[x&&e.jsx(dn,{text:k===b.PREDEFINED?D==null?void 0:D.label:"",children:e.jsx(we,{maxHeight:380,groupOrder:"first",testId:w&&`${w}-predefined-menu`,disabled:n,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(pn,{type:"text",name:ke,testId:w,disabled:n,placeholder:de?F(V,v.unit,xe,A):a,value:v.value,onChange:Qt,onFocus:Lt,error:u||Zt,warning:Kt,right:!o},ke),G&&(en||!zt?e.jsx(on,{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(),Xt(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:jn}=__STORYBOOK_MODULE_ADDONS__,ia={title:"Basic/UnitInput",component:p,args:{name:"example",unitkey:"length",value:"123|m"}},C=t=>{const[a,n]=jn(),s=u=>{n({value:u.target.value})};return e.jsx(p,{...t,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=t=>{const[a,n]=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:()=>n(a==="123|m"?"456|m":"123|m")}),e.jsx(S,{}),e.jsx(p,{name:"example",onChange:g=>{n(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(gn,{}),e.jsx("h4",{children:"Without initUnit property (taken from the redux store)"}),e.jsx(p,{name:"example",onChange:g=>{n(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 t="500px",[a,n]=m.useState(void 0);return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different edge cases such as +/- infinity, undefined, NaN, null:"}),e.jsxs(qt,{children:[e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value infinity",onClick:()=>n(1/0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value -infinity",onClick:()=>n(-1/0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value null",onClick:()=>n(null)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - undefined",onClick:()=>n(void 0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - NaN",onClick:()=>n(NaN)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - nothing (empty)",onClick:()=>n(void 0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - empty string",onClick:()=>n("")})]}),e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value infinity|m",onClick:()=>n("Infinity|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value -infinity|m",onClick:()=>n("-Infinity|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value null|m",onClick:()=>n("null|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - undefined|m",onClick:()=>n("undefined|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - NaN|m",onClick:()=>n("NaN|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - nothing (empty)|m",onClick:()=>n("|m")})]})]}),e.jsx("br",{}),e.jsx(I,{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(I,{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(I,{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(ge,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})},te=()=>{const t="500px",[a,n]=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(qt,{children:e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value to ''",onClick:()=>n("")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to 1",onClick:()=>n("1")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to 1|m",onClick:()=>n("1|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to |m - empty value",onClick:()=>n("|m")})]})}),e.jsx("br",{}),e.jsx(I,{label:"Normal PUI (placeholder + auto)",children:e.jsx(p,{name:"example1",onChange:i=>n(i.target.value),value:a,unitkey:"length",width:t,placeholder:"value|unit",autoValue:o})}),e.jsx(I,{label:"Normal PUI (only auto)",children:e.jsx(p,{name:"example1",onChange:i=>n(i.target.value),value:a,unitkey:"length",width:t,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:t,autoValue:o})}),e.jsx(I,{label:"Normal PUI (only placeholder)",children:e.jsx(p,{name:"example1",onChange:i=>n(i.target.value),value:a,unitkey:"length",width:t,placeholder:"Placeholder test"})}),e.jsx(I,{label:"Normal PUI (placeholder + allowEmpty)",children:e.jsx(p,{name:"example1",onChange:i=>n(i.target.value),value:a,unitkey:"length",width:t,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 ne=()=>{const[t,a]=m.useState("123|%"),[n,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:!n||u,validationCallback:o,value:t}),e.jsx("br",{}),e.jsx(S,{}),e.jsx("h4",{children:"Original validation message: "}),e.jsx(ge,{message:{heading:n,visible:!0}})]})},ae=()=>{const[t,a]=m.useState("123|m"),[n,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:t,allowEmpty:!0,placeholder:n,initUnit:u,unitkey:"length"}),e.jsx("br",{}),e.jsx(S,{}),e.jsx(c,{label:"Change value |m and unit ft",onClick:()=>i()})]})},le=()=>{const[t,a]=m.useState("123|m"),[n,s]=m.useState("m");return e.jsxs(e.Fragment,{children:[e.jsx(p,{name:"example",onChange:u=>a(u.target.value),value:t,initUnit:n,unitkey:"length",onSwitchUnit:s}),e.jsx(S,{}),e.jsx(p,{name:"example",onChange:u=>a(u.target.value),value:t,initUnit:n,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 rn}from"./index-IQMsp8Ab.js";import{c as sn}from"./index-VW3EWkuE.js";import{u as un}from"./use-previous-VKMmnaK7.js";import{M as we}from"./actions-Z9jDWreP.js";import{I as on}from"./input-group-addon-BHVsW9mL.js";import{B as c}from"./button-7V8oA22w.js";import{T as dn}from"./tooltip-HEHiU__l.js";import{I as cn}from"./input-group-R8LoqKRn.js";import{S}from"./spacer-Yji9g2AW.js";import{T as mn}from"./text-6KQ6ntOV.js";import{I as pn}from"./input-u1He-wWs.js";import{M as Ee}from"./types-VB5zD18b.js";import{l as E}from"./lodash-Bmg8FrMx.js";import{D as gn}from"./divider-RwW2f_N0.js";import{R as qt,C as pe}from"./row-vFUhHoz5.js";import{F as I}from"./field-eknsj_Ll.js";import{a as ge}from"./message-uMHaTEXV.js";import"./index-cCpkwrS5.js";import"./common-types-U65vzrrz.js";import"./disabled-context-urNQThQz.js";import"./icon-y1a2N5SZ.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-0_Qf6I8t.js";import"./help-icon--rUDxLUD.js";const hn=()=>{const t=m.useRef(null);return m.useLayoutEffect(()=>{t.current&&(t.current(),t.current=null)}),n=>{t.current=n}},vn=(t,a)=>{const n=a==null?void 0:a[t];return n||(console.log(`Warning: 'unitTemplate' does not define a preferred unit for '${t}'. Defaulting to standard unit.`),r.unitFromQuantity(t)??"")};var b=(t=>(t.CUSTOM="custom",t.PREDEFINED="predefined",t))(b||{});const Wt=t=>t==="undefined"||t===void 0||t===""||t==="null"||t===null||t==="NaN"||isNaN(t),Tt=(t="",a,n="",s=!1)=>{if(s)return t;if(a&&!Wt(t))try{const u=r.isValueWithUnit(t)?t:r.withUnit(t,n),o=r.convertSamePrecision(u,a);return r.getValue(o)}catch{}return t},fn=t=>t?!!r.getUnit(t):!1,F=(t="",a,n,s)=>{if(s)return t;const u=fn(t)||r.isValueWithUnit(t),o=r.getValue(t);return Wt(o)?o:u?Tt(o,a,n,s):t},Ne=t=>E.isObject(t)&&!E.isArray(t)&&!E.isFunction(t)?E.get(t,"fieldName",""):typeof t=="string"?t:"",Cn=t=>E.isObjectLike(t)&&E.has(t,"message"),bn=t=>typeof t=="string"?t:Cn(t)?t.message:null;var Un=rn();const yn=t=>t.search(RegExp(/(^0{2}\.)|(^0+[1-9])/g))===0,Ae=(t,a)=>{var j;const{allowEmpty:n=!1,autoValue:s,placeholder:u,disabledValidation:o=!1}=a||{},i=String(t);if(o||s||u)return null;const g=Un.isValueWithUnit(i)?r.getValue(i):i;if(n&&g==="")return null;if(yn(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 bn(re)}return null},Pe=(t="")=>{var a;return(a=r.KNOWN_UNITS)==null?void 0:a.includes(t)},xn=(t,a)=>{const n=r.getUnit(t||"");return Pe(a)&&Pe(n)},Vn="_predefinedMenuActive_1yvt4_1",In={predefinedMenuActive:Vn},p=({name:t,placeholder:a="",disabled:n=!1,disabledUnit:s=!1,error:u=null,left:o=!1,small:i=!1,width:g="100%",value:h,unitkey:j="",initUnit:re,noConversion:Rt=!1,onChange:ie=()=>{},onClick:kn=()=>{},onFocus:Lt=()=>{},onSwitchUnit:he=()=>{},unitTemplate:ve,doNotConvertValue:A=!1,testId:w,warning:Kt=null,predefinedOptions:x,initialPredefinedOption:$t=!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 Ht=hn(),[se="",P=""]=h!==void 0?r.split(h):[],xe=V?r.getUnit(V):"",Ve=m.useMemo(()=>vn(j,ve),[j,ve]),zt=xn(h,Ve),U=re||Ve||P,Jt=un(U),Ie=F(h,U,P,A),je=F(V,U,xe,A),Yt=Ie!==""?{value:Ie,unit:U}:je!==""?{value:je,unit:U}:{value:se,unit:P},[v,Y]=m.useState(Yt),[Zt,ue]=m.useState(null),[k,oe]=m.useState($t?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(Tt(h,d),d)===l.value}),Gt=()=>{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}},Qt=l=>{const d=Ne(t),f=l.target,{value:y,selectionStart:X}=f,Se=r.cleanNumStr(y.replaceAll(" ","").replaceAll("|","")),ce=r.withUnit(Se,(v==null?void 0:v.unit)||""),nn=r.getValue(ce),me=Ae(nn,{allowEmpty:ye,autoValue:V,placeholder:a,disabledValidation:Ue});if(me===null){ie({target:{value:ce,name:d}});const[an,ln]=r.split(ce);Y({value:an,unit:ln}),ue(null),be(d,null)}else Y({value:Se,unit:v.unit}),ue(me),be(d,me);Ht(()=>{f.selectionStart=X,f.selectionEnd=X})},Xt=(l,d)=>{d===v.unit||isNaN(Number(l))||(Y({value:l,unit:d}),he&&he(d))};m.useEffect(()=>{if(U){let f,y="";Jt!==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=Gt(),G=r.label(v.unit)||v.unit||"",en=Rt||!Z||Z&&Z.length===1,ke=Ne(t);let Q;const tn=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&&!n&&(oe(b.PREDEFINED),ie({target:{value:l.value,name:typeof t=="string"?t:(t==null?void 0:t.fieldName)||"",predefinedSelected:!0,predefinedOption:l}}))},label:e.jsxs(e.Fragment,{children:[e.jsx(mn,{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&&!n&&ie({target:{value:r.withUnit(v.value,v.unit),name:typeof t=="string"?t:(t==null?void 0:t.fieldName)||""}})},label:"Custom",selected:k===b.CUSTOM}],x!=null&&x.length){const l=x.map(tn);Q=[...Q,...l]}return e.jsx("div",{className:k===b.PREDEFINED?sn(In.predefinedMenuActive):"",children:e.jsxs(cn,{small:i,width:g,children:[x&&e.jsx(dn,{text:k===b.PREDEFINED?D==null?void 0:D.label:"",children:e.jsx(we,{maxHeight:380,groupOrder:"first",testId:w&&`${w}-predefined-menu`,disabled:n,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(pn,{type:"text",name:ke,testId:w,disabled:n,placeholder:de?F(V,v.unit,xe,A):a,value:v.value,onChange:Qt,onFocus:Lt,error:u||Zt,warning:Kt,right:!o},ke),G&&(en||!zt?e.jsx(on,{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(),Xt(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:jn}=__STORYBOOK_MODULE_ADDONS__,ia={title:"Basic/UnitInput",component:p,args:{name:"example",unitkey:"length",value:"123|m"}},C=t=>{const[a,n]=jn(),s=u=>{n({value:u.target.value})};return e.jsx(p,{...t,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=t=>{const[a,n]=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:()=>n(a==="123|m"?"456|m":"123|m")}),e.jsx(S,{}),e.jsx(p,{name:"example",onChange:g=>{n(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(gn,{}),e.jsx("h4",{children:"Without initUnit property (taken from the redux store)"}),e.jsx(p,{name:"example",onChange:g=>{n(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 t="500px",[a,n]=m.useState(void 0);return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different edge cases such as +/- infinity, undefined, NaN, null:"}),e.jsxs(qt,{children:[e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value infinity",onClick:()=>n(1/0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value -infinity",onClick:()=>n(-1/0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value null",onClick:()=>n(null)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - undefined",onClick:()=>n(void 0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - NaN",onClick:()=>n(NaN)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - nothing (empty)",onClick:()=>n(void 0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - empty string",onClick:()=>n("")})]}),e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value infinity|m",onClick:()=>n("Infinity|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value -infinity|m",onClick:()=>n("-Infinity|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value null|m",onClick:()=>n("null|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - undefined|m",onClick:()=>n("undefined|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - NaN|m",onClick:()=>n("NaN|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - nothing (empty)|m",onClick:()=>n("|m")})]})]}),e.jsx("br",{}),e.jsx(I,{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(I,{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(I,{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(ge,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})},te=()=>{const t="500px",[a,n]=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(qt,{children:e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value to ''",onClick:()=>n("")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to 1",onClick:()=>n("1")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to 1|m",onClick:()=>n("1|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to |m - empty value",onClick:()=>n("|m")})]})}),e.jsx("br",{}),e.jsx(I,{label:"Normal PUI (placeholder + auto)",children:e.jsx(p,{name:"example1",onChange:i=>n(i.target.value),value:a,unitkey:"length",width:t,placeholder:"value|unit",autoValue:o})}),e.jsx(I,{label:"Normal PUI (only auto)",children:e.jsx(p,{name:"example1",onChange:i=>n(i.target.value),value:a,unitkey:"length",width:t,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:t,autoValue:o})}),e.jsx(I,{label:"Normal PUI (only placeholder)",children:e.jsx(p,{name:"example1",onChange:i=>n(i.target.value),value:a,unitkey:"length",width:t,placeholder:"Placeholder test"})}),e.jsx(I,{label:"Normal PUI (placeholder + allowEmpty)",children:e.jsx(p,{name:"example1",onChange:i=>n(i.target.value),value:a,unitkey:"length",width:t,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 ne=()=>{const[t,a]=m.useState("123|%"),[n,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:!n||u,validationCallback:o,value:t}),e.jsx("br",{}),e.jsx(S,{}),e.jsx("h4",{children:"Original validation message: "}),e.jsx(ge,{message:{heading:n,visible:!0}})]})},ae=()=>{const[t,a]=m.useState("123|m"),[n,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:t,allowEmpty:!0,placeholder:n,initUnit:u,unitkey:"length"}),e.jsx("br",{}),e.jsx(S,{}),e.jsx(c,{label:"Change value |m and unit ft",onClick:()=>i()})]})},le=()=>{const[t,a]=m.useState("123|m"),[n,s]=m.useState("m");return e.jsxs(e.Fragment,{children:[e.jsx(p,{name:"example",onChange:u=>a(u.target.value),value:t,initUnit:n,unitkey:"length",onSwitchUnit:s}),e.jsx(S,{}),e.jsx(p,{name:"example",onChange:u=>a(u.target.value),value:t,initUnit:n,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,100 @@
1
+ import{j as l}from"./jsx-runtime-FsUICBgo.js";import{r as f}from"./index-RfLt4OUa.js";import{f as E}from"./immer.esm-bD7SSJ7T.js";import{d as T}from"./index-IQMsp8Ab.js";import{G}from"./grid-u1mZpaML.js";import{C as V}from"./card-0r8RRVk-.js";import{F as N}from"./field-eknsj_Ll.js";import{H as j}from"./heading-Bk0bpNfe.js";import{S as q}from"./select-JjEPivho.js";import{l as O}from"./lodash-Bmg8FrMx.js";import{u as Q}from"./use-previous-VKMmnaK7.js";import{T as J}from"./table-i8WT9qpj.js";import"./index-cCpkwrS5.js";import"./styled-components.browser.esm-qIipjd6c.js";import"./tslib.es6-OIsz3r9a.js";import"./index-VW3EWkuE.js";import"./label-0_Qf6I8t.js";import"./common-types-U65vzrrz.js";import"./help-icon--rUDxLUD.js";import"./tooltip-HEHiU__l.js";import"./index-miLrID2P.js";import"./icon-y1a2N5SZ.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-Z9jDWreP.js";import"./button-7V8oA22w.js";import"./spinner-R8Il4aRe.js";import"./badge-23Ty_zBt.js";import"./select.input-zP5tW20f.js";import"./index.es-JXn3JM7k.js";import"./redux-F5dueAP3.js";import"./objectSpread2-93s0nBry.js";import"./pagination-5n5spTRo.js";import"./input-u1He-wWs.js";import"./input-group-R8LoqKRn.js";import"./input-group-addon-BHVsW9mL.js";import"./number-input-SvjJIGsW.js";import"./check-box-LZdXXKhv.js";import"./slider-nl2rJ9LF.js";import"./index-ugi_ZH6T.js";import"./popover-Y3FpGdUS.js";const $=a=>a.reduce(({preferredUnits:n,storageUnits:e},{unitKey:i,preferredUnit:c,storageUnit:s})=>(n[i]=c,e[i]=s,{preferredUnits:n,storageUnits:e}),{preferredUnits:{},storageUnits:{}}),z=({headers:a,rows:n,selectedUnits:e,storageUnits:i,onChangeUnit:c,convertBackToStorageUnit:s,convertBackToString:r,enableCosmeticRounding:d})=>{const p=a.map(u=>({...u,cells:u.cells.map(o=>{if(o.type==="AutoUnit"){const{unitKey:t}=o;return{value:e[t],type:"Select",options:T.getUnitsForQuantity(t),native:!0,onChange:v=>c({unitKey:t,value:v.target.value})}}return o})})),m=n.map((u,o)=>({...u,cells:u.cells.map((t,v)=>{if(t.autoUnit){const{formatDisplayValue:g}=t,b=T.convertAndGetValue(t.value,e[t.unitKey],i[t.unitKey]),y=d?T.roundToPrecision(b,14):b,x=g?g(y):y;return{...t,value:x,onChange:h=>{const{value:C}=h.target,{unitKey:R}=t,S=i[R],w=e[R],I=w!==S&&s?T.convertAndGetValue(C,S,w):C,F=r?String(I):I,P=s?S:w;t.onChange({rowIndex:o,cellIndex:v,value:F,unit:P})}}}return t})}));return{convertedHeaders:p,convertedRows:m}},D=({table:a,unitConfig:n,convertBackToStorageUnit:e=!0,convertBackToString:i=!1,enableCosmeticRounding:c=!0})=>{const{rows:s,headers:r,otherProps:d}=a,{storageUnits:p,preferredUnits:m}=$(n),u=Q(m),[o,t]=f.useState(m),v=({unitKey:h,value:C})=>t({...o,[h]:C}),g=h=>z({headers:r,rows:s,selectedUnits:h,storageUnits:p,onChangeUnit:v,convertBackToStorageUnit:e,convertBackToString:i,enableCosmeticRounding:c}),b=g(o),[y,x]=f.useState(b);return f.useEffect(()=>{!O.isEqual(m,u)&&(t(m),x(g(m)))},[n]),f.useEffect(()=>{x(g(o))},[a]),f.useEffect(()=>{x(g(o))},[o]),l.jsx(J,{table:{...d,headers:y.convertedHeaders,rows:y.convertedRows}})};try{D.displayName="UnitTable",D.__docgenInfo={description:"",displayName:"UnitTable",props:{table:{defaultValue:null,description:"",name:"table",required:!0,type:{name:"any"}},unitConfig:{defaultValue:null,description:"",name:"unitConfig",required:!0,type:{name:"any"}},convertBackToStorageUnit:{defaultValue:{value:"true"},description:"",name:"convertBackToStorageUnit",required:!1,type:{name:"boolean"}},convertBackToString:{defaultValue:{value:"false"},description:"",name:"convertBackToString",required:!1,type:{name:"boolean"}},enableCosmeticRounding:{defaultValue:{value:"true"},description:"",name:"enableCosmeticRounding",required:!1,type:{name:"boolean"}}}}}catch{}const Me={title:"Basic/UnitTable",args:{}},W=!0,L=!0,M=!1,k="m",X=3,Y=(a,n)=>{const e=[n,n,n],i=[...Array(Number(a))].map((c,s)=>{const r=s,d=s+1.25,p=d-r;return[String(r),String(d),String(p)]});return[e].concat(i)},Z=Y(X,k),ee=({reduxTable:a,value:n,rowIndex:e,cellIndex:i})=>E(a,c=>{c[e+1][i]=n}),U=()=>{const[a,n]=f.useState(k),[e,i]=f.useState(Z),c=({rowIndex:r,cellIndex:d,value:p,unit:m})=>{const u=ee({reduxTable:e,value:p,rowIndex:r,cellIndex:d});i(u)},s=e.reduce((r,d,p)=>(p===0?r.headers=[{cells:[{value:"From"},{value:"To"},{value:"Delta"}]},{cells:[{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"length"}]}]:r.rows=r.rows.concat({cells:d.map((m,u)=>{const o=p===1&&u===1;return{value:m,type:o?"Text":"NumberInput",unitKey:"length",onChange:c,formatDisplayValue:o?b=>`T* ${b}`:null,autoUnit:!0}})}),r),{headers:[],rows:[]});return l.jsxs(G,{columns:"1fr 1fr",gap:!0,children:[l.jsx(V,{heading:l.jsx(j,{children:"Global View Settings"}),children:l.jsx(N,{label:"Active Unit Template",children:l.jsx(q,{options:T.getUnitsForQuantity("length"),value:{value:a},onChange:r=>n(r.target.value),width:"100px"})})}),l.jsx(V,{heading:l.jsx(j,{children:"UnitTable"}),children:l.jsx(D,{table:s,unitConfig:[{unitKey:"length",storageUnit:e[0][0],preferredUnit:a}],convertBackToStorageUnit:W,convertBackToString:M,enableCosmeticRounding:L})}),l.jsx(V,{heading:l.jsx(j,{children:"Storage State (Redux)"}),children:l.jsx("pre",{children:l.jsx("code",{children:JSON.stringify(e,null,2)})})})]})};var K,A,_,B,H;U.parameters={...U.parameters,docs:{...(K=U.parameters)==null?void 0:K.docs,source:{originalSource:`() => {
2
+ const [preferredUnit, setPreferredUnit] = useState(initialUnit);
3
+ const [reduxTable, setReduxTable] = useState(initialTable);
4
+
5
+ /*********************************************************************************************************************
6
+ Cell onChange handler
7
+ *********************************************************************************************************************/
8
+ const onUpdateCell = ({
9
+ rowIndex,
10
+ cellIndex,
11
+ value,
12
+ unit
13
+ }) => {
14
+ const nextTable = convertWholeTable ? convertStorageTable({
15
+ reduxTable,
16
+ value,
17
+ unit,
18
+ rowIndex,
19
+ cellIndex
20
+ }) : updateCell({
21
+ reduxTable,
22
+ value,
23
+ rowIndex,
24
+ cellIndex
25
+ });
26
+ setReduxTable(nextTable);
27
+ };
28
+
29
+ /*********************************************************************************************************************
30
+ Construct table view data (same as old Table component, with a new props)
31
+ *********************************************************************************************************************/
32
+ const tableViewData = reduxTable.reduce((acc, row, rowIndex) => {
33
+ if (rowIndex === 0) {
34
+ acc.headers = [{
35
+ cells: [{
36
+ value: 'From'
37
+ }, {
38
+ value: 'To'
39
+ }, {
40
+ value: 'Delta'
41
+ }]
42
+ }, {
43
+ cells: [{
44
+ type: 'AutoUnit',
45
+ unitKey: 'length'
46
+ }, {
47
+ type: 'AutoUnit',
48
+ unitKey: 'length'
49
+ }, {
50
+ type: 'AutoUnit',
51
+ unitKey: 'length'
52
+ }]
53
+ }];
54
+ } else {
55
+ acc.rows = acc.rows.concat({
56
+ cells: row.map((cell, cellIndex) => {
57
+ const specialCell = rowIndex === 1 && cellIndex === 1;
58
+ const type = specialCell ? 'Text' : 'NumberInput';
59
+ const formatDisplayValue = specialCell ? value => \`T* \${value}\` : null;
60
+ const value = cell;
61
+ return {
62
+ value,
63
+ type,
64
+ unitKey: 'length',
65
+ onChange: onUpdateCell,
66
+ formatDisplayValue,
67
+ autoUnit: true
68
+ };
69
+ })
70
+ });
71
+ }
72
+ return acc;
73
+ }, {
74
+ headers: [],
75
+ rows: []
76
+ });
77
+ return <Grid columns="1fr 1fr" gap>
78
+ <Card heading={<Heading>Global View Settings</Heading>}>
79
+ <Field label="Active Unit Template">
80
+ <Select options={getUnitsForQuantity('length')} value={{
81
+ value: preferredUnit
82
+ }} onChange={evt => setPreferredUnit(evt.target.value)} width="100px" />
83
+ </Field>
84
+ </Card>
85
+ <Card heading={<Heading>UnitTable</Heading>}>
86
+ <UnitTable table={tableViewData}
87
+ //New props:
88
+ unitConfig={[{
89
+ unitKey: 'length',
90
+ storageUnit: reduxTable[0][0],
91
+ preferredUnit
92
+ }]} convertBackToStorageUnit={convertBackToStorageUnit} convertBackToString={convertBackToString} enableCosmeticRounding={enableCosmeticRounding} />
93
+ </Card>
94
+ <Card heading={<Heading>Storage State (Redux)</Heading>}>
95
+ <pre>
96
+ <code>{JSON.stringify(reduxTable, null, 2)}</code>
97
+ </pre>
98
+ </Card>
99
+ </Grid>;
100
+ }`,...(_=(A=U.parameters)==null?void 0:A.docs)==null?void 0:_.source},description:{story:"Story",...(H=(B=U.parameters)==null?void 0:B.docs)==null?void 0:H.description}}};const Xe=["UnitTablePrototype"];export{U as UnitTablePrototype,Xe as __namedExportsOrder,Me as default};
@@ -357,7 +357,7 @@
357
357
  }
358
358
  </script>
359
359
 
360
- <script type="module" crossorigin src="./assets/iframe-L_X6E7p9.js"></script>
360
+ <script type="module" crossorigin src="./assets/iframe-NU_z28D3.js"></script>
361
361
  </head>
362
362
 
363
363
  <body>
@@ -1 +1 @@
1
- {"generatedAt":1716467499549,"hasCustomBabel":false,"hasCustomWebpack":false,"hasStaticDirs":false,"hasStorybookEslint":true,"refCount":0,"packageManager":{"type":"yarn","version":"1.22.19"},"features":{"storyStoreV7":true},"preview":{"usesGlobals":false},"framework":{"name":"@storybook/react-vite","options":{}},"builder":"@storybook/builder-vite","renderer":"@storybook/react","storybookVersion":"7.5.3","storybookVersionSpecifier":"^7.5.3","language":"typescript","storybookPackages":{"@storybook/addon-essentials":{"version":"7.5.3"},"@storybook/addon-links":{"version":"7.5.3"},"@storybook/addons":{"version":"7.5.3"},"@storybook/react":{"version":"7.5.3"},"@storybook/react-vite":{"version":"7.5.3"},"eslint-plugin-storybook":{"version":"0.6.15"},"storybook":{"version":"7.5.3"}},"addons":{"@storybook/addon-actions":{"version":"7.5.3"},"@storybook/addon-docs":{"version":"7.5.3"},"storybook-dark-mode":{"version":"3.0.3"}}}
1
+ {"generatedAt":1716537625609,"hasCustomBabel":false,"hasCustomWebpack":false,"hasStaticDirs":false,"hasStorybookEslint":true,"refCount":0,"packageManager":{"type":"yarn","version":"1.22.19"},"features":{"storyStoreV7":true},"preview":{"usesGlobals":false},"framework":{"name":"@storybook/react-vite","options":{}},"builder":"@storybook/builder-vite","renderer":"@storybook/react","storybookVersion":"7.5.3","storybookVersionSpecifier":"^7.5.3","language":"typescript","storybookPackages":{"@storybook/addon-essentials":{"version":"7.5.3"},"@storybook/addon-links":{"version":"7.5.3"},"@storybook/addons":{"version":"7.5.3"},"@storybook/react":{"version":"7.5.3"},"@storybook/react-vite":{"version":"7.5.3"},"eslint-plugin-storybook":{"version":"0.6.15"},"storybook":{"version":"7.5.3"}},"addons":{"@storybook/addon-actions":{"version":"7.5.3"},"@storybook/addon-docs":{"version":"7.5.3"},"storybook-dark-mode":{"version":"3.0.3"}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/react-ui-library",
3
- "version": "4.6.0-beta-1-beta-1",
3
+ "version": "4.7.0-beta-1",
4
4
  "description": "Reusable UI components for React projects",
5
5
  "homepage": "https://oliasoft-open-source.gitlab.io/react-ui-library",
6
6
  "bugs": {
@@ -1,84 +0,0 @@
1
- import{j as i}from"./jsx-runtime-FsUICBgo.js";import{r as f}from"./index-RfLt4OUa.js";import{f as D}from"./immer.esm-bD7SSJ7T.js";import{d as y}from"./index-IQMsp8Ab.js";import{G as K}from"./grid-u1mZpaML.js";import{C as U}from"./card-0r8RRVk-.js";import{F as A}from"./field-kOZPBHf6.js";import{H as T}from"./heading-cUVItwKq.js";import{S as I}from"./select-Z1HqJ5aU.js";import{l as R}from"./lodash-Bmg8FrMx.js";import{u as _}from"./use-previous-VKMmnaK7.js";import{T as H}from"./table-_jWgMFOi.js";import"./index-cCpkwrS5.js";import"./styled-components.browser.esm-qIipjd6c.js";import"./tslib.es6-OIsz3r9a.js";import"./index-VW3EWkuE.js";import"./label-RpB4JmHX.js";import"./common-types-U65vzrrz.js";import"./help-icon-nI9A506M.js";import"./tooltip-ZHdi6rl-.js";import"./index-miLrID2P.js";import"./icon-y1a2N5SZ.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-SGexXf58.js";import"./button-IoNblLER.js";import"./spinner-R8Il4aRe.js";import"./badge-23Ty_zBt.js";import"./select.input-zP5tW20f.js";import"./index.es-JXn3JM7k.js";import"./redux-F5dueAP3.js";import"./objectSpread2-93s0nBry.js";import"./pagination-Eaj_UOBW.js";import"./input-iDZqV-2m.js";import"./input-group-R8LoqKRn.js";import"./input-group-addon-BHVsW9mL.js";import"./number-input-d7hXQldd.js";import"./check-box-BX5dfQFk.js";import"./slider-_5NQKbM-.js";import"./index-ugi_ZH6T.js";import"./popover-uAo1e4-D.js";const F=a=>a.reduce(({preferredUnits:o,storageUnits:r},{unitKey:l,preferredUnit:d,storageUnit:s})=>(o[l]=d,r[l]=s,{preferredUnits:o,storageUnits:r}),{preferredUnits:{},storageUnits:{}}),E=({headers:a,rows:o,selectedUnits:r,storageUnits:l,onChangeUnit:d,cosmeticRounding:s=!1})=>{const e=a.map(t=>({...t,cells:t.cells.map(u=>{if(u.type==="AutoUnit"){const{unitKey:n}=u;return{value:r[n],type:"Select",options:y.getUnitsForQuantity(n),native:!0,onChange:p=>d({unitKey:n,value:p.target.value})}}return u})})),c=o.map((t,u)=>({...t,cells:t.cells.map((n,p)=>{const{formatDisplayValue:h}=n,v=y.convertAndGetValue(n.value,r[n.unitKey],l[n.unitKey]),g=s?y.round(v,14):v,m=h?h(g):g;return{...n,value:m,onChange:b=>{n.onChange({rowIndex:u,cellIndex:p,value:b.target.value,unit:r[n.unitKey]})}}})}));return{convertedHeaders:e,convertedRows:c}},w=({table:a,unitConfig:o})=>{const{rows:r,headers:l,otherProps:d}=a,{storageUnits:s,preferredUnits:e}=F(o),c=_(e),[t,u]=f.useState(e),n=({unitKey:m,value:b})=>u({...t,[m]:b}),p=m=>E({headers:l,rows:r,selectedUnits:m,storageUnits:s,onChangeUnit:n}),h=p(t),[v,g]=f.useState(h);return f.useEffect(()=>{!R.isEqual(e,c)&&(u(e),g(p(e)))},[o]),f.useEffect(()=>{g(p(t))},[a]),f.useEffect(()=>{g(p(t))},[t]),i.jsx(H,{table:{...d,headers:v.convertedHeaders,rows:v.convertedRows}})};try{w.displayName="UnitTable",w.__docgenInfo={description:"",displayName:"UnitTable",props:{table:{defaultValue:null,description:"",name:"table",required:!0,type:{name:"any"}},unitConfig:{defaultValue:null,description:"",name:"unitConfig",required:!0,type:{name:"any"}}}}}catch{}const Ee={title:"Basic/UnitTable",args:{}},j="m",G=3,P=!1,N=(a,o)=>{const r=[o,o,o],l=[...Array(Number(a))].map((d,s)=>{const e=s,c=s+1.25,t=c-e;return[String(e),String(c),String(t)]});return[r].concat(l)},q=N(G,j),O=({reduxTable:a,value:o,unit:r,rowIndex:l,cellIndex:d})=>{const s=a[0][0];return D(a,e=>{const c=y.convertAndGetValue(o,s,r),t=String(c);e[l+1][d]=t})},x=()=>{const[a,o]=f.useState(j),[r,l]=f.useState(q),d=({rowIndex:e,cellIndex:c,value:t,unit:u})=>{const n=O({reduxTable:r,value:t,unit:u,rowIndex:e,cellIndex:c});l(n)},s=r.reduce((e,c,t)=>(t===0?e.headers=[{cells:[{value:"From"},{value:"To"},{value:"Delta"}]},{cells:[{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"length"}]}]:e.rows=e.rows.concat({cells:c.map((u,n)=>{const p=t===1&&n===1;return{value:u,type:p?"Text":"NumberInput",unitKey:"length",onChange:d,formatDisplayValue:p?m=>`T* ${m}`:null}})}),e),{headers:[],rows:[]});return i.jsxs(K,{columns:"1fr 1fr",gap:!0,children:[i.jsx(U,{heading:i.jsx(T,{children:"Global View Settings"}),children:i.jsx(A,{label:"Active Unit Template",children:i.jsx(I,{options:y.getUnitsForQuantity("length"),value:{value:a},onChange:e=>o(e.target.value),width:"100px"})})}),i.jsx(U,{heading:i.jsx(T,{children:"UnitTable"}),children:i.jsx(w,{table:s,unitConfig:[{unitKey:"length",storageUnit:r[0][0],preferredUnit:a}],cosmeticRounding:P})}),i.jsx(U,{heading:i.jsx(T,{children:"Storage State (Redux)"}),children:i.jsx("pre",{children:i.jsx("code",{children:JSON.stringify(r,null,2)})})})]})};var C,S,V;x.parameters={...x.parameters,docs:{...(C=x.parameters)==null?void 0:C.docs,source:{originalSource:`() => {
2
- const [preferredUnit, setPreferredUnit] = useState(initialUnit);
3
- const [reduxTable, setReduxTable] = useState(initialTable);
4
- const onUpdateCell = ({
5
- rowIndex,
6
- cellIndex,
7
- value,
8
- unit
9
- }) => {
10
- const nextTable = convertStorageTable({
11
- reduxTable,
12
- value,
13
- unit,
14
- rowIndex,
15
- cellIndex
16
- });
17
- setReduxTable(nextTable);
18
- };
19
- const tableViewData = reduxTable.reduce((acc, row, rowIndex) => {
20
- if (rowIndex === 0) {
21
- acc.headers = [{
22
- cells: [{
23
- value: 'From'
24
- }, {
25
- value: 'To'
26
- }, {
27
- value: 'Delta'
28
- }]
29
- }, {
30
- cells: [{
31
- type: 'AutoUnit',
32
- unitKey: 'length'
33
- }, {
34
- type: 'AutoUnit',
35
- unitKey: 'length'
36
- }, {
37
- type: 'AutoUnit',
38
- unitKey: 'length'
39
- }]
40
- }];
41
- } else {
42
- acc.rows = acc.rows.concat({
43
- cells: row.map((cell, cellIndex) => {
44
- const specialCell = rowIndex === 1 && cellIndex === 1;
45
- const type = specialCell ? 'Text' : 'NumberInput';
46
- const formatDisplayValue = specialCell ? value => \`T* \${value}\` : null;
47
- const value = cell;
48
- return {
49
- value,
50
- type,
51
- unitKey: 'length',
52
- onChange: onUpdateCell,
53
- formatDisplayValue
54
- };
55
- })
56
- });
57
- }
58
- return acc;
59
- }, {
60
- headers: [],
61
- rows: []
62
- });
63
- return <Grid columns="1fr 1fr" gap>
64
- <Card heading={<Heading>Global View Settings</Heading>}>
65
- <Field label="Active Unit Template">
66
- <Select options={getUnitsForQuantity('length')} value={{
67
- value: preferredUnit
68
- }} onChange={evt => setPreferredUnit(evt.target.value)} width="100px" />
69
- </Field>
70
- </Card>
71
- <Card heading={<Heading>UnitTable</Heading>}>
72
- <UnitTable table={tableViewData} unitConfig={[{
73
- unitKey: 'length',
74
- storageUnit: reduxTable[0][0],
75
- preferredUnit
76
- }]} cosmeticRounding={convertWholeTable} />
77
- </Card>
78
- <Card heading={<Heading>Storage State (Redux)</Heading>}>
79
- <pre>
80
- <code>{JSON.stringify(reduxTable, null, 2)}</code>
81
- </pre>
82
- </Card>
83
- </Grid>;
84
- }`,...(V=(S=x.parameters)==null?void 0:S.docs)==null?void 0:V.source}}};const Ge=["UnitTablePrototype"];export{x as UnitTablePrototype,Ge as __namedExportsOrder,Ee as default};