@oliasoft-open-source/react-ui-library 4.9.0-beta-1 → 4.9.0-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.
Files changed (35) hide show
  1. package/dist/index.js +14 -19
  2. package/dist/index.js.map +1 -1
  3. package/dist/storybook/assets/{Color-KGDBMAHA-nHvSq78M.js → Color-KGDBMAHA-CHN1S2X8.js} +1 -1
  4. package/dist/storybook/assets/{DocsRenderer-PKQXORMH-C1krXrOf.js → DocsRenderer-PKQXORMH-DmD_BuR8.js} +1 -1
  5. package/dist/storybook/assets/{accordion.stories-kLk1OtZZ.js → accordion.stories-BtQXhKld.js} +1 -1
  6. package/dist/storybook/assets/{buttons-and-links-DC-E4soa.js → buttons-and-links-CofJkf3B.js} +1 -1
  7. package/dist/storybook/assets/{casing-loads.stories-B2lND_PU.js → casing-loads.stories-1KCWDoR3.js} +1 -1
  8. package/dist/storybook/assets/{cell.stories-BVDrv2SU.js → cell.stories-CBq3IOiP.js} +1 -1
  9. package/dist/storybook/assets/{chunk-HLWAVYOI-DX3eyNf5.js → chunk-HLWAVYOI-D6plKxhM.js} +1 -1
  10. package/dist/storybook/assets/{color-BgW0SkoL.js → color-Cm8Vinoa.js} +1 -1
  11. package/dist/storybook/assets/{footer.stories-BVXSVjq1.js → footer.stories-D-rIL9Q8.js} +1 -1
  12. package/dist/storybook/assets/{formation.stories-DmecxRaM.js → formation.stories-ByGQlyM6.js} +1 -1
  13. package/dist/storybook/assets/{iframe-DHWiHrZY.js → iframe-Z2m5WTzB.js} +2 -2
  14. package/dist/storybook/assets/{index-B7q2KU2k.js → index-BDuzEdVP.js} +1 -1
  15. package/dist/storybook/assets/{index-BRAKCNI8.js → index-Cq__GtHn.js} +4 -4
  16. package/dist/storybook/assets/{input-validation-CD_0XD31.js → input-validation-ZIuVwPoa.js} +1 -1
  17. package/dist/storybook/assets/{inputs-DmKjdzn7.js → inputs-CNXjhlBh.js} +1 -1
  18. package/dist/storybook/assets/{layout-forms-BxdMnma9.js → layout-forms-C-SoBg1o.js} +1 -1
  19. package/dist/storybook/assets/{layout-general-DTuKIl0f.js → layout-general-Clz5Yc1Q.js} +1 -1
  20. package/dist/storybook/assets/number-input-F3bqJ0z5.js +16 -0
  21. package/dist/storybook/assets/number-input.stories-Dw2eW2Mc.js +166 -0
  22. package/dist/storybook/assets/{padding-and-spacing-pWMUN6u_.js → padding-and-spacing-BmsvMp30.js} +1 -1
  23. package/dist/storybook/assets/{preview-BCA8OXOK.js → preview-D7bLtJOF.js} +1 -1
  24. package/dist/storybook/assets/{preview-Ddw3AHiS.js → preview-PrNfVOD8.js} +2 -2
  25. package/dist/storybook/assets/{row.stories-BO2s7oph.js → row.stories-ghcsAzwW.js} +1 -1
  26. package/dist/storybook/assets/{table-CB6btQu9.js → table-BCdvBxub.js} +1 -1
  27. package/dist/storybook/assets/{table.stories-CvHvaYMC.js → table.stories-DkmbUVHr.js} +1 -1
  28. package/dist/storybook/assets/{title.stories-DYXG2_x-.js → title.stories-DpFDK9o1.js} +1 -1
  29. package/dist/storybook/assets/{unit-input.stories-DRP-nDdh.js → unit-input.stories-D7vlYO8f.js} +2 -2
  30. package/dist/storybook/assets/{unit-table.stories-DiER-CMn.js → unit-table.stories-u1PeEt0F.js} +1 -1
  31. package/dist/storybook/iframe.html +1 -1
  32. package/dist/storybook/project.json +1 -1
  33. package/package.json +1 -1
  34. package/dist/storybook/assets/number-input-DBZIl9dz.js +0 -16
  35. package/dist/storybook/assets/number-input.stories-BRQWeYF6.js +0 -166
