@oliasoft-open-source/react-ui-library 4.9.0 → 4.9.2
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/index.js +83 -143
- package/dist/index.js.map +1 -1
- package/dist/storybook/assets/{Color-KGDBMAHA-BnHaqcsT.js → Color-KGDBMAHA-sr_lo8VN.js} +1 -1
- package/dist/storybook/assets/{DocsRenderer-PKQXORMH-DcoD1y-5.js → DocsRenderer-PKQXORMH-Dio4TQT6.js} +1 -1
- package/dist/storybook/assets/{accordion.stories-D0wb2n-9.js → accordion.stories-BtQXhKld.js} +2 -2
- package/dist/storybook/assets/{afe.stories-DM18uTAa.js → afe.stories-DFQsvqIV.js} +2 -2
- package/dist/storybook/assets/{buttons-and-links-jPZ2UUsp.js → buttons-and-links-BOcv8xIU.js} +1 -1
- package/dist/storybook/assets/{casing-loads.stories-Dga1QkGC.js → casing-loads.stories-1KCWDoR3.js} +2 -2
- package/dist/storybook/assets/{cell.stories-DfyQwzEH.js → cell.stories-CBq3IOiP.js} +2 -2
- package/dist/storybook/assets/{chunk-HLWAVYOI-D2AwGCE9.js → chunk-HLWAVYOI-SLqzrZ8s.js} +1 -1
- package/dist/storybook/assets/{color-CLf9xt55.js → color-D1FmkH7Y.js} +1 -1
- package/dist/storybook/assets/footer.stories-D-rIL9Q8.js +3 -0
- package/dist/storybook/assets/form.stories-BrUnmw7R.js +49 -0
- package/dist/storybook/assets/{formation.stories-CZGQhWyA.js → formation.stories-ByGQlyM6.js} +2 -2
- package/dist/storybook/assets/iframe-NUuxNiwO.js +2 -0
- package/dist/storybook/assets/{index-Sr04i8ct.js → index-Bhtru3gK.js} +4 -4
- package/dist/storybook/assets/{index-BQ_6rM6u.js → index-DNcuiqfZ.js} +1 -1
- package/dist/storybook/assets/{input-group.stories-EhmORqH9.js → input-group.stories-CElwRt3p.js} +3 -3
- package/dist/storybook/assets/{input-validation-Tr-aD1VJ.js → input-validation-FFJCXfNa.js} +2 -2
- package/dist/storybook/assets/{inputs-BGIgggtv.js → inputs-D3ZjmDIl.js} +1 -1
- package/dist/storybook/assets/{layout-forms-n-mRkolR.js → layout-forms-DNUCHjRh.js} +5 -5
- package/dist/storybook/assets/{layout-general-CNsKoPG6.js → layout-general-CuxE1EOt.js} +1 -1
- package/dist/storybook/assets/{modal.stories-C6Bh0Oda.js → modal.stories-LhoWfDE6.js} +2 -2
- package/dist/storybook/assets/number-input-F3bqJ0z5.js +16 -0
- package/dist/storybook/assets/number-input.stories-Dw2eW2Mc.js +166 -0
- package/dist/storybook/assets/{padding-and-spacing-B10oZ-Ww.js → padding-and-spacing-B-LaxRb4.js} +1 -1
- package/dist/storybook/assets/{pagination-DWc8zp3k.js → pagination-CLt-kUlx.js} +1 -1
- package/dist/storybook/assets/{pagination.stories-B5cOvzik.js → pagination.stories-CTRM0Xou.js} +2 -2
- package/dist/storybook/assets/popover.stories-CGm0M5fv.js +10 -0
- package/dist/storybook/assets/{preview-Cym3ID9p.js → preview-ClcAw55r.js} +2 -2
- package/dist/storybook/assets/{preview-pQMX-q5x.js → preview-DQgT2zeu.js} +1 -1
- package/dist/storybook/assets/{projects.stories-Co_WnKSx.js → projects.stories-BQswWVCx.js} +2 -2
- package/dist/storybook/assets/{radio-button-C4ljBRED.js → radio-button-DmDuw4DA.js} +1 -1
- package/dist/storybook/assets/{radio-button.stories-BzyW2CtK.js → radio-button.stories-5gvV0LD0.js} +2 -2
- package/dist/storybook/assets/{reservoirs.stories-UW_8sofe.js → reservoirs.stories-B12tIrmZ.js} +2 -2
- package/dist/storybook/assets/{rich-text-input.stories-0pm7-gTq.js → rich-text-input.stories-hAHCnDHk.js} +3 -3
- package/dist/storybook/assets/{row.stories-B8OWE9yd.js → row.stories-ghcsAzwW.js} +2 -2
- package/dist/storybook/assets/select-DnRuRG_N.js +61 -0
- package/dist/storybook/assets/select.input-D0UkAPd9.js +1 -0
- package/dist/storybook/assets/{select.stories-B0KIHiMX.js → select.stories-B9w9ONzj.js} +2 -2
- package/dist/storybook/assets/{site.stories-ZGohyW6Z.js → site.stories-umpPYjkq.js} +2 -2
- package/dist/storybook/assets/{table-qmf29AIJ.js → table-BCdvBxub.js} +1 -1
- package/dist/storybook/assets/{table.stories-DzHGqXth.js → table.stories-DkmbUVHr.js} +2 -2
- package/dist/storybook/assets/{tabs-BoToLVEP.js → tabs-C3NG6m9W.js} +1 -1
- package/dist/storybook/assets/tabs.stories-dsXjRHJy.js +30 -0
- package/dist/storybook/assets/{title.stories-B8l1sfdo.js → title.stories-DpFDK9o1.js} +3 -3
- package/dist/storybook/assets/unit-input.stories-BHTxKnOU.js +380 -0
- package/dist/storybook/assets/unit-table.stories-u1PeEt0F.js +152 -0
- package/dist/storybook/iframe.html +1 -1
- package/dist/storybook/index.json +1 -1
- package/dist/storybook/project.json +1 -1
- package/package.json +1 -1
- package/dist/storybook/assets/enum-Bnn40S8Q.js +0 -1
- package/dist/storybook/assets/footer.stories-DYBxUtZh.js +0 -3
- package/dist/storybook/assets/form.stories-BLcmnfy8.js +0 -49
- package/dist/storybook/assets/helpers-JJxzGegQ.js +0 -1
- package/dist/storybook/assets/iframe-BnDar59m.js +0 -2
- package/dist/storybook/assets/number-input-DZ9ERbK_.js +0 -16
- package/dist/storybook/assets/number-input.stories-CmVUHT2d.js +0 -124
- package/dist/storybook/assets/popover.stories-p9_-pH_Q.js +0 -10
- package/dist/storybook/assets/select-03uRbc4I.js +0 -61
- package/dist/storybook/assets/select.input-CJed_LLR.js +0 -1
- package/dist/storybook/assets/tabs.stories-B52iEaHf.js +0 -30
- package/dist/storybook/assets/unit-input.stories-BnLB_Avl.js +0 -316
- package/dist/storybook/assets/unit-table.stories-DquyyMbD.js +0 -152
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./jsx-runtime-eps93zm2.js";import{r as I}from"./index-DhsZuJvc.js";import{T as b}from"./tabs-BoToLVEP.js";import"./index-Bk2sglWO.js";import"./disabled-context-rmpd7YJS.js";import"./lodash-c4VUpsOs.js";import"./badge-CLQ59MDF.js";import"./select.input-CJed_LLR.js";import"./helpers-JJxzGegQ.js";import"./types-BmbYqTX_.js";const U={title:"Navigation/Tabs",component:b,args:{name:"example",options:[{label:"Tab",value:0},{label:"Tab",value:1},{label:"With Badge",value:2,badge:"3"},{label:"Invalid",value:3,invalid:!0},{label:"Disabled",value:4,disabled:!0},{label:"Hidden tab",value:5,hidden:!0}],value:0}},s=i=>e.jsx(b,{...i}),d=s.bind({}),r=s.bind({});r.args={children:[e.jsx("div",{label:"Tab 0",children:e.jsx("h3",{children:"Tab 0 Content"})}),e.jsx("div",{label:"Tab 1",hidden:!0,children:e.jsx("h3",{children:"Tab 1 Content"})}),e.jsx("div",{label:"Tab 2",disabled:!0,children:e.jsx("h3",{children:"Tab 2 Content"})}),e.jsx("div",{label:"Tab 3",children:e.jsx("h3",{children:"Tab 3 Content"})}),e.jsx("div",{label:"Tab 4",children:e.jsx("h3",{children:"Tab 4 Content"})})]};const l=s.bind({});l.args={margin:!1};const a=s.bind({});a.parameters={layout:"fullscreen",docs:{description:{story:"When you want the divider to fill the edges of its container."}}};a.args={padding:!0};const t=s.bind({});t.args={options:[{label:"Tab 0",value:0},{label:"Tab 1",value:1},{label:"Tab 2",value:2},{label:"Tab 3",value:3,right:!0},{label:"Tab 4",value:4,right:!0}]};const o=()=>{const i=[{label:"Strawberries",value:"strawberries"},{label:"Bananas",value:"bananas"},{label:"Apples",value:"apples",disabled:!0},{label:"Pomegranates",value:"pomegranates"}],[p,D]=I.useState(i[0]);return e.jsxs(e.Fragment,{children:[e.jsx(b,{name:"example",value:p,options:i,onChange:c=>{const{value:H,label:z}=(c==null?void 0:c.target)??{};D({value:H,label:z})}}),e.jsxs("span",{children:["Eating ",p.value,"..."]})]})},n=s.bind({});n.args={options:[{label:"Title Case Label",value:0},{label:"Mixed case label",value:1},{label:"lower case label",value:2}]};o.__docgenInfo={description:"",methods:[],displayName:"Managed"};var u,m,g;d.parameters={...d.parameters,docs:{...(u=d.parameters)==null?void 0:u.docs,source:{originalSource:"args => <Tabs {...args} />",...(g=(m=d.parameters)==null?void 0:m.docs)==null?void 0:g.source}}};var T,v,h;r.parameters={...r.parameters,docs:{...(T=r.parameters)==null?void 0:T.docs,source:{originalSource:"args => <Tabs {...args} />",...(h=(v=r.parameters)==null?void 0:v.docs)==null?void 0:h.source}}};var x,j,S;l.parameters={...l.parameters,docs:{...(x=l.parameters)==null?void 0:x.docs,source:{originalSource:"args => <Tabs {...args} />",...(S=(j=l.parameters)==null?void 0:j.docs)==null?void 0:S.source}}};var C,f,w;a.parameters={...a.parameters,docs:{...(C=a.parameters)==null?void 0:C.docs,source:{originalSource:"args => <Tabs {...args} />",...(w=(f=a.parameters)==null?void 0:f.docs)==null?void 0:w.source}}};var M,y,E;t.parameters={...t.parameters,docs:{...(M=t.parameters)==null?void 0:M.docs,source:{originalSource:"args => <Tabs {...args} />",...(E=(y=t.parameters)==null?void 0:y.docs)==null?void 0:E.source}}};var _,A,N;o.parameters={...o.parameters,docs:{...(_=o.parameters)==null?void 0:_.docs,source:{originalSource:`() => {
|
|
2
|
-
const options = [{
|
|
3
|
-
label: 'Strawberries',
|
|
4
|
-
value: 'strawberries'
|
|
5
|
-
}, {
|
|
6
|
-
label: 'Bananas',
|
|
7
|
-
value: 'bananas'
|
|
8
|
-
}, {
|
|
9
|
-
label: 'Apples',
|
|
10
|
-
value: 'apples',
|
|
11
|
-
disabled: true
|
|
12
|
-
}, {
|
|
13
|
-
label: 'Pomegranates',
|
|
14
|
-
value: 'pomegranates'
|
|
15
|
-
}];
|
|
16
|
-
const [selectedTab, setSelectedTab] = useState(options[0]);
|
|
17
|
-
return <>
|
|
18
|
-
<Tabs name="example" value={selectedTab} options={options} onChange={evt => {
|
|
19
|
-
const {
|
|
20
|
-
value,
|
|
21
|
-
label
|
|
22
|
-
} = ((evt?.target ?? {}) as any);
|
|
23
|
-
setSelectedTab({
|
|
24
|
-
value,
|
|
25
|
-
label
|
|
26
|
-
});
|
|
27
|
-
}} />
|
|
28
|
-
<span>Eating {selectedTab.value}...</span>
|
|
29
|
-
</>;
|
|
30
|
-
}`,...(N=(A=o.parameters)==null?void 0:A.docs)==null?void 0:N.source}}};var P,W,B;n.parameters={...n.parameters,docs:{...(P=n.parameters)==null?void 0:P.docs,source:{originalSource:"args => <Tabs {...args} />",...(B=(W=n.parameters)==null?void 0:W.docs)==null?void 0:B.source}}};const V=["Default","WithChildren","NoMargin","HorizontalPadding","Alignment","Managed","TestTitleCase"];export{t as Alignment,d as Default,a as HorizontalPadding,o as Managed,l as NoMargin,n as TestTitleCase,r as WithChildren,V as __namedExportsOrder,U as default};
|
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./jsx-runtime-eps93zm2.js";import{r as m}from"./index-DhsZuJvc.js";import{d as l}from"./index-C0x1JmaP.js";import{c as Un}from"./index-Bk2sglWO.js";import{u as wn}from"./use-previous-D775JrO6.js";import{M as Ee}from"./actions-D-uVCDzk.js";import{I as xn}from"./input-group-addon-D68iUKV2.js";import{B as g}from"./button-DHevvVBE.js";import{T as In}from"./tooltip-1V7clEnw.js";import{I as Tn}from"./input-group-BaRSJAEN.js";import{S as I}from"./spacer-BWoNR27H.js";import{T as Yt}from"./text-B3-TSWok.js";import{M as Ne}from"./types-BmbYqTX_.js";import{l as V}from"./lodash-c4VUpsOs.js";import{i as Vn}from"./helpers-JJxzGegQ.js";import{N as kn}from"./number-input-DZ9ERbK_.js";import{D as jn}from"./divider-DY9nJ_7N.js";import{R as Zt,C as ye}from"./row-Bmiy2Lh0.js";import{F as T}from"./field-HrLaMLbx.js";import{M as be}from"./message-Y48EomV-.js";import{w as de,u as d,e as w,f as Qt,a as Xt}from"./index-DMAnyMX5.js";import"./index-DRSy5Ssd.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"./enum-Bnn40S8Q.js";import"./input-DTXbDJaL.js";import"./styled-components.browser.esm-BQ9GQzDc.js";import"./label-CqmyC9he.js";import"./help-icon-Buhx5nl6.js";import"./index-CF7H4eMJ.js";const Sn=()=>{const t=m.useRef(null);return m.useLayoutEffect(()=>{t.current&&(t.current(),t.current=null)}),n=>{t.current=n}},En=(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.`),l.unitFromQuantity(t)??"")};var b=(t=>(t.CUSTOM="custom",t.PREDEFINED="predefined",t))(b||{});const en=t=>t==="undefined"||t===void 0||t===""||t==="null"||t===null||t==="NaN"||isNaN(t),tn=(t="",a,n="",s=!1)=>{if(s)return t;if(a&&!en(t))try{const i=l.isValueWithUnit(t)?t:l.withUnit(t,n),p=l.convertSamePrecision(i,a);return l.getValue(p)}catch{}return t},Nn=t=>t?!!l.getUnit(t):!1,O=(t="",a,n,s)=>{if(s)return t;const i=Nn(t)||l.isValueWithUnit(t),p=l.getValue(t);return en(p)?p:i?tn(p,a,n,s):t},Ae=t=>V.isObject(t)&&!V.isArray(t)&&!V.isFunction(t)?V.get(t,"fieldName",""):typeof t=="string"?t:"",qe=(t="")=>{var a;return(a=l.KNOWN_UNITS)==null?void 0:a.includes(t)},An=(t,a)=>{const n=l.getUnit(t||"");return qe(a)&&qe(n)};let qn=m.createContext(null);const Dn=()=>m.useContext(qn),Fn="_predefinedMenuActive_ye9w9_1",Pn="_inputWrapper_ye9w9_4",De={predefinedMenuActive:Fn,inputWrapper:Pn},c=({name:t,placeholder:a="",disabled:n=!1,disabledUnit:s=!1,error:i=null,left:p=!1,small:o=!1,width:h="100%",value:v,unitkey:ie="",initUnit:nn,noConversion:an=!1,onChange:ce=V.noop,onClick:_n=V.noop,onFocus:rn=V.noop,onSwitchUnit:Ce=V.noop,unitTemplate:Ue,doNotConvertValue:B=!1,testId:E,warning:we=null,predefinedOptions:x,initialPredefinedOption:sn=!1,shouldLinkAutomaticly:xe=!0,selectedPredefinedOptionKey:Ie,validationCallback:ln=()=>({name:"",error:null}),disabledValidation:un=!1,allowEmpty:on=!1,autoValue:k})=>{const N=Dn(),dn=Sn();typeof v=="number"&&(v=`${v}`);const[Te="",_=""]=v!==void 0?l.split(v):[],Ve=k?l.getUnit(k):"",ke=m.useMemo(()=>En(ie,Ue||(N==null?void 0:N.unitTemplate)),[ie,Ue,N==null?void 0:N.unitTemplate]),cn=An(v,ke),C=nn||ke||_,mn=wn(C),je=O(v,C,_,B),Se=O(k,C,Ve,B),pn=je!==""?{value:je,unit:C}:Se!==""?{value:Se,unit:C}:{value:Te,unit:_},[f,me]=m.useState(pn),[j,pe]=m.useState(sn?b.PREDEFINED:b.CUSTOM),ge=Te===""&&k,gn=!!(un||k||a&&Vn(v)),M=x&&x.find(r=>{if(!(r!=null&&r.value))return;if(Ie)return Ie===r.valueKey;const u=l.isValueWithUnit(r.value)?l.getUnit(r.value):"";return l.withUnit(tn(v,u),u)===r.value}),hn=()=>{if(ie)try{const r=ge?k:v??"";let u=l.altUnitsList(r,ie);return l.getValue(r)===""?u.map(U=>["",U[1]]):u}catch{return null}},vn=r=>{const u=Ae(t),U=r.target,{value:S,selectionStart:ue}=U,ve=l.withUnit(S,(f==null?void 0:f.unit)||"");ce({target:{value:ve,name:u}});const[fe,Cn]=l.split(ve);me({value:fe,unit:Cn}),dn(()=>{U.selectionStart=ue,U.selectionEnd=ue})},fn=(r,u)=>{u===f.unit||isNaN(Number(r))||(me({value:r,unit:u}),Ce&&Ce(u))};m.useEffect(()=>{if(C){let r,u="";mn!==C?(r=O(v,C,_,B),u=C):l.withUnit(f.value,f.unit)!==v&&(r=O(v,f.unit,_,B),u=f.unit),r!==void 0&&me({value:r,unit:u}),x&&pe(M&&xe?b.PREDEFINED:b.CUSTOM)}},[C,v,i,xe]);const re=hn(),se=l.label(f.unit)||f.unit||"",yn=an||!re||re&&re.length===1,he=Ae(t);let le;const bn=r=>{const u=r!=null&&r.value?r.value:"",[U="",S=""]=l.isValueWithUnit(u)?l.split(u):[u];return{type:Ne.OPTION,inline:!0,onClick:()=>{l.validateNumber(U).valid&&!n&&(pe(b.PREDEFINED),ce({target:{value:u,name:typeof t=="string"?t:(t==null?void 0:t.fieldName)||"",predefinedSelected:!0,predefinedOption:r}}))},label:e.jsxs(e.Fragment,{children:[e.jsx(Yt,{children:r.label}),e.jsx(I,{width:"20px",height:"0"})]}),description:l.isValueWithUnit(u)?`${U} ${S}`:u,selected:M===r&&j===b.PREDEFINED}};if(le=[{type:Ne.OPTION,inline:!0,onClick:()=>{j!==b.CUSTOM&&!n&&ce({target:{value:l.withUnit(f.value,f.unit),name:typeof t=="string"?t:(t==null?void 0:t.fieldName)||""}})},label:"Custom",selected:j===b.CUSTOM}],x!=null&&x.length){const r=x.map(bn);le=[...le,...r]}return e.jsx("div",{className:j===b.PREDEFINED?Un(De.predefinedMenuActive):"",children:e.jsxs(Tn,{small:o,width:h,children:[x&&e.jsx(In,{text:j===b.PREDEFINED?M==null?void 0:M.label:"",children:e.jsx(Ee,{maxHeight:380,groupOrder:"first",testId:E&&`${E}-predefined-menu`,disabled:n,menu:{colored:!0,trigger:"Component",component:e.jsx(g,{groupOrder:"first",active:j===b.PREDEFINED,icon:j===b.PREDEFINED?"link":"unlink"}),small:o,sections:le}})}),e.jsx("div",{className:De.inputWrapper,children:e.jsx(kn,{name:he,testId:E,disabled:n,placeholder:ge?O(k,f.unit,Ve,B):a,value:f.value,onChange:vn,onFocus:rn,error:i===null?void 0:i,warning:we===null?void 0:we,left:p,allowEmpty:on,validationCallback:(r,u)=>ln(he,u),groupOrder:x?"middle":"first",disableInternalErrorValidationMessages:gn},he)}),se&&(yn||!cn?e.jsx(xn,{groupOrder:"last",children:se}):e.jsx(Ee,{maxHeight:380,groupOrder:"last",disabled:s,testId:E&&`${E}-menu`,menu:{label:se,trigger:"DropDownButton",small:o,sections:re.map(([r,u,U])=>{const S=U||u||"";return{type:"Option",label:isNaN(Number(r))?"":r,inline:!0,onClick:fe=>{fe.stopPropagation(),fn(ge?"":r,u)},description:S,selected:S===se,testId:`${E}-unit-${S}`}})}}))]})})};c.__docgenInfo={description:"",methods:[],displayName:"UnitInput",props:{name:{required:!0,tsType:{name:"union",raw:"string | { fieldName?: string }",elements:[{name:"string"},{name:"signature",type:"object",raw:"{ fieldName?: string }",signature:{properties:[{key:"fieldName",value:{name:"string",required:!1}}]}}]},description:""},placeholder:{required:!1,tsType:{name:"string"},description:"",defaultValue:{value:"''",computed:!1}},disabled:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},disabledUnit:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},error:{required:!1,tsType:{name:"union",raw:"string | null | boolean",elements:[{name:"string"},{name:"null"},{name:"boolean"}]},description:"",defaultValue:{value:"null",computed:!1}},left:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},small:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},width:{required:!1,tsType:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},description:"",defaultValue:{value:"'100%'",computed:!1}},value:{required:!1,tsType:{name:"string"},description:""},unitkey:{required:!1,tsType:{name:"string"},description:"",defaultValue:{value:"''",computed:!1}},initUnit:{required:!1,tsType:{name:"string"},description:""},noConversion:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},doNotConvertValue:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},testId:{required:!1,tsType:{name:"string"},description:""},warning:{required:!1,tsType:{name:"union",raw:"string | boolean | null",elements:[{name:"string"},{name:"boolean"},{name:"null"}]},description:"",defaultValue:{value:"null",computed:!1}},predefinedOptions:{required:!1,tsType:{name:"union",raw:"IPredefinedOption[] | null",elements:[{name:"Array",elements:[{name:"IPredefinedOption"}],raw:"IPredefinedOption[]"},{name:"null"}]},description:""},initialPredefinedOption:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},shouldLinkAutomaticly:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},selectedPredefinedOptionKey:{required:!1,tsType:{name:"string"},description:""},validationCallback:{required:!1,tsType:{name:"signature",type:"function",raw:"(name: string, error: string | null) => any",signature:{arguments:[{type:{name:"string"},name:"name"},{type:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}]},name:"error"}],return:{name:"any"}}},description:"",defaultValue:{value:"() => ({ name: '', error: null })",computed:!1}},disabledValidation:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},allowEmpty:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},autoValue:{required:!1,tsType:{name:"string"},description:""},onChange:{required:!1,tsType:{name:"signature",type:"function",raw:"(event: TChangeEvent | ICustomChangeEvent) => void",signature:{arguments:[{type:{name:"union",raw:"TChangeEvent | ICustomChangeEvent",elements:[{name:"intersection",raw:`ChangeEvent<T> & {
|
|
2
|
-
target:
|
|
3
|
-
| T
|
|
4
|
-
| { name: string; value: any; label?: string; files?: FileList | null };
|
|
5
|
-
}`,elements:[{name:"ChangeEvent",elements:[{name:"T"}],raw:"ChangeEvent<T>"},{name:"signature",type:"object",raw:`{
|
|
6
|
-
target:
|
|
7
|
-
| T
|
|
8
|
-
| { name: string; value: any; label?: string; files?: FileList | null };
|
|
9
|
-
}`,signature:{properties:[{key:"target",value:{name:"union",raw:`| T
|
|
10
|
-
| { name: string; value: any; label?: string; files?: FileList | null }`,elements:[{name:"T"},{name:"signature",type:"object",raw:"{ name: string; value: any; label?: string; files?: FileList | null }",signature:{properties:[{key:"name",value:{name:"string",required:!0}},{key:"value",value:{name:"any",required:!0}},{key:"label",value:{name:"string",required:!1}},{key:"files",value:{name:"union",raw:"FileList | null",elements:[{name:"FileList"},{name:"null"}],required:!1}}]}}],required:!0}}]}}]},{name:"ICustomChangeEvent"}]},name:"event"}],return:{name:"void"}}},description:"",defaultValue:{value:"noop",computed:!0}},onSwitchUnit:{required:!1,tsType:{name:"signature",type:"function",raw:"(unit: string) => void",signature:{arguments:[{type:{name:"string"},name:"unit"}],return:{name:"void"}}},description:"",defaultValue:{value:"noop",computed:!0}},onClick:{required:!1,tsType:{name:"MouseEventHandler",elements:[{name:"HTMLInputElement"}],raw:"MouseEventHandler<HTMLInputElement>"},description:"",defaultValue:{value:"noop",computed:!0}},onFocus:{required:!1,tsType:{name:"FocusEventHandler",elements:[{name:"HTMLInputElement"}],raw:"FocusEventHandler<HTMLInputElement>"},description:"",defaultValue:{value:"noop",computed:!0}},unitTemplate:{required:!1,tsType:{name:"Record",elements:[{name:"string"},{name:"any"}],raw:"Record<string, any>"},description:""}}};const{useArgs:Bn}=__STORYBOOK_MODULE_PREVIEW_API__,xa={title:"Forms/UnitInput",component:c,args:{name:"example",unitkey:"length",value:"123|m"}},y=t=>{const[a,n]=Bn(),s=i=>{n({value:i.target.value})};return e.jsx(c,{...t,onChange:s})},oe=y.bind({}),W=y.bind({});W.args={initUnit:"ft",unitTemplate:{length:"ft"}};const R=y.bind({});R.args={value:'123|"',unitkey:'"'};const L=y.bind({});L.args={width:"180px"};const H=y.bind({});H.args={noConversion:!0};const K=y.bind({});K.args={small:!0};const A=()=>{const[t,a]=m.useState("123|m");return e.jsx(c,{name:"example",onChange:n=>a(n.target.value),placeholder:"Type a value...",value:t,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"},testId:"testId"})};A.play=async({canvasElement:t,step:a})=>{const n=de(t),s=de(t.ownerDocument.body);await a("Shows validation error for non-numeric input",async()=>{const i=n.getByTestId("testId");await d.clear(i),await d.type(i,"123x45s6"),await d.click(t),await w(n.getByDisplayValue("123x45s6")).toBeInTheDocument(),await Qt.mouseOver(i),await Xt(()=>{w(s.getByText("Must be a numerical value")).toBeInTheDocument()})})};const $=y.bind({});$.args={error:"Error message goes here"};const G=y.bind({});G.args={value:"asas123asd|%"};const q=y.bind({});q.args={disabled:!0,disabledUnit:!0};q.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 z=y.bind({});z.args={disabled:!0,disabledUnit:!0,noConversion:!0};const J=y.bind({});J.args={disabledUnit:!0,unitkey:void 0};const Y=y.bind({});Y.args={disabledUnit:!0,unitkey:"length"};const Z=y.bind({});Z.args={disabledUnit:!1,disabled:!0};const D=t=>{const[a,n]=m.useState("123|m"),[s,i]=m.useState("223|m"),[p,o]=m.useState("ft");return e.jsxs(e.Fragment,{children:[e.jsx(g,{label:"Change initUnit",onClick:()=>o(p==="m"?"ft":"m")}),e.jsx(I,{}),e.jsx(g,{label:"Change value",onClick:()=>n(a==="123|m"?"456|m":"123|m")}),e.jsx(I,{}),e.jsx(c,{name:"example",onChange:h=>{n(h.target.value)},unitkey:"length",value:a,initUnit:p,onSwitchUnit:o}),e.jsx(I,{}),e.jsx(c,{name:"example2",onChange:h=>{i(h.target.value)},unitkey:"length",value:s,initUnit:p,onSwitchUnit:o}),e.jsx(jn,{}),e.jsx("h4",{children:"Without initUnit property (taken from the redux store)"}),e.jsx(c,{name:"example",onChange:h=>{n(h.target.value)},unitkey:"length",value:a,onSwitchUnit:o}),e.jsx(c,{name:"example2",onChange:h=>{i(h.target.value)},unitkey:"length",value:s,onSwitchUnit:o})]})};D.parameters={docs:{description:{story:"[OW-4380](https://oliasoft.atlassian.net/browse/OW-4380?atlOrigin=eyJpIjoiMmM1N2RkNWU3Mjk5NDYxY2E0YzhkMzk5ZTVmZTJhMjciLCJwIjoiaiJ9)"}}};const Q=y.bind({});Q.args={predefinedOptions:[{label:"bottom of casing",value:"12|km"},{label:"mud weight at shoe depth",value:"8|mm"}]};const F=()=>{const t="500px",[a,n]=m.useState(void 0);return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different edge cases such as +/- infinity, undefined, NaN, null:"}),e.jsxs(Zt,{children:[e.jsxs(ye,{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(ye,{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(c,{name:"example1",onChange:s=>n(s.target.value),value:a,unitkey:"length",width:t,placeholder:"value|unit"})}),e.jsx(T,{label:"Disabled validation",children:e.jsx(c,{name:"example2",onChange:s=>n(s.target.value),value:a,unitkey:"length",disabledValidation:!0,width:t})}),e.jsx(T,{label:"Disabled validation and manual error",children:e.jsx(c,{name:"example3",onChange:s=>n(s.target.value),value:a,unitkey:"length",error:"test",disabledValidation:!0,width:t})}),e.jsx(be,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})},X=()=>{const t="500px",[a,n]=m.useState("1|m"),[s,i]=m.useState("|m"),p="123|km";return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different cases for automatic (placeholder) values:"}),e.jsx(Zt,{children:e.jsxs(ye,{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(c,{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(c,{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(c,{name:"example1",onChange:o=>i(o.target.value),value:s,unitkey:"length",width:t,autoValue:p})}),e.jsx(T,{label:"Normal PUI (only placeholder)",children:e.jsx(c,{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(c,{name:"example1",onChange:o=>n(o.target.value),value:a,unitkey:"length",width:t,placeholder:"Placeholder test",allowEmpty:!0})}),e.jsx(be,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})};F.parameters={docs:{description:{story:"[OW-8884](https://oliasoft.atlassian.net/browse/OW-8884)"}}};const ee=()=>{const[t,a]=m.useState("123|%"),[n,s]=m.useState(null),i="This should be visible when an error appears",p=(o,h)=>(s(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(c,{name:"example",onChange:o=>a(o.target.value),error:!n||i,validationCallback:p,value:t}),e.jsx("br",{}),e.jsx(I,{}),e.jsx("h4",{children:"Original validation message: "}),e.jsx(be,{message:{heading:n,visible:!0}})]})},te=()=>{const[t,a]=m.useState("123|m"),[n,s]=m.useState(""),[i,p]=m.useState("km"),o=()=>{p("ft"),s("placeholder"),a("|m")};return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Empty value case:"}),e.jsx(c,{name:"example",onChange:h=>a(h.target.value),value:t,allowEmpty:!0,placeholder:n,initUnit:i,unitkey:"length"}),e.jsx("br",{}),e.jsx(I,{}),e.jsx(g,{label:"Change value |m and unit ft",onClick:()=>o()})]})},ne=()=>{const[t,a]=m.useState("123|m"),[n,s]=m.useState("m");return e.jsxs(e.Fragment,{children:[e.jsx(c,{name:"example",onChange:i=>a(i.target.value),value:t,initUnit:n,unitkey:"length",onSwitchUnit:s}),e.jsx(I,{}),e.jsx(c,{name:"example",onChange:i=>a(i.target.value),value:t,initUnit:n,unitkey:"length",onSwitchUnit:s})]})},ae=()=>e.jsxs(e.Fragment,{children:[e.jsx(Yt,{faint:!0,children:"Reproduce OW-10614 rounding noise bug when storing values in a different unit to the display unit"}),e.jsx(I,{}),e.jsx(c,{name:"example",onChange:()=>{},value:l.withUnit(l.convertAndGetValue("9750|psi","bar"),"bar"),initUnit:"psi",unitkey:"pressure",unitTemplate:{pressure:"psi"}}),e.jsx(I,{}),e.jsx(c,{name:"example2",onChange:()=>{},value:l.withUnit(l.convertAndGetValue("8642|lbf","tonneForce"),"tonneForce"),initUnit:"lbf",unitkey:"force",unitTemplate:{force:"tonneForce"}})]}),P=()=>{const[t,a]=m.useState("123|m");return e.jsx(c,{name:"example",onChange:n=>a(n.target.value),value:t,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"},testId:"testId"})};P.play=async({canvasElement:t,step:a})=>{const n=de(t),s=de(t.ownerDocument.body);await a("Can enter decimal values",async()=>{const i=n.getByTestId("testId");await d.clear(i),await d.type(i,"123.123456789"),await d.click(t),await w(n.getByDisplayValue("123.123456789")).toBeInTheDocument()}),await a("Can enter scientific notation",async()=>{const i=n.getByTestId("testId");await d.clear(i),await d.type(i,"-1.12e3"),await d.click(t),await w(n.getByDisplayValue("-1.12e3")).toBeInTheDocument()}),await a("Can enter comma decimals (converts to dot)",async()=>{const i=n.getByTestId("testId");await d.clear(i),await d.type(i,"123,456"),await d.click(t),await w(n.getByDisplayValue("123.456")).toBeInTheDocument()}),await a("Can enter small numbers",async()=>{const i=n.getByTestId("testId");await d.clear(i),await d.type(i,"0.0000000023"),await d.click(t),await w(n.getByDisplayValue("0.0000000023")).toBeInTheDocument()}),await a("Can enter large numbers",async()=>{const i=n.getByTestId("testId");await d.clear(i),await d.type(i,"999999999999"),await d.click(t),await w(n.getByDisplayValue("999999999999")).toBeInTheDocument()}),await a("Can convert units",async()=>{const i=n.getByTestId("testId"),p=n.getByTestId("testId-menu");await d.clear(i),await d.type(i,"456.1"),await d.click(t),await d.click(p),await d.click(s.getByTestId("testId-unit-ft")),await w(n.getByDisplayValue("1496")).toBeInTheDocument()}),await a("Shows validation error for non-numeric input",async()=>{const i=n.getByTestId("testId");await d.clear(i),await d.type(i,"123x45s6"),await d.click(t),await w(n.getByDisplayValue("123x45s6")).toBeInTheDocument(),await Qt.mouseOver(i),await Xt(()=>{w(s.getByText("Must be a numerical value")).toBeInTheDocument()})})};A.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"Placeholder"};D.__docgenInfo={description:"",methods:[],displayName:"TestExternalStateChangeWithSynchronizedUnits",props:{name:{required:!0,tsType:{name:"union",raw:"string | { fieldName?: string }",elements:[{name:"string"},{name:"signature",type:"object",raw:"{ fieldName?: string }",signature:{properties:[{key:"fieldName",value:{name:"string",required:!1}}]}}]},description:""},placeholder:{required:!1,tsType:{name:"string"},description:""},disabled:{required:!1,tsType:{name:"boolean"},description:""},disabledUnit:{required:!1,tsType:{name:"boolean"},description:""},error:{required:!1,tsType:{name:"union",raw:"string | null | boolean",elements:[{name:"string"},{name:"null"},{name:"boolean"}]},description:""},left:{required:!1,tsType:{name:"boolean"},description:""},small:{required:!1,tsType:{name:"boolean"},description:""},width:{required:!1,tsType:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},description:""},value:{required:!1,tsType:{name:"string"},description:""},unitkey:{required:!1,tsType:{name:"string"},description:""},initUnit:{required:!1,tsType:{name:"string"},description:""},noConversion:{required:!1,tsType:{name:"boolean"},description:""},doNotConvertValue:{required:!1,tsType:{name:"boolean"},description:""},testId:{required:!1,tsType:{name:"string"},description:""},warning:{required:!1,tsType:{name:"union",raw:"string | boolean | null",elements:[{name:"string"},{name:"boolean"},{name:"null"}]},description:""},predefinedOptions:{required:!1,tsType:{name:"union",raw:"IPredefinedOption[] | null",elements:[{name:"Array",elements:[{name:"IPredefinedOption"}],raw:"IPredefinedOption[]"},{name:"null"}]},description:""},initialPredefinedOption:{required:!1,tsType:{name:"boolean"},description:""},shouldLinkAutomaticly:{required:!1,tsType:{name:"boolean"},description:""},selectedPredefinedOptionKey:{required:!1,tsType:{name:"string"},description:""},validationCallback:{required:!1,tsType:{name:"signature",type:"function",raw:"(name: string, error: string | null) => any",signature:{arguments:[{type:{name:"string"},name:"name"},{type:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}]},name:"error"}],return:{name:"any"}}},description:""},disabledValidation:{required:!1,tsType:{name:"boolean"},description:""},allowEmpty:{required:!1,tsType:{name:"boolean"},description:""},autoValue:{required:!1,tsType:{name:"string"},description:""},onChange:{required:!1,tsType:{name:"signature",type:"function",raw:"(event: TChangeEvent | ICustomChangeEvent) => void",signature:{arguments:[{type:{name:"union",raw:"TChangeEvent | ICustomChangeEvent",elements:[{name:"intersection",raw:`ChangeEvent<T> & {
|
|
11
|
-
target:
|
|
12
|
-
| T
|
|
13
|
-
| { name: string; value: any; label?: string; files?: FileList | null };
|
|
14
|
-
}`,elements:[{name:"ChangeEvent",elements:[{name:"T"}],raw:"ChangeEvent<T>"},{name:"signature",type:"object",raw:`{
|
|
15
|
-
target:
|
|
16
|
-
| T
|
|
17
|
-
| { name: string; value: any; label?: string; files?: FileList | null };
|
|
18
|
-
}`,signature:{properties:[{key:"target",value:{name:"union",raw:`| T
|
|
19
|
-
| { name: string; value: any; label?: string; files?: FileList | null }`,elements:[{name:"T"},{name:"signature",type:"object",raw:"{ name: string; value: any; label?: string; files?: FileList | null }",signature:{properties:[{key:"name",value:{name:"string",required:!0}},{key:"value",value:{name:"any",required:!0}},{key:"label",value:{name:"string",required:!1}},{key:"files",value:{name:"union",raw:"FileList | null",elements:[{name:"FileList"},{name:"null"}],required:!1}}]}}],required:!0}}]}}]},{name:"ICustomChangeEvent"}]},name:"event"}],return:{name:"void"}}},description:""},onSwitchUnit:{required:!1,tsType:{name:"signature",type:"function",raw:"(unit: string) => void",signature:{arguments:[{type:{name:"string"},name:"unit"}],return:{name:"void"}}},description:""},onClick:{required:!1,tsType:{name:"MouseEventHandler",elements:[{name:"HTMLInputElement"}],raw:"MouseEventHandler<HTMLInputElement>"},description:""},onFocus:{required:!1,tsType:{name:"FocusEventHandler",elements:[{name:"HTMLInputElement"}],raw:"FocusEventHandler<HTMLInputElement>"},description:""},unitTemplate:{required:!1,tsType:{name:"Record",elements:[{name:"string"},{name:"any"}],raw:"Record<string, any>"},description:""}}};F.__docgenInfo={description:"",methods:[],displayName:"TestEdgeCases"};X.__docgenInfo={description:"",methods:[],displayName:"AutomaticValues"};ee.__docgenInfo={description:"",methods:[],displayName:"ValidationCallback"};te.__docgenInfo={description:"",methods:[],displayName:"AllowEmptyPUI"};ne.__docgenInfo={description:"",methods:[],displayName:"onSwitchUnit"};ae.__docgenInfo={description:"",methods:[],displayName:"OW_10614TestCase"};P.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"TestUserInput"};var Fe,Pe,Be;oe.parameters={...oe.parameters,docs:{...(Fe=oe.parameters)==null?void 0:Fe.docs,source:{originalSource:`args => {
|
|
20
|
-
const [_, updateArgs] = useArgs();
|
|
21
|
-
const handleChange = (evt: any) => {
|
|
22
|
-
updateArgs({
|
|
23
|
-
value: evt.target.value
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
return <UnitInput {...args} onChange={handleChange} />;
|
|
27
|
-
}`,...(Be=(Pe=oe.parameters)==null?void 0:Pe.docs)==null?void 0:Be.source}}};var _e,Me,Oe;W.parameters={...W.parameters,docs:{...(_e=W.parameters)==null?void 0:_e.docs,source:{originalSource:`args => {
|
|
28
|
-
const [_, updateArgs] = useArgs();
|
|
29
|
-
const handleChange = (evt: any) => {
|
|
30
|
-
updateArgs({
|
|
31
|
-
value: evt.target.value
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
return <UnitInput {...args} onChange={handleChange} />;
|
|
35
|
-
}`,...(Oe=(Me=W.parameters)==null?void 0:Me.docs)==null?void 0:Oe.source}}};var We,Re,Le;R.parameters={...R.parameters,docs:{...(We=R.parameters)==null?void 0:We.docs,source:{originalSource:`args => {
|
|
36
|
-
const [_, updateArgs] = useArgs();
|
|
37
|
-
const handleChange = (evt: any) => {
|
|
38
|
-
updateArgs({
|
|
39
|
-
value: evt.target.value
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
return <UnitInput {...args} onChange={handleChange} />;
|
|
43
|
-
}`,...(Le=(Re=R.parameters)==null?void 0:Re.docs)==null?void 0:Le.source}}};var He,Ke,$e;L.parameters={...L.parameters,docs:{...(He=L.parameters)==null?void 0:He.docs,source:{originalSource:`args => {
|
|
44
|
-
const [_, updateArgs] = useArgs();
|
|
45
|
-
const handleChange = (evt: any) => {
|
|
46
|
-
updateArgs({
|
|
47
|
-
value: evt.target.value
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
return <UnitInput {...args} onChange={handleChange} />;
|
|
51
|
-
}`,...($e=(Ke=L.parameters)==null?void 0:Ke.docs)==null?void 0:$e.source}}};var Ge,ze,Je;H.parameters={...H.parameters,docs:{...(Ge=H.parameters)==null?void 0:Ge.docs,source:{originalSource:`args => {
|
|
52
|
-
const [_, updateArgs] = useArgs();
|
|
53
|
-
const handleChange = (evt: any) => {
|
|
54
|
-
updateArgs({
|
|
55
|
-
value: evt.target.value
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
return <UnitInput {...args} onChange={handleChange} />;
|
|
59
|
-
}`,...(Je=(ze=H.parameters)==null?void 0:ze.docs)==null?void 0:Je.source}}};var Ye,Ze,Qe;K.parameters={...K.parameters,docs:{...(Ye=K.parameters)==null?void 0:Ye.docs,source:{originalSource:`args => {
|
|
60
|
-
const [_, updateArgs] = useArgs();
|
|
61
|
-
const handleChange = (evt: any) => {
|
|
62
|
-
updateArgs({
|
|
63
|
-
value: evt.target.value
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
return <UnitInput {...args} onChange={handleChange} />;
|
|
67
|
-
}`,...(Qe=(Ze=K.parameters)==null?void 0:Ze.docs)==null?void 0:Qe.source}}};var Xe,et,tt;A.parameters={...A.parameters,docs:{...(Xe=A.parameters)==null?void 0:Xe.docs,source:{originalSource:`() => {
|
|
68
|
-
const [value, setValue] = useState('123|m');
|
|
69
|
-
return <UnitInput name="example" onChange={evt => setValue(evt.target.value)} placeholder="Type a value..." value={value} initUnit="m" unitkey="depth" unitTemplate={{
|
|
70
|
-
depth: 'm'
|
|
71
|
-
}} testId="testId" />;
|
|
72
|
-
}`,...(tt=(et=A.parameters)==null?void 0:et.docs)==null?void 0:tt.source}}};var nt,at,it;$.parameters={...$.parameters,docs:{...(nt=$.parameters)==null?void 0:nt.docs,source:{originalSource:`args => {
|
|
73
|
-
const [_, updateArgs] = useArgs();
|
|
74
|
-
const handleChange = (evt: any) => {
|
|
75
|
-
updateArgs({
|
|
76
|
-
value: evt.target.value
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
return <UnitInput {...args} onChange={handleChange} />;
|
|
80
|
-
}`,...(it=(at=$.parameters)==null?void 0:at.docs)==null?void 0:it.source}}};var rt,st,lt;G.parameters={...G.parameters,docs:{...(rt=G.parameters)==null?void 0:rt.docs,source:{originalSource:`args => {
|
|
81
|
-
const [_, updateArgs] = useArgs();
|
|
82
|
-
const handleChange = (evt: any) => {
|
|
83
|
-
updateArgs({
|
|
84
|
-
value: evt.target.value
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
return <UnitInput {...args} onChange={handleChange} />;
|
|
88
|
-
}`,...(lt=(st=G.parameters)==null?void 0:st.docs)==null?void 0:lt.source}}};var ut,ot,dt;q.parameters={...q.parameters,docs:{...(ut=q.parameters)==null?void 0:ut.docs,source:{originalSource:`args => {
|
|
89
|
-
const [_, updateArgs] = useArgs();
|
|
90
|
-
const handleChange = (evt: any) => {
|
|
91
|
-
updateArgs({
|
|
92
|
-
value: evt.target.value
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
return <UnitInput {...args} onChange={handleChange} />;
|
|
96
|
-
}`,...(dt=(ot=q.parameters)==null?void 0:ot.docs)==null?void 0:dt.source}}};var ct,mt,pt;z.parameters={...z.parameters,docs:{...(ct=z.parameters)==null?void 0:ct.docs,source:{originalSource:`args => {
|
|
97
|
-
const [_, updateArgs] = useArgs();
|
|
98
|
-
const handleChange = (evt: any) => {
|
|
99
|
-
updateArgs({
|
|
100
|
-
value: evt.target.value
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
return <UnitInput {...args} onChange={handleChange} />;
|
|
104
|
-
}`,...(pt=(mt=z.parameters)==null?void 0:mt.docs)==null?void 0:pt.source}}};var gt,ht,vt;J.parameters={...J.parameters,docs:{...(gt=J.parameters)==null?void 0:gt.docs,source:{originalSource:`args => {
|
|
105
|
-
const [_, updateArgs] = useArgs();
|
|
106
|
-
const handleChange = (evt: any) => {
|
|
107
|
-
updateArgs({
|
|
108
|
-
value: evt.target.value
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
return <UnitInput {...args} onChange={handleChange} />;
|
|
112
|
-
}`,...(vt=(ht=J.parameters)==null?void 0:ht.docs)==null?void 0:vt.source}}};var ft,yt,bt;Y.parameters={...Y.parameters,docs:{...(ft=Y.parameters)==null?void 0:ft.docs,source:{originalSource:`args => {
|
|
113
|
-
const [_, updateArgs] = useArgs();
|
|
114
|
-
const handleChange = (evt: any) => {
|
|
115
|
-
updateArgs({
|
|
116
|
-
value: evt.target.value
|
|
117
|
-
});
|
|
118
|
-
};
|
|
119
|
-
return <UnitInput {...args} onChange={handleChange} />;
|
|
120
|
-
}`,...(bt=(yt=Y.parameters)==null?void 0:yt.docs)==null?void 0:bt.source}}};var Ct,Ut,wt;Z.parameters={...Z.parameters,docs:{...(Ct=Z.parameters)==null?void 0:Ct.docs,source:{originalSource:`args => {
|
|
121
|
-
const [_, updateArgs] = useArgs();
|
|
122
|
-
const handleChange = (evt: any) => {
|
|
123
|
-
updateArgs({
|
|
124
|
-
value: evt.target.value
|
|
125
|
-
});
|
|
126
|
-
};
|
|
127
|
-
return <UnitInput {...args} onChange={handleChange} />;
|
|
128
|
-
}`,...(wt=(Ut=Z.parameters)==null?void 0:Ut.docs)==null?void 0:wt.source}}};var xt,It,Tt;D.parameters={...D.parameters,docs:{...(xt=D.parameters)==null?void 0:xt.docs,source:{originalSource:`(args: IUnitInputProps) => {
|
|
129
|
-
const [value, setValue] = useState('123|m');
|
|
130
|
-
const [value2, setValue2] = useState('223|m');
|
|
131
|
-
const [initUnit, setInitUnit] = useState('ft');
|
|
132
|
-
return <>
|
|
133
|
-
<Button label="Change initUnit" onClick={() => setInitUnit(initUnit === 'm' ? 'ft' : 'm')} />
|
|
134
|
-
<Spacer />
|
|
135
|
-
<Button label="Change value" onClick={() => setValue(value === '123|m' ? '456|m' : '123|m')} />
|
|
136
|
-
<Spacer />
|
|
137
|
-
<UnitInput name="example" onChange={evt => {
|
|
138
|
-
setValue(evt.target.value);
|
|
139
|
-
}} unitkey="length" value={value} initUnit={initUnit} onSwitchUnit={setInitUnit} />
|
|
140
|
-
<Spacer />
|
|
141
|
-
<UnitInput name="example2" onChange={evt => {
|
|
142
|
-
setValue2(evt.target.value);
|
|
143
|
-
}} unitkey="length" value={value2} initUnit={initUnit} onSwitchUnit={setInitUnit} />
|
|
144
|
-
<Divider />
|
|
145
|
-
<h4>Without initUnit property (taken from the redux store)</h4>
|
|
146
|
-
<UnitInput name="example" onChange={evt => {
|
|
147
|
-
setValue(evt.target.value);
|
|
148
|
-
}} unitkey="length" value={value} onSwitchUnit={setInitUnit} />
|
|
149
|
-
<UnitInput name="example2" onChange={evt => {
|
|
150
|
-
setValue2(evt.target.value);
|
|
151
|
-
}} unitkey="length" value={value2} onSwitchUnit={setInitUnit} />
|
|
152
|
-
</>;
|
|
153
|
-
}`,...(Tt=(It=D.parameters)==null?void 0:It.docs)==null?void 0:Tt.source}}};var Vt,kt,jt;Q.parameters={...Q.parameters,docs:{...(Vt=Q.parameters)==null?void 0:Vt.docs,source:{originalSource:`args => {
|
|
154
|
-
const [_, updateArgs] = useArgs();
|
|
155
|
-
const handleChange = (evt: any) => {
|
|
156
|
-
updateArgs({
|
|
157
|
-
value: evt.target.value
|
|
158
|
-
});
|
|
159
|
-
};
|
|
160
|
-
return <UnitInput {...args} onChange={handleChange} />;
|
|
161
|
-
}`,...(jt=(kt=Q.parameters)==null?void 0:kt.docs)==null?void 0:jt.source}}};var St,Et,Nt;F.parameters={...F.parameters,docs:{...(St=F.parameters)==null?void 0:St.docs,source:{originalSource:`() => {
|
|
162
|
-
const width = '500px';
|
|
163
|
-
const [value, setValue] = useState<any>(undefined);
|
|
164
|
-
return <>
|
|
165
|
-
<h4>Different edge cases such as +/- infinity, undefined, NaN, null:</h4>
|
|
166
|
-
<Row>
|
|
167
|
-
<Column width="25%">
|
|
168
|
-
<Button label="Change value infinity" onClick={() => setValue(Infinity)} />
|
|
169
|
-
<br />
|
|
170
|
-
<Button label="Change value -infinity" onClick={() => setValue(-Infinity)} />
|
|
171
|
-
<br />
|
|
172
|
-
<Button label="Change value null" onClick={() => setValue(null)} />
|
|
173
|
-
<br />
|
|
174
|
-
<Button label="Change value - undefined" onClick={() => setValue(undefined)} />
|
|
175
|
-
<br />
|
|
176
|
-
<Button label="Change value - NaN" onClick={() => setValue(NaN)} />
|
|
177
|
-
<br />
|
|
178
|
-
<Button label="Change value - nothing (empty)" onClick={() => setValue(undefined)} />
|
|
179
|
-
<br />
|
|
180
|
-
<Button label="Change value - empty string" onClick={() => setValue('')} />
|
|
181
|
-
</Column>
|
|
182
|
-
<Column width="25%">
|
|
183
|
-
<Button label="Change value infinity|m" onClick={() => setValue(Infinity + '|m')} />
|
|
184
|
-
<br />
|
|
185
|
-
<Button label="Change value -infinity|m" onClick={() => setValue(-Infinity + '|m')} />
|
|
186
|
-
<br />
|
|
187
|
-
<Button label="Change value null|m" onClick={() => setValue(null + '|m')} />
|
|
188
|
-
<br />
|
|
189
|
-
<Button label="Change value - undefined|m" onClick={() => setValue(undefined + '|m')} />
|
|
190
|
-
<br />
|
|
191
|
-
<Button label="Change value - NaN|m" onClick={() => setValue(NaN + '|m')} />
|
|
192
|
-
<br />
|
|
193
|
-
<Button label="Change value - nothing (empty)|m" onClick={() => setValue('|m')} />
|
|
194
|
-
</Column>
|
|
195
|
-
</Row>
|
|
196
|
-
<br />
|
|
197
|
-
<Field label="Normal PUI">
|
|
198
|
-
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="value|unit" />
|
|
199
|
-
</Field>
|
|
200
|
-
<Field label="Disabled validation">
|
|
201
|
-
<UnitInput name="example2" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" disabledValidation width={width} />
|
|
202
|
-
</Field>
|
|
203
|
-
<Field label="Disabled validation and manual error">
|
|
204
|
-
<UnitInput name="example3" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" error="test" disabledValidation width={width} />
|
|
205
|
-
</Field>
|
|
206
|
-
<Message message={{
|
|
207
|
-
heading: 'Current value inside PUI: ' + value,
|
|
208
|
-
visible: true
|
|
209
|
-
}} />
|
|
210
|
-
</>;
|
|
211
|
-
}`,...(Nt=(Et=F.parameters)==null?void 0:Et.docs)==null?void 0:Nt.source}}};var At,qt,Dt;X.parameters={...X.parameters,docs:{...(At=X.parameters)==null?void 0:At.docs,source:{originalSource:`() => {
|
|
212
|
-
const width = '500px';
|
|
213
|
-
const [value, setValue] = useState<string>('1|m');
|
|
214
|
-
const [valueB, setValueB] = useState('|m');
|
|
215
|
-
const automaticValue = '123|km';
|
|
216
|
-
return <>
|
|
217
|
-
<h4>Different cases for automatic (placeholder) values:</h4>
|
|
218
|
-
<Row>
|
|
219
|
-
<Column width="25%">
|
|
220
|
-
<Button label="Change value to ''" onClick={() => setValue('')} />
|
|
221
|
-
<br />
|
|
222
|
-
<Button label="Change value to 1" onClick={() => setValue('1')} />
|
|
223
|
-
<br />
|
|
224
|
-
<Button label="Change value to 1|m" onClick={() => setValue('1|m')} />
|
|
225
|
-
<br />
|
|
226
|
-
<Button label="Change value to |m - empty value" onClick={() => setValue('|m')} />
|
|
227
|
-
</Column>
|
|
228
|
-
</Row>
|
|
229
|
-
<br />
|
|
230
|
-
<Field label="Normal PUI (placeholder + auto)">
|
|
231
|
-
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="value|unit" autoValue={automaticValue} />
|
|
232
|
-
</Field>
|
|
233
|
-
<Field label="Normal PUI (only auto)">
|
|
234
|
-
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} autoValue={automaticValue} />
|
|
235
|
-
</Field>
|
|
236
|
-
<Field label="Empty PUI with autoValue">
|
|
237
|
-
<UnitInput name="example1" onChange={evt => setValueB(evt.target.value)} value={valueB} unitkey="length" width={width} autoValue={automaticValue} />
|
|
238
|
-
</Field>
|
|
239
|
-
<Field label="Normal PUI (only placeholder)">
|
|
240
|
-
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="Placeholder test" />
|
|
241
|
-
</Field>
|
|
242
|
-
<Field label="Normal PUI (placeholder + allowEmpty)">
|
|
243
|
-
<UnitInput name="example1" onChange={evt => setValue(evt.target.value)} value={value} unitkey="length" width={width} placeholder="Placeholder test" allowEmpty />
|
|
244
|
-
</Field>
|
|
245
|
-
<Message message={{
|
|
246
|
-
heading: 'Current value inside PUI: ' + value,
|
|
247
|
-
visible: true
|
|
248
|
-
}} />
|
|
249
|
-
</>;
|
|
250
|
-
}`,...(Dt=(qt=X.parameters)==null?void 0:qt.docs)==null?void 0:Dt.source}}};var Ft,Pt,Bt;ee.parameters={...ee.parameters,docs:{...(Ft=ee.parameters)==null?void 0:Ft.docs,source:{originalSource:`() => {
|
|
251
|
-
const [value, setValue] = useState('123|%');
|
|
252
|
-
const [validation, setValidation] = useState<string | null>(null);
|
|
253
|
-
const predictedMessage = 'This should be visible when an error appears';
|
|
254
|
-
const handleValidation = (name: string, error: string | null) => {
|
|
255
|
-
setValidation(error);
|
|
256
|
-
return {
|
|
257
|
-
name,
|
|
258
|
-
error
|
|
259
|
-
};
|
|
260
|
-
};
|
|
261
|
-
return <>
|
|
262
|
-
<h4>3rd party validation message when inputting invalid value:</h4>
|
|
263
|
-
<UnitInput name="example" onChange={evt => setValue(evt.target.value)} error={!validation || predictedMessage} validationCallback={handleValidation} value={value} />
|
|
264
|
-
<br />
|
|
265
|
-
<Spacer />
|
|
266
|
-
<h4>Original validation message: </h4>
|
|
267
|
-
<Message message={{
|
|
268
|
-
heading: validation,
|
|
269
|
-
visible: true
|
|
270
|
-
}} />
|
|
271
|
-
</>;
|
|
272
|
-
}`,...(Bt=(Pt=ee.parameters)==null?void 0:Pt.docs)==null?void 0:Bt.source}}};var _t,Mt,Ot;te.parameters={...te.parameters,docs:{...(_t=te.parameters)==null?void 0:_t.docs,source:{originalSource:`() => {
|
|
273
|
-
const [value, setValue] = useState('123|m');
|
|
274
|
-
const [placeholder, setPlaceholder] = useState('');
|
|
275
|
-
const [initUnit, setInitUnit] = useState('km');
|
|
276
|
-
const setPlaceholderValue = () => {
|
|
277
|
-
setInitUnit('ft');
|
|
278
|
-
setPlaceholder('placeholder');
|
|
279
|
-
setValue('|m');
|
|
280
|
-
};
|
|
281
|
-
return <>
|
|
282
|
-
<h4>Empty value case:</h4>
|
|
283
|
-
<UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} allowEmpty placeholder={placeholder} initUnit={initUnit} unitkey="length" />
|
|
284
|
-
<br />
|
|
285
|
-
<Spacer />
|
|
286
|
-
<Button label="Change value |m and unit ft" onClick={() => setPlaceholderValue()} />
|
|
287
|
-
</>;
|
|
288
|
-
}`,...(Ot=(Mt=te.parameters)==null?void 0:Mt.docs)==null?void 0:Ot.source}}};var Wt,Rt,Lt;ne.parameters={...ne.parameters,docs:{...(Wt=ne.parameters)==null?void 0:Wt.docs,source:{originalSource:`() => {
|
|
289
|
-
const [value, setValue] = useState('123|m');
|
|
290
|
-
const [unit, setUnit] = useState('m');
|
|
291
|
-
return <>
|
|
292
|
-
<UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} initUnit={unit} unitkey="length" onSwitchUnit={setUnit} />
|
|
293
|
-
<Spacer />
|
|
294
|
-
<UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} initUnit={unit} unitkey="length" onSwitchUnit={setUnit} />
|
|
295
|
-
</>;
|
|
296
|
-
}`,...(Lt=(Rt=ne.parameters)==null?void 0:Rt.docs)==null?void 0:Lt.source}}};var Ht,Kt,$t;ae.parameters={...ae.parameters,docs:{...(Ht=ae.parameters)==null?void 0:Ht.docs,source:{originalSource:`() => {
|
|
297
|
-
return <>
|
|
298
|
-
<Text faint>
|
|
299
|
-
Reproduce OW-10614 rounding noise bug when storing values in a different
|
|
300
|
-
unit to the display unit
|
|
301
|
-
</Text>
|
|
302
|
-
<Spacer />
|
|
303
|
-
<UnitInput name="example" onChange={() => {}} value={withUnit(convertAndGetValue('9750|psi', 'bar'), 'bar')} initUnit="psi" unitkey="pressure" unitTemplate={{
|
|
304
|
-
pressure: 'psi'
|
|
305
|
-
}} />
|
|
306
|
-
<Spacer />
|
|
307
|
-
<UnitInput name="example2" onChange={() => {}} value={withUnit(convertAndGetValue('8642|lbf', 'tonneForce'), 'tonneForce')} initUnit="lbf" unitkey="force" unitTemplate={{
|
|
308
|
-
force: 'tonneForce'
|
|
309
|
-
}} />
|
|
310
|
-
</>;
|
|
311
|
-
}`,...($t=(Kt=ae.parameters)==null?void 0:Kt.docs)==null?void 0:$t.source}}};var Gt,zt,Jt;P.parameters={...P.parameters,docs:{...(Gt=P.parameters)==null?void 0:Gt.docs,source:{originalSource:`() => {
|
|
312
|
-
const [value, setValue] = useState('123|m');
|
|
313
|
-
return <UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} initUnit="m" unitkey="depth" unitTemplate={{
|
|
314
|
-
depth: 'm'
|
|
315
|
-
}} testId="testId" />;
|
|
316
|
-
}`,...(Jt=(zt=P.parameters)==null?void 0:zt.docs)==null?void 0:Jt.source}}};const Ia=["Default","InitUnit","notKnownUnit","Width","NoConversion","Small","Placeholder","Error","InternalValidationError","Disabled","DisabledNoConversion","DisabledUnitWithoutUnitKey","DisabledUnitWithUnitKey","DisabledWithEnabledUnitMenu","TestExternalStateChangeWithSynchronizedUnits","PredefinedOptionsMenu","TestEdgeCases","AutomaticValues","ValidationCallback","AllowEmptyPUI","onSwitchUnit","OW_10614TestCase","TestUserInput"];export{te as AllowEmptyPUI,X as AutomaticValues,oe as Default,q as Disabled,z as DisabledNoConversion,Y as DisabledUnitWithUnitKey,J as DisabledUnitWithoutUnitKey,Z as DisabledWithEnabledUnitMenu,$ as Error,W as InitUnit,G as InternalValidationError,H as NoConversion,ae as OW_10614TestCase,A as Placeholder,Q as PredefinedOptionsMenu,K as Small,F as TestEdgeCases,D as TestExternalStateChangeWithSynchronizedUnits,P as TestUserInput,ee as ValidationCallback,L as Width,Ia as __namedExportsOrder,xa as default,R as notKnownUnit,ne as onSwitchUnit};
|
|
@@ -1,152 +0,0 @@
|
|
|
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 T}from"./index-C0x1JmaP.js";import{G as ne}from"./grid-DRkC-bt8.js";import{S as ae}from"./spacer-BWoNR27H.js";import{w as O,u as d,e as B,f as ie,a as re}from"./index-DMAnyMX5.js";import{C as F}from"./card-EcjmryU9.js";import{F as R}from"./field-HrLaMLbx.js";import{H as _}from"./heading-CRNoBc7q.js";import{S as P}from"./select-03uRbc4I.js";import{T as W}from"./toggle-BbFVf61v.js";import{l as oe}from"./lodash-c4VUpsOs.js";import{u as le}from"./use-previous-D775JrO6.js";import{T as se,C as G}from"./table-qmf29AIJ.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"./enum-Bnn40S8Q.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-CJed_LLR.js";import"./helpers-JJxzGegQ.js";import"./index.es-DazXb-ul.js";import"./redux-tRgGMjwY.js";import"./objectSpread2-DW4nTBoq.js";import"./tiny-invariant-DqLgxztJ.js";import"./pagination-DWc8zp3k.js";import"./input-DTXbDJaL.js";import"./input-group-BaRSJAEN.js";import"./input-group-addon-D68iUKV2.js";import"./number-input-DZ9ERbK_.js";import"./check-box-DPLaOkRR.js";import"./slider-C7vnj_3M.js";import"./index-BI4_Bp97.js";import"./popover-rq33c1W2.js";const ue=r=>r.reduce(({preferredUnits:o,storageUnits:a},{unitKey:l,preferredUnit:e,storageUnit:b})=>(o[l]=e,a[l]=b,{preferredUnits:o,storageUnits:a}),{preferredUnits:{},storageUnits:{}}),ce=({headers:r,rows:o,selectedUnits:a,storageUnits:l,onChangeUnit:e,convertBackToStorageUnit:b,enableCosmeticRounding:m,enableDisplayRounding:C})=>{const u=r?r.map(c=>({...c,cells:c.cells.map(p=>{var n;if(p.type===G.AUTO_UNIT){const{testId:x,unitKey:g}=p;return{value:a[g],type:G.SELECT,searchable:!1,options:(n=T.getUnitsForQuantity(g))==null?void 0:n.map(U=>({label:T.label(U),value:U})),native:p.native,onChange:U=>e({unitKey:g,value:U.target.value}),testId:x}}return p})})):[],s=o?o.map((c,p)=>({...c,cells:c.cells.map((n,x)=>{if("autoUnit"in n&&(n!=null&&n.autoUnit)&&(typeof(n==null?void 0:n.value)=="string"||typeof(n==null?void 0:n.value)=="number")){const{unitKey:g,value:U,formatDisplayValue:I}=n,V=C&&"roundDisplayValue"in n?n==null?void 0:n.roundDisplayValue:null,h=a[g],y=l[g],t=h!==y,f=t?T.convertAndGetValue(U,h,y):n.value,w=T.isScientificStringNum(U),k=m&&(t||!w)?T.roundToPrecision(f,14):f,S=I?I(k):k;return{...n,value:S,enableCosmeticRounding:m,enableDisplayRounding:C,roundDisplayValue:V,onChange:D=>{const{value:H}=D.target,A=l[g],E=a[g],K=E!==A,j=b?A:E,Z=K?T.convertAndGetValue(H,j,E):H;if("onChange"in n){const{onChange:ee}=n,te={...D,target:{...D.target,value:String(Z),rowIndex:p,cellIndex:x,unit:j}};ee(te)}}}}return n})})):[];return{convertedHeaders:u,convertedRows:s}},X=({table:r,unitConfig:o,convertBackToStorageUnit:a=!0,enableCosmeticRounding:l=!0,enableDisplayRounding:e=!0})=>{const{rows:b,headers:m,...C}=r,{storageUnits:u,preferredUnits:s}=ue(o),c=le(s),[p,n]=v.useState(s),x=({unitKey:h,value:y})=>{n({...p,[h]:y});const t=o.find(f=>f.unitKey===h);t&&typeof t.onChange=="function"&&t.onChange({oldUnit:p[h],newUnit:y,unitKey:h})},g=h=>ce({headers:m,rows:b,selectedUnits:h,storageUnits:u,onChangeUnit:x,convertBackToStorageUnit:a,enableCosmeticRounding:l,enableDisplayRounding:e}),U=g(p),[I,V]=v.useState(U);return v.useEffect(()=>{!oe.isEqual(s,c)&&(Object.keys(s).forEach(y=>{const t=c==null?void 0:c[y],f=s[y];t!==f&&x({unitKey:y,value:f})}),V(g(s)))},[o]),v.useEffect(()=>{V(g(p))},[r,p]),i.jsx(se,{table:{...C,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 Tt={title:"Basic/UnitTable",args:{}},de=!0,pe=!0,ge=!0,me=!1,N="m",Y="C",he=3,be=(r,o,a)=>{const l=[o,o,a],e=[...Array(r)].map((b,m)=>{const C=m,u=m+1.25,s=4+m*.25;return[String(C),String(u),String(s)]});return[l,...e]},ye=be(he,N,Y),fe=({reduxTable:r,value:o,unit:a,rowIndex:l,cellIndex:e})=>J(r,b=>{const m=b[0][e],C=(u,s)=>s===0;return b.forEach((u,s)=>{if(C(u,s)){u[e]=a;return}if(s===l+1){u[e]=String(o);return}const c=T.convertAndGetValue(u[e],a,m);u[e]=String(c)}),b}),ve=({reduxTable:r,value:o,rowIndex:a,cellIndex:l})=>J(r,e=>{e[a+1][l]=o}),L=()=>{var h,y;const[r,o]=v.useState(N),[a,l]=v.useState(Y),[e,b]=v.useState(ye),[m,C]=v.useState(de),[u,s]=v.useState(ge),[c,p]=v.useState(pe),[n,x]=v.useState(me),[g,U]=v.useState(N),I=t=>{const{rowIndex:f,cellIndex:w,value:k,unit:S}=t.target,D=n?fe({reduxTable:e,value:k,unit:S,rowIndex:f,cellIndex:w}):ve({reduxTable:e,value:k,rowIndex:f,cellIndex:w});b(D)},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((k,S)=>{const D=w===1&&S===1;return{value:k,type:D?"Text":"NumberInput",unitKey:S===2?"temperature":"length",onChange:I,roundDisplayValue:w===3&&S===2?j=>T.roundByMagnitude(j,2):null,formatDisplayValue:D?j=>`T* ${j}`:null,autoUnit:!0,testId:`testId_${w}_${S}`}})}),t),{testId:"testId",headers:[],rows:[]});return i.jsxs(ne,{columns:"1fr 1fr",gap:!0,children:[i.jsxs(F,{heading:i.jsx(_,{children:"Settings"}),children:[i.jsx(R,{label:"Convert back to storage unit:",labelLeft:!0,labelWidth:200,children:i.jsx(W,{checked:m,onChange:t=>C(t.target.checked)})}),i.jsx(R,{label:"Enable display rounding:",labelLeft:!0,labelWidth:200,children:i.jsx(W,{checked:u,onChange:t=>s(t.target.checked)})}),i.jsx(R,{label:"Enable cosmetic rounding:",labelLeft:!0,labelWidth:200,children:i.jsx(W,{checked:c,onChange:t=>p(t.target.checked)})}),i.jsx(R,{label:"Convert whole table:",labelLeft:!0,labelWidth:200,children:i.jsx(W,{checked:n,onChange:t=>x(t.target.checked)})})]}),i.jsxs(F,{heading:i.jsx(_,{children:"Unit template"}),children:[i.jsx(R,{label:"Length unit:",labelLeft:!0,labelWidth:120,children:i.jsx(P,{options:(h=T.getUnitsForQuantity("length"))==null?void 0:h.map(t=>({value:t,label:T.label(t)})),value:{value:r},onChange:t=>o(t.target.value),width:"100px"})}),i.jsx(R,{label:"Temperature unit:",labelLeft:!0,labelWidth:120,children:i.jsx(P,{options:(y=T.getUnitsForQuantity("temperature"))==null?void 0:y.map(t=>({value:t,label:T.label(t)})),value:{value:a},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:r,onChange:({newUnit:t})=>U(t)},{unitKey:"temperature",storageUnit:e[0][2],preferredUnit:a}],convertBackToStorageUnit:m,enableDisplayRounding:u,enableCosmeticRounding:c}),i.jsx(ae,{height:20}),i.jsx(R,{label:"Displayed length unit:",labelLeft:!0,labelWidth:150,children:g})]})]})};L.play=async({canvasElement:r,step:o})=>{const a=O(r),l=O(r.ownerDocument.body);await o("Can enter decimal values",async()=>{const e=a.getByTestId("testId_2_1");await d.clear(e),await d.type(e,"123.123456789"),await d.click(r),await B(a.getByDisplayValue("123.12")).toBeInTheDocument()}),await o("Can enter comma decimals (converts to dot)",async()=>{const e=a.getByTestId("testId_2_1");await d.clear(e),await d.type(e,"123,456"),await d.click(r),await B(a.getByDisplayValue("123.46")).toBeInTheDocument()}),await o("Can enter small numbers",async()=>{const e=a.getByTestId("testId_2_1");await d.clear(e),await d.type(e,"0.0000000023"),await d.click(r),await B(e).toHaveDisplayValue("0.00")}),await o("Can enter large numbers",async()=>{const e=a.getByTestId("testId_2_1");await d.clear(e),await d.type(e,"999999999999"),await d.click(r),await B(a.getByDisplayValue("999999999999.00")).toBeInTheDocument()}),await o("Shows validation error for non-numeric input",async()=>{const e=a.getByTestId("testId_2_1");await d.clear(e),await d.type(e,"123x45s6"),await d.click(r),await ie.mouseOver(e),await re(()=>{B(l.getByText("Must be a numerical value")).toBeInTheDocument()})})};L.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"UnitTableExample"};var q,$,Q,M,z;L.parameters={...L.parameters,docs:{...(q=L.parameters)==null?void 0:q.docs,source:{originalSource:`() => {
|
|
2
|
-
const [preferredLengthUnit, setPreferredLengthUnit] = useState(initialLengthUnit);
|
|
3
|
-
const [preferredTemperatureUnit, setPreferredTemperatureUnit] = useState(initialTemperatureUnit);
|
|
4
|
-
const [reduxTable, setReduxTable] = useState<TTable>(initialTable);
|
|
5
|
-
const [convertBackToStorageUnit, setConvertBackToStorageUnit] = useState(initialConvertBackToStorageUnit);
|
|
6
|
-
const [enableDisplayRounding, setEnableDisplayRounding] = useState(initialEnableDisplayRounding);
|
|
7
|
-
const [enableCosmeticRounding, setEnableCosmeticRounding] = useState(initialEnableCosmeticRounding);
|
|
8
|
-
const [convertWholeTable, setConvertWholeTable] = useState(initialConvertWholeTable);
|
|
9
|
-
const [displayedLengthUnit, setDisplayedLengthUnit] = useState(initialLengthUnit);
|
|
10
|
-
|
|
11
|
-
/*********************************************************************************************************************
|
|
12
|
-
Cell onChange handler
|
|
13
|
-
*********************************************************************************************************************/
|
|
14
|
-
const onUpdateCell = (evt: IUnitTableOnChangeEvent) => {
|
|
15
|
-
const {
|
|
16
|
-
rowIndex,
|
|
17
|
-
cellIndex,
|
|
18
|
-
value,
|
|
19
|
-
unit
|
|
20
|
-
} = evt.target;
|
|
21
|
-
const nextTable = convertWholeTable ? convertStorageTable({
|
|
22
|
-
reduxTable,
|
|
23
|
-
value,
|
|
24
|
-
unit,
|
|
25
|
-
rowIndex,
|
|
26
|
-
cellIndex
|
|
27
|
-
}) : updateCell({
|
|
28
|
-
reduxTable,
|
|
29
|
-
value,
|
|
30
|
-
rowIndex,
|
|
31
|
-
cellIndex
|
|
32
|
-
});
|
|
33
|
-
setReduxTable(nextTable);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/*********************************************************************************************************************
|
|
37
|
-
Construct table view data (same as old Table component, with a new props)
|
|
38
|
-
*********************************************************************************************************************/
|
|
39
|
-
const tableViewData = reduxTable.reduce((acc, row, rowIndex) => {
|
|
40
|
-
if (rowIndex === 0) {
|
|
41
|
-
acc.headers = [{
|
|
42
|
-
cells: [{
|
|
43
|
-
value: 'From'
|
|
44
|
-
}, {
|
|
45
|
-
value: 'To'
|
|
46
|
-
}, {
|
|
47
|
-
value: 'Temperature'
|
|
48
|
-
}]
|
|
49
|
-
}, {
|
|
50
|
-
cells: [{
|
|
51
|
-
type: 'AutoUnit',
|
|
52
|
-
unitKey: 'length'
|
|
53
|
-
}, {
|
|
54
|
-
type: 'AutoUnit',
|
|
55
|
-
unitKey: 'length'
|
|
56
|
-
}, {
|
|
57
|
-
type: 'AutoUnit',
|
|
58
|
-
unitKey: 'temperature',
|
|
59
|
-
testId: 'table-unit-selector-3'
|
|
60
|
-
}]
|
|
61
|
-
}];
|
|
62
|
-
} else {
|
|
63
|
-
acc.rows = acc.rows.concat({
|
|
64
|
-
cells: row.map((cell, cellIndex) => {
|
|
65
|
-
const specialCell = rowIndex === 1 && cellIndex === 1;
|
|
66
|
-
const type = specialCell ? 'Text' : 'NumberInput';
|
|
67
|
-
const formatDisplayValue = specialCell ? (value: number | string) => \`T* \${value}\` : null;
|
|
68
|
-
const customDisplayRounding = rowIndex === 3 && cellIndex === 2 ? (value: TStringNumberNull) => roundByMagnitude(value, 2) : null;
|
|
69
|
-
const value = cell;
|
|
70
|
-
return {
|
|
71
|
-
value,
|
|
72
|
-
type,
|
|
73
|
-
unitKey: cellIndex === 2 ? 'temperature' : 'length',
|
|
74
|
-
onChange: onUpdateCell,
|
|
75
|
-
roundDisplayValue: customDisplayRounding,
|
|
76
|
-
// optionally customize the display rounding of specific columns/cells
|
|
77
|
-
formatDisplayValue,
|
|
78
|
-
// optionally extend/customize the display formatting of specific columns/cells
|
|
79
|
-
autoUnit: true,
|
|
80
|
-
testId: \`testId_\${rowIndex}_\${cellIndex}\`
|
|
81
|
-
};
|
|
82
|
-
})
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
return acc;
|
|
86
|
-
}, {
|
|
87
|
-
testId: 'testId',
|
|
88
|
-
headers: ([] as any[]),
|
|
89
|
-
rows: ([] as IUnitTableRow[])
|
|
90
|
-
});
|
|
91
|
-
return <Grid columns="1fr 1fr" gap>
|
|
92
|
-
<Card heading={<Heading>Settings</Heading>}>
|
|
93
|
-
<Field label="Convert back to storage unit:" labelLeft labelWidth={200}>
|
|
94
|
-
<Toggle checked={convertBackToStorageUnit} onChange={evt => setConvertBackToStorageUnit(evt.target.checked)} />
|
|
95
|
-
</Field>
|
|
96
|
-
<Field label="Enable display rounding:" labelLeft labelWidth={200}>
|
|
97
|
-
<Toggle checked={enableDisplayRounding} onChange={evt => setEnableDisplayRounding(evt.target.checked)} />
|
|
98
|
-
</Field>
|
|
99
|
-
<Field label="Enable cosmetic rounding:" labelLeft labelWidth={200}>
|
|
100
|
-
<Toggle checked={enableCosmeticRounding} onChange={evt => setEnableCosmeticRounding(evt.target.checked)} />
|
|
101
|
-
</Field>
|
|
102
|
-
<Field label="Convert whole table:" labelLeft labelWidth={200}>
|
|
103
|
-
<Toggle checked={convertWholeTable} onChange={evt => setConvertWholeTable(evt.target.checked)} />
|
|
104
|
-
</Field>
|
|
105
|
-
</Card>
|
|
106
|
-
<Card heading={<Heading>Unit template</Heading>}>
|
|
107
|
-
<Field label="Length unit:" labelLeft labelWidth={120}>
|
|
108
|
-
<Select options={getUnitsForQuantity('length')?.map(unit => ({
|
|
109
|
-
value: unit,
|
|
110
|
-
label: label(unit)
|
|
111
|
-
}))} value={{
|
|
112
|
-
value: preferredLengthUnit
|
|
113
|
-
}} onChange={evt => setPreferredLengthUnit(evt.target.value)} width="100px" />
|
|
114
|
-
</Field>
|
|
115
|
-
<Field label="Temperature unit:" labelLeft labelWidth={120}>
|
|
116
|
-
<Select options={getUnitsForQuantity('temperature')?.map(unit => ({
|
|
117
|
-
value: unit,
|
|
118
|
-
label: label(unit)
|
|
119
|
-
}))} value={{
|
|
120
|
-
value: preferredTemperatureUnit
|
|
121
|
-
}} onChange={evt => setPreferredTemperatureUnit(evt.target.value)} width="100px" />
|
|
122
|
-
</Field>
|
|
123
|
-
</Card>
|
|
124
|
-
<Card heading={<Heading>Storage State (Redux)</Heading>}>
|
|
125
|
-
<pre>
|
|
126
|
-
<code>{JSON.stringify(reduxTable, null, 2)}</code>
|
|
127
|
-
</pre>
|
|
128
|
-
</Card>
|
|
129
|
-
<Card heading={<Heading>UnitTable</Heading>}>
|
|
130
|
-
<UnitTable table={tableViewData}
|
|
131
|
-
//New props:
|
|
132
|
-
unitConfig={[{
|
|
133
|
-
unitKey: 'length',
|
|
134
|
-
storageUnit: reduxTable[0][0],
|
|
135
|
-
preferredUnit: preferredLengthUnit,
|
|
136
|
-
onChange: ({
|
|
137
|
-
newUnit
|
|
138
|
-
}) => setDisplayedLengthUnit(newUnit)
|
|
139
|
-
}, {
|
|
140
|
-
unitKey: 'temperature',
|
|
141
|
-
storageUnit: reduxTable[0][2],
|
|
142
|
-
preferredUnit: preferredTemperatureUnit
|
|
143
|
-
}]}
|
|
144
|
-
//Most tables should just use the default values here (true):
|
|
145
|
-
convertBackToStorageUnit={convertBackToStorageUnit} enableDisplayRounding={enableDisplayRounding} enableCosmeticRounding={enableCosmeticRounding} />
|
|
146
|
-
<Spacer height={20} />
|
|
147
|
-
<Field label="Displayed length unit:" labelLeft labelWidth={150}>
|
|
148
|
-
{displayedLengthUnit}
|
|
149
|
-
</Field>
|
|
150
|
-
</Card>
|
|
151
|
-
</Grid>;
|
|
152
|
-
}`,...(Q=($=L.parameters)==null?void 0:$.docs)==null?void 0:Q.source},description:{story:"Story",...(z=(M=L.parameters)==null?void 0:M.docs)==null?void 0:z.description}}};const Ut=["UnitTableExample"];export{L as UnitTableExample,Ut as __namedExportsOrder,Tt as default};
|