@oliasoft-open-source/react-ui-library 4.7.3-beta-2 → 4.7.3-beta-3
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/assets/{index-D5kcnHmD.js → index-7PLAdoQ9.js} +1 -0
- package/dist/index.html +1 -1
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/dist/storybook/assets/Color-KGDBMAHA-Ck2diywb.js +1 -0
- package/dist/storybook/assets/DocsRenderer-PKQXORMH-CO2Q7pkj.js +1 -0
- package/dist/storybook/assets/{accordion-BiuI_LCA.js → accordion-6ouB0WTt.js} +1 -1
- package/dist/storybook/assets/{accordion.stories-Beb4y7rL.js → accordion.stories-DlFZNmdv.js} +2 -2
- package/dist/storybook/assets/{actions-4w-EOz3m.js → actions-Cu_0szZ4.js} +1 -1
- package/dist/storybook/assets/{actions.stories-CtocfSW4.js → actions.stories-SCPuAp0T.js} +1 -1
- package/dist/storybook/assets/{afe.stories-WJoC6FVV.js → afe.stories-G3SzS3sg.js} +2 -2
- package/dist/storybook/assets/{badge.stories-CKnNQLZ5.js → badge.stories-DGYA6_1I.js} +1 -1
- package/dist/storybook/assets/{blowout.stories-AxiXaQQ-.js → blowout.stories-P0LHuXSY.js} +1 -1
- package/dist/storybook/assets/{button-CdEIDAx8.js → button-_0DiND6h.js} +1 -1
- package/dist/storybook/assets/{button-group-BIUVa0X9.js → button-group-BYiHMljF.js} +1 -1
- package/dist/storybook/assets/{button-group.stories-B0Gb9kNs.js → button-group.stories-Bz6NHaeB.js} +1 -1
- package/dist/storybook/assets/{button.stories-CHt71NKu.js → button.stories-vVBGddVf.js} +2 -2
- package/dist/storybook/assets/{buttons-and-links-GWWpybLw.js → buttons-and-links-DsIYBu4t.js} +2 -2
- package/dist/storybook/assets/{card.stories-Cddrprok.js → card.stories-DIlqxO94.js} +1 -1
- package/dist/storybook/assets/{casing-loads.stories-DeIAdq5K.js → casing-loads.stories-0T--WlaD.js} +2 -2
- package/dist/storybook/assets/{cell.stories-DZKcKOIi.js → cell.stories-C5Tkxyfr.js} +2 -2
- package/dist/storybook/assets/{check-box-2fHPdAZG.js → check-box-DkdQxC5c.js} +1 -1
- package/dist/storybook/assets/check-box.stories-D8C12IQo.js +102 -0
- package/dist/storybook/assets/{chunk-HLWAVYOI-rY5YQOb2.js → chunk-HLWAVYOI-CtLnxQiQ.js} +1 -1
- package/dist/storybook/assets/color-Cm4zop4f.js +25 -0
- package/dist/storybook/assets/{column.stories-rKyxUTAG.js → column.stories-C1Sxwh4f.js} +1 -1
- package/dist/storybook/assets/dialog-CAWCUmp3.js +1 -0
- package/dist/storybook/assets/{drawer-BOl7GxGI.js → drawer-vbDFqa4U.js} +1 -1
- package/dist/storybook/assets/{drawer.stories-qH2nYW2a.js → drawer.stories-CmbGsKmS.js} +4 -4
- package/dist/storybook/assets/{empty.stories-BKEXzh9o.js → empty.stories-iHPKKy4z.js} +1 -1
- package/dist/storybook/assets/extends-CF3RwP-h.js +1 -0
- package/dist/storybook/assets/{field-nInV3MuR.js → field-DwLk_uWj.js} +1 -1
- package/dist/storybook/assets/{field.stories-eRSYmEtA.js → field.stories-s-0LQVbp.js} +1 -1
- package/dist/storybook/assets/{file-button.stories-CH6kxEKM.js → file-button.stories-C90kcfbw.js} +1 -1
- package/dist/storybook/assets/{file-input-Amcc9o5I.js → file-input-C_2w1dKj.js} +1 -1
- package/dist/storybook/assets/{file-input.stories-CJLU_nqW.js → file-input.stories-BEsZox6U.js} +1 -1
- package/dist/storybook/assets/{flex.stories-CT6o2gii.js → flex.stories-D-QN0gkk.js} +1 -1
- package/dist/storybook/assets/footer.stories-U_zMDmxF.js +3 -0
- package/dist/storybook/assets/form.stories-1L75MGpX.js +49 -0
- package/dist/storybook/assets/formation.stories-YHpXrXvC.js +74 -0
- package/dist/storybook/assets/{heading-EzI5s4VN.js → heading-DkSFysAb.js} +1 -1
- package/dist/storybook/assets/{heading.stories-D5x1-mKs.js → heading.stories-Dtq7LNlB.js} +1 -1
- package/dist/storybook/assets/{help-icon-CfV3_Ais.js → help-icon-LfPZiYla.js} +1 -1
- package/dist/storybook/assets/{help-icon.stories-D4KS1wlT.js → help-icon.stories-Dh2ylnGq.js} +1 -1
- package/dist/storybook/assets/icon-BP4BO6-k.js +8 -0
- package/dist/storybook/assets/{icon.stories-C1hZXIMX.js → icon.stories-B-tKaIKA.js} +1 -1
- package/dist/storybook/assets/iframe-BRbyeatW.js +2 -0
- package/dist/storybook/assets/{index-4gO9mIeA.js → index-BuBRmFoY.js} +8 -8
- package/dist/storybook/assets/index-DknIsB0y.js +1 -0
- package/dist/storybook/assets/{index.es-DazXb-ul.js → index.es-D2piFfFj.js} +4 -4
- package/dist/storybook/assets/inheritsLoose-DR8r8Ogv.js +1 -0
- package/dist/storybook/assets/{input-group.stories-Dtak6Me2.js → input-group.stories-BcoORZ9x.js} +2 -2
- package/dist/storybook/assets/{input-validation-wltu7rhx.js → input-validation-DHXUjjTW.js} +2 -2
- package/dist/storybook/assets/{inputs-Bsfja93s.js → inputs-DOBN-gBG.js} +2 -2
- package/dist/storybook/assets/{label-Cz6TT90s.js → label-tWjEmTQJ.js} +1 -1
- package/dist/storybook/assets/{label.stories-BzSzxxM-.js → label.stories-BTA8N7tD.js} +1 -1
- package/dist/storybook/assets/layout-forms-CWJU-MMJ.js +16 -0
- package/dist/storybook/assets/{layout-general-DJOJ7Xv5.js → layout-general-DIKhH47g.js} +2 -2
- package/dist/storybook/assets/{list-BtA0jYMp.js → list-BpVed6Pw.js} +1 -1
- package/dist/storybook/assets/{list.stories-CmJsmJZJ.js → list.stories-CiT9J_FH.js} +2 -2
- package/dist/storybook/assets/{list.stories-data-C_w1DX5i.js → list.stories-data-CnVYk3eo.js} +1 -1
- package/dist/storybook/assets/{loader.stories-CA2m3EFj.js → loader.stories-BKBFctQ1.js} +1 -1
- package/dist/storybook/assets/menu.stories-Bp8L83xx.js +82 -0
- package/dist/storybook/assets/message-ttrR1AaP.js +1 -0
- package/dist/storybook/assets/{message.stories-B02RIMXw.js → message.stories-C8YRT7nL.js} +1 -1
- package/dist/storybook/assets/{meta-content-BdypOdcN.js → meta-content-Djgg-tiF.js} +1 -1
- package/dist/storybook/assets/modal.stories-BoVj2EsX.js +200 -0
- package/dist/storybook/assets/number-input.stories-CcNTeD25.js +97 -0
- package/dist/storybook/assets/{option-dropdown.stories-DvgAgTHQ.js → option-dropdown.stories-COGmMWEl.js} +1 -1
- package/dist/storybook/assets/{padding-and-spacing-BnOF4Ueu.js → padding-and-spacing-2bE7HUNT.js} +2 -2
- package/dist/storybook/assets/{page.stories-DdAfcsOc.js → page.stories-BB3g1zwB.js} +1 -1
- package/dist/storybook/assets/{pagination-DRdJ9LGH.js → pagination-DSQeMPG_.js} +1 -1
- package/dist/storybook/assets/{pagination.stories-C_4kzgcf.js → pagination.stories-DjIohcDx.js} +2 -2
- package/dist/storybook/assets/{pop-confirm.stories-Dlm0BaMY.js → pop-confirm.stories-Cr_ZBbLn.js} +1 -1
- package/dist/storybook/assets/{popover-CvS_kBVF.js → popover-Dq3iC_lM.js} +1 -1
- package/dist/storybook/assets/popover.stories-CoWCb2Mn.js +10 -0
- package/dist/storybook/assets/{preview-DtaSOELl.js → preview-C7oeNNbC.js} +2 -2
- package/dist/storybook/assets/preview-DP1caVnC.js +2 -0
- package/dist/storybook/assets/projects.stories-BesbPJ8Z.js +47 -0
- package/dist/storybook/assets/{radio-button-J4oEQdxt.js → radio-button-BD7pi0ao.js} +1 -1
- package/dist/storybook/assets/radio-button.stories-B84Ip3NV.js +61 -0
- package/dist/storybook/assets/react-router-dom-CMITYWBH.js +8 -0
- package/dist/storybook/assets/{reservoirs.stories-BUs7WSxB.js → reservoirs.stories-kxVBoa7Y.js} +2 -2
- package/dist/storybook/assets/{rich-text-input.stories-BP79IJ53.js → rich-text-input.stories-C5pcIbSa.js} +3 -3
- package/dist/storybook/assets/{row.stories-CIJowbkv.js → row.stories-ATsrjumb.js} +2 -2
- package/dist/storybook/assets/select-78sreKsp.js +40 -0
- package/dist/storybook/assets/select.stories-CZwsHVDB.js +914 -0
- package/dist/storybook/assets/{side-bar-DAMfASqb.js → side-bar-WsK6pkmj.js} +1 -1
- package/dist/storybook/assets/{side-bar.stories-BlEIOckL.js → side-bar.stories-Bu2q_b_w.js} +1 -1
- package/dist/storybook/assets/{site.stories-Kk57nhAn.js → site.stories-Yh4uNi3Q.js} +2 -2
- package/dist/storybook/assets/{slider-BLU39INk.js → slider-CxVlS0fh.js} +4 -4
- package/dist/storybook/assets/{slider.stories-DdVxUAfH.js → slider.stories-_wS70xsm.js} +2 -2
- package/dist/storybook/assets/{smart-upload-modal.stories-PeStvjoa.js → smart-upload-modal.stories-DDlO9y2j.js} +1 -1
- package/dist/storybook/assets/{spacer.stories-Dd1QMhoc.js → spacer.stories-B3LrTr7b.js} +1 -1
- package/dist/storybook/assets/{table-B7Ro6zGB.js → table-DPvzYjoq.js} +1 -1
- package/dist/storybook/assets/{table.stories-1mHu1R2T.js → table.stories-BGQ1O9nw.js} +2 -2
- package/dist/storybook/assets/{table.stories-data-C6x-UHeN.js → table.stories-data-2STKbgzG.js} +1 -1
- package/dist/storybook/assets/text-link.stories-BsuVBOWo.js +14 -0
- package/dist/storybook/assets/{title.stories-CcK2ZS1r.js → title.stories-CVRTXggL.js} +2 -2
- package/dist/storybook/assets/toaster-DPbde9Mi.js +1 -0
- package/dist/storybook/assets/toaster.stories-DfbfDavp.js +86 -0
- package/dist/storybook/assets/{toggle-D0yzyALV.js → toggle-t1iTuSL7.js} +1 -1
- package/dist/storybook/assets/toggle.stories-D44S3Nix.js +117 -0
- package/dist/storybook/assets/{tooltip.test-case.stories-BWJhZQg8.js → tooltip.test-case.stories-BtrJUImB.js} +1 -1
- package/dist/storybook/assets/{top-bar-mKg-xcLh.js → top-bar-R-CjhJ21.js} +1 -1
- package/dist/storybook/assets/top-bar.stories-BYN9rcUw.js +21 -0
- package/dist/storybook/assets/{top-bar.testcase.stories-BlbsX9By.js → top-bar.testcase.stories-ZPaSRyIh.js} +1 -1
- package/dist/storybook/assets/{tree.stories-CkYwGe0X.js → tree.stories-Ghxps-dL.js} +1 -1
- package/dist/storybook/assets/unit-input.stories-BaU6h22E.js +290 -0
- package/dist/storybook/assets/unit-table.stories-DXies3fA.js +150 -0
- package/dist/storybook/iframe.html +1 -1
- package/dist/storybook/index.html +2 -6
- package/dist/storybook/index.json +1 -1
- package/dist/storybook/project.json +1 -1
- package/package.json +1 -1
- package/dist/storybook/assets/Color-KGDBMAHA-BDaGFyls.js +0 -1
- package/dist/storybook/assets/DocsRenderer-PKQXORMH-DeAerz72.js +0 -1
- package/dist/storybook/assets/check-box.stories-Dqopb7XV.js +0 -126
- package/dist/storybook/assets/color-lBkUm7cb.js +0 -25
- package/dist/storybook/assets/dialog-dXhT3sJF.js +0 -1
- package/dist/storybook/assets/footer.stories-BlfgJYnF.js +0 -3
- package/dist/storybook/assets/form.stories-RD2lXS5Q.js +0 -49
- package/dist/storybook/assets/formation.stories-BC2p8tEp.js +0 -74
- package/dist/storybook/assets/icon-BSFY3vDO.js +0 -8
- package/dist/storybook/assets/iframe-D9Shj_Nm.js +0 -2
- package/dist/storybook/assets/index-Be0hXiyp.js +0 -179
- package/dist/storybook/assets/index-CF7H4eMJ.js +0 -28
- package/dist/storybook/assets/index-NK2Pj-Tv.js +0 -1
- package/dist/storybook/assets/inheritsLoose-DP0QEDDI.js +0 -1
- package/dist/storybook/assets/layout-forms-Bf7y_Hym.js +0 -16
- package/dist/storybook/assets/menu.stories-BD7P2iMQ.js +0 -84
- package/dist/storybook/assets/message-BYzRg8Ae.js +0 -1
- package/dist/storybook/assets/modal.stories-l76yG1FY.js +0 -228
- package/dist/storybook/assets/number-input.stories-CmgIvuEY.js +0 -105
- package/dist/storybook/assets/popover.stories-D6_Ulo0d.js +0 -10
- package/dist/storybook/assets/preview-DLBQXbKW.js +0 -1
- package/dist/storybook/assets/preview-Dyti8xUp.js +0 -2
- package/dist/storybook/assets/projects.stories-ApHyZURX.js +0 -47
- package/dist/storybook/assets/radio-button.stories-Ds-DfLlj.js +0 -71
- package/dist/storybook/assets/react-router-dom-Ck2Y_Fzc.js +0 -8
- package/dist/storybook/assets/select-BeEJzL_0.js +0 -40
- package/dist/storybook/assets/select.stories-DgC9Agq6.js +0 -579
- package/dist/storybook/assets/text-link.stories-BQAkVO-W.js +0 -14
- package/dist/storybook/assets/toaster-BNO0suPv.js +0 -1
- package/dist/storybook/assets/toaster.stories-DYw4Syxn.js +0 -89
- package/dist/storybook/assets/toggle.stories-DKENe2T9.js +0 -141
- package/dist/storybook/assets/top-bar.stories-CFZoJq-r.js +0 -21
- package/dist/storybook/assets/unit-input.stories-BdhJ50Pr.js +0 -290
- package/dist/storybook/assets/unit-table.stories-_Z6tTx-x.js +0 -150
- package/dist/storybook/sb-addons/interactions-2/manager-bundle.js +0 -233
- package/dist/storybook/sb-addons/storybook-dark-mode-esm-preset-3/manager-bundle.js.LEGAL.txt +0 -0
- /package/dist/storybook/sb-addons/{storybook-dark-mode-esm-preset-3 → storybook-dark-mode-esm-preset-2}/manager-bundle.js +0 -0
- /package/dist/storybook/sb-addons/{interactions-2 → storybook-dark-mode-esm-preset-2}/manager-bundle.js.LEGAL.txt +0 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import{j as e}from"./jsx-runtime-eps93zm2.js";import{r as d}from"./index-DhsZuJvc.js";import{d as r,r as vt}from"./index-DQs5XS8h.js";import{c as ft}from"./index-Bk2sglWO.js";import{u as Ct}from"./use-previous-D775JrO6.js";import{M as Ne}from"./actions-Cu_0szZ4.js";import{I as yt}from"./input-group-addon-D68iUKV2.js";import{B as m}from"./button-_0DiND6h.js";import{T as bt}from"./tooltip-C_E_6ym5.js";import{I as Ut}from"./input-group-BaRSJAEN.js";import{S as V}from"./spacer-BWoNR27H.js";import{T as zn}from"./text-B3-TSWok.js";import{I as xt}from"./input-D97ganXq.js";import{M as Ae}from"./types-BmbYqTX_.js";import{l as T}from"./lodash-BHd_uQHh.js";import{D as It}from"./divider-DY9nJ_7N.js";import{R as $n,C as fe}from"./row-4iAGREkV.js";import{F as w}from"./field-DwLk_uWj.js";import{M as Ce}from"./message-ttrR1AaP.js";import"./index-DRSy5Ssd.js";import"./common-types-Sih75Sav.js";import"./disabled-context-rmpd7YJS.js";import"./icon-BP4BO6-k.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./inheritsLoose-DR8r8Ogv.js";import"./index-CEuq6vkz.js";import"./types-UmZ4Y_CR.js";import"./badge-CLQ59MDF.js";import"./spinner-AWUe4xwQ.js";import"./index-CUZDtIZe.js";import"./styled-components.browser.esm-Bf0q9Yjk.js";import"./label-tWjEmTQJ.js";import"./help-icon-LfPZiYla.js";const wt=()=>{const n=d.useRef(null);return d.useLayoutEffect(()=>{n.current&&(n.current(),n.current=null)}),t=>{n.current=t}},Vt=(n,a)=>{const t=a==null?void 0:a[n];return console.log(a,a),console.log("unitTemplate?.[unitkey]",a==null?void 0:a[n]),t?(console.log("preferredUnit",t),t):(console.log(`Warning: 'unitTemplate' missing for '${n}'. Using initial unit, value unit, or default.`),r.unitFromQuantity(n)??"")};var y=(n=>(n.CUSTOM="custom",n.PREDEFINED="predefined",n))(y||{});const Gn=n=>n==="undefined"||n===void 0||n===""||n==="null"||n===null||n==="NaN"||isNaN(n),Jn=(n="",a,t="",l=!1)=>{if(l)return n;if(a&&!Gn(n))try{const o=r.isValueWithUnit(n)?n:r.withUnit(n,t),c=r.convertSamePrecision(o,a);return r.getValue(c)}catch{}return n},jt=n=>n?!!r.getUnit(n):!1,_=(n="",a,t,l)=>{if(l)return n;const o=jt(n)||r.isValueWithUnit(n),c=r.getValue(n);return Gn(c)?c:o?Jn(c,a,t,l):n},qe=n=>T.isObject(n)&&!T.isArray(n)&&!T.isFunction(n)?T.get(n,"fieldName",""):typeof n=="string"?n:"",Et=n=>T.isObjectLike(n)&&T.has(n,"message"),kt=n=>typeof n=="string"?n:Et(n)?n.message:null;var Tt=vt();const St=n=>n.search(RegExp(/(^0{2}\.)|(^0+[1-9])/g))===0,Pe=(n,a)=>{var j;const{allowEmpty:t=!1,autoValue:l,placeholder:o,disabledValidation:c=!1}=a||{},i=String(n);if(c||l||o)return null;const g=Tt.isValueWithUnit(i)?r.getValue(i):i;if(t&&g==="")return null;if(St(g))return"Invalid number format due to leading zeroes";const h=r.validateNumber(g);if(!h.valid){const le=((j=h==null?void 0:h.errors)==null?void 0:j[0])??null;return kt(le)}return null},Me=(n="")=>{var a;return(a=r.KNOWN_UNITS)==null?void 0:a.includes(n)},Nt=(n,a)=>{const t=r.getUnit(n||"");return Me(a)&&Me(t)},At=d.createContext(null),qt=()=>d.useContext(At),Pt=n=>a=>(console.log("Context not initialized. Call initializeContext first."),e.jsx(n,{...a})),Mt="_predefinedMenuActive_1yvt4_1",Dt={predefinedMenuActive:Mt},Yn=({name:n,placeholder:a="",disabled:t=!1,disabledUnit:l=!1,error:o=null,left:c=!1,small:i=!1,width:g="100%",value:h,unitkey:j="",initUnit:le,noConversion:Zn=!1,onChange:ue=()=>{},onClick:Ft=()=>{},onFocus:Qn=()=>{},onSwitchUnit:ye=()=>{},unitTemplate:Xn,doNotConvertValue:q=!1,testId:k,warning:et=null,predefinedOptions:x,initialPredefinedOption:nt=!1,shouldLinkAutomaticly:be=!0,selectedPredefinedOptionKey:Ue,validationCallback:xe=()=>({name:"",error:null}),disabledValidation:Ie=!1,allowEmpty:we=!1,autoValue:I})=>{const oe=qt(),ne=Xn??(oe==null?void 0:oe.unitTemplate),[de,tt]=d.useState(ne);console.log("currentUnitTemplate ->>>>",de),d.useEffect(()=>{ne&&tt(ne)},[ne]),typeof h=="number"&&(h=`${h}`);const at=wt(),[ce="",P=""]=h!==void 0?r.split(h):[],Ve=I?r.getUnit(I):"",je=d.useMemo(()=>Vt(j,de),[j,de]),rt=Nt(h,je),U=le||P||je,st=Ct(U),Ee=_(h,U,P,q),ke=_(I,U,Ve,q),it=Ee!==""?{value:Ee,unit:U}:ke!==""?{value:ke,unit:U}:{value:ce,unit:P},[v,te]=d.useState(it),[lt,me]=d.useState(null),[E,pe]=d.useState(nt?y.PREDEFINED:y.CUSTOM),ge=ce===""&&I,M=x&&x.find(s=>{if(!(s!=null&&s.value))return;if(Ue)return Ue===s.valueKey;const u=r.isValueWithUnit(s.value)?r.getUnit(s.value):"";return r.withUnit(Jn(h,u),u)===s.value}),ut=()=>{if(j)try{const s=ge?I:h??"";let u=r.altUnitsList(s,j);return r.getValue(s)===""?u.map(f=>["",f[1]]):u}catch{return null}},ot=s=>{const u=qe(n),f=s.target,{value:b,selectionStart:D}=f,Se=r.cleanNumStr(b.replaceAll(" ","").replaceAll("|","")),he=r.withUnit(Se,(v==null?void 0:v.unit)||""),pt=r.getValue(he),ve=Pe(pt,{allowEmpty:we,autoValue:I,placeholder:a,disabledValidation:Ie});if(ve===null){ue({target:{value:he,name:u}});const[gt,ht]=r.split(he);te({value:gt,unit:ht}),me(null),xe(u,null)}else te({value:Se,unit:v.unit}),me(ve),xe(u,ve);at(()=>{f.selectionStart=D,f.selectionEnd=D})},dt=(s,u)=>{u===v.unit||isNaN(Number(s))||(te({value:s,unit:u}),ye&&ye(u))};d.useEffect(()=>{if(U){let f,b="";st!==U?(f=_(h,U,P,q),b=U):r.withUnit(v.value,v.unit)!==h&&(f=_(h,v.unit,P,q),b=v.unit),f!==void 0&&te({value:f,unit:b}),x&&pe(M&&be?y.PREDEFINED:y.CUSTOM)}const s=r.checkAndCleanDecimalComma(ce),u=Pe(s,{allowEmpty:we,autoValue:I,placeholder:a,disabledValidation:Ie});me(u)},[U,h,o,be]);const ae=ut(),re=r.label(v.unit)||v.unit||"",ct=Zn||!ae||ae&&ae.length===1,Te=qe(n);let se;const mt=s=>{const u=s!=null&&s.value?s.value:"",[f="",b=""]=r.isValueWithUnit(u)?r.split(u):[u];return{type:Ae.OPTION,inline:!0,onClick:()=>{r.validateNumber(f).valid&&!t&&(pe(y.PREDEFINED),ue({target:{value:u,name:typeof n=="string"?n:(n==null?void 0:n.fieldName)||"",predefinedSelected:!0,predefinedOption:s}}))},label:e.jsxs(e.Fragment,{children:[e.jsx(zn,{children:s.label}),e.jsx(V,{width:"20px",height:"0"})]}),description:r.isValueWithUnit(u)?`${f} ${b}`:u,selected:M===s&&E===y.PREDEFINED}};if(se=[{type:Ae.OPTION,inline:!0,onClick:()=>{E!==y.CUSTOM&&!t&&ue({target:{value:r.withUnit(v.value,v.unit),name:typeof n=="string"?n:(n==null?void 0:n.fieldName)||""}})},label:"Custom",selected:E===y.CUSTOM}],x!=null&&x.length){const s=x.map(mt);se=[...se,...s]}return e.jsx("div",{className:E===y.PREDEFINED?ft(Dt.predefinedMenuActive):"",children:e.jsxs(Ut,{small:i,width:g,children:[x&&e.jsx(bt,{text:E===y.PREDEFINED?M==null?void 0:M.label:"",children:e.jsx(Ne,{maxHeight:380,groupOrder:"first",testId:k&&`${k}-predefined-menu`,disabled:t,menu:{colored:!0,trigger:"Component",component:e.jsx(m,{groupOrder:"first",active:E===y.PREDEFINED,icon:E===y.PREDEFINED?"link":"unlink"}),small:i,sections:se}})}),e.jsx(xt,{type:"text",name:Te,testId:k,disabled:t,placeholder:ge?_(I,v.unit,Ve,q):a,value:v.value,onChange:ot,onFocus:Qn,error:o||lt,warning:et,right:!c},Te),re&&(ct||!rt?e.jsx(yt,{groupOrder:"last",children:re}):e.jsx(Ne,{maxHeight:380,groupOrder:"last",disabled:l,testId:k&&`${k}-menu`,menu:{label:re,trigger:"DropDownButton",small:i,sections:ae.map(([s,u,f])=>{const b=f||u||"";return{type:"Option",label:isNaN(Number(s))?"":s,inline:!0,onClick:D=>{D.stopPropagation(),dt(ge?"":s,u)},description:b,selected:b===re,testId:`${k}-unit-${b}`}})}}))]})})},p=Pt(Yn);Yn.__docgenInfo={description:"",methods:[],displayName:"UnitInputComponent",props:{name:{required:!0,tsType:{name:"union",raw:"string | { fieldName?: string }",elements:[{name:"string"},{name:"signature",type:"object",raw:"{ fieldName?: string }",signature:{properties:[{key:"fieldName",value:{name:"string",required:!1}}]}}]},description:""},placeholder:{required:!1,tsType:{name:"string"},description:"",defaultValue:{value:"''",computed:!1}},disabled:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},disabledUnit:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},error:{required:!1,tsType:{name:"union",raw:"string | null | boolean",elements:[{name:"string"},{name:"null"},{name:"boolean"}]},description:"",defaultValue:{value:"null",computed:!1}},left:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},small:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},width:{required:!1,tsType:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},description:"",defaultValue:{value:"'100%'",computed:!1}},value:{required:!1,tsType:{name:"string"},description:""},unitkey:{required:!1,tsType:{name:"string"},description:"",defaultValue:{value:"''",computed:!1}},initUnit:{required:!1,tsType:{name:"string"},description:""},noConversion:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},doNotConvertValue:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},testId:{required:!1,tsType:{name:"string"},description:""},warning:{required:!1,tsType:{name:"union",raw:"string | boolean | null",elements:[{name:"string"},{name:"boolean"},{name:"null"}]},description:"",defaultValue:{value:"null",computed:!1}},predefinedOptions:{required:!1,tsType:{name:"union",raw:"IPredefinedOption[] | null",elements:[{name:"Array",elements:[{name:"IPredefinedOption"}],raw:"IPredefinedOption[]"},{name:"null"}]},description:""},initialPredefinedOption:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},shouldLinkAutomaticly:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},selectedPredefinedOptionKey:{required:!1,tsType:{name:"string"},description:""},validationCallback:{required:!1,tsType:{name:"signature",type:"function",raw:`(
|
|
2
|
+
name: string,
|
|
3
|
+
message: string | null,
|
|
4
|
+
) => { name: string; error: string | null }`,signature:{arguments:[{type:{name:"string"},name:"name"},{type:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}]},name:"message"}],return:{name:"signature",type:"object",raw:"{ name: string; error: string | null }",signature:{properties:[{key:"name",value:{name:"string",required:!0}},{key:"error",value:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}],required:!0}}]}}}},description:"",defaultValue:{value:"() => ({ name: '', error: null })",computed:!1}},disabledValidation:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},allowEmpty:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},autoValue:{required:!1,tsType:{name:"string"},description:""},onChange:{required:!1,tsType:{name:"signature",type:"function",raw:"(event: ChangeEvent<HTMLInputElement> | ICustomChangeEvent) => void",signature:{arguments:[{type:{name:"union",raw:"ChangeEvent<HTMLInputElement> | ICustomChangeEvent",elements:[{name:"ChangeEvent",elements:[{name:"HTMLInputElement"}],raw:"ChangeEvent<HTMLInputElement>"},{name:"ICustomChangeEvent"}]},name:"event"}],return:{name:"void"}}},description:"",defaultValue:{value:"() => {}",computed:!1}},onSwitchUnit:{required:!1,tsType:{name:"signature",type:"function",raw:"(unit: string) => void",signature:{arguments:[{type:{name:"string"},name:"unit"}],return:{name:"void"}}},description:"",defaultValue:{value:"() => {}",computed:!1}},onClick:{required:!1,tsType:{name:"MouseEventHandler",elements:[{name:"HTMLInputElement"}],raw:"MouseEventHandler<HTMLInputElement>"},description:"",defaultValue:{value:"() => {}",computed:!1}},onFocus:{required:!1,tsType:{name:"FocusEventHandler",elements:[{name:"HTMLInputElement"}],raw:"FocusEventHandler<HTMLInputElement>"},description:"",defaultValue:{value:"() => {}",computed:!1}},unitTemplate:{required:!1,tsType:{name:"Record",elements:[{name:"string"},{name:"any"}],raw:"Record<string, any>"},description:""}}};const{useArgs:_t}=__STORYBOOK_MODULE_PREVIEW_API__,Ca={title:"Basic/UnitInput",component:p,args:{name:"example",unitkey:"length",value:"123|m"}},C=n=>{const[a,t]=_t(),l=o=>{t({value:o.target.value})};return e.jsx(p,{...n,onChange:l})},ie=C.bind({}),F=C.bind({});F.args={unitkey:"height",unitTemplate:{height:"ft"}};const O=C.bind({});O.args={value:'123|"',unitkey:'"'};const W=C.bind({});W.args={width:"180px"};const B=C.bind({});B.args={noConversion:!0};const R=C.bind({});R.args={small:!0};const H=C.bind({});H.args={error:"Error message goes here"};const L=C.bind({});L.args={value:"asas123asd|%"};const S=C.bind({});S.args={disabled:!0,disabledUnit:!0};S.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 K=C.bind({});K.args={disabled:!0,disabledUnit:!0,noConversion:!0};const z=C.bind({});z.args={disabledUnit:!0,unitkey:void 0};const $=C.bind({});$.args={disabledUnit:!0,unitkey:"length"};const G=C.bind({});G.args={disabledUnit:!1,disabled:!0};const N=n=>{const[a,t]=d.useState("123|m"),[l,o]=d.useState("223|m"),[c,i]=d.useState("ft");return e.jsxs(e.Fragment,{children:[e.jsx(m,{label:"Change initUnit",onClick:()=>i(c==="m"?"ft":"m")}),e.jsx(V,{}),e.jsx(m,{label:"Change value",onClick:()=>t(a==="123|m"?"456|m":"123|m")}),e.jsx(V,{}),e.jsx(p,{name:"example",onChange:g=>{t(g.target.value)},unitkey:"length",value:a,initUnit:c,onSwitchUnit:i}),e.jsx(V,{}),e.jsx(p,{name:"example2",onChange:g=>{o(g.target.value)},unitkey:"length",value:l,initUnit:c,onSwitchUnit:i}),e.jsx(It,{}),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=>{o(g.target.value)},unitkey:"length",value:l,onSwitchUnit:i})]})};N.parameters={docs:{description:{story:"[OW-4380](https://oliasoft.atlassian.net/browse/OW-4380?atlOrigin=eyJpIjoiMmM1N2RkNWU3Mjk5NDYxY2E0YzhkMzk5ZTVmZTJhMjciLCJwIjoiaiJ9)"}}};const J=C.bind({});J.args={predefinedOptions:[{label:"bottom of casing",value:"12|km"},{label:"mud weight at shoe depth",value:"8|mm"}]};const A=()=>{const n="500px",[a,t]=d.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(fe,{width:"25%",children:[e.jsx(m,{label:"Change value infinity",onClick:()=>t(1/0)}),e.jsx("br",{}),e.jsx(m,{label:"Change value -infinity",onClick:()=>t(-1/0)}),e.jsx("br",{}),e.jsx(m,{label:"Change value null",onClick:()=>t(null)}),e.jsx("br",{}),e.jsx(m,{label:"Change value - undefined",onClick:()=>t(void 0)}),e.jsx("br",{}),e.jsx(m,{label:"Change value - NaN",onClick:()=>t(NaN)}),e.jsx("br",{}),e.jsx(m,{label:"Change value - nothing (empty)",onClick:()=>t(void 0)}),e.jsx("br",{}),e.jsx(m,{label:"Change value - empty string",onClick:()=>t("")})]}),e.jsxs(fe,{width:"25%",children:[e.jsx(m,{label:"Change value infinity|m",onClick:()=>t("Infinity|m")}),e.jsx("br",{}),e.jsx(m,{label:"Change value -infinity|m",onClick:()=>t("-Infinity|m")}),e.jsx("br",{}),e.jsx(m,{label:"Change value null|m",onClick:()=>t("null|m")}),e.jsx("br",{}),e.jsx(m,{label:"Change value - undefined|m",onClick:()=>t("undefined|m")}),e.jsx("br",{}),e.jsx(m,{label:"Change value - NaN|m",onClick:()=>t("NaN|m")}),e.jsx("br",{}),e.jsx(m,{label:"Change value - nothing (empty)|m",onClick:()=>t("|m")})]})]}),e.jsx("br",{}),e.jsx(w,{label:"Normal PUI",children:e.jsx(p,{name:"example1",onChange:l=>t(l.target.value),value:a,unitkey:"length",width:n,placeholder:"value|unit"})}),e.jsx(w,{label:"Disabled validation",children:e.jsx(p,{name:"example2",onChange:l=>t(l.target.value),value:a,unitkey:"length",disabledValidation:!0,width:n})}),e.jsx(w,{label:"Disabled validation and manual error",children:e.jsx(p,{name:"example3",onChange:l=>t(l.target.value),value:a,unitkey:"length",error:"test",disabledValidation:!0,width:n})}),e.jsx(Ce,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})},Y=()=>{const n="500px",[a,t]=d.useState("1|m"),[l,o]=d.useState("|m"),c="123|km";return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different cases for automatic (placeholder) values:"}),e.jsx($n,{children:e.jsxs(fe,{width:"25%",children:[e.jsx(m,{label:"Change value to ''",onClick:()=>t("")}),e.jsx("br",{}),e.jsx(m,{label:"Change value to 1",onClick:()=>t("1")}),e.jsx("br",{}),e.jsx(m,{label:"Change value to 1|m",onClick:()=>t("1|m")}),e.jsx("br",{}),e.jsx(m,{label:"Change value to |m - empty value",onClick:()=>t("|m")})]})}),e.jsx("br",{}),e.jsx(w,{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:c})}),e.jsx(w,{label:"Normal PUI (only auto)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,autoValue:c})}),e.jsx(w,{label:"Empty PUI with autoValue",children:e.jsx(p,{name:"example1",onChange:i=>o(i.target.value),value:l,unitkey:"length",width:n,autoValue:c})}),e.jsx(w,{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(w,{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(Ce,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})};A.parameters={docs:{description:{story:"[OW-8884](https://oliasoft.atlassian.net/browse/OW-8884)"}}};const Z=()=>{const[n,a]=d.useState("123|%"),[t,l]=d.useState(null),o="This should be visible when an error appears",c=(i,g)=>(l(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||o,validationCallback:c,value:n}),e.jsx("br",{}),e.jsx(V,{}),e.jsx("h4",{children:"Original validation message: "}),e.jsx(Ce,{message:{heading:t,visible:!0}})]})},Q=()=>{const[n,a]=d.useState("123|m"),[t,l]=d.useState(""),[o,c]=d.useState("km"),i=()=>{c("ft"),l("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:o,unitkey:"length"}),e.jsx("br",{}),e.jsx(V,{}),e.jsx(m,{label:"Change value |m and unit ft",onClick:()=>i()})]})},X=()=>{const[n,a]=d.useState("123|m"),[t,l]=d.useState("m");return e.jsxs(e.Fragment,{children:[e.jsx(p,{name:"example",onChange:o=>a(o.target.value),value:n,initUnit:t,unitkey:"length",onSwitchUnit:l}),e.jsx(V,{}),e.jsx(p,{name:"example",onChange:o=>a(o.target.value),value:n,initUnit:t,unitkey:"length",onSwitchUnit:l})]})},ee=()=>e.jsxs(e.Fragment,{children:[e.jsx(zn,{faint:!0,children:"Reproduce OW-10614 rounding noise bug when storing values in a different unit to the display unit"}),e.jsx(V,{}),e.jsx(p,{name:"example",onChange:()=>{},value:r.withUnit(r.convertAndGetValue("9750|psi","bar"),"bar"),initUnit:"psi",unitkey:"pressure",unitTemplate:{pressure:"psi"}})]});N.__docgenInfo={description:"",methods:[],displayName:"TestExternalStateChangeWithSynchronizedUnits",props:{name:{required:!0,tsType:{name:"union",raw:"string | { fieldName?: string }",elements:[{name:"string"},{name:"signature",type:"object",raw:"{ fieldName?: string }",signature:{properties:[{key:"fieldName",value:{name:"string",required:!1}}]}}]},description:""},placeholder:{required:!1,tsType:{name:"string"},description:""},disabled:{required:!1,tsType:{name:"boolean"},description:""},disabledUnit:{required:!1,tsType:{name:"boolean"},description:""},error:{required:!1,tsType:{name:"union",raw:"string | null | boolean",elements:[{name:"string"},{name:"null"},{name:"boolean"}]},description:""},left:{required:!1,tsType:{name:"boolean"},description:""},small:{required:!1,tsType:{name:"boolean"},description:""},width:{required:!1,tsType:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},description:""},value:{required:!1,tsType:{name:"string"},description:""},unitkey:{required:!1,tsType:{name:"string"},description:""},initUnit:{required:!1,tsType:{name:"string"},description:""},noConversion:{required:!1,tsType:{name:"boolean"},description:""},doNotConvertValue:{required:!1,tsType:{name:"boolean"},description:""},testId:{required:!1,tsType:{name:"string"},description:""},warning:{required:!1,tsType:{name:"union",raw:"string | boolean | null",elements:[{name:"string"},{name:"boolean"},{name:"null"}]},description:""},predefinedOptions:{required:!1,tsType:{name:"union",raw:"IPredefinedOption[] | null",elements:[{name:"Array",elements:[{name:"IPredefinedOption"}],raw:"IPredefinedOption[]"},{name:"null"}]},description:""},initialPredefinedOption:{required:!1,tsType:{name:"boolean"},description:""},shouldLinkAutomaticly:{required:!1,tsType:{name:"boolean"},description:""},selectedPredefinedOptionKey:{required:!1,tsType:{name:"string"},description:""},validationCallback:{required:!1,tsType:{name:"signature",type:"function",raw:`(
|
|
5
|
+
name: string,
|
|
6
|
+
message: string | null,
|
|
7
|
+
) => { name: string; error: string | null }`,signature:{arguments:[{type:{name:"string"},name:"name"},{type:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}]},name:"message"}],return:{name:"signature",type:"object",raw:"{ name: string; error: string | null }",signature:{properties:[{key:"name",value:{name:"string",required:!0}},{key:"error",value:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}],required:!0}}]}}}},description:""},disabledValidation:{required:!1,tsType:{name:"boolean"},description:""},allowEmpty:{required:!1,tsType:{name:"boolean"},description:""},autoValue:{required:!1,tsType:{name:"string"},description:""},onChange:{required:!0,tsType:{name:"signature",type:"function",raw:"(event: ChangeEvent<HTMLInputElement> | ICustomChangeEvent) => void",signature:{arguments:[{type:{name:"union",raw:"ChangeEvent<HTMLInputElement> | ICustomChangeEvent",elements:[{name:"ChangeEvent",elements:[{name:"HTMLInputElement"}],raw:"ChangeEvent<HTMLInputElement>"},{name:"ICustomChangeEvent"}]},name:"event"}],return:{name:"void"}}},description:""},onSwitchUnit:{required:!1,tsType:{name:"signature",type:"function",raw:"(unit: string) => void",signature:{arguments:[{type:{name:"string"},name:"unit"}],return:{name:"void"}}},description:""},onClick:{required:!1,tsType:{name:"MouseEventHandler",elements:[{name:"HTMLInputElement"}],raw:"MouseEventHandler<HTMLInputElement>"},description:""},onFocus:{required:!1,tsType:{name:"FocusEventHandler",elements:[{name:"HTMLInputElement"}],raw:"FocusEventHandler<HTMLInputElement>"},description:""},unitTemplate:{required:!1,tsType:{name:"Record",elements:[{name:"string"},{name:"any"}],raw:"Record<string, any>"},description:""}}};A.__docgenInfo={description:"",methods:[],displayName:"TestEdgeCases"};Y.__docgenInfo={description:"",methods:[],displayName:"AutomaticValues"};Z.__docgenInfo={description:"",methods:[],displayName:"ValidationCallback"};Q.__docgenInfo={description:"",methods:[],displayName:"AllowEmptyPUI"};X.__docgenInfo={description:"",methods:[],displayName:"onSwitchUnit"};ee.__docgenInfo={description:"",methods:[],displayName:"OW_10614TestCase"};var De,_e,Fe;ie.parameters={...ie.parameters,docs:{...(De=ie.parameters)==null?void 0:De.docs,source:{originalSource:`args => {
|
|
8
|
+
const [_, updateArgs] = useArgs();
|
|
9
|
+
const handleChange = (evt: any) => {
|
|
10
|
+
updateArgs({
|
|
11
|
+
value: evt.target.value
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
15
|
+
}`,...(Fe=(_e=ie.parameters)==null?void 0:_e.docs)==null?void 0:Fe.source}}};var Oe,We,Be;F.parameters={...F.parameters,docs:{...(Oe=F.parameters)==null?void 0:Oe.docs,source:{originalSource:`args => {
|
|
16
|
+
const [_, updateArgs] = useArgs();
|
|
17
|
+
const handleChange = (evt: any) => {
|
|
18
|
+
updateArgs({
|
|
19
|
+
value: evt.target.value
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
23
|
+
}`,...(Be=(We=F.parameters)==null?void 0:We.docs)==null?void 0:Be.source}}};var Re,He,Le;O.parameters={...O.parameters,docs:{...(Re=O.parameters)==null?void 0:Re.docs,source:{originalSource:`args => {
|
|
24
|
+
const [_, updateArgs] = useArgs();
|
|
25
|
+
const handleChange = (evt: any) => {
|
|
26
|
+
updateArgs({
|
|
27
|
+
value: evt.target.value
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
31
|
+
}`,...(Le=(He=O.parameters)==null?void 0:He.docs)==null?void 0:Le.source}}};var Ke,ze,$e;W.parameters={...W.parameters,docs:{...(Ke=W.parameters)==null?void 0:Ke.docs,source:{originalSource:`args => {
|
|
32
|
+
const [_, updateArgs] = useArgs();
|
|
33
|
+
const handleChange = (evt: any) => {
|
|
34
|
+
updateArgs({
|
|
35
|
+
value: evt.target.value
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
39
|
+
}`,...($e=(ze=W.parameters)==null?void 0:ze.docs)==null?void 0:$e.source}}};var Ge,Je,Ye;B.parameters={...B.parameters,docs:{...(Ge=B.parameters)==null?void 0:Ge.docs,source:{originalSource:`args => {
|
|
40
|
+
const [_, updateArgs] = useArgs();
|
|
41
|
+
const handleChange = (evt: any) => {
|
|
42
|
+
updateArgs({
|
|
43
|
+
value: evt.target.value
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
47
|
+
}`,...(Ye=(Je=B.parameters)==null?void 0:Je.docs)==null?void 0:Ye.source}}};var Ze,Qe,Xe;R.parameters={...R.parameters,docs:{...(Ze=R.parameters)==null?void 0:Ze.docs,source:{originalSource:`args => {
|
|
48
|
+
const [_, updateArgs] = useArgs();
|
|
49
|
+
const handleChange = (evt: any) => {
|
|
50
|
+
updateArgs({
|
|
51
|
+
value: evt.target.value
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
55
|
+
}`,...(Xe=(Qe=R.parameters)==null?void 0:Qe.docs)==null?void 0:Xe.source}}};var en,nn,tn;H.parameters={...H.parameters,docs:{...(en=H.parameters)==null?void 0:en.docs,source:{originalSource:`args => {
|
|
56
|
+
const [_, updateArgs] = useArgs();
|
|
57
|
+
const handleChange = (evt: any) => {
|
|
58
|
+
updateArgs({
|
|
59
|
+
value: evt.target.value
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
63
|
+
}`,...(tn=(nn=H.parameters)==null?void 0:nn.docs)==null?void 0:tn.source}}};var an,rn,sn;L.parameters={...L.parameters,docs:{...(an=L.parameters)==null?void 0:an.docs,source:{originalSource:`args => {
|
|
64
|
+
const [_, updateArgs] = useArgs();
|
|
65
|
+
const handleChange = (evt: any) => {
|
|
66
|
+
updateArgs({
|
|
67
|
+
value: evt.target.value
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
71
|
+
}`,...(sn=(rn=L.parameters)==null?void 0:rn.docs)==null?void 0:sn.source}}};var ln,un,on;S.parameters={...S.parameters,docs:{...(ln=S.parameters)==null?void 0:ln.docs,source:{originalSource:`args => {
|
|
72
|
+
const [_, updateArgs] = useArgs();
|
|
73
|
+
const handleChange = (evt: any) => {
|
|
74
|
+
updateArgs({
|
|
75
|
+
value: evt.target.value
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
79
|
+
}`,...(on=(un=S.parameters)==null?void 0:un.docs)==null?void 0:on.source}}};var dn,cn,mn;K.parameters={...K.parameters,docs:{...(dn=K.parameters)==null?void 0:dn.docs,source:{originalSource:`args => {
|
|
80
|
+
const [_, updateArgs] = useArgs();
|
|
81
|
+
const handleChange = (evt: any) => {
|
|
82
|
+
updateArgs({
|
|
83
|
+
value: evt.target.value
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
87
|
+
}`,...(mn=(cn=K.parameters)==null?void 0:cn.docs)==null?void 0:mn.source}}};var pn,gn,hn;z.parameters={...z.parameters,docs:{...(pn=z.parameters)==null?void 0:pn.docs,source:{originalSource:`args => {
|
|
88
|
+
const [_, updateArgs] = useArgs();
|
|
89
|
+
const handleChange = (evt: any) => {
|
|
90
|
+
updateArgs({
|
|
91
|
+
value: evt.target.value
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
95
|
+
}`,...(hn=(gn=z.parameters)==null?void 0:gn.docs)==null?void 0:hn.source}}};var vn,fn,Cn;$.parameters={...$.parameters,docs:{...(vn=$.parameters)==null?void 0:vn.docs,source:{originalSource:`args => {
|
|
96
|
+
const [_, updateArgs] = useArgs();
|
|
97
|
+
const handleChange = (evt: any) => {
|
|
98
|
+
updateArgs({
|
|
99
|
+
value: evt.target.value
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
103
|
+
}`,...(Cn=(fn=$.parameters)==null?void 0:fn.docs)==null?void 0:Cn.source}}};var yn,bn,Un;G.parameters={...G.parameters,docs:{...(yn=G.parameters)==null?void 0:yn.docs,source:{originalSource:`args => {
|
|
104
|
+
const [_, updateArgs] = useArgs();
|
|
105
|
+
const handleChange = (evt: any) => {
|
|
106
|
+
updateArgs({
|
|
107
|
+
value: evt.target.value
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
111
|
+
}`,...(Un=(bn=G.parameters)==null?void 0:bn.docs)==null?void 0:Un.source}}};var xn,In,wn;N.parameters={...N.parameters,docs:{...(xn=N.parameters)==null?void 0:xn.docs,source:{originalSource:`(args: IUnitInputProps) => {
|
|
112
|
+
const [value, setValue] = useState('123|m');
|
|
113
|
+
const [value2, setValue2] = useState('223|m');
|
|
114
|
+
const [initUnit, setInitUnit] = useState('ft');
|
|
115
|
+
return <>
|
|
116
|
+
<Button label="Change initUnit" onClick={() => setInitUnit(initUnit === 'm' ? 'ft' : 'm')} />
|
|
117
|
+
<Spacer />
|
|
118
|
+
<Button label="Change value" onClick={() => setValue(value === '123|m' ? '456|m' : '123|m')} />
|
|
119
|
+
<Spacer />
|
|
120
|
+
<UnitInput name="example" onChange={evt => {
|
|
121
|
+
setValue(evt.target.value);
|
|
122
|
+
}} unitkey="length" value={value} initUnit={initUnit} onSwitchUnit={setInitUnit} />
|
|
123
|
+
<Spacer />
|
|
124
|
+
<UnitInput name="example2" onChange={evt => {
|
|
125
|
+
setValue2(evt.target.value);
|
|
126
|
+
}} unitkey="length" value={value2} initUnit={initUnit} onSwitchUnit={setInitUnit} />
|
|
127
|
+
<Divider />
|
|
128
|
+
<h4>Without initUnit property (taken from the redux store)</h4>
|
|
129
|
+
<UnitInput name="example" onChange={evt => {
|
|
130
|
+
setValue(evt.target.value);
|
|
131
|
+
}} unitkey="length" value={value} onSwitchUnit={setInitUnit} />
|
|
132
|
+
<UnitInput name="example2" onChange={evt => {
|
|
133
|
+
setValue2(evt.target.value);
|
|
134
|
+
}} unitkey="length" value={value2} onSwitchUnit={setInitUnit} />
|
|
135
|
+
</>;
|
|
136
|
+
}`,...(wn=(In=N.parameters)==null?void 0:In.docs)==null?void 0:wn.source}}};var Vn,jn,En;J.parameters={...J.parameters,docs:{...(Vn=J.parameters)==null?void 0:Vn.docs,source:{originalSource:`args => {
|
|
137
|
+
const [_, updateArgs] = useArgs();
|
|
138
|
+
const handleChange = (evt: any) => {
|
|
139
|
+
updateArgs({
|
|
140
|
+
value: evt.target.value
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
144
|
+
}`,...(En=(jn=J.parameters)==null?void 0:jn.docs)==null?void 0:En.source}}};var kn,Tn,Sn;A.parameters={...A.parameters,docs:{...(kn=A.parameters)==null?void 0:kn.docs,source:{originalSource:`() => {
|
|
145
|
+
const width = '500px';
|
|
146
|
+
const [value, setValue] = useState<any>(undefined);
|
|
147
|
+
return <>
|
|
148
|
+
<h4>Different edge cases such as +/- infinity, undefined, NaN, null:</h4>
|
|
149
|
+
<Row>
|
|
150
|
+
<Column width="25%">
|
|
151
|
+
<Button label="Change value infinity" onClick={() => setValue(Infinity)} />
|
|
152
|
+
<br />
|
|
153
|
+
<Button label="Change value -infinity" onClick={() => setValue(-Infinity)} />
|
|
154
|
+
<br />
|
|
155
|
+
<Button label="Change value null" onClick={() => setValue(null)} />
|
|
156
|
+
<br />
|
|
157
|
+
<Button label="Change value - undefined" onClick={() => setValue(undefined)} />
|
|
158
|
+
<br />
|
|
159
|
+
<Button label="Change value - NaN" onClick={() => setValue(NaN)} />
|
|
160
|
+
<br />
|
|
161
|
+
<Button label="Change value - nothing (empty)" onClick={() => setValue(undefined)} />
|
|
162
|
+
<br />
|
|
163
|
+
<Button label="Change value - empty string" onClick={() => setValue('')} />
|
|
164
|
+
</Column>
|
|
165
|
+
<Column width="25%">
|
|
166
|
+
<Button label="Change value infinity|m" onClick={() => setValue(Infinity + '|m')} />
|
|
167
|
+
<br />
|
|
168
|
+
<Button label="Change value -infinity|m" onClick={() => setValue(-Infinity + '|m')} />
|
|
169
|
+
<br />
|
|
170
|
+
<Button label="Change value null|m" onClick={() => setValue(null + '|m')} />
|
|
171
|
+
<br />
|
|
172
|
+
<Button label="Change value - undefined|m" onClick={() => setValue(undefined + '|m')} />
|
|
173
|
+
<br />
|
|
174
|
+
<Button label="Change value - NaN|m" onClick={() => setValue(NaN + '|m')} />
|
|
175
|
+
<br />
|
|
176
|
+
<Button label="Change value - nothing (empty)|m" onClick={() => setValue('|m')} />
|
|
177
|
+
</Column>
|
|
178
|
+
</Row>
|
|
179
|
+
<br />
|
|
180
|
+
<Field label="Normal PUI">
|
|
181
|
+
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="value|unit" />
|
|
182
|
+
</Field>
|
|
183
|
+
<Field label="Disabled validation">
|
|
184
|
+
<UnitInput name="example2" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" disabledValidation width={width} />
|
|
185
|
+
</Field>
|
|
186
|
+
<Field label="Disabled validation and manual error">
|
|
187
|
+
<UnitInput name="example3" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" error="test" disabledValidation width={width} />
|
|
188
|
+
</Field>
|
|
189
|
+
<Message message={{
|
|
190
|
+
heading: 'Current value inside PUI: ' + value,
|
|
191
|
+
visible: true
|
|
192
|
+
}} />
|
|
193
|
+
</>;
|
|
194
|
+
}`,...(Sn=(Tn=A.parameters)==null?void 0:Tn.docs)==null?void 0:Sn.source}}};var Nn,An,qn;Y.parameters={...Y.parameters,docs:{...(Nn=Y.parameters)==null?void 0:Nn.docs,source:{originalSource:`() => {
|
|
195
|
+
const width = '500px';
|
|
196
|
+
const [value, setValue] = useState<string>('1|m');
|
|
197
|
+
const [valueB, setValueB] = useState('|m');
|
|
198
|
+
const automaticValue = '123|km';
|
|
199
|
+
return <>
|
|
200
|
+
<h4>Different cases for automatic (placeholder) values:</h4>
|
|
201
|
+
<Row>
|
|
202
|
+
<Column width="25%">
|
|
203
|
+
<Button label="Change value to ''" onClick={() => setValue('')} />
|
|
204
|
+
<br />
|
|
205
|
+
<Button label="Change value to 1" onClick={() => setValue('1')} />
|
|
206
|
+
<br />
|
|
207
|
+
<Button label="Change value to 1|m" onClick={() => setValue('1|m')} />
|
|
208
|
+
<br />
|
|
209
|
+
<Button label="Change value to |m - empty value" onClick={() => setValue('|m')} />
|
|
210
|
+
</Column>
|
|
211
|
+
</Row>
|
|
212
|
+
<br />
|
|
213
|
+
<Field label="Normal PUI (placeholder + auto)">
|
|
214
|
+
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="value|unit" autoValue={automaticValue} />
|
|
215
|
+
</Field>
|
|
216
|
+
<Field label="Normal PUI (only auto)">
|
|
217
|
+
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} autoValue={automaticValue} />
|
|
218
|
+
</Field>
|
|
219
|
+
<Field label="Empty PUI with autoValue">
|
|
220
|
+
<UnitInput name="example1" onChange={evt => setValueB(evt.target.value)} value={valueB} unitkey="length" width={width} autoValue={automaticValue} />
|
|
221
|
+
</Field>
|
|
222
|
+
<Field label="Normal PUI (only placeholder)">
|
|
223
|
+
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="Placeholder test" />
|
|
224
|
+
</Field>
|
|
225
|
+
<Field label="Normal PUI (placeholder + allowEmpty)">
|
|
226
|
+
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="Placeholder test" allowEmpty />
|
|
227
|
+
</Field>
|
|
228
|
+
<Message message={{
|
|
229
|
+
heading: 'Current value inside PUI: ' + value,
|
|
230
|
+
visible: true
|
|
231
|
+
}} />
|
|
232
|
+
</>;
|
|
233
|
+
}`,...(qn=(An=Y.parameters)==null?void 0:An.docs)==null?void 0:qn.source}}};var Pn,Mn,Dn;Z.parameters={...Z.parameters,docs:{...(Pn=Z.parameters)==null?void 0:Pn.docs,source:{originalSource:`() => {
|
|
234
|
+
const [value, setValue] = useState('123|%');
|
|
235
|
+
const [validation, setValidation] = useState<string | null>(null);
|
|
236
|
+
const predictedMessage = 'This should be visible when an error appears';
|
|
237
|
+
const handleValidation = (name: string, message: string | null) => {
|
|
238
|
+
setValidation(message);
|
|
239
|
+
return {
|
|
240
|
+
name,
|
|
241
|
+
error: message
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
return <>
|
|
245
|
+
<h4>3rd party validation message when inputting invalid value:</h4>
|
|
246
|
+
<UnitInput name="example" onChange={evt => setValue(evt.target.value)} error={!validation || predictedMessage} validationCallback={handleValidation} value={value} />
|
|
247
|
+
<br />
|
|
248
|
+
<Spacer />
|
|
249
|
+
<h4>Original validation message: </h4>
|
|
250
|
+
<Message message={{
|
|
251
|
+
heading: validation,
|
|
252
|
+
visible: true
|
|
253
|
+
}} />
|
|
254
|
+
</>;
|
|
255
|
+
}`,...(Dn=(Mn=Z.parameters)==null?void 0:Mn.docs)==null?void 0:Dn.source}}};var _n,Fn,On;Q.parameters={...Q.parameters,docs:{...(_n=Q.parameters)==null?void 0:_n.docs,source:{originalSource:`() => {
|
|
256
|
+
const [value, setValue] = useState('123|m');
|
|
257
|
+
const [placeholder, setPlaceholder] = useState('');
|
|
258
|
+
const [initUnit, setInitUnit] = useState('km');
|
|
259
|
+
const setPlaceholderValue = () => {
|
|
260
|
+
setInitUnit('ft');
|
|
261
|
+
setPlaceholder('placeholder');
|
|
262
|
+
setValue('|m');
|
|
263
|
+
};
|
|
264
|
+
return <>
|
|
265
|
+
<h4>Empty value case:</h4>
|
|
266
|
+
<UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} allowEmpty placeholder={placeholder} initUnit={initUnit} unitkey="length" />
|
|
267
|
+
<br />
|
|
268
|
+
<Spacer />
|
|
269
|
+
<Button label="Change value |m and unit ft" onClick={() => setPlaceholderValue()} />
|
|
270
|
+
</>;
|
|
271
|
+
}`,...(On=(Fn=Q.parameters)==null?void 0:Fn.docs)==null?void 0:On.source}}};var Wn,Bn,Rn;X.parameters={...X.parameters,docs:{...(Wn=X.parameters)==null?void 0:Wn.docs,source:{originalSource:`() => {
|
|
272
|
+
const [value, setValue] = useState('123|m');
|
|
273
|
+
const [unit, setUnit] = useState('m');
|
|
274
|
+
return <>
|
|
275
|
+
<UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} initUnit={unit} unitkey="length" onSwitchUnit={setUnit} />
|
|
276
|
+
<Spacer />
|
|
277
|
+
<UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} initUnit={unit} unitkey="length" onSwitchUnit={setUnit} />
|
|
278
|
+
</>;
|
|
279
|
+
}`,...(Rn=(Bn=X.parameters)==null?void 0:Bn.docs)==null?void 0:Rn.source}}};var Hn,Ln,Kn;ee.parameters={...ee.parameters,docs:{...(Hn=ee.parameters)==null?void 0:Hn.docs,source:{originalSource:`() => {
|
|
280
|
+
return <>
|
|
281
|
+
<Text faint>
|
|
282
|
+
Reproduce OW-10614 rounding noise bug when storing values in a different
|
|
283
|
+
unit to the display unit
|
|
284
|
+
</Text>
|
|
285
|
+
<Spacer />
|
|
286
|
+
<UnitInput name="example" onChange={() => {}} value={withUnit(convertAndGetValue('9750|psi', 'bar'), 'bar')} initUnit="psi" unitkey="pressure" unitTemplate={{
|
|
287
|
+
pressure: 'psi'
|
|
288
|
+
}} />
|
|
289
|
+
</>;
|
|
290
|
+
}`,...(Kn=(Ln=ee.parameters)==null?void 0:Ln.docs)==null?void 0:Kn.source}}};const ya=["Default","InitUnit","notKnownUnit","Width","NoConversion","Small","Error","InternalValidationError","Disabled","DisabledNoConversion","DisabledUnitWithoutUnitKey","DisabledUnitWithUnitKey","DisabledWithEnabledUnitMenu","TestExternalStateChangeWithSynchronizedUnits","PredefinedOptionsMenu","TestEdgeCases","AutomaticValues","ValidationCallback","AllowEmptyPUI","onSwitchUnit","OW_10614TestCase"];export{Q as AllowEmptyPUI,Y as AutomaticValues,ie as Default,S as Disabled,K as DisabledNoConversion,$ as DisabledUnitWithUnitKey,z as DisabledUnitWithoutUnitKey,G as DisabledWithEnabledUnitMenu,H as Error,F as InitUnit,L as InternalValidationError,B as NoConversion,ee as OW_10614TestCase,J as PredefinedOptionsMenu,R as Small,A as TestEdgeCases,N as TestExternalStateChangeWithSynchronizedUnits,Z as ValidationCallback,W as Width,ya as __namedExportsOrder,Ca as default,O as notKnownUnit,X as onSwitchUnit};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import{j as n}from"./jsx-runtime-eps93zm2.js";import{r as v}from"./index-DhsZuJvc.js";import{f as z}from"./immer.esm-BwVl9PS2.js";import{d as U}from"./index-DQs5XS8h.js";import{G as Z}from"./grid-B6LFPf51.js";import{S as ee}from"./spacer-BWoNR27H.js";import{C as F}from"./card-EcjmryU9.js";import{F as L}from"./field-DwLk_uWj.js";import{H as W}from"./heading-DkSFysAb.js";import{S as P}from"./select-78sreKsp.js";import{T as I}from"./toggle-t1iTuSL7.js";import{l as te}from"./lodash-BHd_uQHh.js";import{u as ne}from"./use-previous-D775JrO6.js";import{T as ae,C as _}from"./table-DPvzYjoq.js";import"./index-DRSy5Ssd.js";import"./styled-components.browser.esm-Bf0q9Yjk.js";import"./index-Bk2sglWO.js";import"./label-tWjEmTQJ.js";import"./common-types-Sih75Sav.js";import"./help-icon-LfPZiYla.js";import"./tooltip-C_E_6ym5.js";import"./index-CUZDtIZe.js";import"./icon-BP4BO6-k.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./inheritsLoose-DR8r8Ogv.js";import"./index-CEuq6vkz.js";import"./disabled-context-rmpd7YJS.js";import"./types-UmZ4Y_CR.js";import"./extends-CF3RwP-h.js";import"./assertThisInitialized-B9jnkVVz.js";import"./memoize-one.esm-CcMeOnPo.js";import"./types-BmbYqTX_.js";import"./text-B3-TSWok.js";import"./actions-Cu_0szZ4.js";import"./button-_0DiND6h.js";import"./spinner-AWUe4xwQ.js";import"./badge-CLQ59MDF.js";import"./select.input-DIKP56UZ.js";import"./index.es-D2piFfFj.js";import"./redux-tRgGMjwY.js";import"./objectSpread2-DW4nTBoq.js";import"./tiny-invariant-DqLgxztJ.js";import"./pagination-DSQeMPG_.js";import"./input-D97ganXq.js";import"./input-group-BaRSJAEN.js";import"./input-group-addon-D68iUKV2.js";import"./number-input-B-Nmya5O.js";import"./check-box-DkdQxC5c.js";import"./slider-CxVlS0fh.js";import"./index-BI4_Bp97.js";import"./popover-Dq3iC_lM.js";const ie=l=>l.reduce(({preferredUnits:i,storageUnits:r},{unitKey:s,preferredUnit:a,storageUnit:h})=>(i[s]=a,r[s]=h,{preferredUnits:i,storageUnits:r}),{preferredUnits:{},storageUnits:{}}),re=({headers:l,rows:i,selectedUnits:r,storageUnits:s,onChangeUnit:a,convertBackToStorageUnit:h,enableCosmeticRounding:g,enableDisplayRounding:y})=>{const u=l?l.map(d=>({...d,cells:d.cells.map(c=>{var t;if(c.type===_.AUTO_UNIT){const{testId:C,unitKey:p}=c;return{value:r[p],type:_.SELECT,searchable:!1,options:(t=U.getUnitsForQuantity(p))==null?void 0:t.map(T=>({label:U.label(T),value:T})),native:c.native,onChange:T=>a({unitKey:p,value:T.target.value}),testId:C}}return c})})):[],o=i?i.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:T,formatDisplayValue:w}=t,j=y&&"roundDisplayValue"in t?t==null?void 0:t.roundDisplayValue:null,m=r[p],b=s[p],e=m!==b,f=e?U.convertAndGetValue(T,m,b):t.value,x=U.isScientificStringNum(T),D=g&&(e||!x)?U.roundToPrecision(f,14):f,R=w?w(D):D;return{...t,value:R,enableCosmeticRounding:g,enableDisplayRounding:y,roundDisplayValue:j,onChange:S=>{const{value:B}=S.target,A=s[p],E=r[p],N=E!==A,k=h?A: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:o}},M=({table:l,unitConfig:i,convertBackToStorageUnit:r=!0,enableCosmeticRounding:s=!0,enableDisplayRounding:a=!0})=>{const{rows:h,headers:g,...y}=l,{storageUnits:u,preferredUnits:o}=ie(i),d=ne(o),[c,t]=v.useState(o),C=({unitKey:m,value:b})=>{t({...c,[m]:b});const e=i.find(f=>f.unitKey===m);e&&typeof e.onChange=="function"&&e.onChange({oldUnit:c[m],newUnit:b,unitKey:m})},p=m=>re({headers:g,rows:h,selectedUnits:m,storageUnits:u,onChangeUnit:C,convertBackToStorageUnit:r,enableCosmeticRounding:s,enableDisplayRounding:a}),T=p(c),[w,j]=v.useState(T);return v.useEffect(()=>{!te.isEqual(o,d)&&(Object.keys(o).forEach(b=>{const e=d==null?void 0:d[b],f=o[b];e!==f&&C({unitKey:b,value:f})}),j(p(o)))},[i]),v.useEffect(()=>{j(p(c))},[l,c]),n.jsx(ae,{table:{...y,headers:w.convertedHeaders,rows:w.convertedRows}})};M.__docgenInfo={description:"",methods:[],displayName:"UnitTable",props:{table:{required:!0,tsType:{name:"IUnitTable"},description:""},unitConfig:{required:!0,tsType:{name:"Array",elements:[{name:"IUnitConfigItem"}],raw:"IUnitConfigItem[]"},description:""},convertBackToStorageUnit:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},enableCosmeticRounding:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},enableDisplayRounding:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}}},composes:["Omit"]};const pt={title:"Basic/UnitTable",args:{}},oe=!0,le=!0,se=!0,ue=!1,H="m",J="C",de=3,ce=(l,i,r)=>{const s=[i,i,r],a=[...Array(l)].map((h,g)=>{const y=g,u=g+1.25,o=4+g*.25;return[String(y),String(u),String(o)]});return[s,...a]},pe=ce(de,H,J),ge=({reduxTable:l,value:i,unit:r,rowIndex:s,cellIndex:a})=>z(l,h=>{const g=h[0][a],y=(u,o)=>o===0;return h.forEach((u,o)=>{if(y(u,o)){u[a]=r;return}if(o===s+1){u[a]=String(i);return}const d=U.convertAndGetValue(u[a],r,g);u[a]=String(d)}),h}),me=({reduxTable:l,value:i,rowIndex:r,cellIndex:s})=>z(l,a=>{a[r+1][s]=i}),V=()=>{var m,b;const[l,i]=v.useState(H),[r,s]=v.useState(J),[a,h]=v.useState(pe),[g,y]=v.useState(oe),[u,o]=v.useState(se),[d,c]=v.useState(le),[t,C]=v.useState(ue),[p,T]=v.useState(H),w=e=>{const{rowIndex:f,cellIndex:x,value:D,unit:R}=e.target,S=t?ge({reduxTable:a,value:D,unit:R,rowIndex:f,cellIndex:x}):me({reduxTable:a,value:D,rowIndex:f,cellIndex:x});h(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((D,R)=>{const S=x===1&&R===1;return{value:D,type:S?"Text":"NumberInput",unitKey:R===2?"temperature":"length",onChange:w,roundDisplayValue:x===3&&R===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=>y(e.target.checked)})}),n.jsx(L,{label:"Enable display rounding:",labelLeft:!0,labelWidth:200,children:n.jsx(I,{checked:u,onChange:e=>o(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:l},onChange:e=>i(e.target.value),width:"100px"})}),n.jsx(L,{label:"Temperature unit:",labelLeft:!0,labelWidth:120,children:n.jsx(P,{options:(b=U.getUnitsForQuantity("temperature"))==null?void 0:b.map(e=>({value:e,label:U.label(e)})),value:{value:r},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(M,{table:j,unitConfig:[{unitKey:"length",storageUnit:a[0][0],preferredUnit:l,onChange:({newUnit:e})=>T(e)},{unitKey:"temperature",storageUnit:a[0][2],preferredUnit:r}],convertBackToStorageUnit:g,enableDisplayRounding:u,enableCosmeticRounding:d}),n.jsx(ee,{height:20}),n.jsx(L,{label:"Displayed length unit:",labelLeft:!0,labelWidth:150,children:p})]})]})};V.__docgenInfo={description:"",methods:[],displayName:"UnitTablePrototype"};var K,G,O,q,Q;V.parameters={...V.parameters,docs:{...(K=V.parameters)==null?void 0:K.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",...(Q=(q=V.parameters)==null?void 0:q.docs)==null?void 0:Q.description}}};const gt=["UnitTablePrototype"];export{V as UnitTablePrototype,gt as __namedExportsOrder,pt as default};
|
|
@@ -50,9 +50,7 @@
|
|
|
50
50
|
|
|
51
51
|
<link href="./sb-addons/actions-1/manager-bundle.js" rel="modulepreload" />
|
|
52
52
|
|
|
53
|
-
<link href="./sb-addons/
|
|
54
|
-
|
|
55
|
-
<link href="./sb-addons/storybook-dark-mode-esm-preset-3/manager-bundle.js" rel="modulepreload" />
|
|
53
|
+
<link href="./sb-addons/storybook-dark-mode-esm-preset-2/manager-bundle.js" rel="modulepreload" />
|
|
56
54
|
|
|
57
55
|
|
|
58
56
|
<style>
|
|
@@ -138,9 +136,7 @@
|
|
|
138
136
|
|
|
139
137
|
import './sb-addons/actions-1/manager-bundle.js';
|
|
140
138
|
|
|
141
|
-
import './sb-addons/
|
|
142
|
-
|
|
143
|
-
import './sb-addons/storybook-dark-mode-esm-preset-3/manager-bundle.js';
|
|
139
|
+
import './sb-addons/storybook-dark-mode-esm-preset-2/manager-bundle.js';
|
|
144
140
|
|
|
145
141
|
|
|
146
142
|
import './sb-manager/runtime.js';
|