@@ -1,4 +1,4 @@
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> & {
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-F3bqJ0z5.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=!1,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
2
  target:
3
3
  | T
4
4
  | { name: string; value: any; label?: string; files?: FileList | null };
@@ -7,7 +7,7 @@ import{j as e}from"./jsx-runtime-eps93zm2.js";import{r as u}from"./index-DhsZuJv
7
7
  | T
8
8
  | { name: string; value: any; label?: string; files?: FileList | null };
9
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> & {
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:"false",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
11
  target:
12
12
  | T
13
13
  | { name: string; value: any; label?: string; files?: FileList | null };
@@ -1,4 +1,4 @@
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:`() => {
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-BCdvBxub.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-F3bqJ0z5.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
2
  const [preferredLengthUnit, setPreferredLengthUnit] = useState(initialLengthUnit);
3
3
  const [preferredTemperatureUnit, setPreferredTemperatureUnit] = useState(initialTemperatureUnit);
4
4
  const [reduxTable, setReduxTable] = useState<TTable>(initialTable);
@@ -509,7 +509,7 @@
509
509
  }
510
510
  </script>
511
511
 
512
- <script type="module" crossorigin src="./assets/iframe-DHWiHrZY.js"></script>
512
+ <script type="module" crossorigin src="./assets/iframe-Z2m5WTzB.js"></script>
513
513
  </head>
514
514
 
515
515
  <body>
@@ -1 +1 @@
1
- {"generatedAt":1722531189442,"hasCustomBabel":false,"hasCustomWebpack":false,"hasStaticDirs":false,"hasStorybookEslint":true,"refCount":0,"testPackages":{"@types/jest":"29.5.12","@vitest/coverage-c8":"0.31.4","eslint-plugin-vitest":null,"eslint-plugin-vitest-globals":"1.5.0","vitest":"1.6.0"},"packageManager":{"type":"yarn","version":"1.22.19"},"typescriptOptions":{"reactDocgen":"react-docgen"},"preview":{"usesGlobals":false},"framework":{"name":"@storybook/react-vite","options":{}},"builder":"@storybook/builder-vite","renderer":"@storybook/react","storybookVersion":"8.2.7","storybookVersionSpecifier":"^8.2.4","language":"typescript","storybookPackages":{"@storybook/addon-essentials":{"version":"8.2.7"},"@storybook/addon-links":{"version":"8.2.7"},"@storybook/preview-api":{"version":"8.2.7"},"@storybook/react":{"version":"8.2.7"},"@storybook/react-vite":{"version":"8.2.7"},"@storybook/test":{"version":"8.2.7"},"@storybook/test-runner":{"version":"0.19.1"},"eslint-plugin-storybook":{"version":"0.6.15"},"storybook":{"version":"8.2.7"}},"addons":{"@storybook/addon-actions":{"version":"8.2.7"},"@storybook/addon-docs":{"version":"8.2.7"},"@storybook/addon-interactions":{"version":"8.2.7"},"storybook-dark-mode":{"version":"4.0.2"}}}
1
+ {"generatedAt":1722606322056,"hasCustomBabel":false,"hasCustomWebpack":false,"hasStaticDirs":false,"hasStorybookEslint":true,"refCount":0,"testPackages":{"@types/jest":"29.5.12","@vitest/coverage-c8":"0.31.4","eslint-plugin-vitest":null,"eslint-plugin-vitest-globals":"1.5.0","vitest":"1.6.0"},"packageManager":{"type":"yarn","version":"1.22.19"},"typescriptOptions":{"reactDocgen":"react-docgen"},"preview":{"usesGlobals":false},"framework":{"name":"@storybook/react-vite","options":{}},"builder":"@storybook/builder-vite","renderer":"@storybook/react","storybookVersion":"8.2.7","storybookVersionSpecifier":"^8.2.4","language":"typescript","storybookPackages":{"@storybook/addon-essentials":{"version":"8.2.7"},"@storybook/addon-links":{"version":"8.2.7"},"@storybook/preview-api":{"version":"8.2.7"},"@storybook/react":{"version":"8.2.7"},"@storybook/react-vite":{"version":"8.2.7"},"@storybook/test":{"version":"8.2.7"},"@storybook/test-runner":{"version":"0.19.1"},"eslint-plugin-storybook":{"version":"0.6.15"},"storybook":{"version":"8.2.7"}},"addons":{"@storybook/addon-actions":{"version":"8.2.7"},"@storybook/addon-docs":{"version":"8.2.7"},"@storybook/addon-interactions":{"version":"8.2.7"},"storybook-dark-mode":{"version":"4.0.2"}}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/react-ui-library",
3
- "version": "4.9.0-beta-1",
3
+ "version": "4.9.0-beta-3",
4
4
  "description": "Reusable UI components for React projects",
5
5
  "homepage": "https://oliasoft-open-source.gitlab.io/react-ui-library",
6
6
  "bugs": {
@@ -1,16 +0,0 @@
1
- import{j as I}from"./jsx-runtime-eps93zm2.js";import{r as a}from"./index-DhsZuJvc.js";import{d as r}from"./index-C0x1JmaP.js";import{K as Q,E as X}from"./select-DnRuRG_N.js";import{l as Y}from"./lodash-c4VUpsOs.js";import{I as $}from"./input-DTXbDJaL.js";const ee=14,ne=n=>r.isScientificStringNum(n)?n:r.roundToPrecision(n,ee),d=n=>String(r.toString(n)),te=n=>n?typeof n=="string"?n:Y.isArray(n)?n[0]:n.fieldName:"",ae=({name:n,placeholder:g="",disabled:h=!1,error:y=!1,left:S=!1,small:F=!1,width:C="100%",value:p="",onChange:L=()=>{},onFocus:R=()=>{},onBlur:k=()=>{},tabIndex:x=0,testId:j,tooltip:M=null,warning:H=!1,validationCallback:v=()=>{},allowEmpty:O=!1,isInTable:_,groupOrder:A,enableCosmeticRounding:T=!0,enableDisplayRounding:f=!1,roundDisplayValue:b,disableInternalErrorValidationMessages:K=!1})=>{const s=a.useRef(null),[i,E]=a.useState(d(p)),[l,w]=a.useState(!1),[P,q]=a.useState(!0),o=te(n),B=e=>{const t=r.validateNumber(e);return O&&e===""||t.valid?{...t,valid:!0,errors:void 0}:t},{valid:m,errors:c}=B(i),N=c&&c.length&&!K?c[0]:null;a.useEffect(()=>{E(d(p)),q(!0)},[p,T,f]),a.useEffect(()=>{!l&&!m?v(o,N):v(o,null)},[l,m,y]);const V=e=>{if(m&&!P){const t={...e,target:{...e.target,value:r.stripLeadingZeros(d(i)),name:o}};L(t)}},D=e=>{const t=e.target,{value:z}=t,J=r.cleanNumStr(z.replaceAll(" ","").replaceAll("|",""));E(J),q(!1)};a.useEffect(()=>{if(s&&(s!=null&&s.current)&&f&&l){const e=s.current;e&&setTimeout(()=>{const{length:t}=d(i);e.setSelectionRange(t,t)},0)}},[l]);const U=e=>{w(!0),R(e)},W=e=>{w(!1),V(e),k(e)},u=f&&!l&&m?b?d(b(i)):r.roundToFixed(i,2):i,Z=!!(u!=null&&u.endsWith("0")),G=T&&u&&!Z&&m?ne(u):u;return I.jsx(Q,{handleKeys:[X.ENTER],onKeyEvent:(e,t)=>V(t),children:I.jsx($,{type:"text",name:o,testId:j,disabled:h,placeholder:g,value:G,onChange:D,onFocus:U,onBlur:W,error:!l&&(N||y),warning:H,right:!S,small:F,width:C,isInTable:_,groupOrder:A,tabIndex:x,tooltip:M,ref:s},o)})};ae.__docgenInfo={description:"",methods:[],displayName:"NumberInput",props:{name:{required:!1,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:!0}}]}}]},description:""},placeholder:{required:!1,tsType:{name:"string"},description:"",defaultValue:{value:"''",computed:!1}},disabled:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},error:{required:!1,tsType:{name:"union",raw:"string | boolean",elements:[{name:"string"},{name:"boolean"}]},description:"",defaultValue:{value:"false",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:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},description:"",defaultValue:{value:"''",computed:!1}},onChange:{required:!1,tsType:{name:"signature",type:"function",raw:`(
2
- event: TChangeEvent<T>,
3
- ...additionalProps: { [key: string]: any }[]
4
- ) => void`,signature:{arguments:[{type:{name:"intersection",raw:`ChangeEvent<T> & {
5
- target:
6
- | T
7
- | { name: string; value: any; label?: string; files?: FileList | null };
8
- }`,elements:[{name:"ChangeEvent",elements:[{name:"T"}],raw:"ChangeEvent<T>"},{name:"signature",type:"object",raw:`{
9
- target:
10
- | T
11
- | { name: string; value: any; label?: string; files?: FileList | null };
12
- }`,signature:{properties:[{key:"target",value:{name:"union",raw:`| T
13
- | { 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:"event"},{type:{name:"Array",elements:[{name:"signature",type:"object",raw:"{ [key: string]: any }",signature:{properties:[{key:{name:"string"},value:{name:"any",required:!0}}]}}],raw:"{ [key: string]: any }[]"},name:"additionalProps",rest:!0}],return:{name:"void"}}},description:"",defaultValue:{value:"() => {}",computed:!1}},onFocus:{required:!1,tsType:{name:"signature",type:"function",raw:"(evt: FocusEvent<HTMLInputElement>) => void",signature:{arguments:[{type:{name:"FocusEvent",elements:[{name:"HTMLInputElement"}],raw:"FocusEvent<HTMLInputElement>"},name:"evt"}],return:{name:"void"}}},description:"",defaultValue:{value:"() => {}",computed:!1}},onBlur:{required:!1,tsType:{name:"signature",type:"function",raw:"(evt: FocusEvent<HTMLInputElement>) => void",signature:{arguments:[{type:{name:"FocusEvent",elements:[{name:"HTMLInputElement"}],raw:"FocusEvent<HTMLInputElement>"},name:"evt"}],return:{name:"void"}}},description:"",defaultValue:{value:"() => {}",computed:!1}},tabIndex:{required:!1,tsType:{name:"number"},description:"",defaultValue:{value:"0",computed:!1}},testId:{required:!1,tsType:{name:"string"},description:""},tooltip:{required:!1,tsType:{name:"union",raw:"TStringOrNumber | React.ReactNode",elements:[{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},{name:"ReactReactNode",raw:"React.ReactNode"}]},description:"",defaultValue:{value:"null",computed:!1}},warning:{required:!1,tsType:{name:"union",raw:"string | boolean",elements:[{name:"string"},{name:"boolean"}]},description:"",defaultValue:{value:"false",computed:!1}},validationCallback:{required:!1,tsType:{name:"signature",type:"function",raw:`(
14
- name: string | { fieldName: string },
15
- error: string | null,
16
- ) => void`,signature:{arguments:[{type:{name:"union",raw:"string | { fieldName: string }",elements:[{name:"string"},{name:"signature",type:"object",raw:"{ fieldName: string }",signature:{properties:[{key:"fieldName",value:{name:"string",required:!0}}]}}]},name:"name"},{type:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}]},name:"error"}],return:{name:"void"}}},description:"",defaultValue:{value:"() => {}",computed:!1}},allowEmpty:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},isInTable:{required:!1,tsType:{name:"boolean"},description:""},groupOrder:{required:!1,tsType:{name:"any"},description:""},enableCosmeticRounding:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},enableDisplayRounding:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},roundDisplayValue:{required:!1,tsType:{name:"signature",type:"function",raw:"(args: TStringOrNumber) => TStringOrNumber",signature:{arguments:[{type:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},name:"args"}],return:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]}}},description:""},disableInternalErrorValidationMessages:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}}}};export{ae as N,ne as r};
@@ -1,166 +0,0 @@
1
- import{j as r}from"./jsx-runtime-eps93zm2.js";import{r as c}from"./index-DhsZuJvc.js";import{w as d,u as t,e as o,f as j,a as _e}from"./index-DMAnyMX5.js";import{d as We}from"./index-C0x1JmaP.js";import{S as N}from"./spacer-BWoNR27H.js";import{G as He}from"./grid-DRkC-bt8.js";import{F as H}from"./field-HrLaMLbx.js";import{T as F}from"./toggle-BbFVf61v.js";import{I as Oe}from"./input-group-BaRSJAEN.js";import{I as Pe}from"./input-group-addon-D68iUKV2.js";import{S as Ue}from"./select-DnRuRG_N.js";import{C as g}from"./card-EcjmryU9.js";import{B as Fe}from"./button-DHevvVBE.js";import{H as m}from"./heading-CRNoBc7q.js";import{T as qe}from"./text-B3-TSWok.js";import{M as Ke}from"./message-Y48EomV-.js";import{N as i}from"./number-input-DBZIl9dz.js";import"./index-CF7H4eMJ.js";import"./index-DRSy5Ssd.js";import"./styled-components.browser.esm-BQ9GQzDc.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"./lodash-c4VUpsOs.js";import"./types-Dx2TtIG9.js";import"./assertThisInitialized-B9jnkVVz.js";import"./memoize-one.esm-CcMeOnPo.js";import"./types-BmbYqTX_.js";import"./actions-D-uVCDzk.js";import"./badge-CLQ59MDF.js";import"./select.input-D0UkAPd9.js";import"./spinner-AWUe4xwQ.js";import"./input-DTXbDJaL.js";const{useArgs:Ye}=__STORYBOOK_MODULE_PREVIEW_API__,Ma={title:"Forms/NumberInput",component:i,parameters:{canvas:{page:null}},args:{label:"Label"}},l=n=>{const[s,a]=Ye(),u=e=>{a({value:e.target.value})};return r.jsx(i,{onChange:u,value:123,...n})},A=l.bind({}),b=l.bind({});b.args={small:!0};const C=l.bind({});C.args={width:"150px"};const w=l.bind({});w.args={left:!0};const T=l.bind({});T.args={disabled:!0};const f=l.bind({});f.args={allowEmpty:!0,value:""};const h=()=>{const[n,s]=c.useState("123|m");return r.jsx(i,{name:"example",onChange:a=>s(a.target.value),placeholder:"Type a value...",value:n,testId:"testId"})};h.play=async({canvasElement:n,step:s})=>{const a=d(n),u=d(n.ownerDocument.body);await s("Shows validation error for non-numeric input",async()=>{const e=a.getByTestId("testId");await t.clear(e),await t.type(e,"123x45s6"),await t.click(n),await o(a.getByDisplayValue("123x45s6")).toBeInTheDocument(),await j.mouseOver(e),await _e(()=>{o(u.getByText("Must be a numerical value")).toBeInTheDocument()})})};const x=l.bind({});x.args={warning:"This input number is almost 100!",value:"99"};const B=l.bind({});B.args={error:"This is a error message"};const D=l.bind({});D.args={value:"123test"};const S=l.bind({});S.args={value:"123.123456789",enableDisplayRounding:!0};const E=l.bind({});E.args={value:"123.123456789",enableDisplayRounding:!0,roundDisplayValue:n=>We.roundToFixed(n,4)};const V=()=>r.jsxs(Oe,{small:!0,children:[r.jsx(i,{value:123}),r.jsx(Pe,{children:"to"}),r.jsx(i,{value:123}),r.jsx(Ue,{options:[{value:"units",label:"units"}],width:"auto",value:"units"})]}),v=()=>{const[n,s]=c.useState("123");return r.jsx(i,{value:n,onChange:a=>{s(a.target.value)},testId:"testId",enableDisplayRounding:!0})};v.play=async({canvasElement:n,step:s})=>{const a=d(n);await s("Value should be rounded on blur",async()=>{const u=a.getByTestId("testId");await t.clear(u),await t.type(u,"123.123456789"),await t.click(n),await o(a.getByDisplayValue("123.12")).toBeInTheDocument()}),await s("Full value shown on focus",async()=>{const u=a.getByTestId("testId");await t.click(u),await o(a.getByDisplayValue("123.123456789")).toBeInTheDocument()})};const k=()=>{const[n,s]=c.useState("123");return r.jsxs(He,{columns:"1fr 1fr",gap:!0,children:[r.jsxs(g,{heading:r.jsx(m,{children:"Storage State (Redux)"}),children:[n,r.jsx(N,{}),r.jsx(Fe,{label:"Change value",onClick:()=>s(String(Math.floor(Math.random()*100)))})]}),r.jsx(g,{heading:r.jsx(m,{children:"NumberInput"}),children:r.jsx(i,{value:n,onChange:a=>{s(a.target.value)},error:Number(n)>=0?"":"Value must be positive"})})]})},y=()=>{const[n,s]=c.useState(!1),[a,u]=c.useState(!0),[e,M]=c.useState("0.6889763779527558"),[_,Le]=c.useState(""),Ge=Number(e)*.3048;return r.jsxs(He,{columns:"1fr 1fr",gap:!0,children:[r.jsxs(g,{heading:r.jsx(m,{children:"Settings"}),children:[r.jsx(H,{label:"Enable display rounding:",labelLeft:!0,labelWidth:200,children:r.jsx(F,{checked:n,onChange:p=>s(p.target.checked)})}),r.jsx(H,{label:"Enable cosmetic rounding:",labelLeft:!0,labelWidth:200,children:r.jsx(F,{checked:a,onChange:p=>u(p.target.checked)})})]}),r.jsxs(g,{heading:r.jsx(m,{children:"NumberInput (displayed in Meters)"}),children:[r.jsx(qe,{faint:!0,children:"Cosmetic Rounding Test Cases: type 0.21 then return (compare with enableCosmeticRounding on and off)"}),r.jsx(N,{}),r.jsx(i,{name:"Example",value:Ge,onChange:p=>{const R=String(Number(p.target.value)/.3048);M(R)},enableDisplayRounding:n,enableCosmeticRounding:a,error:Number(e)>=0?"":"Value must be positive",validationCallback:(p,R)=>{Le(R??"")},testId:"testId"})]}),r.jsxs(g,{heading:r.jsx(m,{children:"Storage State / Redux (stored in Feet)"}),children:[e,r.jsx(N,{}),r.jsx(Fe,{label:"Change value",onClick:()=>M(String(Math.floor(Math.random()*100)))})]}),r.jsx(g,{heading:r.jsx(m,{children:"Test Validation Callback"}),children:_&&r.jsx(Ke,{message:{content:_,icon:!0,type:"Error",visible:!0}})})]})};y.play=async({canvasElement:n,step:s})=>{const a=d(n),u=d(n.ownerDocument.body);await s("Can enter decimal values",async()=>{const e=a.getByTestId("testId");await t.clear(e),await t.type(e,"123.123456789"),await t.click(n),await o(a.getByDisplayValue("123.123456789")).toBeInTheDocument()}),await s("Cannot enter scientific notation when storage unit is different (expected)",async()=>{const e=a.getByTestId("testId");await t.clear(e),await t.type(e,"-1.12e3"),await t.click(n),await o(a.getByDisplayValue("-1120")).toBeInTheDocument()}),await s("Can enter comma decimals (converts to dot)",async()=>{const e=a.getByTestId("testId");await t.clear(e),await t.type(e,"123,456"),await t.click(n),await o(a.getByDisplayValue("123.456")).toBeInTheDocument()}),await s("Can enter small numbers",async()=>{const e=a.getByTestId("testId");await t.clear(e),await t.type(e,"0.0000000023"),await t.click(n),await o(a.getByDisplayValue("0.0000000023")).toBeInTheDocument()}),await s("Can enter large numbers",async()=>{const e=a.getByTestId("testId");await t.clear(e),await t.type(e,"999999999999"),await t.click(n),await o(a.getByDisplayValue("999999999999")).toBeInTheDocument()}),await s("Shows validation error for non-numeric input",async()=>{const e=a.getByTestId("testId");await t.clear(e),await t.type(e,"123x45s6"),await t.click(n),await o(a.getByDisplayValue("123x45s6")).toBeInTheDocument(),await j.mouseOver(e),console.log("got here",u.getAllByText("Must be a numerical value")),await o(u.getAllByText("Must be a numerical value").length).toEqual(2)})};const I=()=>{const[n,s]=c.useState("123");return r.jsx(i,{value:n,onChange:a=>{s(a.target.value)},testId:"testId"})};I.play=async({canvasElement:n,step:s})=>{const a=d(n),u=d(n.ownerDocument.body);await s("Can enter decimal values",async()=>{const e=a.getByTestId("testId");await t.clear(e),await t.type(e,"123.123456789"),await t.click(n),await o(a.getByDisplayValue("123.123456789")).toBeInTheDocument()}),await s("Can enter scientific notation",async()=>{const e=a.getByTestId("testId");await t.clear(e),await t.type(e,"-1.12e3"),await t.click(n),await o(a.getByDisplayValue("-1.12e3")).toBeInTheDocument()}),await s("Can enter comma decimals (converts to dot)",async()=>{const e=a.getByTestId("testId");await t.clear(e),await t.type(e,"123,456"),await t.click(n),await o(a.getByDisplayValue("123.456")).toBeInTheDocument()}),await s("Can enter small numbers",async()=>{const e=a.getByTestId("testId");await t.clear(e),await t.type(e,"0.0000000023"),await t.click(n),await o(a.getByDisplayValue("0.0000000023")).toBeInTheDocument()}),await s("Can enter large numbers",async()=>{const e=a.getByTestId("testId");await t.clear(e),await t.type(e,"999999999999"),await t.click(n),await o(a.getByDisplayValue("999999999999")).toBeInTheDocument()}),await s("Shows validation error for non-numeric input",async()=>{const e=a.getByTestId("testId");await t.clear(e),await t.type(e,"123x45s6"),await t.click(n),await o(a.getByDisplayValue("123x45s6")).toBeInTheDocument(),await j.mouseOver(e),await _e(()=>{o(u.getByText("Must be a numerical value")).toBeInTheDocument()})})};h.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"Placeholder"};V.__docgenInfo={description:"",methods:[],displayName:"TestInputGroup"};v.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"TestDisplayRounding"};k.__docgenInfo={description:"",methods:[],displayName:"ManagedTestCase"};y.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"DemoCosmeticRounding"};I.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"TestUserInput"};var L,G,W;A.parameters={...A.parameters,docs:{...(L=A.parameters)==null?void 0:L.docs,source:{originalSource:`args => {
2
- const [_, updateArgs] = useArgs();
3
- const handleChange = (evt: ChangeEvent<HTMLInputElement>) => {
4
- updateArgs({
5
- value: evt.target.value
6
- });
7
- };
8
- return <NumberInput onChange={handleChange} value={123} {...args} />;
9
- }`,...(W=(G=A.parameters)==null?void 0:G.docs)==null?void 0:W.source}}};var O,P,U;b.parameters={...b.parameters,docs:{...(O=b.parameters)==null?void 0:O.docs,source:{originalSource:`args => {
10
- const [_, updateArgs] = useArgs();
11
- const handleChange = (evt: ChangeEvent<HTMLInputElement>) => {
12
- updateArgs({
13
- value: evt.target.value
14
- });
15
- };
16
- return <NumberInput onChange={handleChange} value={123} {...args} />;
17
- }`,...(U=(P=b.parameters)==null?void 0:P.docs)==null?void 0:U.source}}};var q,K,Y;C.parameters={...C.parameters,docs:{...(q=C.parameters)==null?void 0:q.docs,source:{originalSource:`args => {
18
- const [_, updateArgs] = useArgs();
19
- const handleChange = (evt: ChangeEvent<HTMLInputElement>) => {
20
- updateArgs({
21
- value: evt.target.value
22
- });
23
- };
24
- return <NumberInput onChange={handleChange} value={123} {...args} />;
25
- }`,...(Y=(K=C.parameters)==null?void 0:K.docs)==null?void 0:Y.source}}};var z,J,Q;w.parameters={...w.parameters,docs:{...(z=w.parameters)==null?void 0:z.docs,source:{originalSource:`args => {
26
- const [_, updateArgs] = useArgs();
27
- const handleChange = (evt: ChangeEvent<HTMLInputElement>) => {
28
- updateArgs({
29
- value: evt.target.value
30
- });
31
- };
32
- return <NumberInput onChange={handleChange} value={123} {...args} />;
33
- }`,...(Q=(J=w.parameters)==null?void 0:J.docs)==null?void 0:Q.source}}};var X,Z,$;T.parameters={...T.parameters,docs:{...(X=T.parameters)==null?void 0:X.docs,source:{originalSource:`args => {
34
- const [_, updateArgs] = useArgs();
35
- const handleChange = (evt: ChangeEvent<HTMLInputElement>) => {
36
- updateArgs({
37
- value: evt.target.value
38
- });
39
- };
40
- return <NumberInput onChange={handleChange} value={123} {...args} />;
41
- }`,...($=(Z=T.parameters)==null?void 0:Z.docs)==null?void 0:$.source}}};var ee,ae,te;f.parameters={...f.parameters,docs:{...(ee=f.parameters)==null?void 0:ee.docs,source:{originalSource:`args => {
42
- const [_, updateArgs] = useArgs();
43
- const handleChange = (evt: ChangeEvent<HTMLInputElement>) => {
44
- updateArgs({
45
- value: evt.target.value
46
- });
47
- };
48
- return <NumberInput onChange={handleChange} value={123} {...args} />;
49
- }`,...(te=(ae=f.parameters)==null?void 0:ae.docs)==null?void 0:te.source}}};var ne,re,se;h.parameters={...h.parameters,docs:{...(ne=h.parameters)==null?void 0:ne.docs,source:{originalSource:`() => {
50
- const [value, setValue] = useState('123|m');
51
- return <NumberInput name="example" onChange={evt => setValue(evt.target.value)} placeholder="Type a value..." value={value} testId="testId" />;
52
- }`,...(se=(re=h.parameters)==null?void 0:re.docs)==null?void 0:se.source}}};var oe,ue,le;x.parameters={...x.parameters,docs:{...(oe=x.parameters)==null?void 0:oe.docs,source:{originalSource:`args => {
53
- const [_, updateArgs] = useArgs();
54
- const handleChange = (evt: ChangeEvent<HTMLInputElement>) => {
55
- updateArgs({
56
- value: evt.target.value
57
- });
58
- };
59
- return <NumberInput onChange={handleChange} value={123} {...args} />;
60
- }`,...(le=(ue=x.parameters)==null?void 0:ue.docs)==null?void 0:le.source}}};var ie,ce,de;B.parameters={...B.parameters,docs:{...(ie=B.parameters)==null?void 0:ie.docs,source:{originalSource:`args => {
61
- const [_, updateArgs] = useArgs();
62
- const handleChange = (evt: ChangeEvent<HTMLInputElement>) => {
63
- updateArgs({
64
- value: evt.target.value
65
- });
66
- };
67
- return <NumberInput onChange={handleChange} value={123} {...args} />;
68
- }`,...(de=(ce=B.parameters)==null?void 0:ce.docs)==null?void 0:de.source}}};var pe,ge,me;D.parameters={...D.parameters,docs:{...(pe=D.parameters)==null?void 0:pe.docs,source:{originalSource:`args => {
69
- const [_, updateArgs] = useArgs();
70
- const handleChange = (evt: ChangeEvent<HTMLInputElement>) => {
71
- updateArgs({
72
- value: evt.target.value
73
- });
74
- };
75
- return <NumberInput onChange={handleChange} value={123} {...args} />;
76
- }`,...(me=(ge=D.parameters)==null?void 0:ge.docs)==null?void 0:me.source}}};var he,ve,ye;S.parameters={...S.parameters,docs:{...(he=S.parameters)==null?void 0:he.docs,source:{originalSource:`args => {
77
- const [_, updateArgs] = useArgs();
78
- const handleChange = (evt: ChangeEvent<HTMLInputElement>) => {
79
- updateArgs({
80
- value: evt.target.value
81
- });
82
- };
83
- return <NumberInput onChange={handleChange} value={123} {...args} />;
84
- }`,...(ye=(ve=S.parameters)==null?void 0:ve.docs)==null?void 0:ye.source}}};var Ie,be,Ce;E.parameters={...E.parameters,docs:{...(Ie=E.parameters)==null?void 0:Ie.docs,source:{originalSource:`args => {
85
- const [_, updateArgs] = useArgs();
86
- const handleChange = (evt: ChangeEvent<HTMLInputElement>) => {
87
- updateArgs({
88
- value: evt.target.value
89
- });
90
- };
91
- return <NumberInput onChange={handleChange} value={123} {...args} />;
92
- }`,...(Ce=(be=E.parameters)==null?void 0:be.docs)==null?void 0:Ce.source}}};var we,Te,fe;V.parameters={...V.parameters,docs:{...(we=V.parameters)==null?void 0:we.docs,source:{originalSource:`() => <InputGroup small>
93
- <NumberInput value={123} />
94
- <InputGroupAddon>to</InputGroupAddon>
95
- <NumberInput value={123} />
96
- <Select options={[{
97
- value: 'units',
98
- label: 'units'
99
- }]} width="auto" value="units" />
100
- </InputGroup>`,...(fe=(Te=V.parameters)==null?void 0:Te.docs)==null?void 0:fe.source}}};var xe,Be,De;v.parameters={...v.parameters,docs:{...(xe=v.parameters)==null?void 0:xe.docs,source:{originalSource:`() => {
101
- const [value, setValue] = useState('123');
102
- return <NumberInput value={value} onChange={evt => {
103
- setValue(evt.target.value);
104
- }} testId="testId" enableDisplayRounding />;
105
- }`,...(De=(Be=v.parameters)==null?void 0:Be.docs)==null?void 0:De.source}}};var Se,Ee,Ve;k.parameters={...k.parameters,docs:{...(Se=k.parameters)==null?void 0:Se.docs,source:{originalSource:`() => {
106
- const [value, setValue] = useState('123');
107
- return <Grid columns="1fr 1fr" gap>
108
- <Card heading={<Heading>Storage State (Redux)</Heading>}>
109
- {value}
110
- <Spacer />
111
- <Button label="Change value" onClick={() => setValue(String(Math.floor(Math.random() * 100)))} />
112
- </Card>
113
- <Card heading={<Heading>NumberInput</Heading>}>
114
- <NumberInput value={value} onChange={evt => {
115
- setValue(evt.target.value);
116
- }} error={Number(value) >= 0 ? '' : 'Value must be positive'} />
117
- </Card>
118
- </Grid>;
119
- }`,...(Ve=(Ee=k.parameters)==null?void 0:Ee.docs)==null?void 0:Ve.source}}};var ke,Ae,Re;y.parameters={...y.parameters,docs:{...(ke=y.parameters)==null?void 0:ke.docs,source:{originalSource:`() => {
120
- const [enableDisplayRounding, setEnableDisplayRounding] = useState(false);
121
- const [enableCosmeticRounding, setEnableCosmeticRounding] = useState(true);
122
- const [valueInFeet, setValueInFeet] = useState('0.6889763779527558');
123
- const [callBackError, setCallBackError] = useState('');
124
- const valueInMeters = Number(valueInFeet) * 0.3048;
125
- return <Grid columns="1fr 1fr" gap>
126
- <Card heading={<Heading>Settings</Heading>}>
127
- <Field label="Enable display rounding:" labelLeft labelWidth={200}>
128
- <Toggle checked={enableDisplayRounding} onChange={evt => setEnableDisplayRounding(evt.target.checked)} />
129
- </Field>
130
- <Field label="Enable cosmetic rounding:" labelLeft labelWidth={200}>
131
- <Toggle checked={enableCosmeticRounding} onChange={evt => setEnableCosmeticRounding(evt.target.checked)} />
132
- </Field>
133
- </Card>
134
- <Card heading={<Heading>NumberInput (displayed in Meters)</Heading>}>
135
- <Text faint>
136
- Cosmetic Rounding Test Cases: type 0.21 then return (compare with
137
- enableCosmeticRounding on and off)
138
- </Text>
139
- <Spacer />
140
- <NumberInput name="Example" value={valueInMeters} onChange={evt => {
141
- const nextValueInFeet = String(Number(evt.target.value) / 0.3048);
142
- setValueInFeet(nextValueInFeet); // convert back to ft
143
- }} enableDisplayRounding={enableDisplayRounding} enableCosmeticRounding={enableCosmeticRounding} error={Number(valueInFeet) >= 0 ? '' : 'Value must be positive'} validationCallback={(name, error) => {
144
- setCallBackError(error ?? '');
145
- }} testId="testId" />
146
- </Card>
147
- <Card heading={<Heading>Storage State / Redux (stored in Feet)</Heading>}>
148
- {valueInFeet}
149
- <Spacer />
150
- <Button label="Change value" onClick={() => setValueInFeet(String(Math.floor(Math.random() * 100)))} />
151
- </Card>
152
- <Card heading={<Heading>Test Validation Callback</Heading>}>
153
- {callBackError && <Message message={{
154
- content: callBackError,
155
- icon: true,
156
- type: 'Error',
157
- visible: true
158
- }} />}
159
- </Card>
160
- </Grid>;
161
- }`,...(Re=(Ae=y.parameters)==null?void 0:Ae.docs)==null?void 0:Re.source}}};var Ne,je,Me;I.parameters={...I.parameters,docs:{...(Ne=I.parameters)==null?void 0:Ne.docs,source:{originalSource:`() => {
162
- const [value, setValue] = useState('123');
163
- return <NumberInput value={value} onChange={evt => {
164
- setValue(evt.target.value);
165
- }} testId="testId" />;
166
- }`,...(Me=(je=I.parameters)==null?void 0:je.docs)==null?void 0:Me.source}}};const _a=["Default","Small","Width","Left","Disabled","AllowEmpty","Placeholder","Warning","Error","BadInput","WithDisplayRounding","WithCustomDisplayRounding","TestInputGroup","TestDisplayRounding","ManagedTestCase","DemoCosmeticRounding","TestUserInput"];export{f as AllowEmpty,D as BadInput,A as Default,y as DemoCosmeticRounding,T as Disabled,B as Error,w as Left,k as ManagedTestCase,h as Placeholder,b as Small,v as TestDisplayRounding,V as TestInputGroup,I as TestUserInput,x as Warning,C as Width,E as WithCustomDisplayRounding,S as WithDisplayRounding,_a as __namedExportsOrder,Ma as default};