@oliasoft-open-source/react-ui-library 4.8.0 → 4.9.0-beta-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{index-CvGLlWUJ.js → index-CnfDrmnZ.js} +55 -43
- package/dist/index.d.ts +9 -4
- package/dist/index.html +1 -1
- package/dist/index.js +180 -179
- package/dist/index.js.map +1 -1
- package/dist/storybook/assets/{Color-KGDBMAHA-BLtMCq8G.js → Color-KGDBMAHA-nHvSq78M.js} +1 -1
- package/dist/storybook/assets/{DocsRenderer-PKQXORMH-Cq_uPi34.js → DocsRenderer-PKQXORMH-C1krXrOf.js} +1 -1
- package/dist/storybook/assets/{accordion.stories-CNjaOE6j.js → accordion.stories-kLk1OtZZ.js} +2 -2
- package/dist/storybook/assets/{afe.stories-Be4Zi8Qk.js → afe.stories-DFQsvqIV.js} +2 -2
- package/dist/storybook/assets/{buttons-and-links-CGf2fkq-.js → buttons-and-links-DC-E4soa.js} +2 -2
- package/dist/storybook/assets/{casing-loads.stories-9Iu4v1Y5.js → casing-loads.stories-B2lND_PU.js} +2 -2
- package/dist/storybook/assets/{cell.stories-OWJtpzu1.js → cell.stories-BVDrv2SU.js} +2 -2
- package/dist/storybook/assets/{chunk-HLWAVYOI-DQmzN82L.js → chunk-HLWAVYOI-DX3eyNf5.js} +1 -1
- package/dist/storybook/assets/{color-CUmK6HaC.js → color-BgW0SkoL.js} +2 -2
- package/dist/storybook/assets/footer.stories-BVXSVjq1.js +3 -0
- package/dist/storybook/assets/form.stories-BrUnmw7R.js +49 -0
- package/dist/storybook/assets/{formation.stories-BwshNr5I.js → formation.stories-DmecxRaM.js} +2 -2
- package/dist/storybook/assets/iframe-DHWiHrZY.js +2 -0
- package/dist/storybook/assets/index-B7q2KU2k.js +1 -0
- package/dist/storybook/assets/{index-DLsIgQne.js → index-BRAKCNI8.js} +87 -87
- package/dist/storybook/assets/{index-DaLCDjg_.js → index-C0x1JmaP.js} +1 -1
- package/dist/storybook/assets/{input-group.stories-Bqx8op1f.js → input-group.stories-CElwRt3p.js} +2 -2
- package/dist/storybook/assets/{input-validation-CRDfoI4h.js → input-validation-CD_0XD31.js} +2 -2
- package/dist/storybook/assets/{inputs-D3qEs1Q4.js → inputs-DmKjdzn7.js} +2 -2
- package/dist/storybook/assets/{layout-forms-CDGrrwBl.js → layout-forms-BxdMnma9.js} +4 -4
- package/dist/storybook/assets/{layout-general-D9kS22a0.js → layout-general-DTuKIl0f.js} +1 -1
- package/dist/storybook/assets/{modal.stories-BcqAhYEy.js → modal.stories-LhoWfDE6.js} +2 -2
- package/dist/storybook/assets/number-input-DBZIl9dz.js +16 -0
- package/dist/storybook/assets/number-input.stories-BRQWeYF6.js +166 -0
- package/dist/storybook/assets/{padding-and-spacing-Cr5c7WxM.js → padding-and-spacing-pWMUN6u_.js} +1 -1
- package/dist/storybook/assets/{pagination-D6pYWeQM.js → pagination-CLt-kUlx.js} +1 -1
- package/dist/storybook/assets/{pagination.stories-ItfGvzb-.js → pagination.stories-CTRM0Xou.js} +2 -2
- package/dist/storybook/assets/popover.stories-CGm0M5fv.js +10 -0
- package/dist/storybook/assets/{preview-B_VD4s7b.js → preview-BCA8OXOK.js} +2 -2
- package/dist/storybook/assets/{preview-t_Zs3gQw.js → preview-Ddw3AHiS.js} +2 -2
- package/dist/storybook/assets/{projects.stories-Co_WnKSx.js → projects.stories-BQswWVCx.js} +2 -2
- package/dist/storybook/assets/{radio-button-C4ljBRED.js → radio-button-DmDuw4DA.js} +1 -1
- package/dist/storybook/assets/{radio-button.stories-BzyW2CtK.js → radio-button.stories-5gvV0LD0.js} +2 -2
- package/dist/storybook/assets/{reservoirs.stories-FQuUA3DK.js → reservoirs.stories-B12tIrmZ.js} +2 -2
- package/dist/storybook/assets/{rich-text-input.stories-CmFzKTb-.js → rich-text-input.stories-hAHCnDHk.js} +44 -44
- package/dist/storybook/assets/{row.stories-xvzQuDF0.js → row.stories-BO2s7oph.js} +2 -2
- package/dist/storybook/assets/{select-V2ZNp3Pv.js → select-DnRuRG_N.js} +2 -2
- package/dist/storybook/assets/select.input-D0UkAPd9.js +1 -0
- package/dist/storybook/assets/{select.stories-CV9h5z0E.js → select.stories-B9w9ONzj.js} +2 -2
- package/dist/storybook/assets/{site.stories-ZGohyW6Z.js → site.stories-umpPYjkq.js} +2 -2
- package/dist/storybook/assets/{smart-upload-modal.stories-BKNxg_3y.js → smart-upload-modal.stories-Dn7dIsu1.js} +1 -1
- package/dist/storybook/assets/{table-D9JJ68Tx.js → table-CB6btQu9.js} +1 -1
- package/dist/storybook/assets/{table.stories-f-cNU-ed.js → table.stories-CvHvaYMC.js} +2 -2
- package/dist/storybook/assets/{tabs-BoToLVEP.js → tabs-C3NG6m9W.js} +1 -1
- package/dist/storybook/assets/tabs.stories-dsXjRHJy.js +30 -0
- package/dist/storybook/assets/{title.stories-5TyZBiBD.js → title.stories-DYXG2_x-.js} +2 -2
- package/dist/storybook/assets/unit-input-5P4Cogho.css +1 -0
- package/dist/storybook/assets/unit-input.stories-DRP-nDdh.js +380 -0
- package/dist/storybook/assets/unit-table.stories-DiER-CMn.js +152 -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/sb-addons/interactions-2/manager-bundle.js +52 -52
- package/dist/storybook/sb-manager/globals-runtime.js +7164 -7166
- package/dist/storybook/sb-manager/runtime.js +1110 -1111
- package/dist/storybook/sb-preview/runtime.js +1485 -1483
- package/package.json +3 -3
- package/dist/404.html +0 -1
- package/dist/storybook/assets/footer.stories-CCaqnn-t.js +0 -3
- package/dist/storybook/assets/form.stories-CX1WxUVL.js +0 -49
- package/dist/storybook/assets/helpers-JJxzGegQ.js +0 -1
- package/dist/storybook/assets/iframe-aT7NCuic.js +0 -2
- package/dist/storybook/assets/index-CDuLcH5d.js +0 -1
- package/dist/storybook/assets/number-input-Ct8VwJX0.js +0 -16
- package/dist/storybook/assets/number-input.stories-lRKm6_tZ.js +0 -110
- package/dist/storybook/assets/popover.stories-B4sQDryP.js +0 -10
- package/dist/storybook/assets/select.input-CJed_LLR.js +0 -1
- package/dist/storybook/assets/tabs.stories-B52iEaHf.js +0 -30
- package/dist/storybook/assets/unit-input-CoFS2qhN.css +0 -1
- package/dist/storybook/assets/unit-input.stories-tjEyowge.js +0 -318
- package/dist/storybook/assets/unit-table.stories-BDYxeHSM.js +0 -152
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import{j as e}from"./jsx-runtime-eps93zm2.js";import{r as u}from"./index-DhsZuJvc.js";import{d as s}from"./index-C0x1JmaP.js";import{w as ve,u as c,e as I,f as on,a as un}from"./index-DMAnyMX5.js";import{c as Dn}from"./index-Bk2sglWO.js";import{u as qn}from"./use-previous-D775JrO6.js";import{M as Pe}from"./actions-D-uVCDzk.js";import{I as An}from"./input-group-addon-D68iUKV2.js";import{B as g}from"./button-DHevvVBE.js";import{T as Bn}from"./tooltip-1V7clEnw.js";import{I as Fn}from"./input-group-BaRSJAEN.js";import{S as C}from"./spacer-BWoNR27H.js";import{T as fe}from"./text-B3-TSWok.js";import{M as _e}from"./types-BmbYqTX_.js";import{l as V}from"./lodash-c4VUpsOs.js";import{N as Pn,r as _n}from"./number-input-DBZIl9dz.js";import{i as Rn}from"./select.input-D0UkAPd9.js";import{D as Mn}from"./divider-DY9nJ_7N.js";import{R as dn,C as Te}from"./row-Bmiy2Lh0.js";import{F as T}from"./field-HrLaMLbx.js";import{M as ye}from"./message-Y48EomV-.js";import{G as On}from"./grid-DRkC-bt8.js";import{C as H}from"./card-EcjmryU9.js";import{H as G}from"./heading-CRNoBc7q.js";import{T as Re}from"./toggle-BbFVf61v.js";import{S as Wn}from"./select-DnRuRG_N.js";import"./index-DRSy5Ssd.js";import"./index-CF7H4eMJ.js";import"./common-types-Sih75Sav.js";import"./disabled-context-rmpd7YJS.js";import"./icon-BSFY3vDO.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./inheritsLoose-DP0QEDDI.js";import"./index-CEuq6vkz.js";import"./types-Dx2TtIG9.js";import"./badge-CLQ59MDF.js";import"./spinner-AWUe4xwQ.js";import"./index-CUZDtIZe.js";import"./input-DTXbDJaL.js";import"./styled-components.browser.esm-BQ9GQzDc.js";import"./label-CqmyC9he.js";import"./help-icon-Buhx5nl6.js";import"./assertThisInitialized-B9jnkVVz.js";import"./memoize-one.esm-CcMeOnPo.js";const Ln=()=>{const t=u.useRef(null);return u.useLayoutEffect(()=>{t.current&&(t.current(),t.current=null)}),n=>{t.current=n}},Hn=(t,a)=>{const n=a==null?void 0:a[t];return n||(console.log(`Warning: 'unitTemplate' missing for '${t}'. Using initial unit, preferred unit or value unit.`),s.unitFromQuantity(t)??"")};var b=(t=>(t.CUSTOM="custom",t.PREDEFINED="predefined",t))(b||{});const cn=t=>t==="undefined"||t===void 0||t===""||t==="null"||t===null||t==="NaN"||isNaN(t),mn=(t="",a,n="",l=!1)=>{if(l)return t;if(a&&!cn(t))try{const i=s.isValueWithUnit(t)?t:s.withUnit(t,n),p=s.convertSamePrecision(i,a);return s.getValue(p)}catch{}return t},Gn=t=>t?!!s.getUnit(t):!1,K=(t="",a,n,l)=>{if(l)return t;const i=Gn(t)||s.isValueWithUnit(t),p=s.getValue(t);return cn(p)?p:i?mn(p,a,n,l):t},Me=t=>V.isObject(t)&&!V.isArray(t)&&!V.isFunction(t)?V.get(t,"fieldName",""):typeof t=="string"?t:"",Oe=(t="")=>{var a;return(a=s.KNOWN_UNITS)==null?void 0:a.includes(t)},Kn=(t,a)=>{const n=s.getUnit(t||"");return Oe(a)&&Oe(n)};let $n=u.createContext(null);const zn=()=>u.useContext($n),Jn="_predefinedMenuActive_ye9w9_1",Yn="_inputWrapper_ye9w9_4",We={predefinedMenuActive:Jn,inputWrapper:Yn},m=({name:t,placeholder:a="",disabled:n=!1,disabledUnit:l=!1,error:i=null,left:p=!1,small:o=!1,width:h="100%",value:v,unitkey:D="",initUnit:U,noConversion:q=!1,onChange:be=V.noop,onClick:Qn=V.noop,onFocus:pn=V.noop,onSwitchUnit:ke=V.noop,unitTemplate:Ve,doNotConvertValue:W=!1,testId:A,warning:je=null,predefinedOptions:k,initialPredefinedOption:gn=!1,shouldLinkAutomaticly:Se=!0,selectedPredefinedOptionKey:Ee,validationCallback:hn=()=>({name:"",error:null}),disabledValidation:vn=!1,allowEmpty:fn=!1,autoValue:j,convertBackToStorageUnit:yn=!1,enableCosmeticRounding:Ne=!0,enableDisplayRounding:bn=!1})=>{const B=zn(),Cn=Ln();typeof v=="number"&&(v=`${v}`);const[De="",S=""]=v!==void 0?s.split(v):[],qe=j?s.getUnit(j):"",Ae=u.useMemo(()=>Hn(D,Ve||(B==null?void 0:B.unitTemplate)),[D,Ve,B==null?void 0:B.unitTemplate]),Un=Kn(v,Ae),x=U||Ae||S,xn=qn(x),Be=K(v,x,S,W),Fe=K(j,x,qe,W),wn=Be!==""?{value:Be,unit:x}:Fe!==""?{value:Fe,unit:x}:{value:De,unit:S},[f,Ce]=u.useState(wn),[E,Ue]=u.useState(gn?b.PREDEFINED:b.CUSTOM),xe=De===""&&j,In=!!(vn||j||a&&Rn(v)),L=k&&k.find(r=>{if(!(r!=null&&r.value))return;if(Ee)return Ee===r.valueKey;const d=s.isValueWithUnit(r.value)?s.getUnit(r.value):"";return s.withUnit(mn(v,d),d)===r.value}),Tn=()=>{if(D)try{const r=xe?j:v??"";let d=s.altUnitsList(r,D);return s.getValue(r)===""?d.map(w=>["",w[1]]):d}catch{return null}},kn=r=>{const d=Me(t),w=r.target,{value:N,selectionStart:F}=w,ge=s.withUnit(N,(f==null?void 0:f.unit)||""),Ie=yn?s.withUnit(s.convertAndGetValue(ge,S),S):ge;be({target:{value:Ie,name:d}});const[En,Nn]=s.split(ge);Ce({value:En,unit:Nn}),Cn(()=>{w.selectionStart=F,w.selectionEnd=F})},Vn=(r,d)=>{d===f.unit||isNaN(Number(r))||(Ce({value:r,unit:d}),ke&&ke(d))};u.useEffect(()=>{if(x){let r,d="";xn!==x?(r=K(v,x,S,W),d=x):s.withUnit(f.value,f.unit)!==v&&(r=K(v,f.unit,S,W),d=f.unit),r!==void 0&&Ce({value:r,unit:d}),k&&Ue(L&&Se?b.PREDEFINED:b.CUSTOM)}},[x,v,i,Se]);const ce=Tn(),me=s.label(f.unit)||f.unit||"",jn=q||!ce||ce&&ce.length===1,we=Me(t);let pe;const Sn=r=>{const d=r!=null&&r.value?r.value:"",[w="",N=""]=s.isValueWithUnit(d)?s.split(d):[d];return{type:_e.OPTION,inline:!0,onClick:()=>{s.validateNumber(w).valid&&!n&&(Ue(b.PREDEFINED),be({target:{value:d,name:typeof t=="string"?t:(t==null?void 0:t.fieldName)||"",predefinedSelected:!0,predefinedOption:r}}))},label:e.jsxs(e.Fragment,{children:[e.jsx(fe,{children:r.label}),e.jsx(C,{width:"20px",height:"0"})]}),description:s.isValueWithUnit(d)?`${w} ${N}`:d,selected:L===r&&E===b.PREDEFINED}};if(pe=[{type:_e.OPTION,inline:!0,onClick:()=>{E!==b.CUSTOM&&!n&&be({target:{value:s.withUnit(f.value,f.unit),name:typeof t=="string"?t:(t==null?void 0:t.fieldName)||""}})},label:"Custom",selected:E===b.CUSTOM}],k!=null&&k.length){const r=k.map(Sn);pe=[...pe,...r]}return e.jsx("div",{className:E===b.PREDEFINED?Dn(We.predefinedMenuActive):"",children:e.jsxs(Fn,{small:o,width:h,children:[k&&e.jsx(Bn,{text:E===b.PREDEFINED?L==null?void 0:L.label:"",children:e.jsx(Pe,{maxHeight:380,groupOrder:"first",testId:A&&`${A}-predefined-menu`,disabled:n,menu:{colored:!0,trigger:"Component",component:e.jsx(g,{groupOrder:"first",active:E===b.PREDEFINED,icon:E===b.PREDEFINED?"link":"unlink"}),small:o,sections:pe}})}),e.jsx("div",{className:We.inputWrapper,children:e.jsx(Pn,{name:we,testId:A,disabled:n,placeholder:xe?K(j,f.unit,qe,W):a,value:f.value,onChange:kn,onFocus:pn,error:i===null?void 0:i,warning:je===null?void 0:je,left:p,allowEmpty:fn,validationCallback:(r,d)=>hn(we,d),enableCosmeticRounding:Ne,enableDisplayRounding:bn,groupOrder:k?"middle":"first",disableInternalErrorValidationMessages:In},we)}),me&&(jn||!Un?e.jsx(An,{groupOrder:"last",children:me}):e.jsx(Pe,{maxHeight:380,groupOrder:"last",disabled:l,testId:A&&`${A}-menu`,menu:{label:me,trigger:"DropDownButton",small:o,sections:ce.map(([r,d,w])=>{const N=w||d||"",F=isNaN(Number(r))?"":r;return{type:"Option",label:Ne?_n(F):F,inline:!0,onClick:Ie=>{Ie.stopPropagation(),Vn(xe?"":r,d)},description:N,selected:N===me,testId:`${A}-unit-${N}`}})}}))]})})};m.__docgenInfo={description:"",methods:[],displayName:"UnitInput",props:{name:{required:!0,tsType:{name:"union",raw:"string | { fieldName?: string }",elements:[{name:"string"},{name:"signature",type:"object",raw:"{ fieldName?: string }",signature:{properties:[{key:"fieldName",value:{name:"string",required:!1}}]}}]},description:""},placeholder:{required:!1,tsType:{name:"string"},description:"",defaultValue:{value:"''",computed:!1}},disabled:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},disabledUnit:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},error:{required:!1,tsType:{name:"union",raw:"string | null | boolean",elements:[{name:"string"},{name:"null"},{name:"boolean"}]},description:"",defaultValue:{value:"null",computed:!1}},left:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},small:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},width:{required:!1,tsType:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},description:"",defaultValue:{value:"'100%'",computed:!1}},value:{required:!1,tsType:{name:"string"},description:""},unitkey:{required:!1,tsType:{name:"string"},description:"",defaultValue:{value:"''",computed:!1}},initUnit:{required:!1,tsType:{name:"string"},description:""},noConversion:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},doNotConvertValue:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},testId:{required:!1,tsType:{name:"string"},description:""},warning:{required:!1,tsType:{name:"union",raw:"string | boolean | null",elements:[{name:"string"},{name:"boolean"},{name:"null"}]},description:"",defaultValue:{value:"null",computed:!1}},predefinedOptions:{required:!1,tsType:{name:"union",raw:"IPredefinedOption[] | null",elements:[{name:"Array",elements:[{name:"IPredefinedOption"}],raw:"IPredefinedOption[]"},{name:"null"}]},description:""},initialPredefinedOption:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},shouldLinkAutomaticly:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},selectedPredefinedOptionKey:{required:!1,tsType:{name:"string"},description:""},validationCallback:{required:!1,tsType:{name:"signature",type:"function",raw:"(name: string, error: string | null) => any",signature:{arguments:[{type:{name:"string"},name:"name"},{type:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}]},name:"error"}],return:{name:"any"}}},description:"",defaultValue:{value:"() => ({ name: '', error: null })",computed:!1}},disabledValidation:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},allowEmpty:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},autoValue:{required:!1,tsType:{name:"string"},description:""},onChange:{required:!1,tsType:{name:"signature",type:"function",raw:"(event: TChangeEvent | ICustomChangeEvent) => void",signature:{arguments:[{type:{name:"union",raw:"TChangeEvent | ICustomChangeEvent",elements:[{name:"intersection",raw:`ChangeEvent<T> & {
|
|
2
|
+
target:
|
|
3
|
+
| T
|
|
4
|
+
| { name: string; value: any; label?: string; files?: FileList | null };
|
|
5
|
+
}`,elements:[{name:"ChangeEvent",elements:[{name:"T"}],raw:"ChangeEvent<T>"},{name:"signature",type:"object",raw:`{
|
|
6
|
+
target:
|
|
7
|
+
| T
|
|
8
|
+
| { name: string; value: any; label?: string; files?: FileList | null };
|
|
9
|
+
}`,signature:{properties:[{key:"target",value:{name:"union",raw:`| T
|
|
10
|
+
| { name: string; value: any; label?: string; files?: FileList | null }`,elements:[{name:"T"},{name:"signature",type:"object",raw:"{ name: string; value: any; label?: string; files?: FileList | null }",signature:{properties:[{key:"name",value:{name:"string",required:!0}},{key:"value",value:{name:"any",required:!0}},{key:"label",value:{name:"string",required:!1}},{key:"files",value:{name:"union",raw:"FileList | null",elements:[{name:"FileList"},{name:"null"}],required:!1}}]}}],required:!0}}]}}]},{name:"ICustomChangeEvent"}]},name:"event"}],return:{name:"void"}}},description:"",defaultValue:{value:"noop",computed:!0}},onSwitchUnit:{required:!1,tsType:{name:"signature",type:"function",raw:"(unit: string) => void",signature:{arguments:[{type:{name:"string"},name:"unit"}],return:{name:"void"}}},description:"",defaultValue:{value:"noop",computed:!0}},onClick:{required:!1,tsType:{name:"MouseEventHandler",elements:[{name:"HTMLInputElement"}],raw:"MouseEventHandler<HTMLInputElement>"},description:"",defaultValue:{value:"noop",computed:!0}},onFocus:{required:!1,tsType:{name:"FocusEventHandler",elements:[{name:"HTMLInputElement"}],raw:"FocusEventHandler<HTMLInputElement>"},description:"",defaultValue:{value:"noop",computed:!0}},unitTemplate:{required:!1,tsType:{name:"Record",elements:[{name:"string"},{name:"any"}],raw:"Record<string, any>"},description:""},convertBackToStorageUnit:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},enableCosmeticRounding:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},enableDisplayRounding:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}}}};const{useArgs:Zn}=__STORYBOOK_MODULE_PREVIEW_API__,La={title:"Forms/UnitInput",component:m,args:{name:"example",unitkey:"length",value:"123|m"}},y=t=>{const[a,n]=Zn(),l=i=>{n({value:i.target.value})};return e.jsx(m,{...t,onChange:l})},he=y.bind({}),$=y.bind({});$.args={initUnit:"ft",unitTemplate:{length:"ft"}};const z=y.bind({});z.args={value:'123|"',unitkey:'"'};const J=y.bind({});J.args={width:"180px"};const Y=y.bind({});Y.args={noConversion:!0};const Z=y.bind({});Z.args={small:!0};const P=()=>{const[t,a]=u.useState("123|m");return e.jsx(m,{name:"example",onChange:n=>a(n.target.value),placeholder:"Type a value...",value:t,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"},testId:"testId"})};P.play=async({canvasElement:t,step:a})=>{const n=ve(t),l=ve(t.ownerDocument.body);await a("Shows validation error for non-numeric input",async()=>{const i=n.getByTestId("testId");await c.clear(i),await c.type(i,"123x45s6"),await c.click(t),await I(n.getByDisplayValue("123x45s6")).toBeInTheDocument(),await on.mouseOver(i),await un(()=>{I(l.getByText("Must be a numerical value")).toBeInTheDocument()})})};const Q=y.bind({});Q.args={error:"Error message goes here"};const X=y.bind({});X.args={value:"asas123asd|%"};const _=y.bind({});_.args={disabled:!0,disabledUnit:!0};_.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 ee=y.bind({});ee.args={disabled:!0,disabledUnit:!0,noConversion:!0};const te=y.bind({});te.args={disabledUnit:!0,unitkey:void 0};const ne=y.bind({});ne.args={disabledUnit:!0,unitkey:"length"};const ae=y.bind({});ae.args={disabledUnit:!1,disabled:!0};const R=t=>{const[a,n]=u.useState("123|m"),[l,i]=u.useState("223|m"),[p,o]=u.useState("ft");return e.jsxs(e.Fragment,{children:[e.jsx(g,{label:"Change initUnit",onClick:()=>o(p==="m"?"ft":"m")}),e.jsx(C,{}),e.jsx(g,{label:"Change value",onClick:()=>n(a==="123|m"?"456|m":"123|m")}),e.jsx(C,{}),e.jsx(m,{name:"example",onChange:h=>{n(h.target.value)},unitkey:"length",value:a,initUnit:p,onSwitchUnit:o}),e.jsx(C,{}),e.jsx(m,{name:"example2",onChange:h=>{i(h.target.value)},unitkey:"length",value:l,initUnit:p,onSwitchUnit:o}),e.jsx(Mn,{}),e.jsx("h4",{children:"Without initUnit property (taken from the redux store)"}),e.jsx(m,{name:"example",onChange:h=>{n(h.target.value)},unitkey:"length",value:a,onSwitchUnit:o}),e.jsx(m,{name:"example2",onChange:h=>{i(h.target.value)},unitkey:"length",value:l,onSwitchUnit:o})]})};R.parameters={docs:{description:{story:"[OW-4380](https://oliasoft.atlassian.net/browse/OW-4380?atlOrigin=eyJpIjoiMmM1N2RkNWU3Mjk5NDYxY2E0YzhkMzk5ZTVmZTJhMjciLCJwIjoiaiJ9)"}}};const ie=y.bind({});ie.args={predefinedOptions:[{label:"bottom of casing",value:"12|km"},{label:"mud weight at shoe depth",value:"8|mm"}]};const M=()=>{const t="500px",[a,n]=u.useState(void 0);return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different edge cases such as +/- infinity, undefined, NaN, null:"}),e.jsxs(dn,{children:[e.jsxs(Te,{width:"25%",children:[e.jsx(g,{label:"Change value infinity",onClick:()=>n(1/0)}),e.jsx("br",{}),e.jsx(g,{label:"Change value -infinity",onClick:()=>n(-1/0)}),e.jsx("br",{}),e.jsx(g,{label:"Change value null",onClick:()=>n(null)}),e.jsx("br",{}),e.jsx(g,{label:"Change value - undefined",onClick:()=>n(void 0)}),e.jsx("br",{}),e.jsx(g,{label:"Change value - NaN",onClick:()=>n(NaN)}),e.jsx("br",{}),e.jsx(g,{label:"Change value - nothing (empty)",onClick:()=>n(void 0)}),e.jsx("br",{}),e.jsx(g,{label:"Change value - empty string",onClick:()=>n("")})]}),e.jsxs(Te,{width:"25%",children:[e.jsx(g,{label:"Change value infinity|m",onClick:()=>n("Infinity|m")}),e.jsx("br",{}),e.jsx(g,{label:"Change value -infinity|m",onClick:()=>n("-Infinity|m")}),e.jsx("br",{}),e.jsx(g,{label:"Change value null|m",onClick:()=>n("null|m")}),e.jsx("br",{}),e.jsx(g,{label:"Change value - undefined|m",onClick:()=>n("undefined|m")}),e.jsx("br",{}),e.jsx(g,{label:"Change value - NaN|m",onClick:()=>n("NaN|m")}),e.jsx("br",{}),e.jsx(g,{label:"Change value - nothing (empty)|m",onClick:()=>n("|m")})]})]}),e.jsx("br",{}),e.jsx(T,{label:"Normal PUI",children:e.jsx(m,{name:"example1",onChange:l=>n(l.target.value),value:a,unitkey:"length",width:t,placeholder:"value|unit"})}),e.jsx(T,{label:"Disabled validation",children:e.jsx(m,{name:"example2",onChange:l=>n(l.target.value),value:a,unitkey:"length",disabledValidation:!0,width:t})}),e.jsx(T,{label:"Disabled validation and manual error",children:e.jsx(m,{name:"example3",onChange:l=>n(l.target.value),value:a,unitkey:"length",error:"test",disabledValidation:!0,width:t})}),e.jsx(ye,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})},re=()=>{const t="500px",[a,n]=u.useState("1|m"),[l,i]=u.useState("|m"),p="123|km";return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different cases for automatic (placeholder) values:"}),e.jsx(dn,{children:e.jsxs(Te,{width:"25%",children:[e.jsx(g,{label:"Change value to ''",onClick:()=>n("")}),e.jsx("br",{}),e.jsx(g,{label:"Change value to 1",onClick:()=>n("1")}),e.jsx("br",{}),e.jsx(g,{label:"Change value to 1|m",onClick:()=>n("1|m")}),e.jsx("br",{}),e.jsx(g,{label:"Change value to |m - empty value",onClick:()=>n("|m")})]})}),e.jsx("br",{}),e.jsx(T,{label:"Normal PUI (placeholder + auto)",children:e.jsx(m,{name:"example1",onChange:o=>n(o.target.value),value:a,unitkey:"length",width:t,placeholder:"value|unit",autoValue:p})}),e.jsx(T,{label:"Normal PUI (only auto)",children:e.jsx(m,{name:"example1",onChange:o=>n(o.target.value),value:a,unitkey:"length",width:t,autoValue:p})}),e.jsx(T,{label:"Empty PUI with autoValue",children:e.jsx(m,{name:"example1",onChange:o=>i(o.target.value),value:l,unitkey:"length",width:t,autoValue:p})}),e.jsx(T,{label:"Normal PUI (only placeholder)",children:e.jsx(m,{name:"example1",onChange:o=>n(o.target.value),value:a,unitkey:"length",width:t,placeholder:"Placeholder test"})}),e.jsx(T,{label:"Normal PUI (placeholder + allowEmpty)",children:e.jsx(m,{name:"example1",onChange:o=>n(o.target.value),value:a,unitkey:"length",width:t,placeholder:"Placeholder test",allowEmpty:!0})}),e.jsx(ye,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})};M.parameters={docs:{description:{story:"[OW-8884](https://oliasoft.atlassian.net/browse/OW-8884)"}}};const se=()=>{const[t,a]=u.useState("123|%"),[n,l]=u.useState(null),i="This should be visible when an error appears",p=(o,h)=>(l(h),{name:o,error:h});return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"3rd party validation message when inputting invalid value:"}),e.jsx(m,{name:"example",onChange:o=>a(o.target.value),error:!n||i,validationCallback:p,value:t}),e.jsx("br",{}),e.jsx(C,{}),e.jsx("h4",{children:"Original validation message: "}),e.jsx(ye,{message:{heading:n,visible:!0}})]})},le=()=>{const[t,a]=u.useState("123|m"),[n,l]=u.useState(""),[i,p]=u.useState("km"),o=()=>{p("ft"),l("placeholder"),a("|m")};return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Empty value case:"}),e.jsx(m,{name:"example",onChange:h=>a(h.target.value),value:t,allowEmpty:!0,placeholder:n,initUnit:i,unitkey:"length"}),e.jsx("br",{}),e.jsx(C,{}),e.jsx(g,{label:"Change value |m and unit ft",onClick:()=>o()})]})},oe=()=>{const[t,a]=u.useState("123|m"),[n,l]=u.useState("m");return e.jsxs(e.Fragment,{children:[e.jsx(m,{name:"example",onChange:i=>a(i.target.value),value:t,initUnit:n,unitkey:"length",onSwitchUnit:l}),e.jsx(C,{}),e.jsx(m,{name:"example",onChange:i=>a(i.target.value),value:t,initUnit:n,unitkey:"length",onSwitchUnit:l})]})},ue=()=>e.jsxs(e.Fragment,{children:[e.jsx(fe,{faint:!0,children:"Reproduce OW-10614 rounding noise bug when storing values in a different unit to the display unit"}),e.jsx(C,{}),e.jsx(m,{name:"example",onChange:()=>{},value:s.withUnit(s.convertAndGetValue("9750|psi","bar"),"bar"),initUnit:"psi",unitkey:"pressure",unitTemplate:{pressure:"psi"}}),e.jsx(C,{}),e.jsx(m,{name:"example2",onChange:()=>{},value:s.withUnit(s.convertAndGetValue("8642|lbf","tonneForce"),"tonneForce"),initUnit:"lbf",unitkey:"force",unitTemplate:{force:"tonneForce"}})]}),de=()=>{const[t,a]=u.useState("psi"),[n,l]=u.useState(!1),[i,p]=u.useState(!0),[o,h]=u.useState("672.2388357750001|bar"),[v,D]=u.useState("");return e.jsxs(On,{columns:"1fr 1fr",gap:!0,children:[e.jsxs(H,{heading:e.jsx(G,{children:"Settings"}),children:[e.jsx(T,{label:"Enable display rounding:",labelLeft:!0,labelWidth:200,children:e.jsx(Re,{checked:n,onChange:U=>l(U.target.checked)})}),e.jsx(T,{label:"Enable cosmetic rounding:",labelLeft:!0,labelWidth:200,children:e.jsx(Re,{checked:i,onChange:U=>p(U.target.checked)})})]}),e.jsxs(H,{heading:e.jsx(G,{children:"NumberInput (displayed in Meters)"}),children:[e.jsx(fe,{faint:!0,children:"Cosmetic Rounding Test Case: type 9750 then return (compare with enableCosmeticRounding on and off)"}),e.jsx(C,{}),e.jsx(fe,{warning:!0,children:"Note: UnitInput uses convertSamePrecision internally (decision prior to cosmetic value implementation). This means not all rounding noise occurrences seen in NumberInput will be reproducible in UnitInput, because they get rounded off by other logic."}),e.jsx(C,{}),e.jsx(m,{name:"Example",unitkey:"pressure",initUnit:t,unitTemplate:{pressure:"psi"},value:o,onChange:U=>{const{value:q}=U.target;q&&h(q)},enableDisplayRounding:n,enableCosmeticRounding:i,error:s.convertAndGetValue(o,"bar")>=0?"":"Value must be positive",validationCallback:(U,q)=>{D(q??"")},convertBackToStorageUnit:!0})]}),e.jsx(H,{heading:e.jsx(G,{children:"Unit Template"}),children:e.jsx(Wn,{options:[{label:"Bar",value:"bar"},{label:"psi",value:"psi"}],value:t,width:70,onChange:U=>a(U.target.value)})}),e.jsx(H,{heading:e.jsx(G,{children:"Test Validation Callback"}),children:v&&e.jsx(ye,{message:{content:v,icon:!0,type:"Error",visible:!0}})}),e.jsxs(H,{heading:e.jsx(G,{children:"Storage State / Redux (stored in Feet)"}),children:[o,e.jsx(C,{}),e.jsx(g,{label:"Change value",onClick:()=>h(s.withUnit(String(Math.floor(Math.random()*100)),"bar"))})]})]})},O=()=>{const[t,a]=u.useState("123|m");return e.jsx(m,{name:"example",onChange:n=>a(n.target.value),value:t,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"},testId:"testId"})};O.play=async({canvasElement:t,step:a})=>{const n=ve(t),l=ve(t.ownerDocument.body);await a("Can enter decimal values",async()=>{const i=n.getByTestId("testId");await c.clear(i),await c.type(i,"123.123456789"),await c.click(t),await I(n.getByDisplayValue("123.123456789")).toBeInTheDocument()}),await a("Can enter scientific notation",async()=>{const i=n.getByTestId("testId");await c.clear(i),await c.type(i,"-1.12e3"),await c.click(t),await I(n.getByDisplayValue("-1.12e3")).toBeInTheDocument()}),await a("Can enter comma decimals (converts to dot)",async()=>{const i=n.getByTestId("testId");await c.clear(i),await c.type(i,"123,456"),await c.click(t),await I(n.getByDisplayValue("123.456")).toBeInTheDocument()}),await a("Can enter small numbers",async()=>{const i=n.getByTestId("testId");await c.clear(i),await c.type(i,"0.0000000023"),await c.click(t),await I(n.getByDisplayValue("0.0000000023")).toBeInTheDocument()}),await a("Can enter large numbers",async()=>{const i=n.getByTestId("testId");await c.clear(i),await c.type(i,"999999999999"),await c.click(t),await I(n.getByDisplayValue("999999999999")).toBeInTheDocument()}),await a("Can convert units",async()=>{const i=n.getByTestId("testId"),p=n.getByTestId("testId-menu");await c.clear(i),await c.type(i,"456.1"),await c.click(t),await c.click(p),await c.click(l.getByTestId("testId-unit-ft")),await I(n.getByDisplayValue("1496")).toBeInTheDocument()}),await a("Shows validation error for non-numeric input",async()=>{const i=n.getByTestId("testId");await c.clear(i),await c.type(i,"123x45s6"),await c.click(t),await I(n.getByDisplayValue("123x45s6")).toBeInTheDocument(),await on.mouseOver(i),await un(()=>{I(l.getByText("Must be a numerical value")).toBeInTheDocument()})})};P.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"Placeholder"};R.__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:"(name: string, error: string | null) => any",signature:{arguments:[{type:{name:"string"},name:"name"},{type:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}]},name:"error"}],return:{name:"any"}}},description:""},disabledValidation:{required:!1,tsType:{name:"boolean"},description:""},allowEmpty:{required:!1,tsType:{name:"boolean"},description:""},autoValue:{required:!1,tsType:{name:"string"},description:""},onChange:{required:!1,tsType:{name:"signature",type:"function",raw:"(event: TChangeEvent | ICustomChangeEvent) => void",signature:{arguments:[{type:{name:"union",raw:"TChangeEvent | ICustomChangeEvent",elements:[{name:"intersection",raw:`ChangeEvent<T> & {
|
|
11
|
+
target:
|
|
12
|
+
| T
|
|
13
|
+
| { name: string; value: any; label?: string; files?: FileList | null };
|
|
14
|
+
}`,elements:[{name:"ChangeEvent",elements:[{name:"T"}],raw:"ChangeEvent<T>"},{name:"signature",type:"object",raw:`{
|
|
15
|
+
target:
|
|
16
|
+
| T
|
|
17
|
+
| { name: string; value: any; label?: string; files?: FileList | null };
|
|
18
|
+
}`,signature:{properties:[{key:"target",value:{name:"union",raw:`| T
|
|
19
|
+
| { name: string; value: any; label?: string; files?: FileList | null }`,elements:[{name:"T"},{name:"signature",type:"object",raw:"{ name: string; value: any; label?: string; files?: FileList | null }",signature:{properties:[{key:"name",value:{name:"string",required:!0}},{key:"value",value:{name:"any",required:!0}},{key:"label",value:{name:"string",required:!1}},{key:"files",value:{name:"union",raw:"FileList | null",elements:[{name:"FileList"},{name:"null"}],required:!1}}]}}],required:!0}}]}}]},{name:"ICustomChangeEvent"}]},name:"event"}],return:{name:"void"}}},description:""},onSwitchUnit:{required:!1,tsType:{name:"signature",type:"function",raw:"(unit: string) => void",signature:{arguments:[{type:{name:"string"},name:"unit"}],return:{name:"void"}}},description:""},onClick:{required:!1,tsType:{name:"MouseEventHandler",elements:[{name:"HTMLInputElement"}],raw:"MouseEventHandler<HTMLInputElement>"},description:""},onFocus:{required:!1,tsType:{name:"FocusEventHandler",elements:[{name:"HTMLInputElement"}],raw:"FocusEventHandler<HTMLInputElement>"},description:""},unitTemplate:{required:!1,tsType:{name:"Record",elements:[{name:"string"},{name:"any"}],raw:"Record<string, any>"},description:""},convertBackToStorageUnit:{required:!1,tsType:{name:"boolean"},description:""},enableCosmeticRounding:{required:!1,tsType:{name:"boolean"},description:""},enableDisplayRounding:{required:!1,tsType:{name:"boolean"},description:""}}};M.__docgenInfo={description:"",methods:[],displayName:"TestEdgeCases"};re.__docgenInfo={description:"",methods:[],displayName:"AutomaticValues"};se.__docgenInfo={description:"",methods:[],displayName:"ValidationCallback"};le.__docgenInfo={description:"",methods:[],displayName:"AllowEmptyPUI"};oe.__docgenInfo={description:"",methods:[],displayName:"onSwitchUnit"};ue.__docgenInfo={description:"",methods:[],displayName:"OW_10614TestCase"};de.__docgenInfo={description:"",methods:[],displayName:"DemoCosmeticRounding"};O.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"TestUserInput"};var Le,He,Ge;he.parameters={...he.parameters,docs:{...(Le=he.parameters)==null?void 0:Le.docs,source:{originalSource:`args => {
|
|
20
|
+
const [_, updateArgs] = useArgs();
|
|
21
|
+
const handleChange = (evt: any) => {
|
|
22
|
+
updateArgs({
|
|
23
|
+
value: evt.target.value
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
27
|
+
}`,...(Ge=(He=he.parameters)==null?void 0:He.docs)==null?void 0:Ge.source}}};var Ke,$e,ze;$.parameters={...$.parameters,docs:{...(Ke=$.parameters)==null?void 0:Ke.docs,source:{originalSource:`args => {
|
|
28
|
+
const [_, updateArgs] = useArgs();
|
|
29
|
+
const handleChange = (evt: any) => {
|
|
30
|
+
updateArgs({
|
|
31
|
+
value: evt.target.value
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
35
|
+
}`,...(ze=($e=$.parameters)==null?void 0:$e.docs)==null?void 0:ze.source}}};var Je,Ye,Ze;z.parameters={...z.parameters,docs:{...(Je=z.parameters)==null?void 0:Je.docs,source:{originalSource:`args => {
|
|
36
|
+
const [_, updateArgs] = useArgs();
|
|
37
|
+
const handleChange = (evt: any) => {
|
|
38
|
+
updateArgs({
|
|
39
|
+
value: evt.target.value
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
43
|
+
}`,...(Ze=(Ye=z.parameters)==null?void 0:Ye.docs)==null?void 0:Ze.source}}};var Qe,Xe,et;J.parameters={...J.parameters,docs:{...(Qe=J.parameters)==null?void 0:Qe.docs,source:{originalSource:`args => {
|
|
44
|
+
const [_, updateArgs] = useArgs();
|
|
45
|
+
const handleChange = (evt: any) => {
|
|
46
|
+
updateArgs({
|
|
47
|
+
value: evt.target.value
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
51
|
+
}`,...(et=(Xe=J.parameters)==null?void 0:Xe.docs)==null?void 0:et.source}}};var tt,nt,at;Y.parameters={...Y.parameters,docs:{...(tt=Y.parameters)==null?void 0:tt.docs,source:{originalSource:`args => {
|
|
52
|
+
const [_, updateArgs] = useArgs();
|
|
53
|
+
const handleChange = (evt: any) => {
|
|
54
|
+
updateArgs({
|
|
55
|
+
value: evt.target.value
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
59
|
+
}`,...(at=(nt=Y.parameters)==null?void 0:nt.docs)==null?void 0:at.source}}};var it,rt,st;Z.parameters={...Z.parameters,docs:{...(it=Z.parameters)==null?void 0:it.docs,source:{originalSource:`args => {
|
|
60
|
+
const [_, updateArgs] = useArgs();
|
|
61
|
+
const handleChange = (evt: any) => {
|
|
62
|
+
updateArgs({
|
|
63
|
+
value: evt.target.value
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
67
|
+
}`,...(st=(rt=Z.parameters)==null?void 0:rt.docs)==null?void 0:st.source}}};var lt,ot,ut;P.parameters={...P.parameters,docs:{...(lt=P.parameters)==null?void 0:lt.docs,source:{originalSource:`() => {
|
|
68
|
+
const [value, setValue] = useState('123|m');
|
|
69
|
+
return <UnitInput name="example" onChange={evt => setValue(evt.target.value)} placeholder="Type a value..." value={value} initUnit="m" unitkey="depth" unitTemplate={{
|
|
70
|
+
depth: 'm'
|
|
71
|
+
}} testId="testId" />;
|
|
72
|
+
}`,...(ut=(ot=P.parameters)==null?void 0:ot.docs)==null?void 0:ut.source}}};var dt,ct,mt;Q.parameters={...Q.parameters,docs:{...(dt=Q.parameters)==null?void 0:dt.docs,source:{originalSource:`args => {
|
|
73
|
+
const [_, updateArgs] = useArgs();
|
|
74
|
+
const handleChange = (evt: any) => {
|
|
75
|
+
updateArgs({
|
|
76
|
+
value: evt.target.value
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
80
|
+
}`,...(mt=(ct=Q.parameters)==null?void 0:ct.docs)==null?void 0:mt.source}}};var pt,gt,ht;X.parameters={...X.parameters,docs:{...(pt=X.parameters)==null?void 0:pt.docs,source:{originalSource:`args => {
|
|
81
|
+
const [_, updateArgs] = useArgs();
|
|
82
|
+
const handleChange = (evt: any) => {
|
|
83
|
+
updateArgs({
|
|
84
|
+
value: evt.target.value
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
88
|
+
}`,...(ht=(gt=X.parameters)==null?void 0:gt.docs)==null?void 0:ht.source}}};var vt,ft,yt;_.parameters={..._.parameters,docs:{...(vt=_.parameters)==null?void 0:vt.docs,source:{originalSource:`args => {
|
|
89
|
+
const [_, updateArgs] = useArgs();
|
|
90
|
+
const handleChange = (evt: any) => {
|
|
91
|
+
updateArgs({
|
|
92
|
+
value: evt.target.value
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
96
|
+
}`,...(yt=(ft=_.parameters)==null?void 0:ft.docs)==null?void 0:yt.source}}};var bt,Ct,Ut;ee.parameters={...ee.parameters,docs:{...(bt=ee.parameters)==null?void 0:bt.docs,source:{originalSource:`args => {
|
|
97
|
+
const [_, updateArgs] = useArgs();
|
|
98
|
+
const handleChange = (evt: any) => {
|
|
99
|
+
updateArgs({
|
|
100
|
+
value: evt.target.value
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
104
|
+
}`,...(Ut=(Ct=ee.parameters)==null?void 0:Ct.docs)==null?void 0:Ut.source}}};var xt,wt,It;te.parameters={...te.parameters,docs:{...(xt=te.parameters)==null?void 0:xt.docs,source:{originalSource:`args => {
|
|
105
|
+
const [_, updateArgs] = useArgs();
|
|
106
|
+
const handleChange = (evt: any) => {
|
|
107
|
+
updateArgs({
|
|
108
|
+
value: evt.target.value
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
112
|
+
}`,...(It=(wt=te.parameters)==null?void 0:wt.docs)==null?void 0:It.source}}};var Tt,kt,Vt;ne.parameters={...ne.parameters,docs:{...(Tt=ne.parameters)==null?void 0:Tt.docs,source:{originalSource:`args => {
|
|
113
|
+
const [_, updateArgs] = useArgs();
|
|
114
|
+
const handleChange = (evt: any) => {
|
|
115
|
+
updateArgs({
|
|
116
|
+
value: evt.target.value
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
120
|
+
}`,...(Vt=(kt=ne.parameters)==null?void 0:kt.docs)==null?void 0:Vt.source}}};var jt,St,Et;ae.parameters={...ae.parameters,docs:{...(jt=ae.parameters)==null?void 0:jt.docs,source:{originalSource:`args => {
|
|
121
|
+
const [_, updateArgs] = useArgs();
|
|
122
|
+
const handleChange = (evt: any) => {
|
|
123
|
+
updateArgs({
|
|
124
|
+
value: evt.target.value
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
128
|
+
}`,...(Et=(St=ae.parameters)==null?void 0:St.docs)==null?void 0:Et.source}}};var Nt,Dt,qt;R.parameters={...R.parameters,docs:{...(Nt=R.parameters)==null?void 0:Nt.docs,source:{originalSource:`(args: IUnitInputProps) => {
|
|
129
|
+
const [value, setValue] = useState('123|m');
|
|
130
|
+
const [value2, setValue2] = useState('223|m');
|
|
131
|
+
const [initUnit, setInitUnit] = useState('ft');
|
|
132
|
+
return <>
|
|
133
|
+
<Button label="Change initUnit" onClick={() => setInitUnit(initUnit === 'm' ? 'ft' : 'm')} />
|
|
134
|
+
<Spacer />
|
|
135
|
+
<Button label="Change value" onClick={() => setValue(value === '123|m' ? '456|m' : '123|m')} />
|
|
136
|
+
<Spacer />
|
|
137
|
+
<UnitInput name="example" onChange={evt => {
|
|
138
|
+
setValue(evt.target.value);
|
|
139
|
+
}} unitkey="length" value={value} initUnit={initUnit} onSwitchUnit={setInitUnit} />
|
|
140
|
+
<Spacer />
|
|
141
|
+
<UnitInput name="example2" onChange={evt => {
|
|
142
|
+
setValue2(evt.target.value);
|
|
143
|
+
}} unitkey="length" value={value2} initUnit={initUnit} onSwitchUnit={setInitUnit} />
|
|
144
|
+
<Divider />
|
|
145
|
+
<h4>Without initUnit property (taken from the redux store)</h4>
|
|
146
|
+
<UnitInput name="example" onChange={evt => {
|
|
147
|
+
setValue(evt.target.value);
|
|
148
|
+
}} unitkey="length" value={value} onSwitchUnit={setInitUnit} />
|
|
149
|
+
<UnitInput name="example2" onChange={evt => {
|
|
150
|
+
setValue2(evt.target.value);
|
|
151
|
+
}} unitkey="length" value={value2} onSwitchUnit={setInitUnit} />
|
|
152
|
+
</>;
|
|
153
|
+
}`,...(qt=(Dt=R.parameters)==null?void 0:Dt.docs)==null?void 0:qt.source}}};var At,Bt,Ft;ie.parameters={...ie.parameters,docs:{...(At=ie.parameters)==null?void 0:At.docs,source:{originalSource:`args => {
|
|
154
|
+
const [_, updateArgs] = useArgs();
|
|
155
|
+
const handleChange = (evt: any) => {
|
|
156
|
+
updateArgs({
|
|
157
|
+
value: evt.target.value
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
161
|
+
}`,...(Ft=(Bt=ie.parameters)==null?void 0:Bt.docs)==null?void 0:Ft.source}}};var Pt,_t,Rt;M.parameters={...M.parameters,docs:{...(Pt=M.parameters)==null?void 0:Pt.docs,source:{originalSource:`() => {
|
|
162
|
+
const width = '500px';
|
|
163
|
+
const [value, setValue] = useState<any>(undefined);
|
|
164
|
+
return <>
|
|
165
|
+
<h4>Different edge cases such as +/- infinity, undefined, NaN, null:</h4>
|
|
166
|
+
<Row>
|
|
167
|
+
<Column width="25%">
|
|
168
|
+
<Button label="Change value infinity" onClick={() => setValue(Infinity)} />
|
|
169
|
+
<br />
|
|
170
|
+
<Button label="Change value -infinity" onClick={() => setValue(-Infinity)} />
|
|
171
|
+
<br />
|
|
172
|
+
<Button label="Change value null" onClick={() => setValue(null)} />
|
|
173
|
+
<br />
|
|
174
|
+
<Button label="Change value - undefined" onClick={() => setValue(undefined)} />
|
|
175
|
+
<br />
|
|
176
|
+
<Button label="Change value - NaN" onClick={() => setValue(NaN)} />
|
|
177
|
+
<br />
|
|
178
|
+
<Button label="Change value - nothing (empty)" onClick={() => setValue(undefined)} />
|
|
179
|
+
<br />
|
|
180
|
+
<Button label="Change value - empty string" onClick={() => setValue('')} />
|
|
181
|
+
</Column>
|
|
182
|
+
<Column width="25%">
|
|
183
|
+
<Button label="Change value infinity|m" onClick={() => setValue(Infinity + '|m')} />
|
|
184
|
+
<br />
|
|
185
|
+
<Button label="Change value -infinity|m" onClick={() => setValue(-Infinity + '|m')} />
|
|
186
|
+
<br />
|
|
187
|
+
<Button label="Change value null|m" onClick={() => setValue(null + '|m')} />
|
|
188
|
+
<br />
|
|
189
|
+
<Button label="Change value - undefined|m" onClick={() => setValue(undefined + '|m')} />
|
|
190
|
+
<br />
|
|
191
|
+
<Button label="Change value - NaN|m" onClick={() => setValue(NaN + '|m')} />
|
|
192
|
+
<br />
|
|
193
|
+
<Button label="Change value - nothing (empty)|m" onClick={() => setValue('|m')} />
|
|
194
|
+
</Column>
|
|
195
|
+
</Row>
|
|
196
|
+
<br />
|
|
197
|
+
<Field label="Normal PUI">
|
|
198
|
+
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="value|unit" />
|
|
199
|
+
</Field>
|
|
200
|
+
<Field label="Disabled validation">
|
|
201
|
+
<UnitInput name="example2" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" disabledValidation width={width} />
|
|
202
|
+
</Field>
|
|
203
|
+
<Field label="Disabled validation and manual error">
|
|
204
|
+
<UnitInput name="example3" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" error="test" disabledValidation width={width} />
|
|
205
|
+
</Field>
|
|
206
|
+
<Message message={{
|
|
207
|
+
heading: 'Current value inside PUI: ' + value,
|
|
208
|
+
visible: true
|
|
209
|
+
}} />
|
|
210
|
+
</>;
|
|
211
|
+
}`,...(Rt=(_t=M.parameters)==null?void 0:_t.docs)==null?void 0:Rt.source}}};var Mt,Ot,Wt;re.parameters={...re.parameters,docs:{...(Mt=re.parameters)==null?void 0:Mt.docs,source:{originalSource:`() => {
|
|
212
|
+
const width = '500px';
|
|
213
|
+
const [value, setValue] = useState<string>('1|m');
|
|
214
|
+
const [valueB, setValueB] = useState('|m');
|
|
215
|
+
const automaticValue = '123|km';
|
|
216
|
+
return <>
|
|
217
|
+
<h4>Different cases for automatic (placeholder) values:</h4>
|
|
218
|
+
<Row>
|
|
219
|
+
<Column width="25%">
|
|
220
|
+
<Button label="Change value to ''" onClick={() => setValue('')} />
|
|
221
|
+
<br />
|
|
222
|
+
<Button label="Change value to 1" onClick={() => setValue('1')} />
|
|
223
|
+
<br />
|
|
224
|
+
<Button label="Change value to 1|m" onClick={() => setValue('1|m')} />
|
|
225
|
+
<br />
|
|
226
|
+
<Button label="Change value to |m - empty value" onClick={() => setValue('|m')} />
|
|
227
|
+
</Column>
|
|
228
|
+
</Row>
|
|
229
|
+
<br />
|
|
230
|
+
<Field label="Normal PUI (placeholder + auto)">
|
|
231
|
+
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="value|unit" autoValue={automaticValue} />
|
|
232
|
+
</Field>
|
|
233
|
+
<Field label="Normal PUI (only auto)">
|
|
234
|
+
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} autoValue={automaticValue} />
|
|
235
|
+
</Field>
|
|
236
|
+
<Field label="Empty PUI with autoValue">
|
|
237
|
+
<UnitInput name="example1" onChange={evt => setValueB(evt.target.value)} value={valueB} unitkey="length" width={width} autoValue={automaticValue} />
|
|
238
|
+
</Field>
|
|
239
|
+
<Field label="Normal PUI (only placeholder)">
|
|
240
|
+
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="Placeholder test" />
|
|
241
|
+
</Field>
|
|
242
|
+
<Field label="Normal PUI (placeholder + allowEmpty)">
|
|
243
|
+
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="Placeholder test" allowEmpty />
|
|
244
|
+
</Field>
|
|
245
|
+
<Message message={{
|
|
246
|
+
heading: 'Current value inside PUI: ' + value,
|
|
247
|
+
visible: true
|
|
248
|
+
}} />
|
|
249
|
+
</>;
|
|
250
|
+
}`,...(Wt=(Ot=re.parameters)==null?void 0:Ot.docs)==null?void 0:Wt.source}}};var Lt,Ht,Gt;se.parameters={...se.parameters,docs:{...(Lt=se.parameters)==null?void 0:Lt.docs,source:{originalSource:`() => {
|
|
251
|
+
const [value, setValue] = useState('123|%');
|
|
252
|
+
const [validation, setValidation] = useState<string | null>(null);
|
|
253
|
+
const predictedMessage = 'This should be visible when an error appears';
|
|
254
|
+
const handleValidation = (name: string, error: string | null) => {
|
|
255
|
+
setValidation(error);
|
|
256
|
+
return {
|
|
257
|
+
name,
|
|
258
|
+
error
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
return <>
|
|
262
|
+
<h4>3rd party validation message when inputting invalid value:</h4>
|
|
263
|
+
<UnitInput name="example" onChange={evt => setValue(evt.target.value)} error={!validation || predictedMessage} validationCallback={handleValidation} value={value} />
|
|
264
|
+
<br />
|
|
265
|
+
<Spacer />
|
|
266
|
+
<h4>Original validation message: </h4>
|
|
267
|
+
<Message message={{
|
|
268
|
+
heading: validation,
|
|
269
|
+
visible: true
|
|
270
|
+
}} />
|
|
271
|
+
</>;
|
|
272
|
+
}`,...(Gt=(Ht=se.parameters)==null?void 0:Ht.docs)==null?void 0:Gt.source}}};var Kt,$t,zt;le.parameters={...le.parameters,docs:{...(Kt=le.parameters)==null?void 0:Kt.docs,source:{originalSource:`() => {
|
|
273
|
+
const [value, setValue] = useState('123|m');
|
|
274
|
+
const [placeholder, setPlaceholder] = useState('');
|
|
275
|
+
const [initUnit, setInitUnit] = useState('km');
|
|
276
|
+
const setPlaceholderValue = () => {
|
|
277
|
+
setInitUnit('ft');
|
|
278
|
+
setPlaceholder('placeholder');
|
|
279
|
+
setValue('|m');
|
|
280
|
+
};
|
|
281
|
+
return <>
|
|
282
|
+
<h4>Empty value case:</h4>
|
|
283
|
+
<UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} allowEmpty placeholder={placeholder} initUnit={initUnit} unitkey="length" />
|
|
284
|
+
<br />
|
|
285
|
+
<Spacer />
|
|
286
|
+
<Button label="Change value |m and unit ft" onClick={() => setPlaceholderValue()} />
|
|
287
|
+
</>;
|
|
288
|
+
}`,...(zt=($t=le.parameters)==null?void 0:$t.docs)==null?void 0:zt.source}}};var Jt,Yt,Zt;oe.parameters={...oe.parameters,docs:{...(Jt=oe.parameters)==null?void 0:Jt.docs,source:{originalSource:`() => {
|
|
289
|
+
const [value, setValue] = useState('123|m');
|
|
290
|
+
const [unit, setUnit] = useState('m');
|
|
291
|
+
return <>
|
|
292
|
+
<UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} initUnit={unit} unitkey="length" onSwitchUnit={setUnit} />
|
|
293
|
+
<Spacer />
|
|
294
|
+
<UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} initUnit={unit} unitkey="length" onSwitchUnit={setUnit} />
|
|
295
|
+
</>;
|
|
296
|
+
}`,...(Zt=(Yt=oe.parameters)==null?void 0:Yt.docs)==null?void 0:Zt.source}}};var Qt,Xt,en;ue.parameters={...ue.parameters,docs:{...(Qt=ue.parameters)==null?void 0:Qt.docs,source:{originalSource:`() => {
|
|
297
|
+
return <>
|
|
298
|
+
<Text faint>
|
|
299
|
+
Reproduce OW-10614 rounding noise bug when storing values in a different
|
|
300
|
+
unit to the display unit
|
|
301
|
+
</Text>
|
|
302
|
+
<Spacer />
|
|
303
|
+
<UnitInput name="example" onChange={() => {}} value={withUnit(convertAndGetValue('9750|psi', 'bar'), 'bar')} initUnit="psi" unitkey="pressure" unitTemplate={{
|
|
304
|
+
pressure: 'psi'
|
|
305
|
+
}} />
|
|
306
|
+
<Spacer />
|
|
307
|
+
<UnitInput name="example2" onChange={() => {}} value={withUnit(convertAndGetValue('8642|lbf', 'tonneForce'), 'tonneForce')} initUnit="lbf" unitkey="force" unitTemplate={{
|
|
308
|
+
force: 'tonneForce'
|
|
309
|
+
}} />
|
|
310
|
+
</>;
|
|
311
|
+
}`,...(en=(Xt=ue.parameters)==null?void 0:Xt.docs)==null?void 0:en.source}}};var tn,nn,an;de.parameters={...de.parameters,docs:{...(tn=de.parameters)==null?void 0:tn.docs,source:{originalSource:`() => {
|
|
312
|
+
const [preferredUnit, setPreferredUnit] = useState('psi');
|
|
313
|
+
const [enableDisplayRounding, setEnableDisplayRounding] = useState(false);
|
|
314
|
+
const [enableCosmeticRounding, setEnableCosmeticRounding] = useState(true);
|
|
315
|
+
const [value, setValue] = useState('672.2388357750001|bar');
|
|
316
|
+
const [callBackError, setCallBackError] = useState('');
|
|
317
|
+
return <Grid columns="1fr 1fr" gap>
|
|
318
|
+
<Card heading={<Heading>Settings</Heading>}>
|
|
319
|
+
<Field label="Enable display rounding:" labelLeft labelWidth={200}>
|
|
320
|
+
<Toggle checked={enableDisplayRounding} onChange={evt => setEnableDisplayRounding(evt.target.checked)} />
|
|
321
|
+
</Field>
|
|
322
|
+
<Field label="Enable cosmetic rounding:" labelLeft labelWidth={200}>
|
|
323
|
+
<Toggle checked={enableCosmeticRounding} onChange={evt => setEnableCosmeticRounding(evt.target.checked)} />
|
|
324
|
+
</Field>
|
|
325
|
+
</Card>
|
|
326
|
+
<Card heading={<Heading>NumberInput (displayed in Meters)</Heading>}>
|
|
327
|
+
<Text faint>
|
|
328
|
+
Cosmetic Rounding Test Case: type 9750 then return (compare with
|
|
329
|
+
enableCosmeticRounding on and off)
|
|
330
|
+
</Text>
|
|
331
|
+
<Spacer />
|
|
332
|
+
<Text warning>
|
|
333
|
+
Note: UnitInput uses convertSamePrecision internally (decision prior
|
|
334
|
+
to cosmetic value implementation). This means not all rounding noise
|
|
335
|
+
occurrences seen in NumberInput will be reproducible in UnitInput,
|
|
336
|
+
because they get rounded off by other logic.
|
|
337
|
+
</Text>
|
|
338
|
+
<Spacer />
|
|
339
|
+
<UnitInput name="Example" unitkey="pressure" initUnit={preferredUnit} unitTemplate={{
|
|
340
|
+
pressure: 'psi'
|
|
341
|
+
}} value={value} onChange={evt => {
|
|
342
|
+
const {
|
|
343
|
+
value
|
|
344
|
+
} = evt.target;
|
|
345
|
+
if (value) {
|
|
346
|
+
setValue(value);
|
|
347
|
+
}
|
|
348
|
+
}} enableDisplayRounding={enableDisplayRounding} enableCosmeticRounding={enableCosmeticRounding} error={convertAndGetValue(value, 'bar') >= 0 ? '' : 'Value must be positive'} validationCallback={(name, error) => {
|
|
349
|
+
setCallBackError(error ?? '');
|
|
350
|
+
}} convertBackToStorageUnit />
|
|
351
|
+
</Card>
|
|
352
|
+
<Card heading={<Heading>Unit Template</Heading>}>
|
|
353
|
+
<Select options={[{
|
|
354
|
+
label: 'Bar',
|
|
355
|
+
value: 'bar'
|
|
356
|
+
}, {
|
|
357
|
+
label: 'psi',
|
|
358
|
+
value: 'psi'
|
|
359
|
+
}]} value={preferredUnit} width={70} onChange={evt => setPreferredUnit(evt.target.value)} />
|
|
360
|
+
</Card>
|
|
361
|
+
<Card heading={<Heading>Test Validation Callback</Heading>}>
|
|
362
|
+
{callBackError && <Message message={{
|
|
363
|
+
content: callBackError,
|
|
364
|
+
icon: true,
|
|
365
|
+
type: 'Error',
|
|
366
|
+
visible: true
|
|
367
|
+
}} />}
|
|
368
|
+
</Card>
|
|
369
|
+
<Card heading={<Heading>Storage State / Redux (stored in Feet)</Heading>}>
|
|
370
|
+
{value}
|
|
371
|
+
<Spacer />
|
|
372
|
+
<Button label="Change value" onClick={() => setValue(withUnit(String(Math.floor(Math.random() * 100)), 'bar'))} />
|
|
373
|
+
</Card>
|
|
374
|
+
</Grid>;
|
|
375
|
+
}`,...(an=(nn=de.parameters)==null?void 0:nn.docs)==null?void 0:an.source}}};var rn,sn,ln;O.parameters={...O.parameters,docs:{...(rn=O.parameters)==null?void 0:rn.docs,source:{originalSource:`() => {
|
|
376
|
+
const [value, setValue] = useState('123|m');
|
|
377
|
+
return <UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} initUnit="m" unitkey="depth" unitTemplate={{
|
|
378
|
+
depth: 'm'
|
|
379
|
+
}} testId="testId" />;
|
|
380
|
+
}`,...(ln=(sn=O.parameters)==null?void 0:sn.docs)==null?void 0:ln.source}}};const Ha=["Default","InitUnit","notKnownUnit","Width","NoConversion","Small","Placeholder","Error","InternalValidationError","Disabled","DisabledNoConversion","DisabledUnitWithoutUnitKey","DisabledUnitWithUnitKey","DisabledWithEnabledUnitMenu","TestExternalStateChangeWithSynchronizedUnits","PredefinedOptionsMenu","TestEdgeCases","AutomaticValues","ValidationCallback","AllowEmptyPUI","onSwitchUnit","OW_10614TestCase","DemoCosmeticRounding","TestUserInput"];export{le as AllowEmptyPUI,re as AutomaticValues,he as Default,de as DemoCosmeticRounding,_ as Disabled,ee as DisabledNoConversion,ne as DisabledUnitWithUnitKey,te as DisabledUnitWithoutUnitKey,ae as DisabledWithEnabledUnitMenu,Q as Error,$ as InitUnit,X as InternalValidationError,Y as NoConversion,ue as OW_10614TestCase,P as Placeholder,ie as PredefinedOptionsMenu,Z as Small,M as TestEdgeCases,R as TestExternalStateChangeWithSynchronizedUnits,O as TestUserInput,se as ValidationCallback,J as Width,Ha as __namedExportsOrder,La as default,z as notKnownUnit,oe as onSwitchUnit};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import{j as i}from"./jsx-runtime-eps93zm2.js";import{r as v}from"./index-DhsZuJvc.js";import{f as J}from"./immer.esm-BwVl9PS2.js";import{d as C}from"./index-C0x1JmaP.js";import{G as ee}from"./grid-DRkC-bt8.js";import{S as te}from"./spacer-BWoNR27H.js";import{w as O,u as d,e as j,f as ne,a as ae}from"./index-DMAnyMX5.js";import{C as F}from"./card-EcjmryU9.js";import{F as k}from"./field-HrLaMLbx.js";import{H as _}from"./heading-CRNoBc7q.js";import{S as G}from"./select-DnRuRG_N.js";import{T as W}from"./toggle-BbFVf61v.js";import{l as ie}from"./lodash-c4VUpsOs.js";import{u as oe}from"./use-previous-D775JrO6.js";import{T as re,C as P}from"./table-CB6btQu9.js";import"./index-DRSy5Ssd.js";import"./styled-components.browser.esm-BQ9GQzDc.js";import"./index-CF7H4eMJ.js";import"./index-Bk2sglWO.js";import"./label-CqmyC9he.js";import"./common-types-Sih75Sav.js";import"./help-icon-Buhx5nl6.js";import"./tooltip-1V7clEnw.js";import"./index-CUZDtIZe.js";import"./icon-BSFY3vDO.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./inheritsLoose-DP0QEDDI.js";import"./index-CEuq6vkz.js";import"./disabled-context-rmpd7YJS.js";import"./types-Dx2TtIG9.js";import"./assertThisInitialized-B9jnkVVz.js";import"./memoize-one.esm-CcMeOnPo.js";import"./types-BmbYqTX_.js";import"./text-B3-TSWok.js";import"./actions-D-uVCDzk.js";import"./button-DHevvVBE.js";import"./spinner-AWUe4xwQ.js";import"./badge-CLQ59MDF.js";import"./select.input-D0UkAPd9.js";import"./index.es-DazXb-ul.js";import"./redux-tRgGMjwY.js";import"./objectSpread2-DW4nTBoq.js";import"./tiny-invariant-DqLgxztJ.js";import"./pagination-CLt-kUlx.js";import"./input-DTXbDJaL.js";import"./input-group-BaRSJAEN.js";import"./input-group-addon-D68iUKV2.js";import"./number-input-DBZIl9dz.js";import"./check-box-DPLaOkRR.js";import"./slider-C7vnj_3M.js";import"./index-BI4_Bp97.js";import"./popover-rq33c1W2.js";const le=o=>o.reduce(({preferredUnits:r,storageUnits:n},{unitKey:l,preferredUnit:e,storageUnit:h})=>(r[l]=e,n[l]=h,{preferredUnits:r,storageUnits:n}),{preferredUnits:{},storageUnits:{}}),se=({headers:o,rows:r,selectedUnits:n,storageUnits:l,onChangeUnit:e,convertBackToStorageUnit:h,enableCosmeticRounding:b,enableDisplayRounding:T})=>{const u=o?o.map(c=>({...c,cells:c.cells.map(p=>{var a;if(p.type===P.AUTO_UNIT){const{testId:S,unitKey:g}=p;return{value:n[g],type:P.SELECT,searchable:!1,options:(a=C.getUnitsForQuantity(g))==null?void 0:a.map(U=>({label:C.label(U),value:U})),native:p.native,onChange:U=>e({unitKey:g,value:U.target.value}),testId:S}}return p})})):[],s=r?r.map((c,p)=>({...c,cells:c.cells.map((a,S)=>{if("autoUnit"in a&&(a!=null&&a.autoUnit)&&(typeof(a==null?void 0:a.value)=="string"||typeof(a==null?void 0:a.value)=="number")){const{unitKey:g,value:U,formatDisplayValue:I}=a,V=T&&"roundDisplayValue"in a?a==null?void 0:a.roundDisplayValue:null,m=n[g],y=l[g],t=m!==y,f=t?C.convertAndGetValue(U,m,y):a.value,w=I?I(f):f;return{...a,value:w,enableCosmeticRounding:b&&t,enableDisplayRounding:T,roundDisplayValue:V,onChange:D=>{const{value:x}=D.target,R=l[g],E=n[g],N=E!==R,H=h?R:E,K=N?C.convertAndGetValue(x,H,E):x;if("onChange"in a){const{onChange:B}=a,Z={...D,target:{...D.target,value:String(K),rowIndex:p,cellIndex:S,unit:H}};B(Z)}}}}return a})})):[];return{convertedHeaders:u,convertedRows:s}},X=({table:o,unitConfig:r,convertBackToStorageUnit:n=!0,enableCosmeticRounding:l=!0,enableDisplayRounding:e=!0})=>{const{rows:h,headers:b,...T}=o,{storageUnits:u,preferredUnits:s}=le(r),c=oe(s),[p,a]=v.useState(s),S=({unitKey:m,value:y})=>{a({...p,[m]:y});const t=r.find(f=>f.unitKey===m);t&&typeof t.onChange=="function"&&t.onChange({oldUnit:p[m],newUnit:y,unitKey:m})},g=m=>se({headers:b,rows:h,selectedUnits:m,storageUnits:u,onChangeUnit:S,convertBackToStorageUnit:n,enableCosmeticRounding:l,enableDisplayRounding:e}),U=g(p),[I,V]=v.useState(U);return v.useEffect(()=>{!ie.isEqual(s,c)&&(Object.keys(s).forEach(y=>{const t=c==null?void 0:c[y],f=s[y];t!==f&&S({unitKey:y,value:f})}),V(g(s)))},[r]),v.useEffect(()=>{V(g(p))},[o,p]),i.jsx(re,{table:{...T,headers:I.convertedHeaders,rows:I.convertedRows}})};X.__docgenInfo={description:"",methods:[],displayName:"UnitTable",props:{table:{required:!0,tsType:{name:"IUnitTable"},description:""},unitConfig:{required:!0,tsType:{name:"Array",elements:[{name:"IUnitConfigItem"}],raw:"IUnitConfigItem[]"},description:""},convertBackToStorageUnit:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},enableCosmeticRounding:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},enableDisplayRounding:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}}},composes:["Omit"]};const bt={title:"Basic/UnitTable",args:{}},ue=!0,ce=!0,de=!0,pe=!1,A="ft",Y="C",ge=3,me=(o,r,n)=>{const l=[r,r,n],e=[...Array(o)].map((h,b)=>{const T=b,u=b+1.25,s=4+b*.25;return[String(T),String(u),String(s)]});return[l,...e]},he=me(ge,A,Y),be=({reduxTable:o,value:r,unit:n,rowIndex:l,cellIndex:e})=>J(o,h=>{const b=h[0][e],T=(u,s)=>s===0;return h.forEach((u,s)=>{if(T(u,s)){u[e]=n;return}if(s===l+1){u[e]=String(r);return}const c=C.convertAndGetValue(u[e],n,b);u[e]=String(c)}),h}),ye=({reduxTable:o,value:r,rowIndex:n,cellIndex:l})=>J(o,e=>{e[n+1][l]=r}),L=()=>{var m,y;const[o,r]=v.useState(A),[n,l]=v.useState(Y),[e,h]=v.useState(he),[b,T]=v.useState(ue),[u,s]=v.useState(de),[c,p]=v.useState(ce),[a,S]=v.useState(pe),[g,U]=v.useState(A),I=t=>{const{rowIndex:f,cellIndex:w,value:D,unit:x}=t.target,R=a?be({reduxTable:e,value:D,unit:x,rowIndex:f,cellIndex:w}):ye({reduxTable:e,value:D,rowIndex:f,cellIndex:w});h(R)},V=e.reduce((t,f,w)=>(w===0?t.headers=[{cells:[{value:"From"},{value:"To"},{value:"Temperature"}]},{cells:[{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"temperature",testId:"table-unit-selector-3"}]}]:t.rows=t.rows.concat({cells:f.map((D,x)=>{const R=w===1&&x===1;return{value:D,type:R?"Text":"NumberInput",unitKey:x===2?"temperature":"length",onChange:I,roundDisplayValue:w===3&&x===2?B=>C.roundByMagnitude(B,2):null,formatDisplayValue:R?B=>`T* ${B}`:null,autoUnit:!0,testId:`testId_${w}_${x}`}})}),t),{testId:"testId",headers:[],rows:[]});return i.jsxs(ee,{columns:"1fr 1fr",gap:!0,children:[i.jsxs(F,{heading:i.jsx(_,{children:"Settings"}),children:[i.jsx(k,{label:"Convert back to storage unit:",labelLeft:!0,labelWidth:200,children:i.jsx(W,{checked:b,onChange:t=>T(t.target.checked)})}),i.jsx(k,{label:"Enable display rounding:",labelLeft:!0,labelWidth:200,children:i.jsx(W,{checked:u,onChange:t=>s(t.target.checked)})}),i.jsx(k,{label:"Enable cosmetic rounding:",labelLeft:!0,labelWidth:200,children:i.jsx(W,{checked:c,onChange:t=>p(t.target.checked)})}),i.jsx(k,{label:"Convert whole table:",labelLeft:!0,labelWidth:200,children:i.jsx(W,{checked:a,onChange:t=>S(t.target.checked)})})]}),i.jsxs(F,{heading:i.jsx(_,{children:"Unit template"}),children:[i.jsx(k,{label:"Length unit:",labelLeft:!0,labelWidth:120,children:i.jsx(G,{options:(m=C.getUnitsForQuantity("length"))==null?void 0:m.map(t=>({value:t,label:C.label(t)})),value:{value:o},onChange:t=>r(t.target.value),width:"100px"})}),i.jsx(k,{label:"Temperature unit:",labelLeft:!0,labelWidth:120,children:i.jsx(G,{options:(y=C.getUnitsForQuantity("temperature"))==null?void 0:y.map(t=>({value:t,label:C.label(t)})),value:{value:n},onChange:t=>l(t.target.value),width:"100px"})})]}),i.jsx(F,{heading:i.jsx(_,{children:"Storage State (Redux)"}),children:i.jsx("pre",{children:i.jsx("code",{children:JSON.stringify(e,null,2)})})}),i.jsxs(F,{heading:i.jsx(_,{children:"UnitTable"}),children:[i.jsx(X,{table:V,unitConfig:[{unitKey:"length",storageUnit:e[0][0],preferredUnit:o,onChange:({newUnit:t})=>U(t)},{unitKey:"temperature",storageUnit:e[0][2],preferredUnit:n}],convertBackToStorageUnit:b,enableDisplayRounding:u,enableCosmeticRounding:c}),i.jsx(te,{height:20}),i.jsx(k,{label:"Displayed length unit:",labelLeft:!0,labelWidth:150,children:g})]})]})};L.play=async({canvasElement:o,step:r})=>{const n=O(o),l=O(o.ownerDocument.body);await r("Can enter decimal values",async()=>{const e=n.getByTestId("testId_2_1");await d.clear(e),await d.type(e,"123.123456789"),await d.click(o),await j(n.getByDisplayValue("123.12")).toBeInTheDocument()}),await r("Can enter comma decimals (converts to dot)",async()=>{const e=n.getByTestId("testId_2_1");await d.clear(e),await d.type(e,"123,456"),await d.click(o),await j(n.getByDisplayValue("123.46")).toBeInTheDocument()}),await r("Can enter small numbers",async()=>{const e=n.getByTestId("testId_2_1");await d.clear(e),await d.type(e,"0.0000000023"),await d.click(o),await j(e).toHaveDisplayValue("0.00")}),await r("Can enter large numbers",async()=>{const e=n.getByTestId("testId_2_1");await d.clear(e),await d.type(e,"999999999999"),await d.click(o),await j(n.getByDisplayValue("999999999999.00")).toBeInTheDocument()}),await r("Shows validation error for non-numeric input",async()=>{const e=n.getByTestId("testId_2_1");await d.clear(e),await d.type(e,"123x45s6"),await d.click(o),await j(n.getByDisplayValue("123x45s6")).toBeInTheDocument(),await ne.mouseOver(e),await ae(()=>{j(l.getByText("Must be a numerical value")).toBeInTheDocument()})})};L.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"UnitTableExample"};var q,$,Q,M,z;L.parameters={...L.parameters,docs:{...(q=L.parameters)==null?void 0:q.docs,source:{originalSource:`() => {
|
|
2
|
+
const [preferredLengthUnit, setPreferredLengthUnit] = useState(initialLengthUnit);
|
|
3
|
+
const [preferredTemperatureUnit, setPreferredTemperatureUnit] = useState(initialTemperatureUnit);
|
|
4
|
+
const [reduxTable, setReduxTable] = useState<TTable>(initialTable);
|
|
5
|
+
const [convertBackToStorageUnit, setConvertBackToStorageUnit] = useState(initialConvertBackToStorageUnit);
|
|
6
|
+
const [enableDisplayRounding, setEnableDisplayRounding] = useState(initialEnableDisplayRounding);
|
|
7
|
+
const [enableCosmeticRounding, setEnableCosmeticRounding] = useState(initialEnableCosmeticRounding);
|
|
8
|
+
const [convertWholeTable, setConvertWholeTable] = useState(initialConvertWholeTable);
|
|
9
|
+
const [displayedLengthUnit, setDisplayedLengthUnit] = useState(initialLengthUnit);
|
|
10
|
+
|
|
11
|
+
/*********************************************************************************************************************
|
|
12
|
+
Cell onChange handler
|
|
13
|
+
*********************************************************************************************************************/
|
|
14
|
+
const onUpdateCell = (evt: IUnitTableOnChangeEvent) => {
|
|
15
|
+
const {
|
|
16
|
+
rowIndex,
|
|
17
|
+
cellIndex,
|
|
18
|
+
value,
|
|
19
|
+
unit
|
|
20
|
+
} = evt.target;
|
|
21
|
+
const nextTable = convertWholeTable ? convertStorageTable({
|
|
22
|
+
reduxTable,
|
|
23
|
+
value,
|
|
24
|
+
unit,
|
|
25
|
+
rowIndex,
|
|
26
|
+
cellIndex
|
|
27
|
+
}) : updateCell({
|
|
28
|
+
reduxTable,
|
|
29
|
+
value,
|
|
30
|
+
rowIndex,
|
|
31
|
+
cellIndex
|
|
32
|
+
});
|
|
33
|
+
setReduxTable(nextTable);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/*********************************************************************************************************************
|
|
37
|
+
Construct table view data (same as old Table component, with a new props)
|
|
38
|
+
*********************************************************************************************************************/
|
|
39
|
+
const tableViewData = reduxTable.reduce((acc, row, rowIndex) => {
|
|
40
|
+
if (rowIndex === 0) {
|
|
41
|
+
acc.headers = [{
|
|
42
|
+
cells: [{
|
|
43
|
+
value: 'From'
|
|
44
|
+
}, {
|
|
45
|
+
value: 'To'
|
|
46
|
+
}, {
|
|
47
|
+
value: 'Temperature'
|
|
48
|
+
}]
|
|
49
|
+
}, {
|
|
50
|
+
cells: [{
|
|
51
|
+
type: 'AutoUnit',
|
|
52
|
+
unitKey: 'length'
|
|
53
|
+
}, {
|
|
54
|
+
type: 'AutoUnit',
|
|
55
|
+
unitKey: 'length'
|
|
56
|
+
}, {
|
|
57
|
+
type: 'AutoUnit',
|
|
58
|
+
unitKey: 'temperature',
|
|
59
|
+
testId: 'table-unit-selector-3'
|
|
60
|
+
}]
|
|
61
|
+
}];
|
|
62
|
+
} else {
|
|
63
|
+
acc.rows = acc.rows.concat({
|
|
64
|
+
cells: row.map((cell, cellIndex) => {
|
|
65
|
+
const specialCell = rowIndex === 1 && cellIndex === 1;
|
|
66
|
+
const type = specialCell ? 'Text' : 'NumberInput';
|
|
67
|
+
const formatDisplayValue = specialCell ? (value: number | string) => \`T* \${value}\` : null;
|
|
68
|
+
const customDisplayRounding = rowIndex === 3 && cellIndex === 2 ? (value: TStringNumberNull) => roundByMagnitude(value, 2) : null;
|
|
69
|
+
const value = cell;
|
|
70
|
+
return {
|
|
71
|
+
value,
|
|
72
|
+
type,
|
|
73
|
+
unitKey: cellIndex === 2 ? 'temperature' : 'length',
|
|
74
|
+
onChange: onUpdateCell,
|
|
75
|
+
roundDisplayValue: customDisplayRounding,
|
|
76
|
+
// optionally customize the display rounding of specific columns/cells
|
|
77
|
+
formatDisplayValue,
|
|
78
|
+
// optionally extend/customize the display formatting of specific columns/cells
|
|
79
|
+
autoUnit: true,
|
|
80
|
+
testId: \`testId_\${rowIndex}_\${cellIndex}\`
|
|
81
|
+
};
|
|
82
|
+
})
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return acc;
|
|
86
|
+
}, {
|
|
87
|
+
testId: 'testId',
|
|
88
|
+
headers: ([] as any[]),
|
|
89
|
+
rows: ([] as IUnitTableRow[])
|
|
90
|
+
});
|
|
91
|
+
return <Grid columns="1fr 1fr" gap>
|
|
92
|
+
<Card heading={<Heading>Settings</Heading>}>
|
|
93
|
+
<Field label="Convert back to storage unit:" labelLeft labelWidth={200}>
|
|
94
|
+
<Toggle checked={convertBackToStorageUnit} onChange={evt => setConvertBackToStorageUnit(evt.target.checked)} />
|
|
95
|
+
</Field>
|
|
96
|
+
<Field label="Enable display rounding:" labelLeft labelWidth={200}>
|
|
97
|
+
<Toggle checked={enableDisplayRounding} onChange={evt => setEnableDisplayRounding(evt.target.checked)} />
|
|
98
|
+
</Field>
|
|
99
|
+
<Field label="Enable cosmetic rounding:" labelLeft labelWidth={200}>
|
|
100
|
+
<Toggle checked={enableCosmeticRounding} onChange={evt => setEnableCosmeticRounding(evt.target.checked)} />
|
|
101
|
+
</Field>
|
|
102
|
+
<Field label="Convert whole table:" labelLeft labelWidth={200}>
|
|
103
|
+
<Toggle checked={convertWholeTable} onChange={evt => setConvertWholeTable(evt.target.checked)} />
|
|
104
|
+
</Field>
|
|
105
|
+
</Card>
|
|
106
|
+
<Card heading={<Heading>Unit template</Heading>}>
|
|
107
|
+
<Field label="Length unit:" labelLeft labelWidth={120}>
|
|
108
|
+
<Select options={getUnitsForQuantity('length')?.map(unit => ({
|
|
109
|
+
value: unit,
|
|
110
|
+
label: label(unit)
|
|
111
|
+
}))} value={{
|
|
112
|
+
value: preferredLengthUnit
|
|
113
|
+
}} onChange={evt => setPreferredLengthUnit(evt.target.value)} width="100px" />
|
|
114
|
+
</Field>
|
|
115
|
+
<Field label="Temperature unit:" labelLeft labelWidth={120}>
|
|
116
|
+
<Select options={getUnitsForQuantity('temperature')?.map(unit => ({
|
|
117
|
+
value: unit,
|
|
118
|
+
label: label(unit)
|
|
119
|
+
}))} value={{
|
|
120
|
+
value: preferredTemperatureUnit
|
|
121
|
+
}} onChange={evt => setPreferredTemperatureUnit(evt.target.value)} width="100px" />
|
|
122
|
+
</Field>
|
|
123
|
+
</Card>
|
|
124
|
+
<Card heading={<Heading>Storage State (Redux)</Heading>}>
|
|
125
|
+
<pre>
|
|
126
|
+
<code>{JSON.stringify(reduxTable, null, 2)}</code>
|
|
127
|
+
</pre>
|
|
128
|
+
</Card>
|
|
129
|
+
<Card heading={<Heading>UnitTable</Heading>}>
|
|
130
|
+
<UnitTable table={tableViewData}
|
|
131
|
+
//New props:
|
|
132
|
+
unitConfig={[{
|
|
133
|
+
unitKey: 'length',
|
|
134
|
+
storageUnit: reduxTable[0][0],
|
|
135
|
+
preferredUnit: preferredLengthUnit,
|
|
136
|
+
onChange: ({
|
|
137
|
+
newUnit
|
|
138
|
+
}) => setDisplayedLengthUnit(newUnit)
|
|
139
|
+
}, {
|
|
140
|
+
unitKey: 'temperature',
|
|
141
|
+
storageUnit: reduxTable[0][2],
|
|
142
|
+
preferredUnit: preferredTemperatureUnit
|
|
143
|
+
}]}
|
|
144
|
+
//Most tables should just use the default values here (true):
|
|
145
|
+
convertBackToStorageUnit={convertBackToStorageUnit} enableDisplayRounding={enableDisplayRounding} enableCosmeticRounding={enableCosmeticRounding} />
|
|
146
|
+
<Spacer height={20} />
|
|
147
|
+
<Field label="Displayed length unit:" labelLeft labelWidth={150}>
|
|
148
|
+
{displayedLengthUnit}
|
|
149
|
+
</Field>
|
|
150
|
+
</Card>
|
|
151
|
+
</Grid>;
|
|
152
|
+
}`,...(Q=($=L.parameters)==null?void 0:$.docs)==null?void 0:Q.source},description:{story:"Story",...(z=(M=L.parameters)==null?void 0:M.docs)==null?void 0:z.description}}};const yt=["UnitTableExample"];export{L as UnitTableExample,yt as __namedExportsOrder,bt as default};
|