@oliasoft-open-source/react-ui-library 4.7.0-beta-3 → 4.7.0
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/404.html +1 -0
- package/dist/assets/{index-ffnttoim.js → index-3CeHq3uM.js} +5 -6
- package/dist/assets/{index-dOfLgtRX.css → index-DdTheZoQ.css} +1 -4
- package/dist/global.css +45 -48
- package/dist/index.d.ts +69 -79
- package/dist/index.html +1 -1
- package/dist/index.js +2013 -2282
- package/dist/index.js.map +1 -1
- package/dist/storybook/assets/{Color-6VNJS4EI-5mv-gOfo.js → Color-6VNJS4EI-xX703Erw.js} +1 -1
- package/dist/storybook/assets/{DocsRenderer-NNNQARDV-WaSwS_18.js → DocsRenderer-NNNQARDV-jfRj2DTn.js} +1 -1
- package/dist/storybook/assets/{WithTooltip-V3YHNWJZ-Dlt0G_eH.js → WithTooltip-V3YHNWJZ-AvjzxEIz.js} +1 -1
- package/dist/storybook/assets/{accordion.stories-BbpRXaiJ.js → accordion.stories-N0ePGIzZ.js} +1 -1
- package/dist/storybook/assets/{actions-MkrpU3sl.js → actions-0ELEGFed.js} +1 -1
- package/dist/storybook/assets/{actions.stories-9i52_Rux.js → actions.stories-kCR8bnxR.js} +1 -1
- package/dist/storybook/assets/{afe.stories-U0-W5U64.js → afe.stories-gS6IvugS.js} +1 -1
- package/dist/storybook/assets/{badge.stories--T9ak5cr.js → badge.stories-fpUlm73g.js} +1 -1
- package/dist/storybook/assets/{blowout.stories-G-gAIxfk.js → blowout.stories-vtbbYHQT.js} +1 -1
- package/dist/storybook/assets/{button-MXXjI7Bb.js → button-BiJw0fB3.js} +1 -1
- package/dist/storybook/assets/{button-group-f5VgIRsa.js → button-group-uKCjEKYR.js} +1 -1
- package/dist/storybook/assets/{button-group.stories-C7TuTTy6.js → button-group.stories-mynaBhDz.js} +1 -1
- package/dist/storybook/assets/{button.stories-rq3SXBTn.js → button.stories-7N3AZjiw.js} +1 -1
- package/dist/storybook/assets/{buttons-and-links-VQgmPqVJ.js → buttons-and-links-0h-AVRdJ.js} +1 -1
- package/dist/storybook/assets/{card.stories-pCYBc-Vt.js → card.stories-N8mLrD63.js} +1 -1
- package/dist/storybook/assets/{casing-loads.stories-gq4jb1p0.js → casing-loads.stories-cCvBYMPa.js} +1 -1
- package/dist/storybook/assets/{cell.stories-ycwhWlIa.js → cell.stories-hT2-0Ekx.js} +1 -1
- package/dist/storybook/assets/{check-box-w174Mu0R.js → check-box-KynSyTaY.js} +1 -1
- package/dist/storybook/assets/{check-box.stories-72A4TN39.js → check-box.stories-yE82OQod.js} +1 -1
- package/dist/storybook/assets/{chunk-HLWAVYOI-_b1tlWM3.js → chunk-HLWAVYOI-UQuxjHgI.js} +1 -1
- package/dist/storybook/assets/{color-cEzs-xnA.js → color-Sdh3kTOi.js} +1 -1
- package/dist/storybook/assets/{column.stories-U4nQqgWb.js → column.stories-cX-u-DHI.js} +1 -1
- package/dist/storybook/assets/{dialog-u5m1F-lX.js → dialog-Au78k7wS.js} +1 -1
- package/dist/storybook/assets/{drawer-was2OGqf.js → drawer-Vhj7CUNA.js} +1 -1
- package/dist/storybook/assets/{drawer.stories-euYpu-I_.js → drawer.stories-FPi2nBqL.js} +1 -1
- package/dist/storybook/assets/{empty.stories-T-_CrIhL.js → empty.stories-oRmjEU7P.js} +1 -1
- package/dist/storybook/assets/{field-fx75Y95f.js → field-m7XXDdEG.js} +1 -1
- package/dist/storybook/assets/{field.stories-2Qckj9Ou.js → field.stories-6xmZA-uD.js} +1 -1
- package/dist/storybook/assets/{file-button.stories-0zVuRMcp.js → file-button.stories-gojUYo7t.js} +1 -1
- package/dist/storybook/assets/{file-input-fzEQtraw.js → file-input-X63bjABB.js} +1 -1
- package/dist/storybook/assets/{file-input.stories-P1T12gxg.js → file-input.stories-KZSe0jKl.js} +1 -1
- package/dist/storybook/assets/{flex.stories-Vlk77f1V.js → flex.stories-xAOrglx5.js} +1 -1
- package/dist/storybook/assets/{footer.stories-OOGCWJOv.js → footer.stories-2AIpYgl_.js} +1 -1
- package/dist/storybook/assets/{form.stories-NIwGiDxn.js → form.stories-qFitN202.js} +1 -1
- package/dist/storybook/assets/{formation.stories-1BHk-Z5n.js → formation.stories-u2HG5vE1.js} +1 -1
- package/dist/storybook/assets/{formatter-SWP5E3XI-lPjnxviv.js → formatter-SWP5E3XI-AcQFFmvi.js} +1 -1
- package/dist/storybook/assets/{heading-CRsqGmBL.js → heading-4tVgoT7O.js} +1 -1
- package/dist/storybook/assets/{heading.stories-i7xajcE_.js → heading.stories-7Bqlw14c.js} +1 -1
- package/dist/storybook/assets/{help-icon-DUhtRK0A.js → help-icon-eelulTML.js} +1 -1
- package/dist/storybook/assets/{help-icon.stories-FyPetqQr.js → help-icon.stories-CptgOV2E.js} +1 -1
- package/dist/storybook/assets/iframe-3RlYxWwB.js +7 -0
- package/dist/storybook/assets/{index-xs8f072L.js → index-dKL70FW5.js} +5 -5
- package/dist/storybook/assets/{index-VSx05S_2.js → index-qZmQ7nA9.js} +1 -1
- package/dist/storybook/assets/{input-vzl5J-q1.js → input-fYKvBwPs.js} +1 -1
- package/dist/storybook/assets/{input-group.stories-6EUjHyss.js → input-group.stories-MuX_NnP5.js} +1 -1
- package/dist/storybook/assets/{input-validation-fn2c7CZI.js → input-validation--CWCjQnL.js} +1 -1
- package/dist/storybook/assets/{input.stories-rTyGPzfX.js → input.stories-Y5X-JFWU.js} +1 -1
- package/dist/storybook/assets/{inputs-4CE3Qz8f.js → inputs-97VxSPJR.js} +4 -4
- package/dist/storybook/assets/{label-CezqEpI3.js → label-bLcoUwtK.js} +1 -1
- package/dist/storybook/assets/{label.stories-niFJlzWW.js → label.stories-KbJuUVw3.js} +1 -1
- package/dist/storybook/assets/{layout-forms-hnqEzhUh.js → layout-forms-N4FQBaG8.js} +1 -1
- package/dist/storybook/assets/{layout-general-GKzWTVlq.js → layout-general-NDOvxP4q.js} +1 -1
- package/dist/storybook/assets/{list-obj4NAnI.js → list-oRkYBU-W.js} +1 -1
- package/dist/storybook/assets/{list.stories-q5ZUuhM_.js → list.stories-EMdcTvdT.js} +1 -1
- package/dist/storybook/assets/{list.stories-data-xxLjz2Y6.js → list.stories-data-oQzKw4Pq.js} +1 -1
- package/dist/storybook/assets/{loader.stories-UWhF9bJF.js → loader.stories-B5lK8-XB.js} +1 -1
- package/dist/storybook/assets/{menu.stories-y0NlwAvu.js → menu.stories-PBBlly2o.js} +1 -1
- package/dist/storybook/assets/{message.stories-iT_DKpjU.js → message.stories-aLAQs_iU.js} +1 -1
- package/dist/storybook/assets/{meta-content-egPJiNdW.js → meta-content-sjR-N3-O.js} +1 -1
- package/dist/storybook/assets/{modal.stories-VOY0gBdV.js → modal.stories-w8Ga2is6.js} +1 -1
- package/dist/storybook/assets/number-input-ymd7m-s5.js +1 -0
- package/dist/storybook/assets/number-input.stories-vPnYf6Zp.js +97 -0
- package/dist/storybook/assets/{option-dropdown.stories-hrDlMrbm.js → option-dropdown.stories-TfHqGoeH.js} +1 -1
- package/dist/storybook/assets/{padding-and-spacing-J0l6qP8c.js → padding-and-spacing-c8LvBBMe.js} +1 -1
- package/dist/storybook/assets/{page.stories--jUrPw0e.js → page.stories-uG2-dlo7.js} +1 -1
- package/dist/storybook/assets/{pagination-APbPWlVY.js → pagination-H0l4VC9v.js} +1 -1
- package/dist/storybook/assets/{pagination.stories-r3XGZlP9.js → pagination.stories-NQ91Xlrk.js} +1 -1
- package/dist/storybook/assets/{pop-confirm.stories-pXKS5ukj.js → pop-confirm.stories-6V_XrhKa.js} +1 -1
- package/dist/storybook/assets/{popover-ZJGe9jlj.js → popover-N9B8JT3G.js} +1 -1
- package/dist/storybook/assets/{popover.stories-2K90u4uo.js → popover.stories-7Q50puZs.js} +1 -1
- package/dist/storybook/assets/{preview-BYvKcpdH.js → preview-AHjAdEy1.js} +2 -2
- package/dist/storybook/assets/{preview-vq7_vD2k.js → preview-VX4P0egZ.js} +1 -1
- package/dist/storybook/assets/{projects.stories-LB28sKC4.js → projects.stories-UnlGjNFI.js} +1 -1
- package/dist/storybook/assets/{radio-button-9Xi1TwWI.js → radio-button-HPU-KHv4.js} +1 -1
- package/dist/storybook/assets/{radio-button.stories-7dkCcpUZ.js → radio-button.stories-ZyjCpReq.js} +1 -1
- package/dist/storybook/assets/{reservoirs.stories-f7usYIda.js → reservoirs.stories-tIoVea3g.js} +1 -1
- package/dist/storybook/assets/{rich-text-input.stories-YWaiFQEd.js → rich-text-input.stories-vk9xwB_D.js} +1 -1
- package/dist/storybook/assets/{row.stories-wtewEk0Z.js → row.stories-ot7Jjnt6.js} +1 -1
- package/dist/storybook/assets/{select-Bp8YY8Ze.js → select-I01_W6_4.js} +1 -1
- package/dist/storybook/assets/{select.stories-RjqGVn2g.js → select.stories-XAI8pyEc.js} +1 -1
- package/dist/storybook/assets/{side-bar-V0uxIghC.js → side-bar-evBxuVzm.js} +1 -1
- package/dist/storybook/assets/{side-bar.stories-rKoL8lrf.js → side-bar.stories-mtQSbRi1.js} +1 -1
- package/dist/storybook/assets/{site.stories-nwcDZZdB.js → site.stories-L_U9kFiJ.js} +1 -1
- package/dist/storybook/assets/{slider-0HIxE6AZ.js → slider-n3IxC2iq.js} +1 -1
- package/dist/storybook/assets/{slider.stories-9wM3WmDC.js → slider.stories-ZZQVWjaY.js} +1 -1
- package/dist/storybook/assets/{smart-upload-modal.stories-Lqh7FFLe.js → smart-upload-modal.stories-2PLKfrKC.js} +1 -1
- package/dist/storybook/assets/{spacer.stories-4n4RL13L.js → spacer.stories-oFV2pFb8.js} +1 -1
- package/dist/storybook/assets/{syntaxhighlighter-B5GMVT5T-jJ-aXkjr.js → syntaxhighlighter-B5GMVT5T-exhsGVYA.js} +1 -1
- package/dist/storybook/assets/table-yS0o5bJS.js +1 -0
- package/dist/storybook/assets/{table.stories-data-6LXl4zwR.js → table.stories-data-UtsQXBjO.js} +1 -1
- package/dist/storybook/assets/{table.stories-N07QxfiK.js → table.stories-gVTJDINj.js} +1 -1
- package/dist/storybook/assets/{textarea-c5fYK9-8.js → textarea-RrPYPGCC.js} +1 -1
- package/dist/storybook/assets/{textarea.stories-soUP2Yhm.js → textarea.stories-rqdJWVro.js} +1 -1
- package/dist/storybook/assets/{title.stories-MKmiziEV.js → title.stories-ILp8GFMp.js} +1 -1
- package/dist/storybook/assets/{toaster.stories-Na9wGy65.js → toaster.stories-Cu8HbPc6.js} +1 -1
- package/dist/storybook/assets/{toggle-gxvny8zu.js → toggle-R__kwKym.js} +1 -1
- package/dist/storybook/assets/{toggle.stories-_Qd5Xk1K.js → toggle.stories-ViKd2aK_.js} +1 -1
- package/dist/storybook/assets/{tooltip-pjcB4ZxN.js → tooltip-dueTLnwA.js} +1 -1
- package/dist/storybook/assets/{tooltip.stories-YJfYxnb3.js → tooltip.stories-a_gd0XYu.js} +1 -1
- package/dist/storybook/assets/{tooltip.test-case.stories-ZUrHDklJ.js → tooltip.test-case.stories-68kziAjk.js} +1 -1
- package/dist/storybook/assets/{top-bar--h98E6oo.js → top-bar-KGd_PI0n.js} +1 -1
- package/dist/storybook/assets/{top-bar.stories-eahNLSjM.js → top-bar.stories-wVH6POte.js} +1 -1
- package/dist/storybook/assets/{top-bar.testcase.stories-AbbFHB0-.js → top-bar.testcase.stories-ATUEatgx.js} +1 -1
- package/dist/storybook/assets/{tree.stories-JyczIgiP.js → tree.stories-cTww9R00.js} +1 -1
- package/dist/storybook/assets/unit-input-qBUtqoTb.css +1 -0
- package/dist/storybook/assets/unit-input.stories-AGMYBqCC.js +284 -0
- package/dist/storybook/assets/unit-table.stories-KRnQ5bCj.js +150 -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 +8 -9
- package/dist/storybook/assets/iframe-7Gvk33Dy.js +0 -7
- package/dist/storybook/assets/number-input-yoDwXp2C.js +0 -1
- package/dist/storybook/assets/number-input.stories-QRbtwUKs.js +0 -153
- package/dist/storybook/assets/table-tDId3FKL.js +0 -1
- package/dist/storybook/assets/unit-input-OT-AqIIa.css +0 -1
- package/dist/storybook/assets/unit-input.stories-diwgawFe.js +0 -349
- package/dist/storybook/assets/unit-table.stories-6agZ80lN.js +0 -150
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as p}from"./index-RfLt4OUa.js";import{d as i,r as ct}from"./index-qZmQ7nA9.js";import{c as mt}from"./index-VW3EWkuE.js";import{u as pt}from"./use-previous-VKMmnaK7.js";import{M as Ee}from"./actions-0ELEGFed.js";import{I as gt}from"./input-group-addon-BHVsW9mL.js";import{B as c}from"./button-BiJw0fB3.js";import{T as ht}from"./tooltip-dueTLnwA.js";import{I as vt}from"./input-group-R8LoqKRn.js";import{S as I}from"./spacer-Yji9g2AW.js";import{T as Kn}from"./text-6KQ6ntOV.js";import{I as ft}from"./input-fYKvBwPs.js";import{M as Ne}from"./types-VB5zD18b.js";import{l as E}from"./lodash-Bmg8FrMx.js";import{D as Ct}from"./divider-RwW2f_N0.js";import{R as $n,C as ge}from"./row-vFUhHoz5.js";import{F as j}from"./field-m7XXDdEG.js";import{M as he}from"./message-CRKuTfOl.js";import"./index-cCpkwrS5.js";import"./common-types-U65vzrrz.js";import"./disabled-context-urNQThQz.js";import"./icon-8EQazuuW.js";import"./objectWithoutPropertiesLoose-9Q1jwsKS.js";import"./inheritsLoose-8sb_A2v4.js";import"./tslib.es6-OIsz3r9a.js";import"./index-4QtD-hFu.js";import"./types-5uVBABF4.js";import"./badge-23Ty_zBt.js";import"./spinner-R8Il4aRe.js";import"./index-miLrID2P.js";import"./styled-components.browser.esm-qIipjd6c.js";import"./label-bLcoUwtK.js";import"./help-icon-eelulTML.js";const bt=()=>{const n=p.useRef(null);return p.useLayoutEffect(()=>{n.current&&(n.current(),n.current=null)}),t=>{n.current=t}},Ut=(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.`),i.unitFromQuantity(n)??"")};var b=(n=>(n.CUSTOM="custom",n.PREDEFINED="predefined",n))(b||{});const Hn=n=>n==="undefined"||n===void 0||n===""||n==="null"||n===null||n==="NaN"||isNaN(n),zn=(n="",a,t="",s=!1)=>{if(s)return n;if(a&&!Hn(n))try{const o=i.isValueWithUnit(n)?n:i.withUnit(n,t),d=i.convertSamePrecision(o,a);return i.getValue(d)}catch{}return n},yt=n=>n?!!i.getUnit(n):!1,M=(n="",a,t,s)=>{if(s)return n;const o=yt(n)||i.isValueWithUnit(n),d=i.getValue(n);return Hn(d)?d:o?zn(d,a,t,s):n},Ae=n=>E.isObject(n)&&!E.isArray(n)&&!E.isFunction(n)?E.get(n,"fieldName",""):typeof n=="string"?n:"",xt=n=>E.isObjectLike(n)&&E.has(n,"message"),Vt=n=>typeof n=="string"?n:xt(n)?n.message:null;var jt=ct();const It=n=>n.search(RegExp(/(^0{2}\.)|(^0+[1-9])/g))===0,Pe=(n,a)=>{var k;const{allowEmpty:t=!1,autoValue:s,placeholder:o,disabledValidation:d=!1}=a||{},l=String(n);if(d||s||o)return null;const g=jt.isValueWithUnit(l)?i.getValue(l):l;if(t&&g==="")return null;if(It(g))return"Invalid number format due to leading zeroes";const h=i.validateNumber(g);if(!h.valid){const le=((k=h==null?void 0:h.errors)==null?void 0:k[0])??null;return Vt(le)}return null},De=(n="")=>{var a;return(a=i.KNOWN_UNITS)==null?void 0:a.includes(n)},kt=(n,a)=>{const t=i.getUnit(n||"");return De(a)&&De(t)},St="_predefinedMenuActive_1yvt4_1",wt={predefinedMenuActive:St},m=({name:n,placeholder:a="",disabled:t=!1,disabledUnit:s=!1,error:o=null,left:d=!1,small:l=!1,width:g="100%",value:h,unitkey:k="",initUnit:le,noConversion:Gn=!1,onChange:se=()=>{},onClick:Nt=()=>{},onFocus:Jn=()=>{},onSwitchUnit:ve=()=>{},unitTemplate:fe,doNotConvertValue:A=!1,testId:w,warning:Yn=null,predefinedOptions:x,initialPredefinedOption:Zn=!1,shouldLinkAutomaticly:Ce=!0,selectedPredefinedOptionKey:be,validationCallback:Ue=()=>({name:"",error:null}),disabledValidation:ye=!1,allowEmpty:xe=!1,autoValue:V})=>{typeof h=="number"&&(h=`${h}`);const Qn=bt(),[ue="",P=""]=h!==void 0?i.split(h):[],Ve=V?i.getUnit(V):"",je=p.useMemo(()=>Ut(k,fe),[k,fe]),Xn=kt(h,je),y=le||je||P,et=pt(y),Ie=M(h,y,P,A),ke=M(V,y,Ve,A),nt=Ie!==""?{value:Ie,unit:y}:ke!==""?{value:ke,unit:y}:{value:ue,unit:P},[v,Y]=p.useState(nt),[tt,oe]=p.useState(null),[S,de]=p.useState(Zn?b.PREDEFINED:b.CUSTOM),ce=ue===""&&V,D=x&&x.find(r=>{if(!(r!=null&&r.value))return;if(be)return be===r.valueKey;const u=i.isValueWithUnit(r==null?void 0:r.value)?i.getUnit(r==null?void 0:r.value):"";return i.withUnit(zn(h,u),u)===(r==null?void 0:r.value)}),at=()=>{if(k)try{const r=ce?V:h??"";let u=i.altUnitsList(r,k);return i.getValue(r)===""?u.map(f=>["",f[1]]):u}catch{return null}},rt=r=>{const u=Ae(n),f=r.target,{value:U,selectionStart:F}=f,we=i.cleanNumStr(U.replaceAll(" ","").replaceAll("|","")),me=i.withUnit(we,(v==null?void 0:v.unit)||""),ut=i.getValue(me),pe=Pe(ut,{allowEmpty:xe,autoValue:V,placeholder:a,disabledValidation:ye});if(pe===null){se({target:{value:me,name:u}});const[ot,dt]=i.split(me);Y({value:ot,unit:dt}),oe(null),Ue(u,null)}else Y({value:we,unit:v.unit}),oe(pe),Ue(u,pe);Qn(()=>{f.selectionStart=F,f.selectionEnd=F})},it=(r,u)=>{u===v.unit||isNaN(Number(r))||(Y({value:r,unit:u}),ve&&ve(u))};p.useEffect(()=>{if(y){let f,U="";et!==y?(f=M(h,y,P,A),U=y):i.withUnit(v.value,v.unit)!==h&&(f=M(h,v.unit,P,A),U=v.unit),f!==void 0&&Y({value:f,unit:U}),x&&de(D&&Ce?b.PREDEFINED:b.CUSTOM)}const r=i.checkAndCleanDecimalComma(ue),u=Pe(r,{allowEmpty:xe,autoValue:V,placeholder:a,disabledValidation:ye});oe(u)},[y,h,o,Ce]);const Z=at(),Q=i.label(v.unit)||v.unit||"",lt=Gn||!Z||Z&&Z.length===1,Se=Ae(n);let X;const st=r=>{const u=r!=null&&r.value?r.value:"",[f="",U=""]=i.isValueWithUnit(u)?i.split(u):[u];return{type:Ne.OPTION,inline:!0,onClick:()=>{i.validateNumber(f).valid&&!t&&(de(b.PREDEFINED),se({target:{value:u,name:typeof n=="string"?n:(n==null?void 0:n.fieldName)||"",predefinedSelected:!0,predefinedOption:r}}))},label:e.jsxs(e.Fragment,{children:[e.jsx(Kn,{children:r.label}),e.jsx(I,{width:"20px",height:"0"})]}),description:i.isValueWithUnit(u)?`${f} ${U}`:u,selected:D===r&&S===b.PREDEFINED}};if(X=[{type:Ne.OPTION,inline:!0,onClick:()=>{S!==b.CUSTOM&&!t&&se({target:{value:i.withUnit(v.value,v.unit),name:typeof n=="string"?n:(n==null?void 0:n.fieldName)||""}})},label:"Custom",selected:S===b.CUSTOM}],x!=null&&x.length){const r=x.map(st);X=[...X,...r]}return e.jsx("div",{className:S===b.PREDEFINED?mt(wt.predefinedMenuActive):"",children:e.jsxs(vt,{small:l,width:g,children:[x&&e.jsx(ht,{text:S===b.PREDEFINED?D==null?void 0:D.label:"",children:e.jsx(Ee,{maxHeight:380,groupOrder:"first",testId:w&&`${w}-predefined-menu`,disabled:t,menu:{colored:!0,trigger:"Component",component:e.jsx(c,{groupOrder:"first",active:S===b.PREDEFINED,icon:S===b.PREDEFINED?"link":"unlink"}),small:l,sections:X}})}),e.jsx(ft,{type:"text",name:Se,testId:w,disabled:t,placeholder:ce?M(V,v.unit,Ve,A):a,value:v.value,onChange:rt,onFocus:Jn,error:o||tt,warning:Yn,right:!d},Se),Q&&(lt||!Xn?e.jsx(gt,{groupOrder:"last",children:Q}):e.jsx(Ee,{maxHeight:380,groupOrder:"last",disabled:s,testId:w&&`${w}-menu`,menu:{label:Q,trigger:"DropDownButton",small:l,sections:Z.map(([r,u,f])=>{const U=f||u||"";return{type:"Option",label:isNaN(Number(r))?"":r,inline:!0,onClick:F=>{F.stopPropagation(),it(ce?"":r,u)},description:U,selected:U===Q,testId:`${w}-unit-${U}`}})}}))]})})};try{m.displayName="UnitInput",m.__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[] | null"}},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:Et}=__STORYBOOK_MODULE_ADDONS__,ca={title:"Basic/UnitInput",component:m,args:{name:"example",unitkey:"length",value:"123|m"}},C=n=>{const[a,t]=Et(),s=o=>{t({value:o.target.value})};return e.jsx(m,{...n,onChange:s})},ee=C.bind({}),O=C.bind({});O.args={initUnit:"ft",unitTemplate:{length:"ft"}};const _=C.bind({});_.args={value:'123|"',unitkey:'"'};const W=C.bind({});W.args={width:"180px"};const B=C.bind({});B.args={noConversion:!0};const T=C.bind({});T.args={small:!0};const q=C.bind({});q.args={error:"Error message goes here"};const R=C.bind({});R.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 L=C.bind({});L.args={disabled:!0,disabledUnit:!0,noConversion:!0};const K=C.bind({});K.args={disabledUnit:!0,unitkey:void 0};const $=C.bind({});$.args={disabledUnit:!0,unitkey:"length"};const H=C.bind({});H.args={disabledUnit:!1,disabled:!0};const z=n=>{const[a,t]=p.useState("123|m"),[s,o]=p.useState("223|m"),[d,l]=p.useState("ft");return e.jsxs(e.Fragment,{children:[e.jsx(c,{label:"Change initUnit",onClick:()=>l(d==="m"?"ft":"m")}),e.jsx(I,{}),e.jsx(c,{label:"Change value",onClick:()=>t(a==="123|m"?"456|m":"123|m")}),e.jsx(I,{}),e.jsx(m,{name:"example",onChange:g=>{t(g.target.value)},unitkey:"length",value:a,initUnit:d,onSwitchUnit:l}),e.jsx(I,{}),e.jsx(m,{name:"example2",onChange:g=>{o(g.target.value)},unitkey:"length",value:s,initUnit:d,onSwitchUnit:l}),e.jsx(Ct,{}),e.jsx("h4",{children:"Without initUnit property (taken from the redux store)"}),e.jsx(m,{name:"example",onChange:g=>{t(g.target.value)},unitkey:"length",value:a,onSwitchUnit:l}),e.jsx(m,{name:"example2",onChange:g=>{o(g.target.value)},unitkey:"length",value:s,onSwitchUnit:l})]})};z.parameters={docs:{description:{story:"[OW-4380](https://oliasoft.atlassian.net/browse/OW-4380?atlOrigin=eyJpIjoiMmM1N2RkNWU3Mjk5NDYxY2E0YzhkMzk5ZTVmZTJhMjciLCJwIjoiaiJ9)"}}};const G=C.bind({});G.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]=p.useState(void 0);return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different edge cases such as +/- infinity, undefined, NaN, null:"}),e.jsxs($n,{children:[e.jsxs(ge,{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(ge,{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(j,{label:"Normal PUI",children:e.jsx(m,{name:"example1",onChange:s=>t(s.target.value),value:a,unitkey:"length",width:n,placeholder:"value|unit"})}),e.jsx(j,{label:"Disabled validation",children:e.jsx(m,{name:"example2",onChange:s=>t(s.target.value),value:a,unitkey:"length",disabledValidation:!0,width:n})}),e.jsx(j,{label:"Disabled validation and manual error",children:e.jsx(m,{name:"example3",onChange:s=>t(s.target.value),value:a,unitkey:"length",error:"test",disabledValidation:!0,width:n})}),e.jsx(he,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})},ne=()=>{const n="500px",[a,t]=p.useState("1|m"),[s,o]=p.useState("|m"),d="123|km";return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different cases for automatic (placeholder) values:"}),e.jsx($n,{children:e.jsxs(ge,{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(j,{label:"Normal PUI (placeholder + auto)",children:e.jsx(m,{name:"example1",onChange:l=>t(l.target.value),value:a,unitkey:"length",width:n,placeholder:"value|unit",autoValue:d})}),e.jsx(j,{label:"Normal PUI (only auto)",children:e.jsx(m,{name:"example1",onChange:l=>t(l.target.value),value:a,unitkey:"length",width:n,autoValue:d})}),e.jsx(j,{label:"Empty PUI with autoValue",children:e.jsx(m,{name:"example1",onChange:l=>o(l.target.value),value:s,unitkey:"length",width:n,autoValue:d})}),e.jsx(j,{label:"Normal PUI (only placeholder)",children:e.jsx(m,{name:"example1",onChange:l=>t(l.target.value),value:a,unitkey:"length",width:n,placeholder:"Placeholder test"})}),e.jsx(j,{label:"Normal PUI (placeholder + allowEmpty)",children:e.jsx(m,{name:"example1",onChange:l=>t(l.target.value),value:a,unitkey:"length",width:n,placeholder:"Placeholder test",allowEmpty:!0})}),e.jsx(he,{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]=p.useState("123|%"),[t,s]=p.useState(null),o="This should be visible when an error appears",d=(l,g)=>(s(g),{name:l,error:g});return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"3rd party validation message when inputting invalid value:"}),e.jsx(m,{name:"example",onChange:l=>a(l.target.value),error:!t||o,validationCallback:d,value:n}),e.jsx("br",{}),e.jsx(I,{}),e.jsx("h4",{children:"Original validation message: "}),e.jsx(he,{message:{heading:t,visible:!0}})]})},ae=()=>{const[n,a]=p.useState("123|m"),[t,s]=p.useState(""),[o,d]=p.useState("km"),l=()=>{d("ft"),s("placeholder"),a("|m")};return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Empty value case:"}),e.jsx(m,{name:"example",onChange:g=>a(g.target.value),value:n,allowEmpty:!0,placeholder:t,initUnit:o,unitkey:"length"}),e.jsx("br",{}),e.jsx(I,{}),e.jsx(c,{label:"Change value |m and unit ft",onClick:()=>l()})]})},re=()=>{const[n,a]=p.useState("123|m"),[t,s]=p.useState("m");return e.jsxs(e.Fragment,{children:[e.jsx(m,{name:"example",onChange:o=>a(o.target.value),value:n,initUnit:t,unitkey:"length",onSwitchUnit:s}),e.jsx(I,{}),e.jsx(m,{name:"example",onChange:o=>a(o.target.value),value:n,initUnit:t,unitkey:"length",onSwitchUnit:s})]})},ie=()=>e.jsxs(e.Fragment,{children:[e.jsx(Kn,{faint:!0,children:"Reproduce OW-10614 rounding noise bug when storing values in a different unit to the display unit"}),e.jsx(I,{}),e.jsx(m,{name:"example",onChange:()=>{},value:i.withUnit(i.convertAndGetValue("9750|psi","bar"),"bar"),initUnit:"psi",unitkey:"pressure",unitTemplate:{pressure:"psi"}})]});var Fe,Me,Oe;ee.parameters={...ee.parameters,docs:{...(Fe=ee.parameters)==null?void 0:Fe.docs,source:{originalSource:`args => {
|
|
2
|
+
const [_, updateArgs] = useArgs();
|
|
3
|
+
const handleChange = (evt: any) => {
|
|
4
|
+
updateArgs({
|
|
5
|
+
value: evt.target.value
|
|
6
|
+
});
|
|
7
|
+
};
|
|
8
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
9
|
+
}`,...(Oe=(Me=ee.parameters)==null?void 0:Me.docs)==null?void 0:Oe.source}}};var _e,We,Be;O.parameters={...O.parameters,docs:{...(_e=O.parameters)==null?void 0:_e.docs,source:{originalSource:`args => {
|
|
10
|
+
const [_, updateArgs] = useArgs();
|
|
11
|
+
const handleChange = (evt: any) => {
|
|
12
|
+
updateArgs({
|
|
13
|
+
value: evt.target.value
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
17
|
+
}`,...(Be=(We=O.parameters)==null?void 0:We.docs)==null?void 0:Be.source}}};var Te,qe,Re;_.parameters={..._.parameters,docs:{...(Te=_.parameters)==null?void 0:Te.docs,source:{originalSource:`args => {
|
|
18
|
+
const [_, updateArgs] = useArgs();
|
|
19
|
+
const handleChange = (evt: any) => {
|
|
20
|
+
updateArgs({
|
|
21
|
+
value: evt.target.value
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
25
|
+
}`,...(Re=(qe=_.parameters)==null?void 0:qe.docs)==null?void 0:Re.source}}};var Le,Ke,$e;W.parameters={...W.parameters,docs:{...(Le=W.parameters)==null?void 0:Le.docs,source:{originalSource:`args => {
|
|
26
|
+
const [_, updateArgs] = useArgs();
|
|
27
|
+
const handleChange = (evt: any) => {
|
|
28
|
+
updateArgs({
|
|
29
|
+
value: evt.target.value
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
33
|
+
}`,...($e=(Ke=W.parameters)==null?void 0:Ke.docs)==null?void 0:$e.source}}};var He,ze,Ge;B.parameters={...B.parameters,docs:{...(He=B.parameters)==null?void 0:He.docs,source:{originalSource:`args => {
|
|
34
|
+
const [_, updateArgs] = useArgs();
|
|
35
|
+
const handleChange = (evt: any) => {
|
|
36
|
+
updateArgs({
|
|
37
|
+
value: evt.target.value
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
41
|
+
}`,...(Ge=(ze=B.parameters)==null?void 0:ze.docs)==null?void 0:Ge.source}}};var Je,Ye,Ze;T.parameters={...T.parameters,docs:{...(Je=T.parameters)==null?void 0:Je.docs,source:{originalSource:`args => {
|
|
42
|
+
const [_, updateArgs] = useArgs();
|
|
43
|
+
const handleChange = (evt: any) => {
|
|
44
|
+
updateArgs({
|
|
45
|
+
value: evt.target.value
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
49
|
+
}`,...(Ze=(Ye=T.parameters)==null?void 0:Ye.docs)==null?void 0:Ze.source}}};var Qe,Xe,en;q.parameters={...q.parameters,docs:{...(Qe=q.parameters)==null?void 0:Qe.docs,source:{originalSource:`args => {
|
|
50
|
+
const [_, updateArgs] = useArgs();
|
|
51
|
+
const handleChange = (evt: any) => {
|
|
52
|
+
updateArgs({
|
|
53
|
+
value: evt.target.value
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
57
|
+
}`,...(en=(Xe=q.parameters)==null?void 0:Xe.docs)==null?void 0:en.source}}};var nn,tn,an;R.parameters={...R.parameters,docs:{...(nn=R.parameters)==null?void 0:nn.docs,source:{originalSource:`args => {
|
|
58
|
+
const [_, updateArgs] = useArgs();
|
|
59
|
+
const handleChange = (evt: any) => {
|
|
60
|
+
updateArgs({
|
|
61
|
+
value: evt.target.value
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
65
|
+
}`,...(an=(tn=R.parameters)==null?void 0:tn.docs)==null?void 0:an.source}}};var rn,ln,sn;N.parameters={...N.parameters,docs:{...(rn=N.parameters)==null?void 0:rn.docs,source:{originalSource:`args => {
|
|
66
|
+
const [_, updateArgs] = useArgs();
|
|
67
|
+
const handleChange = (evt: any) => {
|
|
68
|
+
updateArgs({
|
|
69
|
+
value: evt.target.value
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
73
|
+
}`,...(sn=(ln=N.parameters)==null?void 0:ln.docs)==null?void 0:sn.source}}};var un,on,dn;L.parameters={...L.parameters,docs:{...(un=L.parameters)==null?void 0:un.docs,source:{originalSource:`args => {
|
|
74
|
+
const [_, updateArgs] = useArgs();
|
|
75
|
+
const handleChange = (evt: any) => {
|
|
76
|
+
updateArgs({
|
|
77
|
+
value: evt.target.value
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
81
|
+
}`,...(dn=(on=L.parameters)==null?void 0:on.docs)==null?void 0:dn.source}}};var cn,mn,pn;K.parameters={...K.parameters,docs:{...(cn=K.parameters)==null?void 0:cn.docs,source:{originalSource:`args => {
|
|
82
|
+
const [_, updateArgs] = useArgs();
|
|
83
|
+
const handleChange = (evt: any) => {
|
|
84
|
+
updateArgs({
|
|
85
|
+
value: evt.target.value
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
89
|
+
}`,...(pn=(mn=K.parameters)==null?void 0:mn.docs)==null?void 0:pn.source}}};var gn,hn,vn;$.parameters={...$.parameters,docs:{...(gn=$.parameters)==null?void 0:gn.docs,source:{originalSource:`args => {
|
|
90
|
+
const [_, updateArgs] = useArgs();
|
|
91
|
+
const handleChange = (evt: any) => {
|
|
92
|
+
updateArgs({
|
|
93
|
+
value: evt.target.value
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
97
|
+
}`,...(vn=(hn=$.parameters)==null?void 0:hn.docs)==null?void 0:vn.source}}};var fn,Cn,bn;H.parameters={...H.parameters,docs:{...(fn=H.parameters)==null?void 0:fn.docs,source:{originalSource:`args => {
|
|
98
|
+
const [_, updateArgs] = useArgs();
|
|
99
|
+
const handleChange = (evt: any) => {
|
|
100
|
+
updateArgs({
|
|
101
|
+
value: evt.target.value
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
105
|
+
}`,...(bn=(Cn=H.parameters)==null?void 0:Cn.docs)==null?void 0:bn.source}}};var Un,yn,xn;z.parameters={...z.parameters,docs:{...(Un=z.parameters)==null?void 0:Un.docs,source:{originalSource:`(args: IUnitInputProps) => {
|
|
106
|
+
const [value, setValue] = useState<string | undefined>('123|m');
|
|
107
|
+
const [value2, setValue2] = useState<string | undefined>('223|m');
|
|
108
|
+
const [initUnit, setInitUnit] = useState<string | undefined>('ft');
|
|
109
|
+
return <>
|
|
110
|
+
<Button label="Change initUnit" onClick={() => setInitUnit(initUnit === 'm' ? 'ft' : 'm')} />
|
|
111
|
+
<Spacer />
|
|
112
|
+
<Button label="Change value" onClick={() => setValue(value === '123|m' ? '456|m' : '123|m')} />
|
|
113
|
+
<Spacer />
|
|
114
|
+
<UnitInput name="example" onChange={evt => {
|
|
115
|
+
setValue(evt.target.value);
|
|
116
|
+
}} unitkey="length" value={value} initUnit={initUnit} onSwitchUnit={setInitUnit} />
|
|
117
|
+
<Spacer />
|
|
118
|
+
<UnitInput name="example2" onChange={evt => {
|
|
119
|
+
setValue2(evt.target.value);
|
|
120
|
+
}} unitkey="length" value={value2} initUnit={initUnit} onSwitchUnit={setInitUnit} />
|
|
121
|
+
<Divider />
|
|
122
|
+
<h4>Without initUnit property (taken from the redux store)</h4>
|
|
123
|
+
<UnitInput name="example" onChange={evt => {
|
|
124
|
+
setValue(evt.target.value);
|
|
125
|
+
}} unitkey="length" value={value} onSwitchUnit={setInitUnit} />
|
|
126
|
+
<UnitInput name="example2" onChange={evt => {
|
|
127
|
+
setValue2(evt.target.value);
|
|
128
|
+
}} unitkey="length" value={value2} onSwitchUnit={setInitUnit} />
|
|
129
|
+
</>;
|
|
130
|
+
}`,...(xn=(yn=z.parameters)==null?void 0:yn.docs)==null?void 0:xn.source}}};var Vn,jn,In;G.parameters={...G.parameters,docs:{...(Vn=G.parameters)==null?void 0:Vn.docs,source:{originalSource:`args => {
|
|
131
|
+
const [_, updateArgs] = useArgs();
|
|
132
|
+
const handleChange = (evt: any) => {
|
|
133
|
+
updateArgs({
|
|
134
|
+
value: evt.target.value
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
138
|
+
}`,...(In=(jn=G.parameters)==null?void 0:jn.docs)==null?void 0:In.source}}};var kn,Sn,wn;J.parameters={...J.parameters,docs:{...(kn=J.parameters)==null?void 0:kn.docs,source:{originalSource:`() => {
|
|
139
|
+
const width = '500px';
|
|
140
|
+
const [value, setValue] = useState<any>(undefined);
|
|
141
|
+
return <>
|
|
142
|
+
<h4>Different edge cases such as +/- infinity, undefined, NaN, null:</h4>
|
|
143
|
+
<Row>
|
|
144
|
+
<Column width="25%">
|
|
145
|
+
<Button label="Change value infinity" onClick={() => setValue(Infinity)} />
|
|
146
|
+
<br />
|
|
147
|
+
<Button label="Change value -infinity" onClick={() => setValue(-Infinity)} />
|
|
148
|
+
<br />
|
|
149
|
+
<Button label="Change value null" onClick={() => setValue(null)} />
|
|
150
|
+
<br />
|
|
151
|
+
<Button label="Change value - undefined" onClick={() => setValue(undefined)} />
|
|
152
|
+
<br />
|
|
153
|
+
<Button label="Change value - NaN" onClick={() => setValue(NaN)} />
|
|
154
|
+
<br />
|
|
155
|
+
<Button label="Change value - nothing (empty)" onClick={() => setValue(undefined)} />
|
|
156
|
+
<br />
|
|
157
|
+
<Button label="Change value - empty string" onClick={() => setValue('')} />
|
|
158
|
+
</Column>
|
|
159
|
+
<Column width="25%">
|
|
160
|
+
<Button label="Change value infinity|m" onClick={() => setValue(Infinity + '|m')} />
|
|
161
|
+
<br />
|
|
162
|
+
<Button label="Change value -infinity|m" onClick={() => setValue(-Infinity + '|m')} />
|
|
163
|
+
<br />
|
|
164
|
+
<Button label="Change value null|m" onClick={() => setValue(null + '|m')} />
|
|
165
|
+
<br />
|
|
166
|
+
<Button label="Change value - undefined|m" onClick={() => setValue(undefined + '|m')} />
|
|
167
|
+
<br />
|
|
168
|
+
<Button label="Change value - NaN|m" onClick={() => setValue(NaN + '|m')} />
|
|
169
|
+
<br />
|
|
170
|
+
<Button label="Change value - nothing (empty)|m" onClick={() => setValue('|m')} />
|
|
171
|
+
</Column>
|
|
172
|
+
</Row>
|
|
173
|
+
<br />
|
|
174
|
+
<Field label="Normal PUI">
|
|
175
|
+
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="value|unit" />
|
|
176
|
+
</Field>
|
|
177
|
+
<Field label="Disabled validation">
|
|
178
|
+
<UnitInput name="example2" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" disabledValidation width={width} />
|
|
179
|
+
</Field>
|
|
180
|
+
<Field label="Disabled validation and manual error">
|
|
181
|
+
<UnitInput name="example3" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" error="test" disabledValidation width={width} />
|
|
182
|
+
</Field>
|
|
183
|
+
<Message message={{
|
|
184
|
+
heading: 'Current value inside PUI: ' + value,
|
|
185
|
+
visible: true
|
|
186
|
+
}} />
|
|
187
|
+
</>;
|
|
188
|
+
}`,...(wn=(Sn=J.parameters)==null?void 0:Sn.docs)==null?void 0:wn.source}}};var En,Nn,An;ne.parameters={...ne.parameters,docs:{...(En=ne.parameters)==null?void 0:En.docs,source:{originalSource:`() => {
|
|
189
|
+
const width = '500px';
|
|
190
|
+
const [value, setValue] = useState<string | undefined>('1|m');
|
|
191
|
+
const [valueB, setValueB] = useState<string | undefined>('|m');
|
|
192
|
+
const automaticValue = '123|km';
|
|
193
|
+
return <>
|
|
194
|
+
<h4>Different cases for automatic (placeholder) values:</h4>
|
|
195
|
+
<Row>
|
|
196
|
+
<Column width="25%">
|
|
197
|
+
<Button label="Change value to ''" onClick={() => setValue('')} />
|
|
198
|
+
<br />
|
|
199
|
+
<Button label="Change value to 1" onClick={() => setValue('1')} />
|
|
200
|
+
<br />
|
|
201
|
+
<Button label="Change value to 1|m" onClick={() => setValue('1|m')} />
|
|
202
|
+
<br />
|
|
203
|
+
<Button label="Change value to |m - empty value" onClick={() => setValue('|m')} />
|
|
204
|
+
</Column>
|
|
205
|
+
</Row>
|
|
206
|
+
<br />
|
|
207
|
+
<Field label="Normal PUI (placeholder + auto)">
|
|
208
|
+
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="value|unit" autoValue={automaticValue} />
|
|
209
|
+
</Field>
|
|
210
|
+
<Field label="Normal PUI (only auto)">
|
|
211
|
+
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} autoValue={automaticValue} />
|
|
212
|
+
</Field>
|
|
213
|
+
<Field label="Empty PUI with autoValue">
|
|
214
|
+
<UnitInput name="example1" onChange={evt => setValueB(evt.target.value)} value={valueB} unitkey="length" width={width} autoValue={automaticValue} />
|
|
215
|
+
</Field>
|
|
216
|
+
<Field label="Normal PUI (only placeholder)">
|
|
217
|
+
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="Placeholder test" />
|
|
218
|
+
</Field>
|
|
219
|
+
<Field label="Normal PUI (placeholder + allowEmpty)">
|
|
220
|
+
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="Placeholder test" allowEmpty />
|
|
221
|
+
</Field>
|
|
222
|
+
<Message message={{
|
|
223
|
+
heading: 'Current value inside PUI: ' + value,
|
|
224
|
+
visible: true
|
|
225
|
+
}} />
|
|
226
|
+
</>;
|
|
227
|
+
}`,...(An=(Nn=ne.parameters)==null?void 0:Nn.docs)==null?void 0:An.source}}};var Pn,Dn,Fn;te.parameters={...te.parameters,docs:{...(Pn=te.parameters)==null?void 0:Pn.docs,source:{originalSource:`() => {
|
|
228
|
+
const [value, setValue] = useState<string | undefined>('123|%');
|
|
229
|
+
const [validation, setValidation] = useState<string | null>(null);
|
|
230
|
+
const predictedMessage = 'This should be visible when an error appears';
|
|
231
|
+
const handleValidation = (name: string, message: string | null) => {
|
|
232
|
+
setValidation(message);
|
|
233
|
+
return {
|
|
234
|
+
name,
|
|
235
|
+
error: message
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
return <>
|
|
239
|
+
<h4>3rd party validation message when inputting invalid value:</h4>
|
|
240
|
+
<UnitInput name="example" onChange={evt => setValue(evt.target.value)} error={!validation || predictedMessage} validationCallback={handleValidation} value={value} />
|
|
241
|
+
<br />
|
|
242
|
+
<Spacer />
|
|
243
|
+
<h4>Original validation message: </h4>
|
|
244
|
+
<Message message={{
|
|
245
|
+
heading: validation,
|
|
246
|
+
visible: true
|
|
247
|
+
}} />
|
|
248
|
+
</>;
|
|
249
|
+
}`,...(Fn=(Dn=te.parameters)==null?void 0:Dn.docs)==null?void 0:Fn.source}}};var Mn,On,_n;ae.parameters={...ae.parameters,docs:{...(Mn=ae.parameters)==null?void 0:Mn.docs,source:{originalSource:`() => {
|
|
250
|
+
const [value, setValue] = useState<string | undefined>('123|m');
|
|
251
|
+
const [placeholder, setPlaceholder] = useState<string | undefined>('');
|
|
252
|
+
const [initUnit, setInitUnit] = useState<string | undefined>('km');
|
|
253
|
+
const setPlaceholderValue = () => {
|
|
254
|
+
setInitUnit('ft');
|
|
255
|
+
setPlaceholder('placeholder');
|
|
256
|
+
setValue('|m');
|
|
257
|
+
};
|
|
258
|
+
return <>
|
|
259
|
+
<h4>Empty value case:</h4>
|
|
260
|
+
<UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} allowEmpty placeholder={placeholder} initUnit={initUnit} unitkey="length" />
|
|
261
|
+
<br />
|
|
262
|
+
<Spacer />
|
|
263
|
+
<Button label="Change value |m and unit ft" onClick={() => setPlaceholderValue()} />
|
|
264
|
+
</>;
|
|
265
|
+
}`,...(_n=(On=ae.parameters)==null?void 0:On.docs)==null?void 0:_n.source}}};var Wn,Bn,Tn;re.parameters={...re.parameters,docs:{...(Wn=re.parameters)==null?void 0:Wn.docs,source:{originalSource:`() => {
|
|
266
|
+
const [value, setValue] = useState<string | undefined>('123|m');
|
|
267
|
+
const [unit, setUnit] = useState<string | undefined>('m');
|
|
268
|
+
return <>
|
|
269
|
+
<UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} initUnit={unit} unitkey="length" onSwitchUnit={setUnit} />
|
|
270
|
+
<Spacer />
|
|
271
|
+
<UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} initUnit={unit} unitkey="length" onSwitchUnit={setUnit} />
|
|
272
|
+
</>;
|
|
273
|
+
}`,...(Tn=(Bn=re.parameters)==null?void 0:Bn.docs)==null?void 0:Tn.source}}};var qn,Rn,Ln;ie.parameters={...ie.parameters,docs:{...(qn=ie.parameters)==null?void 0:qn.docs,source:{originalSource:`() => {
|
|
274
|
+
return <>
|
|
275
|
+
<Text faint>
|
|
276
|
+
Reproduce OW-10614 rounding noise bug when storing values in a different
|
|
277
|
+
unit to the display unit
|
|
278
|
+
</Text>
|
|
279
|
+
<Spacer />
|
|
280
|
+
<UnitInput name="example" onChange={() => {}} value={withUnit(convertAndGetValue('9750|psi', 'bar'), 'bar')} initUnit="psi" unitkey="pressure" unitTemplate={{
|
|
281
|
+
pressure: 'psi'
|
|
282
|
+
}} />
|
|
283
|
+
</>;
|
|
284
|
+
}`,...(Ln=(Rn=ie.parameters)==null?void 0:Rn.docs)==null?void 0:Ln.source}}};const ma=["Default","InitUnit","notKnownUnit","Width","NoConversion","Small","Error","InternalValidationError","Disabled","DisabledNoConversion","DisabledUnitWithoutUnitKey","DisabledUnitWithUnitKey","DisabledWithEnabledUnitMenu","TestExternalStateChangeWithSynchronizedUnits","PredefinedOptionsMenu","TestEdgeCases","AutomaticValues","ValidationCallback","AllowEmptyPUI","onSwitchUnit","OW_10614TestCase"];export{ae as AllowEmptyPUI,ne as AutomaticValues,ee as Default,N as Disabled,L as DisabledNoConversion,$ as DisabledUnitWithUnitKey,K as DisabledUnitWithoutUnitKey,H as DisabledWithEnabledUnitMenu,q as Error,O as InitUnit,R as InternalValidationError,B as NoConversion,ie as OW_10614TestCase,G as PredefinedOptionsMenu,T as Small,J as TestEdgeCases,z as TestExternalStateChangeWithSynchronizedUnits,te as ValidationCallback,W as Width,ma as __namedExportsOrder,ca as default,_ as notKnownUnit,re as onSwitchUnit};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import{j as n}from"./jsx-runtime-FsUICBgo.js";import{r as v}from"./index-RfLt4OUa.js";import{f as M}from"./immer.esm-bD7SSJ7T.js";import{d as U}from"./index-qZmQ7nA9.js";import{G as Z}from"./grid-u1mZpaML.js";import{S as ee}from"./spacer-Yji9g2AW.js";import{C as F}from"./card-0r8RRVk-.js";import{F as L}from"./field-m7XXDdEG.js";import{H as W}from"./heading-4tVgoT7O.js";import{S as P}from"./select-I01_W6_4.js";import{T as I}from"./toggle-R__kwKym.js";import{l as te}from"./lodash-Bmg8FrMx.js";import{u as ne}from"./use-previous-VKMmnaK7.js";import{T as ae,C as K}from"./table-yS0o5bJS.js";import"./index-cCpkwrS5.js";import"./styled-components.browser.esm-qIipjd6c.js";import"./tslib.es6-OIsz3r9a.js";import"./index-VW3EWkuE.js";import"./label-bLcoUwtK.js";import"./common-types-U65vzrrz.js";import"./help-icon-eelulTML.js";import"./tooltip-dueTLnwA.js";import"./index-miLrID2P.js";import"./icon-8EQazuuW.js";import"./objectWithoutPropertiesLoose-9Q1jwsKS.js";import"./inheritsLoose-8sb_A2v4.js";import"./index-4QtD-hFu.js";import"./disabled-context-urNQThQz.js";import"./types-5uVBABF4.js";import"./assertThisInitialized-4q6YPdh3.js";import"./memoize-one.esm-hqe5SRxC.js";import"./types-VB5zD18b.js";import"./text-6KQ6ntOV.js";import"./actions-0ELEGFed.js";import"./button-BiJw0fB3.js";import"./spinner-R8Il4aRe.js";import"./badge-23Ty_zBt.js";import"./select.input-zP5tW20f.js";import"./index.es-VXFRDikp.js";import"./redux-F5dueAP3.js";import"./objectSpread2-93s0nBry.js";import"./tiny-invariant-R4kOKlvx.js";import"./pagination-H0l4VC9v.js";import"./input-fYKvBwPs.js";import"./input-group-R8LoqKRn.js";import"./input-group-addon-BHVsW9mL.js";import"./number-input-ymd7m-s5.js";import"./check-box-KynSyTaY.js";import"./slider-n3IxC2iq.js";import"./index-ugi_ZH6T.js";import"./popover-N9B8JT3G.js";const re=o=>o.reduce(({preferredUnits:r,storageUnits:i},{unitKey:s,preferredUnit:a,storageUnit:b})=>(r[s]=a,i[s]=b,{preferredUnits:r,storageUnits:i}),{preferredUnits:{},storageUnits:{}}),ie=({headers:o,rows:r,selectedUnits:i,storageUnits:s,onChangeUnit:a,convertBackToStorageUnit:b,enableCosmeticRounding:g,enableDisplayRounding:T})=>{const u=o?o.map(d=>({...d,cells:d.cells.map(c=>{var t;if(c.type===K.AUTO_UNIT){const{testId:C,unitKey:p}=c;return{value:i[p],type:K.SELECT,searchable:!1,options:(t=U.getUnitsForQuantity(p))==null?void 0:t.map(y=>({label:U.label(y),value:y})),native:c.native,onChange:y=>a({unitKey:p,value:y.target.value}),testId:C}}return c})})):[],l=r?r.map((d,c)=>({...d,cells:d.cells.map((t,C)=>{if("autoUnit"in t&&(t!=null&&t.autoUnit)&&(typeof(t==null?void 0:t.value)=="string"||typeof(t==null?void 0:t.value)=="number")){const{unitKey:p,value:y,formatDisplayValue:w}=t,j=T&&"roundDisplayValue"in t?t==null?void 0:t.roundDisplayValue:null,m=i[p],h=s[p],e=m!==h,f=e?U.convertAndGetValue(y,m,h):t.value,x=U.isScientificStringNum(y),R=g&&(e||!x)?U.roundToPrecision(f,14):f,D=w?w(R):R;return{...t,value:D,enableCosmeticRounding:g,enableDisplayRounding:T,roundDisplayValue:j,onChange:S=>{const{value:B}=S.target,_=s[p],E=i[p],N=E!==_,k=b?_:E,$=N?U.convertAndGetValue(B,k,E):B;if("onChange"in t){const{onChange:X}=t,Y={...S,target:{...S.target,value:String($),rowIndex:c,cellIndex:C,unit:k}};X(Y)}}}}return t})})):[];return{convertedHeaders:u,convertedRows:l}},H=({table:o,unitConfig:r,convertBackToStorageUnit:i=!0,enableCosmeticRounding:s=!0,enableDisplayRounding:a=!0})=>{const{rows:b,headers:g,...T}=o,{storageUnits:u,preferredUnits:l}=re(r),d=ne(l),[c,t]=v.useState(l),C=({unitKey:m,value:h})=>{t({...c,[m]:h});const e=r.find(f=>f.unitKey===m);e&&typeof e.onChange=="function"&&e.onChange({oldUnit:c[m],newUnit:h,unitKey:m})},p=m=>ie({headers:g,rows:b,selectedUnits:m,storageUnits:u,onChangeUnit:C,convertBackToStorageUnit:i,enableCosmeticRounding:s,enableDisplayRounding:a}),y=p(c),[w,j]=v.useState(y);return v.useEffect(()=>{!te.isEqual(l,d)&&(Object.keys(l).forEach(h=>{const e=d==null?void 0:d[h],f=l[h];e!==f&&C({unitKey:h,value:f})}),j(p(l)))},[r]),v.useEffect(()=>{j(p(c))},[o,c]),n.jsx(ae,{table:{...T,headers:w.convertedHeaders,rows:w.convertedRows}})};try{H.displayName="UnitTable",H.__docgenInfo={description:"",displayName:"UnitTable",props:{table:{defaultValue:null,description:"",name:"table",required:!0,type:{name:"IUnitTable"}},unitConfig:{defaultValue:null,description:"",name:"unitConfig",required:!0,type:{name:"IUnitConfigItem[]"}},convertBackToStorageUnit:{defaultValue:{value:"true"},description:"",name:"convertBackToStorageUnit",required:!1,type:{name:"boolean"}},enableCosmeticRounding:{defaultValue:{value:"true"},description:"",name:"enableCosmeticRounding",required:!1,type:{name:"boolean"}},enableDisplayRounding:{defaultValue:{value:"true"},description:"",name:"enableDisplayRounding",required:!1,type:{name:"boolean"}},onListReorder:{defaultValue:null,description:"",name:"onListReorder",required:!1,type:{name:"((obj: { from: number; to: number; }) => void)"}}}}}catch{}const pt={title:"Basic/UnitTable",args:{}},oe=!0,le=!0,se=!0,ue=!1,A="m",J="C",de=3,ce=(o,r,i)=>{const s=[r,r,i],a=[...Array(o)].map((b,g)=>{const T=g,u=g+1.25,l=4+g*.25;return[String(T),String(u),String(l)]});return[s,...a]},pe=ce(de,A,J),ge=({reduxTable:o,value:r,unit:i,rowIndex:s,cellIndex:a})=>M(o,b=>{const g=b[0][a],T=(u,l)=>l===0;return b.forEach((u,l)=>{if(T(u,l)){u[a]=i;return}if(l===s+1){u[a]=String(r);return}const d=U.convertAndGetValue(u[a],i,g);u[a]=String(d)}),b}),me=({reduxTable:o,value:r,rowIndex:i,cellIndex:s})=>M(o,a=>{a[i+1][s]=r}),V=()=>{var m,h;const[o,r]=v.useState(A),[i,s]=v.useState(J),[a,b]=v.useState(pe),[g,T]=v.useState(oe),[u,l]=v.useState(se),[d,c]=v.useState(le),[t,C]=v.useState(ue),[p,y]=v.useState(A),w=e=>{const{rowIndex:f,cellIndex:x,value:R,unit:D}=e.target,S=t?ge({reduxTable:a,value:R,unit:D,rowIndex:f,cellIndex:x}):me({reduxTable:a,value:R,rowIndex:f,cellIndex:x});b(S)},j=a.reduce((e,f,x)=>(x===0?e.headers=[{cells:[{value:"From"},{value:"To"},{value:"Temperature"}]},{cells:[{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"temperature",testId:"table-unit-selector-3"}]}]:e.rows=e.rows.concat({cells:f.map((R,D)=>{const S=x===1&&D===1;return{value:R,type:S?"Text":"NumberInput",unitKey:D===2?"temperature":"length",onChange:w,roundDisplayValue:x===3&&D===2?k=>U.roundByMagnitude(k,2):null,formatDisplayValue:S?k=>`T* ${k}`:null,autoUnit:!0}})}),e),{headers:[],rows:[]});return n.jsxs(Z,{columns:"1fr 1fr",gap:!0,children:[n.jsxs(F,{heading:n.jsx(W,{children:"Settings"}),children:[n.jsx(L,{label:"Convert back to storage unit:",labelLeft:!0,labelWidth:200,children:n.jsx(I,{checked:g,onChange:e=>T(e.target.checked)})}),n.jsx(L,{label:"Enable display rounding:",labelLeft:!0,labelWidth:200,children:n.jsx(I,{checked:u,onChange:e=>l(e.target.checked)})}),n.jsx(L,{label:"Enable cosmetic rounding:",labelLeft:!0,labelWidth:200,children:n.jsx(I,{checked:d,onChange:e=>c(e.target.checked)})}),n.jsx(L,{label:"Convert whole table:",labelLeft:!0,labelWidth:200,children:n.jsx(I,{checked:t,onChange:e=>C(e.target.checked)})})]}),n.jsxs(F,{heading:n.jsx(W,{children:"Unit template"}),children:[n.jsx(L,{label:"Length unit:",labelLeft:!0,labelWidth:120,children:n.jsx(P,{options:(m=U.getUnitsForQuantity("length"))==null?void 0:m.map(e=>({value:e,label:U.label(e)})),value:{value:o},onChange:e=>r(e.target.value),width:"100px"})}),n.jsx(L,{label:"Temperature unit:",labelLeft:!0,labelWidth:120,children:n.jsx(P,{options:(h=U.getUnitsForQuantity("temperature"))==null?void 0:h.map(e=>({value:e,label:U.label(e)})),value:{value:i},onChange:e=>s(e.target.value),width:"100px"})})]}),n.jsx(F,{heading:n.jsx(W,{children:"Storage State (Redux)"}),children:n.jsx("pre",{children:n.jsx("code",{children:JSON.stringify(a,null,2)})})}),n.jsxs(F,{heading:n.jsx(W,{children:"UnitTable"}),children:[n.jsx(H,{table:j,unitConfig:[{unitKey:"length",storageUnit:a[0][0],preferredUnit:o,onChange:({newUnit:e})=>y(e)},{unitKey:"temperature",storageUnit:a[0][2],preferredUnit:i}],convertBackToStorageUnit:g,enableDisplayRounding:u,enableCosmeticRounding:d}),n.jsx(ee,{height:20}),n.jsx(L,{label:"Displayed length unit:",labelLeft:!0,labelWidth:150,children:p})]})]})};var q,G,O,Q,z;V.parameters={...V.parameters,docs:{...(q=V.parameters)==null?void 0:q.docs,source:{originalSource:`() => {
|
|
2
|
+
const [preferredLengthUnit, setPreferredLengthUnit] = useState(initialLengthUnit);
|
|
3
|
+
const [preferredTemperatureUnit, setPreferredTemperatureUnit] = useState(initialTemperatureUnit);
|
|
4
|
+
const [reduxTable, setReduxTable] = useState<TTable>(initialTable);
|
|
5
|
+
const [convertBackToStorageUnit, setConvertBackToStorageUnit] = useState(initialConvertBackToStorageUnit);
|
|
6
|
+
const [enableDisplayRounding, setEnableDisplayRounding] = useState(initialEnableDisplayRounding);
|
|
7
|
+
const [enableCosmeticRounding, setEnableCosmeticRounding] = useState(initialEnableCosmeticRounding);
|
|
8
|
+
const [convertWholeTable, setConvertWholeTable] = useState(initialConvertWholeTable);
|
|
9
|
+
const [displayedLengthUnit, setDisplayedLengthUnit] = useState(initialLengthUnit);
|
|
10
|
+
|
|
11
|
+
/*********************************************************************************************************************
|
|
12
|
+
Cell onChange handler
|
|
13
|
+
*********************************************************************************************************************/
|
|
14
|
+
const onUpdateCell = (evt: IUnitTableOnChangeEvent) => {
|
|
15
|
+
const {
|
|
16
|
+
rowIndex,
|
|
17
|
+
cellIndex,
|
|
18
|
+
value,
|
|
19
|
+
unit
|
|
20
|
+
} = evt.target;
|
|
21
|
+
const nextTable = convertWholeTable ? convertStorageTable({
|
|
22
|
+
reduxTable,
|
|
23
|
+
value,
|
|
24
|
+
unit,
|
|
25
|
+
rowIndex,
|
|
26
|
+
cellIndex
|
|
27
|
+
}) : updateCell({
|
|
28
|
+
reduxTable,
|
|
29
|
+
value,
|
|
30
|
+
rowIndex,
|
|
31
|
+
cellIndex
|
|
32
|
+
});
|
|
33
|
+
setReduxTable(nextTable);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/*********************************************************************************************************************
|
|
37
|
+
Construct table view data (same as old Table component, with a new props)
|
|
38
|
+
*********************************************************************************************************************/
|
|
39
|
+
const tableViewData = reduxTable.reduce((acc, row, rowIndex) => {
|
|
40
|
+
if (rowIndex === 0) {
|
|
41
|
+
acc.headers = [{
|
|
42
|
+
cells: [{
|
|
43
|
+
value: 'From'
|
|
44
|
+
}, {
|
|
45
|
+
value: 'To'
|
|
46
|
+
}, {
|
|
47
|
+
value: 'Temperature'
|
|
48
|
+
}]
|
|
49
|
+
}, {
|
|
50
|
+
cells: [{
|
|
51
|
+
type: 'AutoUnit',
|
|
52
|
+
unitKey: 'length'
|
|
53
|
+
}, {
|
|
54
|
+
type: 'AutoUnit',
|
|
55
|
+
unitKey: 'length'
|
|
56
|
+
}, {
|
|
57
|
+
type: 'AutoUnit',
|
|
58
|
+
unitKey: 'temperature',
|
|
59
|
+
testId: 'table-unit-selector-3'
|
|
60
|
+
}]
|
|
61
|
+
}];
|
|
62
|
+
} else {
|
|
63
|
+
acc.rows = acc.rows.concat({
|
|
64
|
+
cells: row.map((cell, cellIndex) => {
|
|
65
|
+
const specialCell = rowIndex === 1 && cellIndex === 1;
|
|
66
|
+
const type = specialCell ? 'Text' : 'NumberInput';
|
|
67
|
+
const formatDisplayValue = specialCell ? (value: number | string) => \`T* \${value}\` : null;
|
|
68
|
+
const customDisplayRounding = rowIndex === 3 && cellIndex === 2 ? (value: TStringNumberNull) => roundByMagnitude(value, 2) : null;
|
|
69
|
+
const value = cell;
|
|
70
|
+
return {
|
|
71
|
+
value,
|
|
72
|
+
type,
|
|
73
|
+
unitKey: cellIndex === 2 ? 'temperature' : 'length',
|
|
74
|
+
onChange: onUpdateCell,
|
|
75
|
+
roundDisplayValue: customDisplayRounding,
|
|
76
|
+
// optionally customize the display rounding of specific columns/cells
|
|
77
|
+
formatDisplayValue,
|
|
78
|
+
// optionally extend/customize the display formatting of specific columns/cells
|
|
79
|
+
autoUnit: true
|
|
80
|
+
};
|
|
81
|
+
})
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return acc;
|
|
85
|
+
}, {
|
|
86
|
+
headers: ([] as any[]),
|
|
87
|
+
rows: ([] as IUnitTableRow[])
|
|
88
|
+
});
|
|
89
|
+
return <Grid columns="1fr 1fr" gap>
|
|
90
|
+
<Card heading={<Heading>Settings</Heading>}>
|
|
91
|
+
<Field label="Convert back to storage unit:" labelLeft labelWidth={200}>
|
|
92
|
+
<Toggle checked={convertBackToStorageUnit} onChange={evt => setConvertBackToStorageUnit(evt.target.checked)} />
|
|
93
|
+
</Field>
|
|
94
|
+
<Field label="Enable display rounding:" labelLeft labelWidth={200}>
|
|
95
|
+
<Toggle checked={enableDisplayRounding} onChange={evt => setEnableDisplayRounding(evt.target.checked)} />
|
|
96
|
+
</Field>
|
|
97
|
+
<Field label="Enable cosmetic rounding:" labelLeft labelWidth={200}>
|
|
98
|
+
<Toggle checked={enableCosmeticRounding} onChange={evt => setEnableCosmeticRounding(evt.target.checked)} />
|
|
99
|
+
</Field>
|
|
100
|
+
<Field label="Convert whole table:" labelLeft labelWidth={200}>
|
|
101
|
+
<Toggle checked={convertWholeTable} onChange={evt => setConvertWholeTable(evt.target.checked)} />
|
|
102
|
+
</Field>
|
|
103
|
+
</Card>
|
|
104
|
+
<Card heading={<Heading>Unit template</Heading>}>
|
|
105
|
+
<Field label="Length unit:" labelLeft labelWidth={120}>
|
|
106
|
+
<Select options={getUnitsForQuantity('length')?.map(unit => ({
|
|
107
|
+
value: unit,
|
|
108
|
+
label: label(unit)
|
|
109
|
+
}))} value={{
|
|
110
|
+
value: preferredLengthUnit
|
|
111
|
+
}} onChange={evt => setPreferredLengthUnit(evt.target.value)} width="100px" />
|
|
112
|
+
</Field>
|
|
113
|
+
<Field label="Temperature unit:" labelLeft labelWidth={120}>
|
|
114
|
+
<Select options={getUnitsForQuantity('temperature')?.map(unit => ({
|
|
115
|
+
value: unit,
|
|
116
|
+
label: label(unit)
|
|
117
|
+
}))} value={{
|
|
118
|
+
value: preferredTemperatureUnit
|
|
119
|
+
}} onChange={evt => setPreferredTemperatureUnit(evt.target.value)} width="100px" />
|
|
120
|
+
</Field>
|
|
121
|
+
</Card>
|
|
122
|
+
<Card heading={<Heading>Storage State (Redux)</Heading>}>
|
|
123
|
+
<pre>
|
|
124
|
+
<code>{JSON.stringify(reduxTable, null, 2)}</code>
|
|
125
|
+
</pre>
|
|
126
|
+
</Card>
|
|
127
|
+
<Card heading={<Heading>UnitTable</Heading>}>
|
|
128
|
+
<UnitTable table={tableViewData}
|
|
129
|
+
//New props:
|
|
130
|
+
unitConfig={[{
|
|
131
|
+
unitKey: 'length',
|
|
132
|
+
storageUnit: reduxTable[0][0],
|
|
133
|
+
preferredUnit: preferredLengthUnit,
|
|
134
|
+
onChange: ({
|
|
135
|
+
newUnit
|
|
136
|
+
}) => setDisplayedLengthUnit(newUnit)
|
|
137
|
+
}, {
|
|
138
|
+
unitKey: 'temperature',
|
|
139
|
+
storageUnit: reduxTable[0][2],
|
|
140
|
+
preferredUnit: preferredTemperatureUnit
|
|
141
|
+
}]}
|
|
142
|
+
//Most tables should just use the default values here (true):
|
|
143
|
+
convertBackToStorageUnit={convertBackToStorageUnit} enableDisplayRounding={enableDisplayRounding} enableCosmeticRounding={enableCosmeticRounding} />
|
|
144
|
+
<Spacer height={20} />
|
|
145
|
+
<Field label="Displayed length unit:" labelLeft labelWidth={150}>
|
|
146
|
+
{displayedLengthUnit}
|
|
147
|
+
</Field>
|
|
148
|
+
</Card>
|
|
149
|
+
</Grid>;
|
|
150
|
+
}`,...(O=(G=V.parameters)==null?void 0:G.docs)==null?void 0:O.source},description:{story:"Story",...(z=(Q=V.parameters)==null?void 0:Q.docs)==null?void 0:z.description}}};const gt=["UnitTablePrototype"];export{V as UnitTablePrototype,gt as __namedExportsOrder,pt as default};
|