@oliasoft-open-source/react-ui-library 4.6.11 → 4.6.13
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.
- package/dist/index.d.ts +22 -0
- package/dist/index.js +150 -1
- package/dist/index.js.map +1 -1
- package/dist/storybook/assets/Color-6VNJS4EI-0Es0Y_hf.js +1 -0
- package/dist/storybook/assets/DocsRenderer-NNNQARDV-8Agqr_1z.js +1 -0
- package/dist/storybook/assets/WithTooltip-V3YHNWJZ-VkPCPx4O.js +1 -0
- package/dist/storybook/assets/{accordion-M-sY23Hd.js → accordion-MRdNs3mQ.js} +1 -1
- package/dist/storybook/assets/{accordion.stories-Ckfdc3yE.js → accordion.stories-fQEMJlxQ.js} +2 -2
- package/dist/storybook/assets/{actions-eW7plDvv.js → actions-0lKGEXVi.js} +1 -1
- package/dist/storybook/assets/{actions.stories-v91cA8Aa.js → actions.stories-1G9apUqW.js} +1 -1
- package/dist/storybook/assets/{afe.stories-O_jbxAft.js → afe.stories-YtbvNBzx.js} +2 -2
- package/dist/storybook/assets/{badge.stories-AQYzIvli.js → badge.stories-YE5hHtSe.js} +1 -1
- package/dist/storybook/assets/{blowout.stories-Vff9htu-.js → blowout.stories-xSwBWe5T.js} +1 -1
- package/dist/storybook/assets/{button-group-rkjreZ1T.js → button-group-0RTzcUIP.js} +1 -1
- package/dist/storybook/assets/{button-group.stories-HnVY5ZDT.js → button-group.stories-eQ5h-50o.js} +1 -1
- package/dist/storybook/assets/{button-yLYf8aC9.js → button-pSDG6Ka2.js} +1 -1
- package/dist/storybook/assets/{button.stories-sp9SbrbR.js → button.stories-QDP0P6s7.js} +6 -6
- package/dist/storybook/assets/{buttons-and-links-05g5wWR_.js → buttons-and-links-dSpYF4I_.js} +2 -2
- package/dist/storybook/assets/{card.stories--XA-NPtn.js → card.stories-nEB15GEp.js} +1 -1
- package/dist/storybook/assets/{casing-loads.stories-qq7nVcz2.js → casing-loads.stories-uu-yK01O.js} +2 -2
- package/dist/storybook/assets/{cell.stories-7M24NqPM.js → cell.stories-jU_N8b9E.js} +2 -2
- package/dist/storybook/assets/{check-box-TRAFDvOc.js → check-box--ih7cmR1.js} +1 -1
- package/dist/storybook/assets/{check-box.stories-xj8y4pvN.js → check-box.stories-WFbOF7kK.js} +1 -1
- package/dist/storybook/assets/{chunk-HLWAVYOI-4ciTSFM-.js → chunk-HLWAVYOI-TfoHKvis.js} +1 -1
- package/dist/storybook/assets/color-LJZaNnUB.js +25 -0
- package/dist/storybook/assets/{column.stories-wGhSlroa.js → column.stories-uR7F6GLZ.js} +1 -1
- package/dist/storybook/assets/dialog-kardLd1s.js +1 -0
- package/dist/storybook/assets/{drawer-NuViVQqw.js → drawer-fq99yzU7.js} +1 -1
- package/dist/storybook/assets/{drawer.stories-mIhzICjZ.js → drawer.stories-zos7-Jef.js} +2 -2
- package/dist/storybook/assets/{empty.stories-3hs4gUgZ.js → empty.stories-V5nX7JMj.js} +1 -1
- package/dist/storybook/assets/extends-dGVwEr9R.js +1 -0
- package/dist/storybook/assets/{field-UZtORY6D.js → field-V2qkm8ON.js} +1 -1
- package/dist/storybook/assets/{field.stories-DPmPvDCm.js → field.stories-oQ-oKw9H.js} +1 -1
- package/dist/storybook/assets/file-input-ASEHnODl.js +1 -0
- package/dist/storybook/assets/file-input.stories-K1-X4A2h.js +66 -0
- package/dist/storybook/assets/{flex.stories-7GcqtV92.js → flex.stories-rUC8irnS.js} +1 -1
- package/dist/storybook/assets/footer.stories-6IYhl3Y9.js +3 -0
- package/dist/storybook/assets/form.stories-TfCufaed.js +49 -0
- package/dist/storybook/assets/formation.stories-arormd_z.js +74 -0
- package/dist/storybook/assets/{formatter-SWP5E3XI-zMN0v4F6.js → formatter-SWP5E3XI-E_AUyOmB.js} +2 -2
- package/dist/storybook/assets/{heading-AvGkZ8ae.js → heading-OSdaYHYE.js} +1 -1
- package/dist/storybook/assets/{heading.stories-aJs549tG.js → heading.stories-YhoAJ5xD.js} +1 -1
- package/dist/storybook/assets/{help-icon-4sFVvBkZ.js → help-icon-jdxRTcvs.js} +1 -1
- package/dist/storybook/assets/{help-icon.stories-9Apwwl_z.js → help-icon.stories-NKBYmv_o.js} +1 -1
- package/dist/storybook/assets/icon-_m67DAr0.js +8 -0
- package/dist/storybook/assets/{icon.stories-j-b_Exev.js → icon.stories-2aZia1VV.js} +1 -1
- package/dist/storybook/assets/iframe-XBWdLgXl.js +7 -0
- package/dist/storybook/assets/{index-ozIFb807.js → index-g34udPZo.js} +5 -5
- package/dist/storybook/assets/{index.es-VXFRDikp.js → index.es-HG2GUH9i.js} +4 -4
- package/dist/storybook/assets/inheritsLoose-Y9jOMJLd.js +1 -0
- package/dist/storybook/assets/{input-group.stories-wQfcKDtd.js → input-group.stories-HXoMZkHB.js} +2 -2
- package/dist/storybook/assets/{input-validation-K4-DmgHM.js → input-validation-EHlvLdps.js} +2 -2
- package/dist/storybook/assets/{inputs-erHcgGCK.js → inputs-UqnSQlzK.js} +2 -2
- package/dist/storybook/assets/{label-am612zWx.js → label-KLaw_y6R.js} +1 -1
- package/dist/storybook/assets/{label.stories-QPyTvO7T.js → label.stories-8KngvJd3.js} +1 -1
- package/dist/storybook/assets/layout-forms-n0KRZ2JT.js +16 -0
- package/dist/storybook/assets/{layout-general-nk8z6z9i.js → layout-general-4Z_dYwOs.js} +2 -2
- package/dist/storybook/assets/{list-LWmKQq1G.js → list-HBgplEUa.js} +1 -1
- package/dist/storybook/assets/{list.stories-fgw3Kx3W.js → list.stories-AC7IBnuA.js} +2 -2
- package/dist/storybook/assets/{list.stories-data-IWB082tu.js → list.stories-data-YuaX7eYb.js} +1 -1
- package/dist/storybook/assets/{loader.stories-NaDVDl7Z.js → loader.stories-A0lEe-_I.js} +1 -1
- package/dist/storybook/assets/{menu.stories-K4nBhFj_.js → menu.stories-wWr6qpLS.js} +6 -6
- package/dist/storybook/assets/{message-CRKuTfOl.js → message-bbAE2zjv.js} +1 -1
- package/dist/storybook/assets/{message.stories-CSw6ElMp.js → message.stories-rANJfalB.js} +1 -1
- package/dist/storybook/assets/{meta-content-70Z_mWPh.js → meta-content-xcMHnFul.js} +1 -1
- package/dist/storybook/assets/{modal.stories-10-XQKON.js → modal.stories-GY64tFtP.js} +2 -2
- package/dist/storybook/assets/{number-input.stories-59JRvVcf.js → number-input.stories-oaHrqqEo.js} +5 -5
- package/dist/storybook/assets/{option-dropdown.stories-ZCnTHpeT.js → option-dropdown.stories-IIXgJvpF.js} +1 -1
- package/dist/storybook/assets/{padding-and-spacing-uyBZRJ5c.js → padding-and-spacing-6Wmzdt8V.js} +2 -2
- package/dist/storybook/assets/{page.stories-GrhPKgmq.js → page.stories-jmoBCw29.js} +1 -1
- package/dist/storybook/assets/{pagination-yFWOmymz.js → pagination-LajpPl1E.js} +1 -1
- package/dist/storybook/assets/{pagination.stories-IahSsrYh.js → pagination.stories-QNaX-nfT.js} +2 -2
- package/dist/storybook/assets/{pop-confirm.stories-StkaY9mZ.js → pop-confirm.stories-qL_Z99O8.js} +1 -1
- package/dist/storybook/assets/{popover-YDVuwgEX.js → popover-dGHzPDyA.js} +1 -1
- package/dist/storybook/assets/popover.stories-4yXf4qke.js +1 -0
- package/dist/storybook/assets/{preview-mNdmFu2O.js → preview-izL99lIf.js} +3 -3
- package/dist/storybook/assets/preview-sTJNaY8B.js +7 -0
- package/dist/storybook/assets/projects.stories-gJiQXNLT.js +47 -0
- package/dist/storybook/assets/{radio-button-g10vtbgR.js → radio-button-YSXmxvG2.js} +1 -1
- package/dist/storybook/assets/{radio-button.stories-Lm3AgSPw.js → radio-button.stories-kcqjIFI9.js} +1 -1
- package/dist/storybook/assets/react-router-dom-4Z66xYqZ.js +8 -0
- package/dist/storybook/assets/{reservoirs.stories-UloVc7w8.js → reservoirs.stories-SK2d9Fio.js} +2 -2
- package/dist/storybook/assets/{rich-text-input.stories-g_yH3vr8.js → rich-text-input.stories-zaKtuZiu.js} +3 -3
- package/dist/storybook/assets/{row.stories-c7qJDc3O.js → row.stories-U-yrdTYI.js} +2 -2
- package/dist/storybook/assets/select-7lyQEtzA.js +1 -0
- package/dist/storybook/assets/{select.stories-XhlzQ7cL.js → select.stories-xDbB-kMM.js} +2 -2
- package/dist/storybook/assets/{side-bar-hJdv8LbH.js → side-bar-5P37lMUr.js} +1 -1
- package/dist/storybook/assets/{side-bar.stories-Yhz9jXs2.js → side-bar.stories-JTyeqg4a.js} +1 -1
- package/dist/storybook/assets/{site.stories-KJRfCDdv.js → site.stories-h1X4It52.js} +2 -2
- package/dist/storybook/assets/slider-bFd0qknB.js +7 -0
- package/dist/storybook/assets/{slider.stories-R5xGydpl.js → slider.stories-EBNa8dCL.js} +2 -2
- package/dist/storybook/assets/smart-upload-modal.stories--J7j_ykg.js +25 -0
- package/dist/storybook/assets/{spacer.stories-9tR72ZgH.js → spacer.stories-Bp11g7WY.js} +1 -1
- package/dist/storybook/assets/syntaxhighlighter-B5GMVT5T-ACJ3LFR3.js +1 -0
- package/dist/storybook/assets/{table-plX5wbPy.js → table-YO72eq6-.js} +1 -1
- package/dist/storybook/assets/{table.stories-w4weqjQS.js → table.stories-87uvXmuW.js} +2 -2
- package/dist/storybook/assets/{table.stories-data-9T_1BLo6.js → table.stories-data-hDQBe08f.js} +1 -1
- package/dist/storybook/assets/text-link.stories-Plmiu8NV.js +14 -0
- package/dist/storybook/assets/{textarea-dAYYNVTs.js → textarea-XY_iUfzV.js} +1 -1
- package/dist/storybook/assets/{textarea.stories-tvP01BwE.js → textarea.stories-tpIT4O3R.js} +1 -1
- package/dist/storybook/assets/{title.stories-o7fCo4X-.js → title.stories-mhWM-m41.js} +3 -3
- package/dist/storybook/assets/{toaster-yPcd4ELJ.js → toaster-IL_npIpU.js} +1 -1
- package/dist/storybook/assets/{toaster.stories-4aAkEVaa.js → toaster.stories-2399ErHt.js} +1 -1
- package/dist/storybook/assets/{toggle-m3EwNS6z.js → toggle-KddTHsTd.js} +1 -1
- package/dist/storybook/assets/{toggle.stories-jaduywRN.js → toggle.stories-ZPLKo1CO.js} +1 -1
- package/dist/storybook/assets/{tooltip.test-case.stories-Sq5qLreq.js → tooltip.test-case.stories-e7KXJ1zz.js} +1 -1
- package/dist/storybook/assets/{top-bar-8ASbRXqr.js → top-bar-xIrfLvE9.js} +1 -1
- package/dist/storybook/assets/top-bar.stories-OWyuBUT6.js +21 -0
- package/dist/storybook/assets/{top-bar.testcase.stories-Yjz8R3nX.js → top-bar.testcase.stories-uu_mJjq3.js} +1 -1
- package/dist/storybook/assets/{tree.stories-VhgtyM-i.js → tree.stories-KFifRduQ.js} +1 -1
- package/dist/storybook/assets/{unit-input.stories--JK_4hwn.js → unit-input.stories-EPjs0Jo3.js} +1 -1
- package/dist/storybook/assets/unit-table.stories-KSzMk2ae.js +142 -0
- package/dist/storybook/iframe.html +1 -1
- package/dist/storybook/index.json +1 -1
- package/dist/storybook/project.json +1 -1
- package/dist/storybook/stories.json +1 -1
- package/package.json +1 -1
- package/dist/storybook/assets/Color-6VNJS4EI-GQwgd_ld.js +0 -1
- package/dist/storybook/assets/DocsRenderer-NNNQARDV-A0C5N1_E.js +0 -1
- package/dist/storybook/assets/WithTooltip-V3YHNWJZ-_ZdSUz6-.js +0 -1
- package/dist/storybook/assets/color-Sklm1A7t.js +0 -25
- package/dist/storybook/assets/dialog--p0h3TPY.js +0 -1
- package/dist/storybook/assets/file-input.stories-Mcb6uqW7.js +0 -66
- package/dist/storybook/assets/footer.stories-rwoGk_OR.js +0 -3
- package/dist/storybook/assets/form.stories-56ONaO3q.js +0 -49
- package/dist/storybook/assets/formation.stories-DzFYQPb4.js +0 -74
- package/dist/storybook/assets/icon-8EQazuuW.js +0 -8
- package/dist/storybook/assets/iframe-SOjg2hBS.js +0 -7
- package/dist/storybook/assets/inheritsLoose-8sb_A2v4.js +0 -1
- package/dist/storybook/assets/layout-forms-Zo8OvCqi.js +0 -16
- package/dist/storybook/assets/popover.stories-QeTPelqE.js +0 -1
- package/dist/storybook/assets/preview-HCxJn5W4.js +0 -7
- package/dist/storybook/assets/projects.stories-HDwAJ2lH.js +0 -47
- package/dist/storybook/assets/react-router-dom-EZH1n7K1.js +0 -8
- package/dist/storybook/assets/select-xiPCWaz8.js +0 -1
- package/dist/storybook/assets/slider-at3_DXQg.js +0 -7
- package/dist/storybook/assets/syntaxhighlighter-B5GMVT5T-bjqZHg5d.js +0 -1
- package/dist/storybook/assets/text-link.stories-Mx9ojcOC.js +0 -14
- package/dist/storybook/assets/top-bar.stories-9LS979MG.js +0 -21
- package/dist/storybook/assets/unit-table.stories-fbIAsylx.js +0 -142
package/dist/storybook/assets/{unit-input.stories--JK_4hwn.js → unit-input.stories-EPjs0Jo3.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as m}from"./index-RfLt4OUa.js";import{d as r,r as it}from"./index-qZmQ7nA9.js";import{c as st}from"./index-VW3EWkuE.js";import{u as ut}from"./use-previous-VKMmnaK7.js";import{M as we}from"./actions-eW7plDvv.js";import{I as ot}from"./input-group-addon-BHVsW9mL.js";import{B as c}from"./button-yLYf8aC9.js";import{T as dt}from"./tooltip-gljV_DQ0.js";import{I as ct}from"./input-group-R8LoqKRn.js";import{S}from"./spacer-Yji9g2AW.js";import{T as mt}from"./text-6KQ6ntOV.js";import{I as pt}from"./input-w-UScEUy.js";import{M as Ee}from"./types-VB5zD18b.js";import{l as E}from"./lodash-Bmg8FrMx.js";import{D as gt}from"./divider-RwW2f_N0.js";import{R as Wn,C as pe}from"./row-vFUhHoz5.js";import{F as I}from"./field-UZtORY6D.js";import{M as ge}from"./message-CRKuTfOl.js";import"./index-cCpkwrS5.js";import"./common-types-U65vzrrz.js";import"./disabled-context-urNQThQz.js";import"./icon-8EQazuuW.js";import"./objectWithoutPropertiesLoose-9Q1jwsKS.js";import"./inheritsLoose-8sb_A2v4.js";import"./tslib.es6-OIsz3r9a.js";import"./index-4QtD-hFu.js";import"./types-5uVBABF4.js";import"./badge-23Ty_zBt.js";import"./spinner-R8Il4aRe.js";import"./index-miLrID2P.js";import"./styled-components.browser.esm-qIipjd6c.js";import"./label-am612zWx.js";import"./help-icon-4sFVvBkZ.js";const ht=()=>{const n=m.useRef(null);return m.useLayoutEffect(()=>{n.current&&(n.current(),n.current=null)}),t=>{n.current=t}},vt=(n,a)=>{const t=a==null?void 0:a[n];return t||(console.log(`Warning: 'unitTemplate' does not define a preferred unit for '${n}'. Defaulting to standard unit.`),r.unitFromQuantity(n)??"")};var b=(n=>(n.CUSTOM="custom",n.PREDEFINED="predefined",n))(b||{});const Tn=n=>n==="undefined"||n===void 0||n===""||n==="null"||n===null||n==="NaN"||isNaN(n),Rn=(n="",a,t="",s=!1)=>{if(s)return n;if(a&&!Tn(n))try{const u=r.isValueWithUnit(n)?n:r.withUnit(n,t),o=r.convertSamePrecision(u,a);return r.getValue(o)}catch{}return n},ft=n=>n?!!r.getUnit(n):!1,F=(n="",a,t,s)=>{if(s)return n;const u=ft(n)||r.isValueWithUnit(n),o=r.getValue(n);return Tn(o)?o:u?Rn(o,a,t,s):n},Ne=n=>E.isObject(n)&&!E.isArray(n)&&!E.isFunction(n)?E.get(n,"fieldName",""):typeof n=="string"?n:"",Ct=n=>E.isObjectLike(n)&&E.has(n,"message"),bt=n=>typeof n=="string"?n:Ct(n)?n.message:null;var Ut=it();const yt=n=>n.search(RegExp(/(^0{2}\.)|(^0+[1-9])/g))===0,Ae=(n,a)=>{var j;const{allowEmpty:t=!1,autoValue:s,placeholder:u,disabledValidation:o=!1}=a||{},i=String(n);if(o||s||u)return null;const g=Ut.isValueWithUnit(i)?r.getValue(i):i;if(t&&g==="")return null;if(yt(g))return"Invalid number format due to leading zeroes";const h=r.validateNumber(g);if(!h.valid){const re=((j=h==null?void 0:h.errors)==null?void 0:j[0])??null;return bt(re)}return null},Pe=(n="")=>{var a;return(a=r.KNOWN_UNITS)==null?void 0:a.includes(n)},xt=(n,a)=>{const t=r.getUnit(n||"");return Pe(a)&&Pe(t)},Vt="_predefinedMenuActive_1yvt4_1",It={predefinedMenuActive:Vt},p=({name:n,placeholder:a="",disabled:t=!1,disabledUnit:s=!1,error:u=null,left:o=!1,small:i=!1,width:g="100%",value:h,unitkey:j="",initUnit:re,noConversion:Ln=!1,onChange:ie=()=>{},onClick:kt=()=>{},onFocus:Kn=()=>{},onSwitchUnit:he=()=>{},unitTemplate:ve,doNotConvertValue:A=!1,testId:w,warning:$n=null,predefinedOptions:x,initialPredefinedOption:Hn=!1,shouldLinkAutomaticly:fe=!0,selectedPredefinedOptionKey:Ce,validationCallback:be=()=>({name:"",error:null}),disabledValidation:Ue=!1,allowEmpty:ye=!1,autoValue:V})=>{typeof h=="number"&&(h=`${h}`);const zn=ht(),[se="",P=""]=h!==void 0?r.split(h):[],xe=V?r.getUnit(V):"",Ve=m.useMemo(()=>vt(j,ve),[j,ve]),Jn=xt(h,Ve),U=re||Ve||P,Yn=ut(U),Ie=F(h,U,P,A),je=F(V,U,xe,A),Zn=Ie!==""?{value:Ie,unit:U}:je!==""?{value:je,unit:U}:{value:se,unit:P},[v,Y]=m.useState(Zn),[Gn,ue]=m.useState(null),[k,oe]=m.useState(Hn?b.PREDEFINED:b.CUSTOM),de=se===""&&V,D=x&&x.find(l=>{if(Ce)return Ce===l.valueKey;const d=r.isValueWithUnit(l.value)?r.getUnit(l.value):"";return r.withUnit(Rn(h,d),d)===l.value}),Qn=()=>{if(j)try{const l=de?V:h??"";let d=r.altUnitsList(l,j);return r.getValue(l)===""?d.map(f=>["",f[1]]):d}catch{return null}},Xn=l=>{const d=Ne(n),f=l.target,{value:y,selectionStart:X}=f,Se=r.cleanNumStr(y.replaceAll(" ","").replaceAll("|","")),ce=r.withUnit(Se,(v==null?void 0:v.unit)||""),at=r.getValue(ce),me=Ae(at,{allowEmpty:ye,autoValue:V,placeholder:a,disabledValidation:Ue});if(me===null){ie({target:{value:ce,name:d}});const[lt,rt]=r.split(ce);Y({value:lt,unit:rt}),ue(null),be(d,null)}else Y({value:Se,unit:v.unit}),ue(me),be(d,me);zn(()=>{f.selectionStart=X,f.selectionEnd=X})},et=(l,d)=>{d===v.unit||isNaN(Number(l))||(Y({value:l,unit:d}),he&&he(d))};m.useEffect(()=>{if(U){let f,y="";Yn!==U?(f=F(h,U,P,A),y=U):r.withUnit(v.value,v.unit)!==h&&(f=F(h,v.unit,P,A),y=v.unit),f!==void 0&&Y({value:f,unit:y}),x&&oe(D&&fe?b.PREDEFINED:b.CUSTOM)}const l=r.checkAndCleanDecimalComma(se),d=Ae(l,{allowEmpty:ye,autoValue:V,placeholder:a,disabledValidation:Ue});ue(d)},[U,h,u,fe]);const Z=Qn(),G=r.label(v.unit)||v.unit||"",nt=Ln||!Z||Z&&Z.length===1,ke=Ne(n);let Q;const tt=l=>{const[d,f=""]=r.isValueWithUnit(l.value)?r.split(l.value):[l.value];return{type:Ee.OPTION,inline:!0,onClick:()=>{r.validateNumber(d).valid&&!t&&(oe(b.PREDEFINED),ie({target:{value:l.value,name:typeof n=="string"?n:(n==null?void 0:n.fieldName)||"",predefinedSelected:!0,predefinedOption:l}}))},label:e.jsxs(e.Fragment,{children:[e.jsx(mt,{children:l.label}),e.jsx(S,{width:"20px",height:"0"})]}),description:r.isValueWithUnit(l.value)?`${d} ${f}`:l.value,selected:D===l&&k===b.PREDEFINED}};if(Q=[{type:Ee.OPTION,inline:!0,onClick:()=>{k!==b.CUSTOM&&!t&&ie({target:{value:r.withUnit(v.value,v.unit),name:typeof n=="string"?n:(n==null?void 0:n.fieldName)||""}})},label:"Custom",selected:k===b.CUSTOM}],x!=null&&x.length){const l=x.map(tt);Q=[...Q,...l]}return e.jsx("div",{className:k===b.PREDEFINED?st(It.predefinedMenuActive):"",children:e.jsxs(ct,{small:i,width:g,children:[x&&e.jsx(dt,{text:k===b.PREDEFINED?D==null?void 0:D.label:"",children:e.jsx(we,{maxHeight:380,groupOrder:"first",testId:w&&`${w}-predefined-menu`,disabled:t,menu:{colored:!0,trigger:"Component",component:e.jsx(c,{groupOrder:"first",active:k===b.PREDEFINED,icon:k===b.PREDEFINED?"link":"unlink"}),small:i,sections:Q}})}),e.jsx(pt,{type:"text",name:ke,testId:w,disabled:t,placeholder:de?F(V,v.unit,xe,A):a,value:v.value,onChange:Xn,onFocus:Kn,error:u||Gn,warning:$n,right:!o},ke),G&&(nt||!Jn?e.jsx(ot,{groupOrder:"last",children:G}):e.jsx(we,{maxHeight:380,groupOrder:"last",disabled:s,testId:w&&`${w}-menu`,menu:{label:G,trigger:"DropDownButton",small:i,sections:Z.map(([l,d,f])=>{const y=f||d||"";return{type:"Option",label:isNaN(Number(l))?"":l,inline:!0,onClick:X=>{X.stopPropagation(),et(de?"":l,d)},description:y,selected:y===G,testId:`${w}-unit-${y}`}})}}))]})})};try{p.displayName="UnitInput",p.__docgenInfo={description:"",displayName:"UnitInput",props:{name:{defaultValue:null,description:"",name:"name",required:!0,type:{name:"string | { fieldName?: string | undefined; }"}},placeholder:{defaultValue:{value:""},description:"",name:"placeholder",required:!1,type:{name:"string"}},disabled:{defaultValue:{value:"false"},description:"",name:"disabled",required:!1,type:{name:"boolean"}},disabledUnit:{defaultValue:{value:"false"},description:"",name:"disabledUnit",required:!1,type:{name:"boolean"}},error:{defaultValue:{value:"null"},description:"",name:"error",required:!1,type:{name:"string | boolean | null"}},left:{defaultValue:{value:"false"},description:"",name:"left",required:!1,type:{name:"boolean"}},small:{defaultValue:{value:"false"},description:"",name:"small",required:!1,type:{name:"boolean"}},width:{defaultValue:{value:"100%"},description:"",name:"width",required:!1,type:{name:"string | number"}},value:{defaultValue:null,description:"",name:"value",required:!1,type:{name:"string"}},unitkey:{defaultValue:{value:""},description:"",name:"unitkey",required:!1,type:{name:"string"}},initUnit:{defaultValue:null,description:"",name:"initUnit",required:!1,type:{name:"string"}},noConversion:{defaultValue:{value:"false"},description:"",name:"noConversion",required:!1,type:{name:"boolean"}},doNotConvertValue:{defaultValue:{value:"false"},description:"",name:"doNotConvertValue",required:!1,type:{name:"boolean"}},testId:{defaultValue:null,description:"",name:"testId",required:!1,type:{name:"string"}},warning:{defaultValue:{value:"null"},description:"",name:"warning",required:!1,type:{name:"string | null"}},predefinedOptions:{defaultValue:null,description:"",name:"predefinedOptions",required:!1,type:{name:"IPredefinedOption[]"}},initialPredefinedOption:{defaultValue:{value:"false"},description:"",name:"initialPredefinedOption",required:!1,type:{name:"boolean"}},shouldLinkAutomaticly:{defaultValue:{value:"true"},description:"",name:"shouldLinkAutomaticly",required:!1,type:{name:"boolean"}},selectedPredefinedOptionKey:{defaultValue:null,description:"",name:"selectedPredefinedOptionKey",required:!1,type:{name:"string"}},validationCallback:{defaultValue:{value:"() => ({ name: '', error: null })"},description:"",name:"validationCallback",required:!1,type:{name:"((name: string, message: string | null) => { name: string; error: string | null; })"}},disabledValidation:{defaultValue:{value:"false"},description:"",name:"disabledValidation",required:!1,type:{name:"boolean"}},allowEmpty:{defaultValue:{value:"false"},description:"",name:"allowEmpty",required:!1,type:{name:"boolean"}},autoValue:{defaultValue:null,description:"",name:"autoValue",required:!1,type:{name:"string"}},onChange:{defaultValue:{value:"() => {}"},description:"",name:"onChange",required:!1,type:{name:"(event: ChangeEvent<HTMLInputElement> | ICustomChangeEvent) => void"}},onSwitchUnit:{defaultValue:{value:"() => {}"},description:"",name:"onSwitchUnit",required:!1,type:{name:"((unit: string) => void)"}},onClick:{defaultValue:{value:"() => {}"},description:"",name:"onClick",required:!1,type:{name:"MouseEventHandler<HTMLInputElement>"}},onFocus:{defaultValue:{value:"() => {}"},description:"",name:"onFocus",required:!1,type:{name:"FocusEventHandler<HTMLInputElement>"}},unitTemplate:{defaultValue:null,description:"",name:"unitTemplate",required:!1,type:{name:"Record<string, any>"}}}}}catch{}const{useArgs:jt}=__STORYBOOK_MODULE_ADDONS__,sa={title:"Basic/UnitInput",component:p,args:{name:"example",unitkey:"length",value:"123|m"}},C=n=>{const[a,t]=jt(),s=u=>{t({value:u.target.value})};return e.jsx(p,{...n,onChange:s})},ee=C.bind({}),M=C.bind({});M.args={initUnit:"ft",unitTemplate:{length:"ft"}};const _=C.bind({});_.args={value:'123|"',unitkey:'"'};const O=C.bind({});O.args={width:"180px"};const B=C.bind({});B.args={noConversion:!0};const q=C.bind({});q.args={small:!0};const W=C.bind({});W.args={error:"Error message goes here"};const T=C.bind({});T.args={value:"asas123asd|%"};const N=C.bind({});N.args={disabled:!0,disabledUnit:!0};N.parameters={docs:{description:{story:"Each part of UnitInput can be disabled separately. `disabled` disables only the main text input, `disabledUnit` disables only the unit menu. **Needs review (comes from Reservoir input requirements)**"}}};const R=C.bind({});R.args={disabled:!0,disabledUnit:!0,noConversion:!0};const L=C.bind({});L.args={disabledUnit:!0,unitkey:void 0};const K=C.bind({});K.args={disabledUnit:!0,unitkey:"length"};const $=C.bind({});$.args={disabledUnit:!1,disabled:!0};const H=n=>{const[a,t]=m.useState("123|m"),[s,u]=m.useState("223|m"),[o,i]=m.useState("ft");return e.jsxs(e.Fragment,{children:[e.jsx(c,{label:"Change initUnit",onClick:()=>i(o==="m"?"ft":"m")}),e.jsx(S,{}),e.jsx(c,{label:"Change value",onClick:()=>t(a==="123|m"?"456|m":"123|m")}),e.jsx(S,{}),e.jsx(p,{name:"example",onChange:g=>{t(g.target.value)},unitkey:"length",value:a,initUnit:o,onSwitchUnit:i}),e.jsx(S,{}),e.jsx(p,{name:"example2",onChange:g=>{u(g.target.value)},unitkey:"length",value:s,initUnit:o,onSwitchUnit:i}),e.jsx(gt,{}),e.jsx("h4",{children:"Without initUnit property (taken from the redux store)"}),e.jsx(p,{name:"example",onChange:g=>{t(g.target.value)},unitkey:"length",value:a,onSwitchUnit:i}),e.jsx(p,{name:"example2",onChange:g=>{u(g.target.value)},unitkey:"length",value:s,onSwitchUnit:i})]})};H.parameters={docs:{description:{story:"[OW-4380](https://oliasoft.atlassian.net/browse/OW-4380?atlOrigin=eyJpIjoiMmM1N2RkNWU3Mjk5NDYxY2E0YzhkMzk5ZTVmZTJhMjciLCJwIjoiaiJ9)"}}};const z=C.bind({});z.args={predefinedOptions:[{label:"bottom of casing",value:"12|km"},{label:"mud weight at shoe depth",value:"8|mm"}]};const J=()=>{const n="500px",[a,t]=m.useState(void 0);return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different edge cases such as +/- infinity, undefined, NaN, null:"}),e.jsxs(Wn,{children:[e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value infinity",onClick:()=>t(1/0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value -infinity",onClick:()=>t(-1/0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value null",onClick:()=>t(null)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - undefined",onClick:()=>t(void 0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - NaN",onClick:()=>t(NaN)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - nothing (empty)",onClick:()=>t(void 0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - empty string",onClick:()=>t("")})]}),e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value infinity|m",onClick:()=>t("Infinity|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value -infinity|m",onClick:()=>t("-Infinity|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value null|m",onClick:()=>t("null|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - undefined|m",onClick:()=>t("undefined|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - NaN|m",onClick:()=>t("NaN|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - nothing (empty)|m",onClick:()=>t("|m")})]})]}),e.jsx("br",{}),e.jsx(I,{label:"Normal PUI",children:e.jsx(p,{name:"example1",onChange:s=>t(s.target.value),value:a,unitkey:"length",width:n,placeholder:"value|unit"})}),e.jsx(I,{label:"Disabled validation",children:e.jsx(p,{name:"example2",onChange:s=>t(s.target.value),value:a,unitkey:"length",disabledValidation:!0,width:n})}),e.jsx(I,{label:"Disabled validation and manual error",children:e.jsx(p,{name:"example3",onChange:s=>t(s.target.value),value:a,unitkey:"length",error:"test",disabledValidation:!0,width:n})}),e.jsx(ge,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})},ne=()=>{const n="500px",[a,t]=m.useState("1|m"),[s,u]=m.useState("|m"),o="123|km";return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different cases for automatic (placeholder) values:"}),e.jsx(Wn,{children:e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value to ''",onClick:()=>t("")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to 1",onClick:()=>t("1")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to 1|m",onClick:()=>t("1|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to |m - empty value",onClick:()=>t("|m")})]})}),e.jsx("br",{}),e.jsx(I,{label:"Normal PUI (placeholder + auto)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,placeholder:"value|unit",autoValue:o})}),e.jsx(I,{label:"Normal PUI (only auto)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,autoValue:o})}),e.jsx(I,{label:"Empty PUI with autoValue",children:e.jsx(p,{name:"example1",onChange:i=>u(i.target.value),value:s,unitkey:"length",width:n,autoValue:o})}),e.jsx(I,{label:"Normal PUI (only placeholder)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,placeholder:"Placeholder test"})}),e.jsx(I,{label:"Normal PUI (placeholder + allowEmpty)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,placeholder:"Placeholder test",allowEmpty:!0})}),e.jsx(ge,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})};J.parameters={docs:{description:{story:"[OW-8884](https://oliasoft.atlassian.net/browse/OW-8884)"}}};const te=()=>{const[n,a]=m.useState("123|%"),[t,s]=m.useState(null),u="This should be visible when an error appears",o=(i,g)=>(s(g),{name:i,error:g});return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"3rd party validation message when inputting invalid value:"}),e.jsx(p,{name:"example",onChange:i=>a(i.target.value),error:!t||u,validationCallback:o,value:n}),e.jsx("br",{}),e.jsx(S,{}),e.jsx("h4",{children:"Original validation message: "}),e.jsx(ge,{message:{heading:t,visible:!0}})]})},ae=()=>{const[n,a]=m.useState("123|m"),[t,s]=m.useState(""),[u,o]=m.useState("km"),i=()=>{o("ft"),s("placeholder"),a("|m")};return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Empty value case:"}),e.jsx(p,{name:"example",onChange:g=>a(g.target.value),value:n,allowEmpty:!0,placeholder:t,initUnit:u,unitkey:"length"}),e.jsx("br",{}),e.jsx(S,{}),e.jsx(c,{label:"Change value |m and unit ft",onClick:()=>i()})]})},le=()=>{const[n,a]=m.useState("123|m"),[t,s]=m.useState("m");return e.jsxs(e.Fragment,{children:[e.jsx(p,{name:"example",onChange:u=>a(u.target.value),value:n,initUnit:t,unitkey:"length",onSwitchUnit:s}),e.jsx(S,{}),e.jsx(p,{name:"example",onChange:u=>a(u.target.value),value:n,initUnit:t,unitkey:"length",onSwitchUnit:s})]})};var De,Fe,Me;ee.parameters={...ee.parameters,docs:{...(De=ee.parameters)==null?void 0:De.docs,source:{originalSource:`args => {
|
|
1
|
+
import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as m}from"./index-RfLt4OUa.js";import{d as r,r as it}from"./index-qZmQ7nA9.js";import{c as st}from"./index-VW3EWkuE.js";import{u as ut}from"./use-previous-VKMmnaK7.js";import{M as we}from"./actions-0lKGEXVi.js";import{I as ot}from"./input-group-addon-BHVsW9mL.js";import{B as c}from"./button-pSDG6Ka2.js";import{T as dt}from"./tooltip-gljV_DQ0.js";import{I as ct}from"./input-group-R8LoqKRn.js";import{S}from"./spacer-Yji9g2AW.js";import{T as mt}from"./text-6KQ6ntOV.js";import{I as pt}from"./input-w-UScEUy.js";import{M as Ee}from"./types-VB5zD18b.js";import{l as E}from"./lodash-Bmg8FrMx.js";import{D as gt}from"./divider-RwW2f_N0.js";import{R as Wn,C as pe}from"./row-vFUhHoz5.js";import{F as I}from"./field-V2qkm8ON.js";import{M as ge}from"./message-bbAE2zjv.js";import"./index-cCpkwrS5.js";import"./common-types-U65vzrrz.js";import"./disabled-context-urNQThQz.js";import"./icon-_m67DAr0.js";import"./objectWithoutPropertiesLoose-9Q1jwsKS.js";import"./inheritsLoose-Y9jOMJLd.js";import"./tslib.es6-OIsz3r9a.js";import"./index-4QtD-hFu.js";import"./types-5uVBABF4.js";import"./badge-23Ty_zBt.js";import"./spinner-R8Il4aRe.js";import"./index-miLrID2P.js";import"./styled-components.browser.esm-qIipjd6c.js";import"./label-KLaw_y6R.js";import"./help-icon-jdxRTcvs.js";const ht=()=>{const n=m.useRef(null);return m.useLayoutEffect(()=>{n.current&&(n.current(),n.current=null)}),t=>{n.current=t}},vt=(n,a)=>{const t=a==null?void 0:a[n];return t||(console.log(`Warning: 'unitTemplate' does not define a preferred unit for '${n}'. Defaulting to standard unit.`),r.unitFromQuantity(n)??"")};var b=(n=>(n.CUSTOM="custom",n.PREDEFINED="predefined",n))(b||{});const Tn=n=>n==="undefined"||n===void 0||n===""||n==="null"||n===null||n==="NaN"||isNaN(n),Rn=(n="",a,t="",s=!1)=>{if(s)return n;if(a&&!Tn(n))try{const u=r.isValueWithUnit(n)?n:r.withUnit(n,t),o=r.convertSamePrecision(u,a);return r.getValue(o)}catch{}return n},ft=n=>n?!!r.getUnit(n):!1,F=(n="",a,t,s)=>{if(s)return n;const u=ft(n)||r.isValueWithUnit(n),o=r.getValue(n);return Tn(o)?o:u?Rn(o,a,t,s):n},Ne=n=>E.isObject(n)&&!E.isArray(n)&&!E.isFunction(n)?E.get(n,"fieldName",""):typeof n=="string"?n:"",Ct=n=>E.isObjectLike(n)&&E.has(n,"message"),bt=n=>typeof n=="string"?n:Ct(n)?n.message:null;var Ut=it();const yt=n=>n.search(RegExp(/(^0{2}\.)|(^0+[1-9])/g))===0,Ae=(n,a)=>{var j;const{allowEmpty:t=!1,autoValue:s,placeholder:u,disabledValidation:o=!1}=a||{},i=String(n);if(o||s||u)return null;const g=Ut.isValueWithUnit(i)?r.getValue(i):i;if(t&&g==="")return null;if(yt(g))return"Invalid number format due to leading zeroes";const h=r.validateNumber(g);if(!h.valid){const re=((j=h==null?void 0:h.errors)==null?void 0:j[0])??null;return bt(re)}return null},Pe=(n="")=>{var a;return(a=r.KNOWN_UNITS)==null?void 0:a.includes(n)},xt=(n,a)=>{const t=r.getUnit(n||"");return Pe(a)&&Pe(t)},Vt="_predefinedMenuActive_1yvt4_1",It={predefinedMenuActive:Vt},p=({name:n,placeholder:a="",disabled:t=!1,disabledUnit:s=!1,error:u=null,left:o=!1,small:i=!1,width:g="100%",value:h,unitkey:j="",initUnit:re,noConversion:Ln=!1,onChange:ie=()=>{},onClick:kt=()=>{},onFocus:Kn=()=>{},onSwitchUnit:he=()=>{},unitTemplate:ve,doNotConvertValue:A=!1,testId:w,warning:$n=null,predefinedOptions:x,initialPredefinedOption:Hn=!1,shouldLinkAutomaticly:fe=!0,selectedPredefinedOptionKey:Ce,validationCallback:be=()=>({name:"",error:null}),disabledValidation:Ue=!1,allowEmpty:ye=!1,autoValue:V})=>{typeof h=="number"&&(h=`${h}`);const zn=ht(),[se="",P=""]=h!==void 0?r.split(h):[],xe=V?r.getUnit(V):"",Ve=m.useMemo(()=>vt(j,ve),[j,ve]),Jn=xt(h,Ve),U=re||Ve||P,Yn=ut(U),Ie=F(h,U,P,A),je=F(V,U,xe,A),Zn=Ie!==""?{value:Ie,unit:U}:je!==""?{value:je,unit:U}:{value:se,unit:P},[v,Y]=m.useState(Zn),[Gn,ue]=m.useState(null),[k,oe]=m.useState(Hn?b.PREDEFINED:b.CUSTOM),de=se===""&&V,D=x&&x.find(l=>{if(Ce)return Ce===l.valueKey;const d=r.isValueWithUnit(l.value)?r.getUnit(l.value):"";return r.withUnit(Rn(h,d),d)===l.value}),Qn=()=>{if(j)try{const l=de?V:h??"";let d=r.altUnitsList(l,j);return r.getValue(l)===""?d.map(f=>["",f[1]]):d}catch{return null}},Xn=l=>{const d=Ne(n),f=l.target,{value:y,selectionStart:X}=f,Se=r.cleanNumStr(y.replaceAll(" ","").replaceAll("|","")),ce=r.withUnit(Se,(v==null?void 0:v.unit)||""),at=r.getValue(ce),me=Ae(at,{allowEmpty:ye,autoValue:V,placeholder:a,disabledValidation:Ue});if(me===null){ie({target:{value:ce,name:d}});const[lt,rt]=r.split(ce);Y({value:lt,unit:rt}),ue(null),be(d,null)}else Y({value:Se,unit:v.unit}),ue(me),be(d,me);zn(()=>{f.selectionStart=X,f.selectionEnd=X})},et=(l,d)=>{d===v.unit||isNaN(Number(l))||(Y({value:l,unit:d}),he&&he(d))};m.useEffect(()=>{if(U){let f,y="";Yn!==U?(f=F(h,U,P,A),y=U):r.withUnit(v.value,v.unit)!==h&&(f=F(h,v.unit,P,A),y=v.unit),f!==void 0&&Y({value:f,unit:y}),x&&oe(D&&fe?b.PREDEFINED:b.CUSTOM)}const l=r.checkAndCleanDecimalComma(se),d=Ae(l,{allowEmpty:ye,autoValue:V,placeholder:a,disabledValidation:Ue});ue(d)},[U,h,u,fe]);const Z=Qn(),G=r.label(v.unit)||v.unit||"",nt=Ln||!Z||Z&&Z.length===1,ke=Ne(n);let Q;const tt=l=>{const[d,f=""]=r.isValueWithUnit(l.value)?r.split(l.value):[l.value];return{type:Ee.OPTION,inline:!0,onClick:()=>{r.validateNumber(d).valid&&!t&&(oe(b.PREDEFINED),ie({target:{value:l.value,name:typeof n=="string"?n:(n==null?void 0:n.fieldName)||"",predefinedSelected:!0,predefinedOption:l}}))},label:e.jsxs(e.Fragment,{children:[e.jsx(mt,{children:l.label}),e.jsx(S,{width:"20px",height:"0"})]}),description:r.isValueWithUnit(l.value)?`${d} ${f}`:l.value,selected:D===l&&k===b.PREDEFINED}};if(Q=[{type:Ee.OPTION,inline:!0,onClick:()=>{k!==b.CUSTOM&&!t&&ie({target:{value:r.withUnit(v.value,v.unit),name:typeof n=="string"?n:(n==null?void 0:n.fieldName)||""}})},label:"Custom",selected:k===b.CUSTOM}],x!=null&&x.length){const l=x.map(tt);Q=[...Q,...l]}return e.jsx("div",{className:k===b.PREDEFINED?st(It.predefinedMenuActive):"",children:e.jsxs(ct,{small:i,width:g,children:[x&&e.jsx(dt,{text:k===b.PREDEFINED?D==null?void 0:D.label:"",children:e.jsx(we,{maxHeight:380,groupOrder:"first",testId:w&&`${w}-predefined-menu`,disabled:t,menu:{colored:!0,trigger:"Component",component:e.jsx(c,{groupOrder:"first",active:k===b.PREDEFINED,icon:k===b.PREDEFINED?"link":"unlink"}),small:i,sections:Q}})}),e.jsx(pt,{type:"text",name:ke,testId:w,disabled:t,placeholder:de?F(V,v.unit,xe,A):a,value:v.value,onChange:Xn,onFocus:Kn,error:u||Gn,warning:$n,right:!o},ke),G&&(nt||!Jn?e.jsx(ot,{groupOrder:"last",children:G}):e.jsx(we,{maxHeight:380,groupOrder:"last",disabled:s,testId:w&&`${w}-menu`,menu:{label:G,trigger:"DropDownButton",small:i,sections:Z.map(([l,d,f])=>{const y=f||d||"";return{type:"Option",label:isNaN(Number(l))?"":l,inline:!0,onClick:X=>{X.stopPropagation(),et(de?"":l,d)},description:y,selected:y===G,testId:`${w}-unit-${y}`}})}}))]})})};try{p.displayName="UnitInput",p.__docgenInfo={description:"",displayName:"UnitInput",props:{name:{defaultValue:null,description:"",name:"name",required:!0,type:{name:"string | { fieldName?: string | undefined; }"}},placeholder:{defaultValue:{value:""},description:"",name:"placeholder",required:!1,type:{name:"string"}},disabled:{defaultValue:{value:"false"},description:"",name:"disabled",required:!1,type:{name:"boolean"}},disabledUnit:{defaultValue:{value:"false"},description:"",name:"disabledUnit",required:!1,type:{name:"boolean"}},error:{defaultValue:{value:"null"},description:"",name:"error",required:!1,type:{name:"string | boolean | null"}},left:{defaultValue:{value:"false"},description:"",name:"left",required:!1,type:{name:"boolean"}},small:{defaultValue:{value:"false"},description:"",name:"small",required:!1,type:{name:"boolean"}},width:{defaultValue:{value:"100%"},description:"",name:"width",required:!1,type:{name:"string | number"}},value:{defaultValue:null,description:"",name:"value",required:!1,type:{name:"string"}},unitkey:{defaultValue:{value:""},description:"",name:"unitkey",required:!1,type:{name:"string"}},initUnit:{defaultValue:null,description:"",name:"initUnit",required:!1,type:{name:"string"}},noConversion:{defaultValue:{value:"false"},description:"",name:"noConversion",required:!1,type:{name:"boolean"}},doNotConvertValue:{defaultValue:{value:"false"},description:"",name:"doNotConvertValue",required:!1,type:{name:"boolean"}},testId:{defaultValue:null,description:"",name:"testId",required:!1,type:{name:"string"}},warning:{defaultValue:{value:"null"},description:"",name:"warning",required:!1,type:{name:"string | null"}},predefinedOptions:{defaultValue:null,description:"",name:"predefinedOptions",required:!1,type:{name:"IPredefinedOption[]"}},initialPredefinedOption:{defaultValue:{value:"false"},description:"",name:"initialPredefinedOption",required:!1,type:{name:"boolean"}},shouldLinkAutomaticly:{defaultValue:{value:"true"},description:"",name:"shouldLinkAutomaticly",required:!1,type:{name:"boolean"}},selectedPredefinedOptionKey:{defaultValue:null,description:"",name:"selectedPredefinedOptionKey",required:!1,type:{name:"string"}},validationCallback:{defaultValue:{value:"() => ({ name: '', error: null })"},description:"",name:"validationCallback",required:!1,type:{name:"((name: string, message: string | null) => { name: string; error: string | null; })"}},disabledValidation:{defaultValue:{value:"false"},description:"",name:"disabledValidation",required:!1,type:{name:"boolean"}},allowEmpty:{defaultValue:{value:"false"},description:"",name:"allowEmpty",required:!1,type:{name:"boolean"}},autoValue:{defaultValue:null,description:"",name:"autoValue",required:!1,type:{name:"string"}},onChange:{defaultValue:{value:"() => {}"},description:"",name:"onChange",required:!1,type:{name:"(event: ChangeEvent<HTMLInputElement> | ICustomChangeEvent) => void"}},onSwitchUnit:{defaultValue:{value:"() => {}"},description:"",name:"onSwitchUnit",required:!1,type:{name:"((unit: string) => void)"}},onClick:{defaultValue:{value:"() => {}"},description:"",name:"onClick",required:!1,type:{name:"MouseEventHandler<HTMLInputElement>"}},onFocus:{defaultValue:{value:"() => {}"},description:"",name:"onFocus",required:!1,type:{name:"FocusEventHandler<HTMLInputElement>"}},unitTemplate:{defaultValue:null,description:"",name:"unitTemplate",required:!1,type:{name:"Record<string, any>"}}}}}catch{}const{useArgs:jt}=__STORYBOOK_MODULE_ADDONS__,sa={title:"Basic/UnitInput",component:p,args:{name:"example",unitkey:"length",value:"123|m"}},C=n=>{const[a,t]=jt(),s=u=>{t({value:u.target.value})};return e.jsx(p,{...n,onChange:s})},ee=C.bind({}),M=C.bind({});M.args={initUnit:"ft",unitTemplate:{length:"ft"}};const _=C.bind({});_.args={value:'123|"',unitkey:'"'};const O=C.bind({});O.args={width:"180px"};const B=C.bind({});B.args={noConversion:!0};const q=C.bind({});q.args={small:!0};const W=C.bind({});W.args={error:"Error message goes here"};const T=C.bind({});T.args={value:"asas123asd|%"};const N=C.bind({});N.args={disabled:!0,disabledUnit:!0};N.parameters={docs:{description:{story:"Each part of UnitInput can be disabled separately. `disabled` disables only the main text input, `disabledUnit` disables only the unit menu. **Needs review (comes from Reservoir input requirements)**"}}};const R=C.bind({});R.args={disabled:!0,disabledUnit:!0,noConversion:!0};const L=C.bind({});L.args={disabledUnit:!0,unitkey:void 0};const K=C.bind({});K.args={disabledUnit:!0,unitkey:"length"};const $=C.bind({});$.args={disabledUnit:!1,disabled:!0};const H=n=>{const[a,t]=m.useState("123|m"),[s,u]=m.useState("223|m"),[o,i]=m.useState("ft");return e.jsxs(e.Fragment,{children:[e.jsx(c,{label:"Change initUnit",onClick:()=>i(o==="m"?"ft":"m")}),e.jsx(S,{}),e.jsx(c,{label:"Change value",onClick:()=>t(a==="123|m"?"456|m":"123|m")}),e.jsx(S,{}),e.jsx(p,{name:"example",onChange:g=>{t(g.target.value)},unitkey:"length",value:a,initUnit:o,onSwitchUnit:i}),e.jsx(S,{}),e.jsx(p,{name:"example2",onChange:g=>{u(g.target.value)},unitkey:"length",value:s,initUnit:o,onSwitchUnit:i}),e.jsx(gt,{}),e.jsx("h4",{children:"Without initUnit property (taken from the redux store)"}),e.jsx(p,{name:"example",onChange:g=>{t(g.target.value)},unitkey:"length",value:a,onSwitchUnit:i}),e.jsx(p,{name:"example2",onChange:g=>{u(g.target.value)},unitkey:"length",value:s,onSwitchUnit:i})]})};H.parameters={docs:{description:{story:"[OW-4380](https://oliasoft.atlassian.net/browse/OW-4380?atlOrigin=eyJpIjoiMmM1N2RkNWU3Mjk5NDYxY2E0YzhkMzk5ZTVmZTJhMjciLCJwIjoiaiJ9)"}}};const z=C.bind({});z.args={predefinedOptions:[{label:"bottom of casing",value:"12|km"},{label:"mud weight at shoe depth",value:"8|mm"}]};const J=()=>{const n="500px",[a,t]=m.useState(void 0);return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different edge cases such as +/- infinity, undefined, NaN, null:"}),e.jsxs(Wn,{children:[e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value infinity",onClick:()=>t(1/0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value -infinity",onClick:()=>t(-1/0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value null",onClick:()=>t(null)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - undefined",onClick:()=>t(void 0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - NaN",onClick:()=>t(NaN)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - nothing (empty)",onClick:()=>t(void 0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - empty string",onClick:()=>t("")})]}),e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value infinity|m",onClick:()=>t("Infinity|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value -infinity|m",onClick:()=>t("-Infinity|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value null|m",onClick:()=>t("null|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - undefined|m",onClick:()=>t("undefined|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - NaN|m",onClick:()=>t("NaN|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - nothing (empty)|m",onClick:()=>t("|m")})]})]}),e.jsx("br",{}),e.jsx(I,{label:"Normal PUI",children:e.jsx(p,{name:"example1",onChange:s=>t(s.target.value),value:a,unitkey:"length",width:n,placeholder:"value|unit"})}),e.jsx(I,{label:"Disabled validation",children:e.jsx(p,{name:"example2",onChange:s=>t(s.target.value),value:a,unitkey:"length",disabledValidation:!0,width:n})}),e.jsx(I,{label:"Disabled validation and manual error",children:e.jsx(p,{name:"example3",onChange:s=>t(s.target.value),value:a,unitkey:"length",error:"test",disabledValidation:!0,width:n})}),e.jsx(ge,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})},ne=()=>{const n="500px",[a,t]=m.useState("1|m"),[s,u]=m.useState("|m"),o="123|km";return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different cases for automatic (placeholder) values:"}),e.jsx(Wn,{children:e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value to ''",onClick:()=>t("")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to 1",onClick:()=>t("1")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to 1|m",onClick:()=>t("1|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to |m - empty value",onClick:()=>t("|m")})]})}),e.jsx("br",{}),e.jsx(I,{label:"Normal PUI (placeholder + auto)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,placeholder:"value|unit",autoValue:o})}),e.jsx(I,{label:"Normal PUI (only auto)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,autoValue:o})}),e.jsx(I,{label:"Empty PUI with autoValue",children:e.jsx(p,{name:"example1",onChange:i=>u(i.target.value),value:s,unitkey:"length",width:n,autoValue:o})}),e.jsx(I,{label:"Normal PUI (only placeholder)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,placeholder:"Placeholder test"})}),e.jsx(I,{label:"Normal PUI (placeholder + allowEmpty)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,placeholder:"Placeholder test",allowEmpty:!0})}),e.jsx(ge,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})};J.parameters={docs:{description:{story:"[OW-8884](https://oliasoft.atlassian.net/browse/OW-8884)"}}};const te=()=>{const[n,a]=m.useState("123|%"),[t,s]=m.useState(null),u="This should be visible when an error appears",o=(i,g)=>(s(g),{name:i,error:g});return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"3rd party validation message when inputting invalid value:"}),e.jsx(p,{name:"example",onChange:i=>a(i.target.value),error:!t||u,validationCallback:o,value:n}),e.jsx("br",{}),e.jsx(S,{}),e.jsx("h4",{children:"Original validation message: "}),e.jsx(ge,{message:{heading:t,visible:!0}})]})},ae=()=>{const[n,a]=m.useState("123|m"),[t,s]=m.useState(""),[u,o]=m.useState("km"),i=()=>{o("ft"),s("placeholder"),a("|m")};return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Empty value case:"}),e.jsx(p,{name:"example",onChange:g=>a(g.target.value),value:n,allowEmpty:!0,placeholder:t,initUnit:u,unitkey:"length"}),e.jsx("br",{}),e.jsx(S,{}),e.jsx(c,{label:"Change value |m and unit ft",onClick:()=>i()})]})},le=()=>{const[n,a]=m.useState("123|m"),[t,s]=m.useState("m");return e.jsxs(e.Fragment,{children:[e.jsx(p,{name:"example",onChange:u=>a(u.target.value),value:n,initUnit:t,unitkey:"length",onSwitchUnit:s}),e.jsx(S,{}),e.jsx(p,{name:"example",onChange:u=>a(u.target.value),value:n,initUnit:t,unitkey:"length",onSwitchUnit:s})]})};var De,Fe,Me;ee.parameters={...ee.parameters,docs:{...(De=ee.parameters)==null?void 0:De.docs,source:{originalSource:`args => {
|
|
2
2
|
const [_, updateArgs] = useArgs();
|
|
3
3
|
const handleChange = (evt: any) => {
|
|
4
4
|
updateArgs({
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import{j as n}from"./jsx-runtime-FsUICBgo.js";import{r as v}from"./index-RfLt4OUa.js";import{f as Q}from"./immer.esm-bD7SSJ7T.js";import{d as b}from"./index-qZmQ7nA9.js";import{G as Z}from"./grid-u1mZpaML.js";import{C as L}from"./card-0r8RRVk-.js";import{F as V}from"./field-V2qkm8ON.js";import{H as E}from"./heading-OSdaYHYE.js";import{S as H}from"./select-7lyQEtzA.js";import{T as F}from"./toggle-KddTHsTd.js";import{l as ee}from"./lodash-Bmg8FrMx.js";import{u as te}from"./use-previous-VKMmnaK7.js";import{T as ne,C as P}from"./table-YO72eq6-.js";import"./index-cCpkwrS5.js";import"./styled-components.browser.esm-qIipjd6c.js";import"./tslib.es6-OIsz3r9a.js";import"./index-VW3EWkuE.js";import"./label-KLaw_y6R.js";import"./common-types-U65vzrrz.js";import"./help-icon-jdxRTcvs.js";import"./tooltip-gljV_DQ0.js";import"./index-miLrID2P.js";import"./icon-_m67DAr0.js";import"./objectWithoutPropertiesLoose-9Q1jwsKS.js";import"./inheritsLoose-Y9jOMJLd.js";import"./index-4QtD-hFu.js";import"./disabled-context-urNQThQz.js";import"./types-5uVBABF4.js";import"./extends-dGVwEr9R.js";import"./assertThisInitialized-4q6YPdh3.js";import"./memoize-one.esm-hqe5SRxC.js";import"./types-VB5zD18b.js";import"./text-6KQ6ntOV.js";import"./actions-0lKGEXVi.js";import"./button-pSDG6Ka2.js";import"./spinner-R8Il4aRe.js";import"./badge-23Ty_zBt.js";import"./select.input-zP5tW20f.js";import"./index.es-HG2GUH9i.js";import"./redux-F5dueAP3.js";import"./objectSpread2-93s0nBry.js";import"./tiny-invariant-R4kOKlvx.js";import"./pagination-LajpPl1E.js";import"./input-w-UScEUy.js";import"./input-group-R8LoqKRn.js";import"./input-group-addon-BHVsW9mL.js";import"./number-input-hrCn3Rag.js";import"./check-box--ih7cmR1.js";import"./slider-bFd0qknB.js";import"./index-ugi_ZH6T.js";import"./popover-dGHzPDyA.js";const ae=o=>o.reduce(({preferredUnits:i,storageUnits:r},{unitKey:s,preferredUnit:a,storageUnit:g})=>(i[s]=a,r[s]=g,{preferredUnits:i,storageUnits:r}),{preferredUnits:{},storageUnits:{}}),re=({headers:o,rows:i,selectedUnits:r,storageUnits:s,onChangeUnit:a,convertBackToStorageUnit:g,enableCosmeticRounding:c,enableDisplayRounding:f})=>{const u=o?o.map(m=>({...m,cells:m.cells.map(p=>{var t;if(p.type===P.AUTO_UNIT){const{testId:C,unitKey:d}=p;return{value:r[d],type:P.SELECT,searchable:!1,options:(t=b.getUnitsForQuantity(d))==null?void 0:t.map(h=>({label:b.label(h),value:h})),native:p.native,onChange:h=>a({unitKey:d,value:h.target.value}),testId:C}}return p})})):[],l=i?i.map((m,p)=>({...m,cells:m.cells.map((t,C)=>{if("autoUnit"in t&&(t!=null&&t.autoUnit)&&(typeof(t==null?void 0:t.value)=="string"||typeof(t==null?void 0:t.value)=="number")){const{unitKey:d,value:h,formatDisplayValue:U}=t,x=f&&"roundDisplayValue"in t?t==null?void 0:t.roundDisplayValue:null,e=r[d],T=s[d],y=e!==T,S=y?b.convertAndGetValue(h,e,T):t.value,R=b.isScientificStringNum(h),w=c&&(y||!R)?b.roundToPrecision(S,14):S,_=U?U(w):w;return{...t,value:_,enableCosmeticRounding:c,enableDisplayRounding:f,roundDisplayValue:x,onChange:j=>{const{value:W}=j.target,I=s[d],D=r[d],J=D!==I,K=g?I:D,$=J?b.convertAndGetValue(W,K,D):W;if("onChange"in t){const{onChange:X}=t,Y={...j,target:{...j.target,value:String($),rowIndex:p,cellIndex:C,unit:K}};X(Y)}}}}return t})})):[];return{convertedHeaders:u,convertedRows:l}},B=({table:o,unitConfig:i,convertBackToStorageUnit:r=!0,enableCosmeticRounding:s=!0,enableDisplayRounding:a=!0})=>{const{rows:g,headers:c,...f}=o,{storageUnits:u,preferredUnits:l}=ae(i),m=te(l),[p,t]=v.useState(l),C=({unitKey:e,value:T})=>t({...p,[e]:T}),d=e=>re({headers:c,rows:g,selectedUnits:e,storageUnits:u,onChangeUnit:C,convertBackToStorageUnit:r,enableCosmeticRounding:s,enableDisplayRounding:a}),h=d(p),[U,x]=v.useState(h);return v.useEffect(()=>{!ee.isEqual(l,m)&&(t(l),x(d(l)))},[i]),v.useEffect(()=>{x(d(p))},[o,p]),n.jsx(ne,{table:{...f,headers:U.convertedHeaders,rows:U.convertedRows}})};try{B.displayName="UnitTable",B.__docgenInfo={description:"",displayName:"UnitTable",props:{table:{defaultValue:null,description:"",name:"table",required:!0,type:{name:"IUnitTable"}},unitConfig:{defaultValue:null,description:"",name:"unitConfig",required:!0,type:{name:"IUnitConfigItem[]"}},convertBackToStorageUnit:{defaultValue:{value:"true"},description:"",name:"convertBackToStorageUnit",required:!1,type:{name:"boolean"}},enableCosmeticRounding:{defaultValue:{value:"true"},description:"",name:"enableCosmeticRounding",required:!1,type:{name:"boolean"}},enableDisplayRounding:{defaultValue:{value:"true"},description:"",name:"enableDisplayRounding",required:!1,type:{name:"boolean"}},onListReorder:{defaultValue:null,description:"",name:"onListReorder",required:!1,type:{name:"((obj: { from: number; to: number; }) => void)"}}}}}catch{}const ct={title:"Basic/UnitTable",args:{}},oe=!0,ie=!0,le=!0,se=!1,z="m",M="C",ue=3,de=(o,i,r)=>{const s=[i,i,r],a=[...Array(o)].map((g,c)=>{const f=c,u=c+1.25,l=4+c*.25;return[String(f),String(u),String(l)]});return[s,...a]},ce=de(ue,z,M),pe=({reduxTable:o,value:i,unit:r,rowIndex:s,cellIndex:a})=>Q(o,g=>{const c=g[0][a],f=(u,l)=>l===0;return g.forEach((u,l)=>{if(f(u,l)){u[a]=r;return}if(l===s+1){u[a]=String(i);return}const m=b.convertAndGetValue(u[a],r,c);u[a]=String(m)}),g}),ge=({reduxTable:o,value:i,rowIndex:r,cellIndex:s})=>Q(o,a=>{a[r+1][s]=i}),k=()=>{var U,x;const[o,i]=v.useState(z),[r,s]=v.useState(M),[a,g]=v.useState(ce),[c,f]=v.useState(oe),[u,l]=v.useState(le),[m,p]=v.useState(ie),[t,C]=v.useState(se),d=e=>{const{rowIndex:T,cellIndex:y,value:S,unit:R}=e.target,w=t?pe({reduxTable:a,value:S,unit:R,rowIndex:T,cellIndex:y}):ge({reduxTable:a,value:S,rowIndex:T,cellIndex:y});g(w)},h=a.reduce((e,T,y)=>(y===0?e.headers=[{cells:[{value:"From"},{value:"To"},{value:"Temperature"}]},{cells:[{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"temperature",testId:"table-unit-selector-3"}]}]:e.rows=e.rows.concat({cells:T.map((S,R)=>{const w=y===1&&R===1;return{value:S,type:w?"Text":"NumberInput",unitKey:R===2?"temperature":"length",onChange:d,roundDisplayValue:y===3&&R===2?D=>b.roundByMagnitude(D,2):null,formatDisplayValue:w?D=>`T* ${D}`:null,autoUnit:!0}})}),e),{headers:[],rows:[]});return n.jsxs(Z,{columns:"1fr 1fr",gap:!0,children:[n.jsxs(L,{heading:n.jsx(E,{children:"Settings"}),children:[n.jsx(V,{label:"Convert back to storage unit:",labelLeft:!0,labelWidth:200,children:n.jsx(F,{checked:c,onChange:e=>f(e.target.checked)})}),n.jsx(V,{label:"Enable display rounding:",labelLeft:!0,labelWidth:200,children:n.jsx(F,{checked:u,onChange:e=>l(e.target.checked)})}),n.jsx(V,{label:"Enable cosmetic rounding:",labelLeft:!0,labelWidth:200,children:n.jsx(F,{checked:m,onChange:e=>p(e.target.checked)})}),n.jsx(V,{label:"Convert whole table:",labelLeft:!0,labelWidth:200,children:n.jsx(F,{checked:t,onChange:e=>C(e.target.checked)})})]}),n.jsxs(L,{heading:n.jsx(E,{children:"Unit template"}),children:[n.jsx(V,{label:"Length unit:",labelLeft:!0,labelWidth:120,children:n.jsx(H,{options:(U=b.getUnitsForQuantity("length"))==null?void 0:U.map(e=>({value:e,label:b.label(e)})),value:{value:o},onChange:e=>i(e.target.value),width:"100px"})}),n.jsx(V,{label:"Temperature unit:",labelLeft:!0,labelWidth:120,children:n.jsx(H,{options:(x=b.getUnitsForQuantity("temperature"))==null?void 0:x.map(e=>({value:e,label:b.label(e)})),value:{value:r},onChange:e=>s(e.target.value),width:"100px"})})]}),n.jsx(L,{heading:n.jsx(E,{children:"Storage State (Redux)"}),children:n.jsx("pre",{children:n.jsx("code",{children:JSON.stringify(a,null,2)})})}),n.jsx(L,{heading:n.jsx(E,{children:"UnitTable"}),children:n.jsx(B,{table:h,unitConfig:[{unitKey:"length",storageUnit:a[0][0],preferredUnit:o},{unitKey:"temperature",storageUnit:a[0][2],preferredUnit:r}],convertBackToStorageUnit:c,enableDisplayRounding:u,enableCosmeticRounding:m})})]})};var A,N,q,G,O;k.parameters={...k.parameters,docs:{...(A=k.parameters)==null?void 0:A.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
|
+
|
|
10
|
+
/*********************************************************************************************************************
|
|
11
|
+
Cell onChange handler
|
|
12
|
+
*********************************************************************************************************************/
|
|
13
|
+
const onUpdateCell = (evt: IUnitTableOnChangeEvent) => {
|
|
14
|
+
const {
|
|
15
|
+
rowIndex,
|
|
16
|
+
cellIndex,
|
|
17
|
+
value,
|
|
18
|
+
unit
|
|
19
|
+
} = evt.target;
|
|
20
|
+
const nextTable = convertWholeTable ? convertStorageTable({
|
|
21
|
+
reduxTable,
|
|
22
|
+
value,
|
|
23
|
+
unit,
|
|
24
|
+
rowIndex,
|
|
25
|
+
cellIndex
|
|
26
|
+
}) : updateCell({
|
|
27
|
+
reduxTable,
|
|
28
|
+
value,
|
|
29
|
+
rowIndex,
|
|
30
|
+
cellIndex
|
|
31
|
+
});
|
|
32
|
+
setReduxTable(nextTable);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/*********************************************************************************************************************
|
|
36
|
+
Construct table view data (same as old Table component, with a new props)
|
|
37
|
+
*********************************************************************************************************************/
|
|
38
|
+
const tableViewData = reduxTable.reduce((acc, row, rowIndex) => {
|
|
39
|
+
if (rowIndex === 0) {
|
|
40
|
+
acc.headers = [{
|
|
41
|
+
cells: [{
|
|
42
|
+
value: 'From'
|
|
43
|
+
}, {
|
|
44
|
+
value: 'To'
|
|
45
|
+
}, {
|
|
46
|
+
value: 'Temperature'
|
|
47
|
+
}]
|
|
48
|
+
}, {
|
|
49
|
+
cells: [{
|
|
50
|
+
type: 'AutoUnit',
|
|
51
|
+
unitKey: 'length'
|
|
52
|
+
}, {
|
|
53
|
+
type: 'AutoUnit',
|
|
54
|
+
unitKey: 'length'
|
|
55
|
+
}, {
|
|
56
|
+
type: 'AutoUnit',
|
|
57
|
+
unitKey: 'temperature',
|
|
58
|
+
testId: 'table-unit-selector-3'
|
|
59
|
+
}]
|
|
60
|
+
}];
|
|
61
|
+
} else {
|
|
62
|
+
acc.rows = acc.rows.concat({
|
|
63
|
+
cells: row.map((cell, cellIndex) => {
|
|
64
|
+
const specialCell = rowIndex === 1 && cellIndex === 1;
|
|
65
|
+
const type = specialCell ? 'Text' : 'NumberInput';
|
|
66
|
+
const formatDisplayValue = specialCell ? (value: number | string) => \`T* \${value}\` : null;
|
|
67
|
+
const customDisplayRounding = rowIndex === 3 && cellIndex === 2 ? (value: TStringNumberNull) => roundByMagnitude(value, 2) : null;
|
|
68
|
+
const value = cell;
|
|
69
|
+
return {
|
|
70
|
+
value,
|
|
71
|
+
type,
|
|
72
|
+
unitKey: cellIndex === 2 ? 'temperature' : 'length',
|
|
73
|
+
onChange: onUpdateCell,
|
|
74
|
+
roundDisplayValue: customDisplayRounding,
|
|
75
|
+
// optionally customize the display rounding of specific columns/cells
|
|
76
|
+
formatDisplayValue,
|
|
77
|
+
// optionally extend/customize the display formatting of specific columns/cells
|
|
78
|
+
autoUnit: true
|
|
79
|
+
};
|
|
80
|
+
})
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return acc;
|
|
84
|
+
}, {
|
|
85
|
+
headers: ([] as any[]),
|
|
86
|
+
rows: ([] as IUnitTableRow[])
|
|
87
|
+
});
|
|
88
|
+
return <Grid columns="1fr 1fr" gap>
|
|
89
|
+
<Card heading={<Heading>Settings</Heading>}>
|
|
90
|
+
<Field label="Convert back to storage unit:" labelLeft labelWidth={200}>
|
|
91
|
+
<Toggle checked={convertBackToStorageUnit} onChange={evt => setConvertBackToStorageUnit(evt.target.checked)} />
|
|
92
|
+
</Field>
|
|
93
|
+
<Field label="Enable display rounding:" labelLeft labelWidth={200}>
|
|
94
|
+
<Toggle checked={enableDisplayRounding} onChange={evt => setEnableDisplayRounding(evt.target.checked)} />
|
|
95
|
+
</Field>
|
|
96
|
+
<Field label="Enable cosmetic rounding:" labelLeft labelWidth={200}>
|
|
97
|
+
<Toggle checked={enableCosmeticRounding} onChange={evt => setEnableCosmeticRounding(evt.target.checked)} />
|
|
98
|
+
</Field>
|
|
99
|
+
<Field label="Convert whole table:" labelLeft labelWidth={200}>
|
|
100
|
+
<Toggle checked={convertWholeTable} onChange={evt => setConvertWholeTable(evt.target.checked)} />
|
|
101
|
+
</Field>
|
|
102
|
+
</Card>
|
|
103
|
+
<Card heading={<Heading>Unit template</Heading>}>
|
|
104
|
+
<Field label="Length unit:" labelLeft labelWidth={120}>
|
|
105
|
+
<Select options={getUnitsForQuantity('length')?.map(unit => ({
|
|
106
|
+
value: unit,
|
|
107
|
+
label: label(unit)
|
|
108
|
+
}))} value={{
|
|
109
|
+
value: preferredLengthUnit
|
|
110
|
+
}} onChange={evt => setPreferredLengthUnit(evt.target.value)} width="100px" />
|
|
111
|
+
</Field>
|
|
112
|
+
<Field label="Temperature unit:" labelLeft labelWidth={120}>
|
|
113
|
+
<Select options={getUnitsForQuantity('temperature')?.map(unit => ({
|
|
114
|
+
value: unit,
|
|
115
|
+
label: label(unit)
|
|
116
|
+
}))} value={{
|
|
117
|
+
value: preferredTemperatureUnit
|
|
118
|
+
}} onChange={evt => setPreferredTemperatureUnit(evt.target.value)} width="100px" />
|
|
119
|
+
</Field>
|
|
120
|
+
</Card>
|
|
121
|
+
<Card heading={<Heading>Storage State (Redux)</Heading>}>
|
|
122
|
+
<pre>
|
|
123
|
+
<code>{JSON.stringify(reduxTable, null, 2)}</code>
|
|
124
|
+
</pre>
|
|
125
|
+
</Card>
|
|
126
|
+
<Card heading={<Heading>UnitTable</Heading>}>
|
|
127
|
+
<UnitTable table={tableViewData}
|
|
128
|
+
//New props:
|
|
129
|
+
unitConfig={[{
|
|
130
|
+
unitKey: 'length',
|
|
131
|
+
storageUnit: reduxTable[0][0],
|
|
132
|
+
preferredUnit: preferredLengthUnit
|
|
133
|
+
}, {
|
|
134
|
+
unitKey: 'temperature',
|
|
135
|
+
storageUnit: reduxTable[0][2],
|
|
136
|
+
preferredUnit: preferredTemperatureUnit
|
|
137
|
+
}]}
|
|
138
|
+
//Most tables should just use the default values here (true):
|
|
139
|
+
convertBackToStorageUnit={convertBackToStorageUnit} enableDisplayRounding={enableDisplayRounding} enableCosmeticRounding={enableCosmeticRounding} />
|
|
140
|
+
</Card>
|
|
141
|
+
</Grid>;
|
|
142
|
+
}`,...(q=(N=k.parameters)==null?void 0:N.docs)==null?void 0:q.source},description:{story:"Story",...(O=(G=k.parameters)==null?void 0:G.docs)==null?void 0:O.description}}};const pt=["UnitTablePrototype"];export{k as UnitTablePrototype,pt as __namedExportsOrder,ct as default};
|