@oliasoft-open-source/react-ui-library 4.2.0-beta-1 → 4.2.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.
- package/dist/assets/{index-9914ac27.js → index-26f804a8.js} +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.html +1 -1
- package/dist/index.js +52 -27
- package/dist/index.js.map +1 -1
- package/dist/storybook/assets/{Color-6VNJS4EI-626cced0.js → Color-6VNJS4EI-4a5d7280.js} +1 -1
- package/dist/storybook/assets/{DocsRenderer-NNNQARDV-576d9da9.js → DocsRenderer-NNNQARDV-72503a2d.js} +1 -1
- package/dist/storybook/assets/{WithTooltip-4HIR6TLV-bee8e125.js → WithTooltip-4HIR6TLV-23437932.js} +1 -1
- package/dist/storybook/assets/{accordion.stories-54aa7085.js → accordion.stories-0f8af16e.js} +1 -1
- package/dist/storybook/assets/{button.stories-531033a8.js → button.stories-9b954335.js} +1 -1
- package/dist/storybook/assets/{buttons-and-links-5c2f81ed.js → buttons-and-links-c7506f52.js} +1 -1
- package/dist/storybook/assets/{casing-loads.stories-d235dd15.js → casing-loads.stories-cfbab702.js} +1 -1
- package/dist/storybook/assets/{cell.stories-6d7c1887.js → cell.stories-524a7418.js} +1 -1
- package/dist/storybook/assets/{chunk-HLWAVYOI-7cf52e0e.js → chunk-HLWAVYOI-1b1e8383.js} +1 -1
- package/dist/storybook/assets/{color-373aeff7.js → color-e373f623.js} +1 -1
- package/dist/storybook/assets/{drawer.stories-2512fef1.js → drawer.stories-39625e91.js} +1 -1
- package/dist/storybook/assets/{file-input.stories-0e546123.js → file-input.stories-1c6ce0ea.js} +1 -1
- package/dist/storybook/assets/{flex-47732c42.js → flex-1d14d86c.js} +1 -1
- package/dist/storybook/assets/{flex.stories-9d4c08a1.js → flex.stories-09e9c602.js} +1 -1
- package/dist/storybook/assets/{footer.stories-9337b9e2.js → footer.stories-57f07ea2.js} +1 -1
- package/dist/storybook/assets/{form.stories-40e17b4c.js → form.stories-45c0cd59.js} +1 -1
- package/dist/storybook/assets/{formation.stories-fc57d144.js → formation.stories-5eeaa826.js} +1 -1
- package/dist/storybook/assets/{formatter-SWP5E3XI-46182822.js → formatter-SWP5E3XI-d3a9e021.js} +1 -1
- package/dist/storybook/assets/{heading.stories-869d41ea.js → heading.stories-9689bddc.js} +1 -1
- package/dist/storybook/assets/{icon.stories-fca93dba.js → icon.stories-8dae69e1.js} +1 -1
- package/dist/storybook/assets/iframe-210f2f48.js +1 -0
- package/dist/storybook/assets/{index-0bfda4aa.js → index-57d7693e.js} +1 -1
- package/dist/storybook/assets/{index-fba8c0d7.js → index-5d28dded.js} +4 -4
- package/dist/storybook/assets/{input-validation-3b7b7cda.js → input-validation-141270c5.js} +1 -1
- package/dist/storybook/assets/{inputs-c02f8012.js → inputs-851ed326.js} +1 -1
- package/dist/storybook/assets/{layout-forms-bdf4b47b.js → layout-forms-8fb9eb93.js} +1 -1
- package/dist/storybook/assets/{layout-general-2c5e127e.js → layout-general-2e5a4012.js} +1 -1
- package/dist/storybook/assets/{list.stories-0f30d0b5.js → list.stories-5715452e.js} +1 -1
- package/dist/storybook/assets/{list.stories-data-390b28e1.js → list.stories-data-94f7c623.js} +1 -1
- package/dist/storybook/assets/{menu.stories-7a422ddf.js → menu.stories-927adf3d.js} +1 -1
- package/dist/storybook/assets/{menu.stories-data-38257c11.js → menu.stories-data-28e27478.js} +1 -1
- package/dist/storybook/assets/{number-input-66bb0350.js → number-input-7d49b0b3.js} +1 -1
- package/dist/storybook/assets/{number-input.stories-ef65b216.js → number-input.stories-02528124.js} +1 -1
- package/dist/storybook/assets/{padding-and-spacing-5cfec3f6.js → padding-and-spacing-d5b7037c.js} +1 -1
- package/dist/storybook/assets/{popover.stories-4c074762.js → popover.stories-f651a81c.js} +1 -1
- package/dist/storybook/assets/{preview-8a38ceb3.js → preview-3a1dcfd9.js} +1 -1
- package/dist/storybook/assets/preview-78133dba.js +1 -0
- package/dist/storybook/assets/{row.stories-4c5f0247.js → row.stories-d5b6b4a6.js} +1 -1
- package/dist/storybook/assets/{side-bar.stories-0887207d.js → side-bar.stories-2c06f8a6.js} +1 -1
- package/dist/storybook/assets/{spacer.stories-97086558.js → spacer.stories-38071af8.js} +1 -1
- package/dist/storybook/assets/{syntaxhighlighter-NMPM6SWI-758c17ef.js → syntaxhighlighter-NMPM6SWI-35b98f86.js} +1 -1
- package/dist/storybook/assets/{table-646201c1.js → table-da6f6045.js} +1 -1
- package/dist/storybook/assets/{table.stories-ca3ed877.js → table.stories-67a3023a.js} +1 -1
- package/dist/storybook/assets/{table.stories-data-aefdf55f.js → table.stories-data-8a836b92.js} +1 -1
- package/dist/storybook/assets/{textarea-54dd1c9a.js → textarea-d48efea2.js} +1 -1
- package/dist/storybook/assets/{textarea.stories-4b85aa60.js → textarea.stories-89c8afd7.js} +1 -1
- package/dist/storybook/assets/{title.stories-7ad1232e.js → title.stories-5b4a226c.js} +1 -1
- package/dist/storybook/assets/{toaster.stories-bed0d43f.js → toaster.stories-5e4d95b1.js} +1 -1
- package/dist/storybook/assets/{tooltip.test-case.stories-ef78bd26.js → tooltip.test-case.stories-9817078b.js} +1 -1
- package/dist/storybook/assets/unit-input.stories-50ac8b0f.js +257 -0
- package/dist/storybook/iframe.html +1 -1
- package/dist/storybook/index.json +1 -1
- package/dist/storybook/project.json +1 -1
- package/dist/storybook/stories.json +1 -1
- package/package.json +1 -1
- package/dist/storybook/assets/iframe-c1f0de6b.js +0 -1
- package/dist/storybook/assets/preview-f8076f66.js +0 -1
- package/dist/storybook/assets/unit-input.stories-c70beb80.js +0 -1
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import{j as e}from"./jsx-runtime-f961835c.js";import{r as c}from"./index-f80c8c95.js";import{d as r,r as Yt}from"./index-57d7693e.js";import{c as Zt}from"./index-a80ed1cf.js";import{M as ke}from"./actions-2d4e1c8e.js";import{I as Gt}from"./input-group-addon-f8f6683a.js";import{B as d}from"./button-74c97e4a.js";import{T as Qt}from"./tooltip-23e84186.js";import{I as Xt}from"./input-group-20c3add3.js";import{S as N}from"./spacer-54db0620.js";import{T as en}from"./text-ad1f5f1d.js";import{I as tn}from"./input-d68625a5.js";import{M as Se}from"./types-cc224262.js";import{l as w}from"./lodash-75c70a11.js";import{D as nn}from"./divider-182aa58c.js";import{R as Nt,C as ce}from"./row-2299f0e7.js";import{F as j}from"./field-a094cd72.js";import{a as pe}from"./message-7e627e60.js";import"./index-54f0d271.js";import"./common-types-2c81813f.js";import"./disabled-context-d654f6ff.js";import"./icon-e9cbb4d7.js";import"./inheritsLoose-d4851ab8.js";import"./tslib.es6-dfef685f.js";import"./index-c89a1915.js";import"./types-332ceaf3.js";import"./badge-20e7ee0b.js";import"./spinner-a81ebe38.js";import"./index-3d476d02.js";import"./styled-components.browser.esm-416d73e5.js";import"./label-13d490a3.js";import"./help-icon-d4189b1b.js";const an=()=>{const t=c.useRef(null);return c.useLayoutEffect(()=>{t.current&&(t.current(),t.current=null)}),n=>{t.current=n}},ln=t=>{const a=c.useRef();return c.useEffect(()=>{a.current=t},[t]),a.current},rn=(t,a)=>{const n=a==null?void 0:a[t];return n||(console.log(`Warning: 'unitTemplate' does not define a preferred unit for '${t}'. Defaulting to standard unit.`),r.unitFromQuantity(t)??"")};var C=(t=>(t.CUSTOM="custom",t.PREDEFINED="predefined",t))(C||{});const me=t=>t==="undefined"||t===void 0||t===""||t==="null"||t===null||t==="NaN"||isNaN(t),At=(t="",a,n="",i=!1)=>{if(a&&!i)try{const u=me(t)?t:r.isValueWithUnit(t)?r.convertSamePrecision(t,a):r.convertSamePrecision(r.withUnit(t,n),a);return r.getValue(u)}catch{}return""},M=(t="",a,n,i)=>{const u=r.isValueWithUnit(t),m=u&&me(r.getValue(t))||!u&&me(t);return u?m?"":At(r.getValue(t),a,n,i):m?"":t},we=t=>w.isObject(t)&&!w.isArray(t)&&!w.isFunction(t)?w.get(t,"fieldName",""):typeof t=="string"?t:"",sn=t=>w.isObjectLike(t)&&w.has(t,"message"),un=t=>typeof t=="string"?t:sn(t)?t.message:null;var on=Yt();const dn=t=>t.search(RegExp(/(^0{2}\.)|(^0+[1-9])/g))===0,Ee=(t,a)=>{var I;const{allowEmpty:n=!1,autoValue:i,placeholder:u,disabledValidation:m=!1}=a||{},s=String(t);if(m||i||u)return null;const p=on.isValueWithUnit(s)?r.getValue(s):s;if(n&&p==="")return null;if(dn(p))return"Invalid number format due to leading zeroes";const v=r.validateNumber(p);if(!v.valid){const ae=((I=v==null?void 0:v.errors)==null?void 0:I[0])??null;return un(ae)}return null},cn="_predefinedMenuActive_1yvt4_1",mn={predefinedMenuActive:cn},h=({name:t,placeholder:a="",disabled:n=!1,disabledUnit:i=!1,error:u=null,left:m=!1,small:s=!1,width:p="100%",value:v,unitkey:I="",initUnit:ae,noConversion:Pt=!1,onChange:le=()=>{},onClick:gn=()=>{},onFocus:Dt=()=>{},onSwitchUnit:ge=()=>{},unitTemplate:he,doNotConvertValue:A=!1,testId:S,warning:Mt=null,predefinedOptions:x,initialPredefinedOption:Ft=!1,shouldLinkAutomaticly:ve=!0,selectedPredefinedOptionKey:fe,validationCallback:Ce=()=>({name:"",error:null}),disabledValidation:be=!1,allowEmpty:ye=!1,autoValue:V})=>{typeof v=="number"&&(v=`${v}`);const _t=an(),[re="",P=""]=v!==void 0?r.split(v):[],Ue=V?r.getUnit(V):"",Ot=c.useMemo(()=>rn(I,he),[I,he]),y=ae||Ot||P,Bt=ln(y),xe=M(v,y,P,A),Ve=M(V,y,Ue,A),qt=xe!==""?{value:xe,unit:y}:Ve!==""?{value:Ve,unit:y}:{value:re,unit:P},[g,J]=c.useState(qt),[Rt,se]=c.useState(null),[k,ie]=c.useState(Ft?C.PREDEFINED:C.CUSTOM),ue=re===""&&V,D=x&&x.find(l=>{if(fe)return fe===l.valueKey;const o=r.isValueWithUnit(l.value)?r.getUnit(l.value):"";return r.withUnit(At(String(v),o),o)===l.value}),Wt=()=>{if(I)try{const l=String(ue?V:v??"");let o=r.altUnitsList(l,I);return r.getValue(l)===""?o.map(f=>["",f[1]]):o}catch{return null}},Tt=l=>{const o=we(t),f=l.target,{value:U,selectionStart:Q}=f,Ie=r.cleanNumStr(U.replaceAll(" ","").replaceAll("|","")),oe=r.withUnit(Ie,(g==null?void 0:g.unit)||""),Kt=r.getValue(oe),de=Ee(Kt,{allowEmpty:ye,autoValue:V,placeholder:a,disabledValidation:be});if(de===null){le({target:{value:oe,name:o}});const[zt,Jt]=r.split(oe);J({value:zt,unit:Jt}),se(null),Ce(o,null)}else J({value:Ie,unit:g.unit}),se(de),Ce(o,de);_t(()=>{f.selectionStart=Q,f.selectionEnd=Q})},Lt=(l,o)=>{o===g.unit||isNaN(Number(l))||(J({value:l,unit:o}),ge&&ge(o))};c.useEffect(()=>{if(y){let f,U="";Bt!==y?(f=M(String(v),y,P,A),U=y):r.withUnit(g.value,g.unit)!==v&&(f=M(String(v),g.unit,P,A),U=g.unit),f!==void 0&&J({value:f,unit:U}),x&&ie(D&&ve?C.PREDEFINED:C.CUSTOM)}const l=r.withUnit(r.checkAndCleanDecimalComma(re),(g==null?void 0:g.unit)||""),o=Ee(l,{allowEmpty:ye,autoValue:V,placeholder:a,disabledValidation:be});se(o)},[y,v,u,ve]);const Y=Wt(),Z=r.label(g.unit)||g.unit||"",$t=Pt||!Y||Y&&Y.length===1,je=we(t);let G;const Ht=l=>{const[o,f=""]=r.isValueWithUnit(l.value)?r.split(l.value):[l.value];return{type:Se.OPTION,inline:!0,onClick:()=>{r.validateNumber(o).valid&&!n&&(ie(C.PREDEFINED),le({target:{value:l.value,name:typeof t=="string"?t:(t==null?void 0:t.fieldName)||"",predefinedSelected:!0,predefinedOption:l}}))},label:e.jsxs(e.Fragment,{children:[e.jsx(en,{children:l.label}),e.jsx(N,{width:"20px",height:"0"})]}),description:r.isValueWithUnit(l.value)?`${o} ${f}`:l.value,selected:D===l&&k===C.PREDEFINED}};if(G=[{type:Se.OPTION,inline:!0,onClick:()=>{k!==C.CUSTOM&&!n&&le({target:{value:r.withUnit(g.value,g.unit),name:typeof t=="string"?t:(t==null?void 0:t.fieldName)||""}})},label:"Custom",selected:k===C.CUSTOM}],x!=null&&x.length){const l=x.map(Ht);G=[...G,...l]}return e.jsx("div",{className:k===C.PREDEFINED?Zt(mn.predefinedMenuActive):"",children:e.jsxs(Xt,{small:s,width:p,children:[x&&e.jsx(Qt,{text:k===C.PREDEFINED?D==null?void 0:D.label:"",children:e.jsx(ke,{maxHeight:380,groupOrder:"first",testId:S&&`${S}-predefined-menu`,disabled:n,menu:{colored:!0,trigger:"Component",component:e.jsx(d,{groupOrder:"first",active:k===C.PREDEFINED,icon:k===C.PREDEFINED?"link":"unlink"}),small:s,sections:G}})}),e.jsx(tn,{type:"text",name:je,testId:S,disabled:n,placeholder:ue?M(V,g.unit,Ue,A):a,value:g.value,onChange:Tt,onFocus:Dt,error:u||Rt,warning:Mt,right:!m},je),Z&&($t?e.jsx(Gt,{groupOrder:"last",children:Z}):e.jsx(ke,{maxHeight:380,groupOrder:"last",disabled:i,testId:S&&`${S}-menu`,menu:{label:Z,trigger:"DropDownButton",small:s,sections:Y.map(([l,o,f])=>{const U=f||o||"";return{type:"Option",label:isNaN(Number(l))?"":l,inline:!0,onClick:Q=>{Q.stopPropagation(),Lt(ue?"":l,o)},description:U,selected:U===Z,testId:`${S}-unit-${U}`}})}}))]})})};try{h.displayName="UnitInput",h.__docgenInfo={description:"",displayName:"UnitInput",props:{name:{defaultValue:null,description:"",name:"name",required:!0,type:{name:"string | { fieldName?: string | undefined; }"}},placeholder:{defaultValue:{value:""},description:"",name:"placeholder",required:!1,type:{name:"string"}},disabled:{defaultValue:{value:"false"},description:"",name:"disabled",required:!1,type:{name:"boolean"}},disabledUnit:{defaultValue:{value:"false"},description:"",name:"disabledUnit",required:!1,type:{name:"boolean"}},error:{defaultValue:{value:"null"},description:"",name:"error",required:!1,type:{name:"string | boolean | null"}},left:{defaultValue:{value:"false"},description:"",name:"left",required:!1,type:{name:"boolean"}},small:{defaultValue:{value:"false"},description:"",name:"small",required:!1,type:{name:"boolean"}},width:{defaultValue:{value:"100%"},description:"",name:"width",required:!1,type:{name:"string | number"}},value:{defaultValue:null,description:"",name:"value",required:!1,type:{name:"string | number"}},unitkey:{defaultValue:{value:""},description:"",name:"unitkey",required:!1,type:{name:"string"}},initUnit:{defaultValue:null,description:"",name:"initUnit",required:!1,type:{name:"string"}},noConversion:{defaultValue:{value:"false"},description:"",name:"noConversion",required:!1,type:{name:"boolean"}},doNotConvertValue:{defaultValue:{value:"false"},description:"",name:"doNotConvertValue",required:!1,type:{name:"boolean"}},testId:{defaultValue:null,description:"",name:"testId",required:!1,type:{name:"string"}},warning:{defaultValue:{value:"null"},description:"",name:"warning",required:!1,type:{name:"string | null"}},predefinedOptions:{defaultValue:null,description:"",name:"predefinedOptions",required:!1,type:{name:"IPredefinedOption[]"}},initialPredefinedOption:{defaultValue:{value:"false"},description:"",name:"initialPredefinedOption",required:!1,type:{name:"boolean"}},shouldLinkAutomaticly:{defaultValue:{value:"true"},description:"",name:"shouldLinkAutomaticly",required:!1,type:{name:"boolean"}},selectedPredefinedOptionKey:{defaultValue:null,description:"",name:"selectedPredefinedOptionKey",required:!1,type:{name:"string"}},validationCallback:{defaultValue:{value:"() => ({ name: '', error: null })"},description:"",name:"validationCallback",required:!1,type:{name:"((name: string, message: string | null) => { name: string; error: string | null; })"}},disabledValidation:{defaultValue:{value:"false"},description:"",name:"disabledValidation",required:!1,type:{name:"boolean"}},allowEmpty:{defaultValue:{value:"false"},description:"",name:"allowEmpty",required:!1,type:{name:"boolean"}},autoValue:{defaultValue:null,description:"",name:"autoValue",required:!1,type:{name:"string"}},onChange:{defaultValue:{value:"() => {}"},description:"",name:"onChange",required:!1,type:{name:"(event: ChangeEvent<HTMLInputElement> | ICustomChangeEvent) => void"}},onSwitchUnit:{defaultValue:{value:"() => {}"},description:"",name:"onSwitchUnit",required:!1,type:{name:"((unit: string) => void)"}},onClick:{defaultValue:{value:"() => {}"},description:"",name:"onClick",required:!1,type:{name:"MouseEventHandler<HTMLInputElement>"}},onFocus:{defaultValue:{value:"() => {}"},description:"",name:"onFocus",required:!1,type:{name:"FocusEventHandler<HTMLInputElement>"}},unitTemplate:{defaultValue:null,description:"",name:"unitTemplate",required:!1,type:{name:"Record<string, any>"}}}}}catch{}const{useArgs:pn}=__STORYBOOK_MODULE_ADDONS__,zn={title:"Basic/UnitInput",component:h,args:{name:"example",unitkey:"length",value:"123|m"}},b=t=>{const[a,n]=pn(),i=u=>{n({value:u.target.value})};return e.jsx(h,{...t,onChange:i})},X=b.bind({}),F=b.bind({});F.args={initUnit:"ft",unitTemplate:{length:"ft"}};const _=b.bind({});_.args={width:"180px"};const O=b.bind({});O.args={noConversion:!0};const B=b.bind({});B.args={small:!0};const q=b.bind({});q.args={error:"Error message goes here"};const R=b.bind({});R.args={value:"asas123asd|%"};const E=b.bind({});E.args={disabled:!0,disabledUnit:!0};E.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 W=b.bind({});W.args={disabled:!0,disabledUnit:!0,noConversion:!0};const T=b.bind({});T.args={disabledUnit:!0,unitkey:void 0};const L=b.bind({});L.args={disabledUnit:!0,unitkey:"length"};const $=b.bind({});$.args={disabledUnit:!1,disabled:!0};const H=t=>{const[a,n]=c.useState("123|m"),[i,u]=c.useState("223|m"),[m,s]=c.useState("ft");return e.jsxs(e.Fragment,{children:[e.jsx(d,{label:"Change initUnit",onClick:()=>s(m==="m"?"ft":"m")}),e.jsx(N,{}),e.jsx(d,{label:"Change value",onClick:()=>n(a==="123|m"?"456|m":"123|m")}),e.jsx(N,{}),e.jsx(h,{name:"example",onChange:p=>{n(p.target.value)},unitkey:"length",value:a,initUnit:m,onSwitchUnit:s}),e.jsx(N,{}),e.jsx(h,{name:"example2",onChange:p=>{u(p.target.value)},unitkey:"length",value:i,initUnit:m,onSwitchUnit:s}),e.jsx(nn,{}),e.jsx("h4",{children:"Without initUnit property (taken from the redux store)"}),e.jsx(h,{name:"example",onChange:p=>{n(p.target.value)},unitkey:"length",value:a,onSwitchUnit:s}),e.jsx(h,{name:"example2",onChange:p=>{u(p.target.value)},unitkey:"length",value:i,onSwitchUnit:s})]})};H.parameters={docs:{description:{story:"[OW-4380](https://oliasoft.atlassian.net/browse/OW-4380?atlOrigin=eyJpIjoiMmM1N2RkNWU3Mjk5NDYxY2E0YzhkMzk5ZTVmZTJhMjciLCJwIjoiaiJ9)"}}};const K=b.bind({});K.args={predefinedOptions:[{label:"bottom of casing",value:"12|km"},{label:"mud weight at shoe depth",value:"8|mm"}]};const z=()=>{const t="500px",[a,n]=c.useState(void 0);return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different edge cases such as +/- infinity, undefined, NaN, null:"}),e.jsxs(Nt,{children:[e.jsxs(ce,{width:"25%",children:[e.jsx(d,{label:"Change value infinity",onClick:()=>n(1/0)}),e.jsx("br",{}),e.jsx(d,{label:"Change value -infinity",onClick:()=>n(-1/0)}),e.jsx("br",{}),e.jsx(d,{label:"Change value null",onClick:()=>n(null)}),e.jsx("br",{}),e.jsx(d,{label:"Change value - undefined",onClick:()=>n(void 0)}),e.jsx("br",{}),e.jsx(d,{label:"Change value - NaN",onClick:()=>n(NaN)}),e.jsx("br",{}),e.jsx(d,{label:"Change value - nothing (empty)",onClick:()=>n(void 0)}),e.jsx("br",{}),e.jsx(d,{label:"Change value - empty string",onClick:()=>n("")})]}),e.jsxs(ce,{width:"25%",children:[e.jsx(d,{label:"Change value infinity|m",onClick:()=>n("Infinity|m")}),e.jsx("br",{}),e.jsx(d,{label:"Change value -infinity|m",onClick:()=>n("-Infinity|m")}),e.jsx("br",{}),e.jsx(d,{label:"Change value null|m",onClick:()=>n(null+"|m")}),e.jsx("br",{}),e.jsx(d,{label:"Change value - undefined|m",onClick:()=>n(void 0+"|m")}),e.jsx("br",{}),e.jsx(d,{label:"Change value - NaN|m",onClick:()=>n("NaN|m")}),e.jsx("br",{}),e.jsx(d,{label:"Change value - nothing (empty)|m",onClick:()=>n("|m")})]})]}),e.jsx("br",{}),e.jsx(j,{label:"Normal PUI",children:e.jsx(h,{name:"example1",onChange:i=>n(i.target.value),value:a,unitkey:"length",width:t,placeholder:"value|unit"})}),e.jsx(j,{label:"Disabled validation",children:e.jsx(h,{name:"example2",onChange:i=>n(i.target.value),value:a,unitkey:"length",disabledValidation:!0,width:t})}),e.jsx(j,{label:"Disabled validation and manual error",children:e.jsx(h,{name:"example3",onChange:i=>n(i.target.value),value:a,unitkey:"length",error:"test",disabledValidation:!0,width:t})}),e.jsx(pe,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})},ee=()=>{const t="500px",[a,n]=c.useState("1|m"),[i,u]=c.useState("|m"),m="123|km";return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different cases for automatic (placeholder) values:"}),e.jsx(Nt,{children:e.jsxs(ce,{width:"25%",children:[e.jsx(d,{label:"Change value to ''",onClick:()=>n("")}),e.jsx("br",{}),e.jsx(d,{label:"Change value to 1",onClick:()=>n(1)}),e.jsx("br",{}),e.jsx(d,{label:"Change value to 1|m",onClick:()=>n("1|m")}),e.jsx("br",{}),e.jsx(d,{label:"Change value to |m - empty value",onClick:()=>n("|m")})]})}),e.jsx("br",{}),e.jsx(j,{label:"Normal PUI (placeholder + auto)",children:e.jsx(h,{name:"example1",onChange:s=>n(s.target.value),value:a,unitkey:"length",width:t,placeholder:"value|unit",autoValue:m})}),e.jsx(j,{label:"Normal PUI (only auto)",children:e.jsx(h,{name:"example1",onChange:s=>n(s.target.value),value:a,unitkey:"length",width:t,autoValue:m})}),e.jsx(j,{label:"Empty PUI with autoValue",children:e.jsx(h,{name:"example1",onChange:s=>u(s.target.value),value:i,unitkey:"length",width:t,autoValue:m})}),e.jsx(j,{label:"Normal PUI (only placeholder)",children:e.jsx(h,{name:"example1",onChange:s=>n(s.target.value),value:a,unitkey:"length",width:t,placeholder:"Placeholder test"})}),e.jsx(j,{label:"Normal PUI (placeholder + allowEmpty)",children:e.jsx(h,{name:"example1",onChange:s=>n(s.target.value),value:a,unitkey:"length",width:t,placeholder:"Placeholder test",allowEmpty:!0})}),e.jsx(pe,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})};z.parameters={docs:{description:{story:"[OW-8884](https://oliasoft.atlassian.net/browse/OW-8884)"}}};const te=()=>{const[t,a]=c.useState("123|%"),[n,i]=c.useState(null),u="This should be visible when an error appears",m=(s,p)=>(i(p),{name:s,error:p});return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"3rd party validation message when inputting invalid value:"}),e.jsx(h,{name:"example",onChange:s=>a(s.target.value),error:!n||u,validationCallback:m,value:t}),e.jsx("br",{}),e.jsx(N,{}),e.jsx("h4",{children:"Original validation message: "}),e.jsx(pe,{message:{heading:n,visible:!0}})]})},ne=()=>{const[t,a]=c.useState("123|m"),[n,i]=c.useState(""),[u,m]=c.useState("km"),s=()=>{m("ft"),i("placeholder"),a("|m")};return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Empty value case:"}),e.jsx(h,{name:"example",onChange:p=>a(p.target.value),value:t,allowEmpty:!0,placeholder:n,initUnit:u,unitkey:"length"}),e.jsx("br",{}),e.jsx(N,{}),e.jsx(d,{label:"Change value |m and unit ft",onClick:()=>s()})]})};var Ne,Ae,Pe;X.parameters={...X.parameters,docs:{...(Ne=X.parameters)==null?void 0:Ne.docs,source:{originalSource:`args => {
|
|
2
|
+
const [_, updateArgs] = useArgs();
|
|
3
|
+
const handleChange = (evt: any) => {
|
|
4
|
+
updateArgs({
|
|
5
|
+
value: evt.target.value
|
|
6
|
+
});
|
|
7
|
+
};
|
|
8
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
9
|
+
}`,...(Pe=(Ae=X.parameters)==null?void 0:Ae.docs)==null?void 0:Pe.source}}};var De,Me,Fe;F.parameters={...F.parameters,docs:{...(De=F.parameters)==null?void 0:De.docs,source:{originalSource:`args => {
|
|
10
|
+
const [_, updateArgs] = useArgs();
|
|
11
|
+
const handleChange = (evt: any) => {
|
|
12
|
+
updateArgs({
|
|
13
|
+
value: evt.target.value
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
17
|
+
}`,...(Fe=(Me=F.parameters)==null?void 0:Me.docs)==null?void 0:Fe.source}}};var _e,Oe,Be;_.parameters={..._.parameters,docs:{...(_e=_.parameters)==null?void 0:_e.docs,source:{originalSource:`args => {
|
|
18
|
+
const [_, updateArgs] = useArgs();
|
|
19
|
+
const handleChange = (evt: any) => {
|
|
20
|
+
updateArgs({
|
|
21
|
+
value: evt.target.value
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
25
|
+
}`,...(Be=(Oe=_.parameters)==null?void 0:Oe.docs)==null?void 0:Be.source}}};var qe,Re,We;O.parameters={...O.parameters,docs:{...(qe=O.parameters)==null?void 0:qe.docs,source:{originalSource:`args => {
|
|
26
|
+
const [_, updateArgs] = useArgs();
|
|
27
|
+
const handleChange = (evt: any) => {
|
|
28
|
+
updateArgs({
|
|
29
|
+
value: evt.target.value
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
33
|
+
}`,...(We=(Re=O.parameters)==null?void 0:Re.docs)==null?void 0:We.source}}};var Te,Le,$e;B.parameters={...B.parameters,docs:{...(Te=B.parameters)==null?void 0:Te.docs,source:{originalSource:`args => {
|
|
34
|
+
const [_, updateArgs] = useArgs();
|
|
35
|
+
const handleChange = (evt: any) => {
|
|
36
|
+
updateArgs({
|
|
37
|
+
value: evt.target.value
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
41
|
+
}`,...($e=(Le=B.parameters)==null?void 0:Le.docs)==null?void 0:$e.source}}};var He,Ke,ze;q.parameters={...q.parameters,docs:{...(He=q.parameters)==null?void 0:He.docs,source:{originalSource:`args => {
|
|
42
|
+
const [_, updateArgs] = useArgs();
|
|
43
|
+
const handleChange = (evt: any) => {
|
|
44
|
+
updateArgs({
|
|
45
|
+
value: evt.target.value
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
49
|
+
}`,...(ze=(Ke=q.parameters)==null?void 0:Ke.docs)==null?void 0:ze.source}}};var Je,Ye,Ze;R.parameters={...R.parameters,docs:{...(Je=R.parameters)==null?void 0:Je.docs,source:{originalSource:`args => {
|
|
50
|
+
const [_, updateArgs] = useArgs();
|
|
51
|
+
const handleChange = (evt: any) => {
|
|
52
|
+
updateArgs({
|
|
53
|
+
value: evt.target.value
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
57
|
+
}`,...(Ze=(Ye=R.parameters)==null?void 0:Ye.docs)==null?void 0:Ze.source}}};var Ge,Qe,Xe;E.parameters={...E.parameters,docs:{...(Ge=E.parameters)==null?void 0:Ge.docs,source:{originalSource:`args => {
|
|
58
|
+
const [_, updateArgs] = useArgs();
|
|
59
|
+
const handleChange = (evt: any) => {
|
|
60
|
+
updateArgs({
|
|
61
|
+
value: evt.target.value
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
65
|
+
}`,...(Xe=(Qe=E.parameters)==null?void 0:Qe.docs)==null?void 0:Xe.source}}};var et,tt,nt;W.parameters={...W.parameters,docs:{...(et=W.parameters)==null?void 0:et.docs,source:{originalSource:`args => {
|
|
66
|
+
const [_, updateArgs] = useArgs();
|
|
67
|
+
const handleChange = (evt: any) => {
|
|
68
|
+
updateArgs({
|
|
69
|
+
value: evt.target.value
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
73
|
+
}`,...(nt=(tt=W.parameters)==null?void 0:tt.docs)==null?void 0:nt.source}}};var at,lt,rt;T.parameters={...T.parameters,docs:{...(at=T.parameters)==null?void 0:at.docs,source:{originalSource:`args => {
|
|
74
|
+
const [_, updateArgs] = useArgs();
|
|
75
|
+
const handleChange = (evt: any) => {
|
|
76
|
+
updateArgs({
|
|
77
|
+
value: evt.target.value
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
81
|
+
}`,...(rt=(lt=T.parameters)==null?void 0:lt.docs)==null?void 0:rt.source}}};var st,it,ut;L.parameters={...L.parameters,docs:{...(st=L.parameters)==null?void 0:st.docs,source:{originalSource:`args => {
|
|
82
|
+
const [_, updateArgs] = useArgs();
|
|
83
|
+
const handleChange = (evt: any) => {
|
|
84
|
+
updateArgs({
|
|
85
|
+
value: evt.target.value
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
89
|
+
}`,...(ut=(it=L.parameters)==null?void 0:it.docs)==null?void 0:ut.source}}};var ot,dt,ct;$.parameters={...$.parameters,docs:{...(ot=$.parameters)==null?void 0:ot.docs,source:{originalSource:`args => {
|
|
90
|
+
const [_, updateArgs] = useArgs();
|
|
91
|
+
const handleChange = (evt: any) => {
|
|
92
|
+
updateArgs({
|
|
93
|
+
value: evt.target.value
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
97
|
+
}`,...(ct=(dt=$.parameters)==null?void 0:dt.docs)==null?void 0:ct.source}}};var mt,pt,gt;H.parameters={...H.parameters,docs:{...(mt=H.parameters)==null?void 0:mt.docs,source:{originalSource:`(args: IUnitInputProps) => {
|
|
98
|
+
const [value, setValue] = useState('123|m');
|
|
99
|
+
const [value2, setValue2] = useState('223|m');
|
|
100
|
+
const [initUnit, setInitUnit] = useState('ft');
|
|
101
|
+
return <>
|
|
102
|
+
<Button label="Change initUnit" onClick={() => setInitUnit(initUnit === 'm' ? 'ft' : 'm')} />
|
|
103
|
+
<Spacer />
|
|
104
|
+
<Button label="Change value" onClick={() => setValue(value === '123|m' ? '456|m' : '123|m')} />
|
|
105
|
+
<Spacer />
|
|
106
|
+
<UnitInput name="example" onChange={evt => {
|
|
107
|
+
setValue(evt.target.value);
|
|
108
|
+
}} unitkey="length" value={value} initUnit={initUnit} onSwitchUnit={setInitUnit} />
|
|
109
|
+
<Spacer />
|
|
110
|
+
<UnitInput name="example2" onChange={evt => {
|
|
111
|
+
setValue2(evt.target.value);
|
|
112
|
+
}} unitkey="length" value={value2} initUnit={initUnit} onSwitchUnit={setInitUnit} />
|
|
113
|
+
<Divider />
|
|
114
|
+
<h4>Without initUnit property (taken from the redux store)</h4>
|
|
115
|
+
<UnitInput name="example" onChange={evt => {
|
|
116
|
+
setValue(evt.target.value);
|
|
117
|
+
}} unitkey="length" value={value} onSwitchUnit={setInitUnit} />
|
|
118
|
+
<UnitInput name="example2" onChange={evt => {
|
|
119
|
+
setValue2(evt.target.value);
|
|
120
|
+
}} unitkey="length" value={value2} onSwitchUnit={setInitUnit} />
|
|
121
|
+
</>;
|
|
122
|
+
}`,...(gt=(pt=H.parameters)==null?void 0:pt.docs)==null?void 0:gt.source}}};var ht,vt,ft;K.parameters={...K.parameters,docs:{...(ht=K.parameters)==null?void 0:ht.docs,source:{originalSource:`args => {
|
|
123
|
+
const [_, updateArgs] = useArgs();
|
|
124
|
+
const handleChange = (evt: any) => {
|
|
125
|
+
updateArgs({
|
|
126
|
+
value: evt.target.value
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
return <UnitInput {...args} onChange={handleChange} />;
|
|
130
|
+
}`,...(ft=(vt=K.parameters)==null?void 0:vt.docs)==null?void 0:ft.source}}};var Ct,bt,yt;z.parameters={...z.parameters,docs:{...(Ct=z.parameters)==null?void 0:Ct.docs,source:{originalSource:`() => {
|
|
131
|
+
const width = '500px';
|
|
132
|
+
const [value, setValue] = useState<any>(undefined);
|
|
133
|
+
return <>
|
|
134
|
+
<h4>Different edge cases such as +/- infinity, undefined, NaN, null:</h4>
|
|
135
|
+
<Row>
|
|
136
|
+
<Column width="25%">
|
|
137
|
+
<Button label="Change value infinity" onClick={() => setValue(Infinity)} />
|
|
138
|
+
<br />
|
|
139
|
+
<Button label="Change value -infinity" onClick={() => setValue(-Infinity)} />
|
|
140
|
+
<br />
|
|
141
|
+
<Button label="Change value null" onClick={() => setValue(null)} />
|
|
142
|
+
<br />
|
|
143
|
+
<Button label="Change value - undefined" onClick={() => setValue(undefined)} />
|
|
144
|
+
<br />
|
|
145
|
+
<Button label="Change value - NaN" onClick={() => setValue(NaN)} />
|
|
146
|
+
<br />
|
|
147
|
+
<Button label="Change value - nothing (empty)" onClick={() => setValue(undefined)} />
|
|
148
|
+
<br />
|
|
149
|
+
<Button label="Change value - empty string" onClick={() => setValue('')} />
|
|
150
|
+
</Column>
|
|
151
|
+
<Column width="25%">
|
|
152
|
+
<Button label="Change value infinity|m" onClick={() => setValue(Infinity + '|m')} />
|
|
153
|
+
<br />
|
|
154
|
+
<Button label="Change value -infinity|m" onClick={() => setValue(-Infinity + '|m')} />
|
|
155
|
+
<br />
|
|
156
|
+
<Button label="Change value null|m" onClick={() => setValue(null + '|m')} />
|
|
157
|
+
<br />
|
|
158
|
+
<Button label="Change value - undefined|m" onClick={() => setValue(undefined + '|m')} />
|
|
159
|
+
<br />
|
|
160
|
+
<Button label="Change value - NaN|m" onClick={() => setValue(NaN + '|m')} />
|
|
161
|
+
<br />
|
|
162
|
+
<Button label="Change value - nothing (empty)|m" onClick={() => setValue('|m')} />
|
|
163
|
+
</Column>
|
|
164
|
+
</Row>
|
|
165
|
+
<br />
|
|
166
|
+
<Field label="Normal PUI">
|
|
167
|
+
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="value|unit" />
|
|
168
|
+
</Field>
|
|
169
|
+
<Field label="Disabled validation">
|
|
170
|
+
<UnitInput name="example2" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" disabledValidation width={width} />
|
|
171
|
+
</Field>
|
|
172
|
+
<Field label="Disabled validation and manual error">
|
|
173
|
+
<UnitInput name="example3" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" error="test" disabledValidation width={width} />
|
|
174
|
+
</Field>
|
|
175
|
+
<Message message={{
|
|
176
|
+
heading: 'Current value inside PUI: ' + value,
|
|
177
|
+
visible: true
|
|
178
|
+
}} />
|
|
179
|
+
</>;
|
|
180
|
+
}`,...(yt=(bt=z.parameters)==null?void 0:bt.docs)==null?void 0:yt.source}}};var Ut,xt,Vt;ee.parameters={...ee.parameters,docs:{...(Ut=ee.parameters)==null?void 0:Ut.docs,source:{originalSource:`() => {
|
|
181
|
+
const width = '500px';
|
|
182
|
+
const [value, setValue] = useState<string | number>('1|m');
|
|
183
|
+
const [valueB, setValueB] = useState('|m');
|
|
184
|
+
const automaticValue = '123|km';
|
|
185
|
+
return <>
|
|
186
|
+
<h4>Different cases for automatic (placeholder) values:</h4>
|
|
187
|
+
<Row>
|
|
188
|
+
<Column width="25%">
|
|
189
|
+
<Button label="Change value to ''" onClick={() => setValue('')} />
|
|
190
|
+
<br />
|
|
191
|
+
<Button label="Change value to 1" onClick={() => setValue(1)} />
|
|
192
|
+
<br />
|
|
193
|
+
<Button label="Change value to 1|m" onClick={() => setValue('1|m')} />
|
|
194
|
+
<br />
|
|
195
|
+
<Button label="Change value to |m - empty value" onClick={() => setValue('|m')} />
|
|
196
|
+
</Column>
|
|
197
|
+
</Row>
|
|
198
|
+
<br />
|
|
199
|
+
<Field label="Normal PUI (placeholder + auto)">
|
|
200
|
+
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="value|unit" autoValue={automaticValue} />
|
|
201
|
+
</Field>
|
|
202
|
+
<Field label="Normal PUI (only auto)">
|
|
203
|
+
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} autoValue={automaticValue} />
|
|
204
|
+
</Field>
|
|
205
|
+
<Field label="Empty PUI with autoValue">
|
|
206
|
+
<UnitInput name="example1" onChange={evt => setValueB(evt.target.value)} value={valueB} unitkey="length" width={width} autoValue={automaticValue} />
|
|
207
|
+
</Field>
|
|
208
|
+
<Field label="Normal PUI (only placeholder)">
|
|
209
|
+
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="Placeholder test" />
|
|
210
|
+
</Field>
|
|
211
|
+
<Field label="Normal PUI (placeholder + allowEmpty)">
|
|
212
|
+
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="Placeholder test" allowEmpty />
|
|
213
|
+
</Field>
|
|
214
|
+
<Message message={{
|
|
215
|
+
heading: 'Current value inside PUI: ' + value,
|
|
216
|
+
visible: true
|
|
217
|
+
}} />
|
|
218
|
+
</>;
|
|
219
|
+
}`,...(Vt=(xt=ee.parameters)==null?void 0:xt.docs)==null?void 0:Vt.source}}};var jt,It,kt;te.parameters={...te.parameters,docs:{...(jt=te.parameters)==null?void 0:jt.docs,source:{originalSource:`() => {
|
|
220
|
+
const [value, setValue] = useState('123|%');
|
|
221
|
+
const [validation, setValidation] = useState<string | null>(null);
|
|
222
|
+
const predictedMessage = 'This should be visible when an error appears';
|
|
223
|
+
const handleValidation = (name: string, message: string | null) => {
|
|
224
|
+
setValidation(message);
|
|
225
|
+
return {
|
|
226
|
+
name,
|
|
227
|
+
error: message
|
|
228
|
+
};
|
|
229
|
+
};
|
|
230
|
+
return <>
|
|
231
|
+
<h4>3rd party validation message when inputting invalid value:</h4>
|
|
232
|
+
<UnitInput name="example" onChange={evt => setValue(evt.target.value)} error={!validation || predictedMessage} validationCallback={handleValidation} value={value} />
|
|
233
|
+
<br />
|
|
234
|
+
<Spacer />
|
|
235
|
+
<h4>Original validation message: </h4>
|
|
236
|
+
<Message message={{
|
|
237
|
+
heading: validation,
|
|
238
|
+
visible: true
|
|
239
|
+
}} />
|
|
240
|
+
</>;
|
|
241
|
+
}`,...(kt=(It=te.parameters)==null?void 0:It.docs)==null?void 0:kt.source}}};var St,wt,Et;ne.parameters={...ne.parameters,docs:{...(St=ne.parameters)==null?void 0:St.docs,source:{originalSource:`() => {
|
|
242
|
+
const [value, setValue] = useState('123|m');
|
|
243
|
+
const [placeholder, setPlaceholder] = useState('');
|
|
244
|
+
const [initUnit, setInitUnit] = useState('km');
|
|
245
|
+
const setPlaceholderValue = () => {
|
|
246
|
+
setInitUnit('ft');
|
|
247
|
+
setPlaceholder('placeholder');
|
|
248
|
+
setValue('|m');
|
|
249
|
+
};
|
|
250
|
+
return <>
|
|
251
|
+
<h4>Empty value case:</h4>
|
|
252
|
+
<UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} allowEmpty placeholder={placeholder} initUnit={initUnit} unitkey="length" />
|
|
253
|
+
<br />
|
|
254
|
+
<Spacer />
|
|
255
|
+
<Button label="Change value |m and unit ft" onClick={() => setPlaceholderValue()} />
|
|
256
|
+
</>;
|
|
257
|
+
}`,...(Et=(wt=ne.parameters)==null?void 0:wt.docs)==null?void 0:Et.source}}};const Jn=["Default","InitUnit","Width","NoConversion","Small","Error","InternalValidationError","Disabled","DisabledNoConversion","DisabledUnitWithoutUnitKey","DisabledUnitWithUnitKey","DisabledWithEnabledUnitMenu","TestExternalStateChangeWithSynchronizedUnits","PredefinedOptionsMenu","TestEdgeCases","AutomaticValues","ValidationCallback","AllowEmptyPUI"];export{ne as AllowEmptyPUI,ee as AutomaticValues,X as Default,E as Disabled,W as DisabledNoConversion,L as DisabledUnitWithUnitKey,T as DisabledUnitWithoutUnitKey,$ as DisabledWithEnabledUnitMenu,q as Error,F as InitUnit,R as InternalValidationError,O as NoConversion,K as PredefinedOptionsMenu,B as Small,z as TestEdgeCases,H as TestExternalStateChangeWithSynchronizedUnits,te as ValidationCallback,_ as Width,Jn as __namedExportsOrder,zn as default};
|