@oliasoft-open-source/react-ui-library 4.6.0 → 4.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -3
- package/dist/index.js +5 -7
- package/dist/index.js.map +1 -1
- package/dist/storybook/assets/Color-6VNJS4EI-LkypNDYY.js +1 -0
- package/dist/storybook/assets/DocsRenderer-NNNQARDV-271EmMHR.js +1 -0
- package/dist/storybook/assets/WithTooltip-V3YHNWJZ-5odABDuO.js +1 -0
- package/dist/storybook/assets/{accordion-MRdNs3mQ.js → accordion-M-sY23Hd.js} +1 -1
- package/dist/storybook/assets/{accordion.stories-3sqRwqly.js → accordion.stories-nYKTmoeA.js} +2 -2
- package/dist/storybook/assets/{actions-AZ9fI-GM.js → actions-mOcj9IlF.js} +1 -1
- package/dist/storybook/assets/{actions.stories-DcHBD8wo.js → actions.stories-ER0_rAT3.js} +1 -1
- package/dist/storybook/assets/afe.stories-gufd9PH8.js +88 -0
- package/dist/storybook/assets/{badge.stories-5O4TV4St.js → badge.stories-QAHZ0hGs.js} +1 -1
- package/dist/storybook/assets/blowout.stories-TT3YZhxD.js +40 -0
- package/dist/storybook/assets/{button-group-O6Di9sNA.js → button-group-mNQThLQb.js} +1 -1
- package/dist/storybook/assets/{button-group.stories-2yCzCoPD.js → button-group.stories-hEWUnlpm.js} +1 -1
- package/dist/storybook/assets/{button-rm22C2wf.js → button-shH4xakS.js} +1 -1
- package/dist/storybook/assets/{button.stories-32q2fViV.js → button.stories-5xHwBO1P.js} +6 -6
- package/dist/storybook/assets/{buttons-and-links-LEUVLdX3.js → buttons-and-links-Sb4bneec.js} +1 -1
- package/dist/storybook/assets/{card.stories-v_QIHoI3.js → card.stories-52XKdWMP.js} +1 -1
- package/dist/storybook/assets/{casing-loads.stories-rcooFkDL.js → casing-loads.stories-58Yzw909.js} +2 -2
- package/dist/storybook/assets/{cell.stories-MEK7F8sN.js → cell.stories-dk65sciA.js} +9 -9
- package/dist/storybook/assets/{check-box-7DccPNCs.js → check-box-2gxosI3y.js} +1 -1
- package/dist/storybook/assets/{check-box.stories-QBPARD7M.js → check-box.stories-dct4BaKG.js} +1 -1
- package/dist/storybook/assets/{chunk-HLWAVYOI-XeHb_zS2.js → chunk-HLWAVYOI-C-Uqv-lv.js} +1 -1
- package/dist/storybook/assets/color-QEPOj0Ib.js +25 -0
- package/dist/storybook/assets/{column.stories-FWqVDX5B.js → column.stories-1Qq8awo0.js} +6 -6
- package/dist/storybook/assets/{dialog-VIWX250Q.js → dialog-roJ8Yns6.js} +1 -1
- package/dist/storybook/assets/{drawer-FAo1Q_ET.js → drawer-GdbVQdWk.js} +1 -1
- package/dist/storybook/assets/{drawer.stories-raVCT-8R.js → drawer.stories-XWMoCncm.js} +2 -2
- package/dist/storybook/assets/{empty.stories-eLsVeLsD.js → empty.stories-XVXKuuiT.js} +1 -1
- package/dist/storybook/assets/entry-preview-TGgN7-T4.js +1 -0
- package/dist/storybook/assets/{config-b-_d5fwn.js → entry-preview-docs-KfUfHYQ7.js} +37 -37
- package/dist/storybook/assets/{field-9udMeZdr.js → field-FZX0Z7IB.js} +1 -1
- package/dist/storybook/assets/{field.stories-H98nslNw.js → field.stories-Quu0snQm.js} +5 -5
- package/dist/storybook/assets/{file-input.stories-d--B8cOO.js → file-input.stories-qbEqmWyt.js} +1 -1
- package/dist/storybook/assets/{flex-KzhjL9yc.js → flex-RYZsoWEN.js} +1 -1
- package/dist/storybook/assets/{flex.stories-I4p46kT6.js → flex.stories-8HJIYv6E.js} +1 -1
- package/dist/storybook/assets/footer.stories-tB9ZiuYm.js +3 -0
- package/dist/storybook/assets/form.stories-7v6JzvJl.js +49 -0
- package/dist/storybook/assets/formation.stories-gIRSy7_9.js +74 -0
- package/dist/storybook/assets/{formatter-SWP5E3XI-DSCJOjJG.js → formatter-SWP5E3XI-a7sBt194.js} +1 -1
- package/dist/storybook/assets/{heading-sY0SLHoQ.js → heading-jZsIIJF0.js} +1 -1
- package/dist/storybook/assets/{heading.stories-zStr3-HL.js → heading.stories-lW_q2VjY.js} +1 -1
- package/dist/storybook/assets/{help-icon-yrJgkgdC.js → help-icon-SKky6KLV.js} +1 -1
- package/dist/storybook/assets/{help-icon.stories-gjzAU_pF.js → help-icon.stories-i7tX8eBl.js} +1 -1
- package/dist/storybook/assets/icon-8EQazuuW.js +8 -0
- package/dist/storybook/assets/{icon.stories-jaMoeuyt.js → icon.stories-j-b_Exev.js} +1 -1
- package/dist/storybook/assets/iframe-Z5bUT4O1.js +7 -0
- package/dist/storybook/assets/index-PPLHz8o0.js +6 -0
- package/dist/storybook/assets/index-R5dkQuFe.js +3 -0
- package/dist/storybook/assets/{index-abKsB-Kl.js → index-i2tVYo5N.js} +20 -20
- package/dist/storybook/assets/{index.es-LXZC0YVN.js → index.es-VXFRDikp.js} +4 -4
- package/dist/storybook/assets/inheritsLoose-8sb_A2v4.js +1 -0
- package/dist/storybook/assets/{input-iDZqV-2m.js → input-2BhbKV-j.js} +1 -1
- package/dist/storybook/assets/{input-group.stories-UDFOhdWz.js → input-group.stories-gJFYuvVb.js} +5 -5
- package/dist/storybook/assets/{input-validation-20MUxBI6.js → input-validation-FFXJoKSI.js} +1 -1
- package/dist/storybook/assets/{input.stories-iopguZKB.js → input.stories-74EIL_bF.js} +1 -1
- package/dist/storybook/assets/{inputs-TmWBRWaW.js → inputs-DtKO2too.js} +1 -1
- package/dist/storybook/assets/{isPlainObject-4RuU_w9g.js → isPlainObject-OQlD0fAV.js} +1 -1
- package/dist/storybook/assets/{label-J7MI85wD.js → label-uCFEME1p.js} +1 -1
- package/dist/storybook/assets/{label.stories-kmvMrgz2.js → label.stories-LhXr4NuA.js} +1 -1
- package/dist/storybook/assets/{layout-forms-kkgtzmiO.js → layout-forms-7ZIITxGs.js} +1 -1
- package/dist/storybook/assets/{layout-general-BO1UiJxQ.js → layout-general-zuo7KumY.js} +1 -1
- package/dist/storybook/assets/{list-vXYnYUi0.js → list-PShi-3TE.js} +1 -1
- package/dist/storybook/assets/{list.stories-KCjHPYZx.js → list.stories-TLnvjaYU.js} +2 -2
- package/dist/storybook/assets/{list.stories-data-p4t83IOz.js → list.stories-data-Qc3oehAh.js} +1 -1
- package/dist/storybook/assets/{loader.stories-NPfeCmtc.js → loader.stories-xsnhGOV_.js} +5 -5
- package/dist/storybook/assets/{menu.stories-data-c8X93fYM.js → menu.stories-data-hEz8P1yK.js} +1 -1
- package/dist/storybook/assets/{menu.stories-t0fFav_z.js → menu.stories-ppWN2JgO.js} +6 -6
- package/dist/storybook/assets/{message-p9VAXLNZ.js → message-CRKuTfOl.js} +1 -1
- package/dist/storybook/assets/{message.stories-uPLoUdpD.js → message.stories-N8ZGvhv2.js} +1 -1
- package/dist/storybook/assets/meta-content-lUynpOsR.js +1 -0
- package/dist/storybook/assets/{modal.stories-7Z_rzYSc.js → modal.stories-dirXv4n_.js} +2 -2
- package/dist/storybook/assets/number-input-CMhEMmUd.js +1 -0
- package/dist/storybook/assets/number-input.stories-AU1jlL6D.js +97 -0
- package/dist/storybook/assets/{option-dropdown.stories-XXhHv7Q-.js → option-dropdown.stories-n7CDZevX.js} +1 -1
- package/dist/storybook/assets/{padding-and-spacing-ResQ517B.js → padding-and-spacing-3Mlm9PiC.js} +1 -1
- package/dist/storybook/assets/{page.stories-WaAu4bZx.js → page.stories-OXhmRr73.js} +1 -1
- package/dist/storybook/assets/{pagination-WmRtOUjO.js → pagination-tnyyuMkB.js} +1 -1
- package/dist/storybook/assets/{pagination.stories-leit5iOS.js → pagination.stories-c7jbEB_j.js} +2 -2
- package/dist/storybook/assets/{pop-confirm.stories-PknEXhpI.js → pop-confirm.stories-kZScSFuk.js} +1 -1
- package/dist/storybook/assets/{popover-ZT5lBU-W.js → popover-cad2llTa.js} +1 -1
- package/dist/storybook/assets/popover.stories-1JvlWYFM.js +1 -0
- package/dist/storybook/assets/{portal.stories-UGkzdgVk.js → portal.stories-1Jnj3LXz.js} +1 -1
- package/dist/storybook/assets/{preview-5oXwpv5M.js → preview-0LPoYPAJ.js} +13 -13
- package/dist/storybook/assets/preview-MDW-geT9.js +7 -0
- package/dist/storybook/assets/preview-OnO0tzRj.js +17 -0
- package/dist/storybook/assets/projects.stories-epAPUAg1.js +47 -0
- package/dist/storybook/assets/{radio-button-T38JdN-I.js → radio-button-5n_38sFk.js} +1 -1
- package/dist/storybook/assets/{radio-button.stories-MbtUJQ4_.js → radio-button.stories-Z_B_oHnZ.js} +1 -1
- package/dist/storybook/assets/react-router-dom-EZH1n7K1.js +8 -0
- package/dist/storybook/assets/{reservoirs.stories-qYaPMbjv.js → reservoirs.stories-vxBxhmZh.js} +2 -2
- package/dist/storybook/assets/{rich-text-input.stories-hYx4gSgs.js → rich-text-input.stories-EbjoMb2s.js} +3 -3
- package/dist/storybook/assets/{row.stories-1uI0HLm0.js → row.stories-p0ssjvtr.js} +2 -2
- package/dist/storybook/assets/select-DZdWUrCW.js +1 -0
- package/dist/storybook/assets/{select.stories-U32XvwIb.js → select.stories-QOxuHSmz.js} +2 -2
- package/dist/storybook/assets/{side-bar-_tR5JeGc.js → side-bar-ZpHvA_KQ.js} +1 -1
- package/dist/storybook/assets/side-bar.stories-GCjyz_UC.js +27 -0
- package/dist/storybook/assets/{site.stories-ltRQw7Km.js → site.stories-k6-tU36k.js} +2 -2
- package/dist/storybook/assets/slider-MN9iDCsS.js +7 -0
- package/dist/storybook/assets/{slider.stories-10JT-qwQ.js → slider.stories-hVrt3K9M.js} +4 -4
- package/dist/storybook/assets/{spacer.stories-hs33H_N9.js → spacer.stories-Tc3LfeOH.js} +1 -1
- package/dist/storybook/assets/syntaxhighlighter-B5GMVT5T-jueltlMw.js +1 -0
- package/dist/storybook/assets/table-033R9jUC.js +1 -0
- package/dist/storybook/assets/{table.stories-data-ehBuODKA.js → table.stories-data-NfE_v-gH.js} +1 -1
- package/dist/storybook/assets/{table.stories-63gTcmnB.js → table.stories-wdVWlpz1.js} +5 -5
- package/dist/storybook/assets/{tabs.stories-KtJc5Yci.js → tabs.stories-aps5NXFv.js} +2 -2
- package/dist/storybook/assets/text-link.stories-Mx9ojcOC.js +14 -0
- package/dist/storybook/assets/{textarea-mYEkEnUR.js → textarea-ygEac3d2.js} +1 -1
- package/dist/storybook/assets/{textarea.stories-ARS3RM31.js → textarea.stories-vr_I38NI.js} +1 -1
- package/dist/storybook/assets/{hoist-non-react-statics.cjs-pnyno-Dk.js → tiny-invariant-R4kOKlvx.js} +2 -2
- package/dist/storybook/assets/title.stories-9QWP9XVr.js +37 -0
- package/dist/storybook/assets/{toaster-bqqWcltU.js → toaster-yPcd4ELJ.js} +1 -1
- package/dist/storybook/assets/toaster.stories-D_1FY8OT.js +86 -0
- package/dist/storybook/assets/{toggle-b0PkHQDl.js → toggle-M_66MP8X.js} +1 -1
- package/dist/storybook/assets/{toggle.stories-zMCWB_3O.js → toggle.stories-VfPLoUW1.js} +1 -1
- package/dist/storybook/assets/{tooltip-ZHdi6rl-.js → tooltip-HEHiU__l.js} +1 -1
- package/dist/storybook/assets/{tooltip.stories-gTfOeEzv.js → tooltip.stories-tiOgoWHH.js} +1 -1
- package/dist/storybook/assets/{tooltip.test-case.stories-Vq8nFCVS.js → tooltip.test-case.stories-g9fe1-Ut.js} +1 -1
- package/dist/storybook/assets/{top-bar-e2jItFw6.js → top-bar-ywJJBf-H.js} +1 -1
- package/dist/storybook/assets/top-bar.stories-KkBPu_h3.js +21 -0
- package/dist/storybook/assets/{top-bar.testcase.stories-2MxbcV7T.js → top-bar.testcase.stories-RJkl6c8Z.js} +2 -2
- package/dist/storybook/assets/{tree.stories-U6RKMnnO.js → tree.stories-UiERA8eJ.js} +1 -1
- package/dist/storybook/assets/{unit-input.stories-S31ymsIe.js → unit-input.stories-NxlXJaPc.js} +15 -15
- package/dist/storybook/assets/unit-table.stories-JkNu_Up6.js +103 -0
- package/dist/storybook/iframe.html +3 -1
- package/dist/storybook/index.json +1 -1
- package/dist/storybook/project.json +1 -1
- package/dist/storybook/sb-addons/actions-0/manager-bundle.js +1 -1
- package/dist/storybook/sb-preview/globals.js +1 -1
- package/dist/storybook/sb-preview/runtime.js +19 -19
- package/dist/storybook/stories.json +1 -1
- package/package.json +1 -1
- package/dist/storybook/assets/Color-6VNJS4EI-7SF_QHKQ.js +0 -1
- package/dist/storybook/assets/DocsRenderer-NNNQARDV-zFqyxzyz.js +0 -1
- package/dist/storybook/assets/WithTooltip-4HIR6TLV--mlcCTTj.js +0 -1
- package/dist/storybook/assets/afe.stories-ArA2txnu.js +0 -88
- package/dist/storybook/assets/blowout.stories-6yWu_xKW.js +0 -40
- package/dist/storybook/assets/color-fUhGriLa.js +0 -25
- package/dist/storybook/assets/extends-dGVwEr9R.js +0 -1
- package/dist/storybook/assets/footer.stories-Mrr_R3r9.js +0 -3
- package/dist/storybook/assets/form.stories-6S2hx2wh.js +0 -49
- package/dist/storybook/assets/formation.stories-pE9W1lT-.js +0 -74
- package/dist/storybook/assets/icon-_m67DAr0.js +0 -8
- package/dist/storybook/assets/iframe-5vkaUfcR.js +0 -7
- package/dist/storybook/assets/index-gM75B7fB.js +0 -8
- package/dist/storybook/assets/inheritsLoose-Y9jOMJLd.js +0 -1
- package/dist/storybook/assets/list-heading-5IIpXtaS.js +0 -1
- package/dist/storybook/assets/number-input-wURqWy_O.js +0 -1
- package/dist/storybook/assets/number-input.stories-V3bsui-x.js +0 -81
- package/dist/storybook/assets/popover.stories-Jsd7AOQD.js +0 -1
- package/dist/storybook/assets/preview-Fi7DQdoQ.js +0 -1
- package/dist/storybook/assets/preview-XaSsmro5.js +0 -7
- package/dist/storybook/assets/projects.stories-thRPHYqQ.js +0 -47
- package/dist/storybook/assets/react-router-dom-2JKSc1g5.js +0 -8
- package/dist/storybook/assets/select-kE9fK8N9.js +0 -1
- package/dist/storybook/assets/side-bar.stories-I7ZQcntL.js +0 -27
- package/dist/storybook/assets/slider-XJwLz14m.js +0 -7
- package/dist/storybook/assets/syntaxhighlighter-NMPM6SWI-CwboJMBs.js +0 -1
- package/dist/storybook/assets/table-geCXJ5Oo.js +0 -1
- package/dist/storybook/assets/text-link.stories-_A7eKI_2.js +0 -14
- package/dist/storybook/assets/title.stories-0uqbMXQe.js +0 -37
- package/dist/storybook/assets/toaster.stories-j_yWcF95.js +0 -86
- package/dist/storybook/assets/top-bar.stories-Dz8tdKm4.js +0 -21
- package/dist/storybook/assets/unit-table.stories-8hLAgPN9.js +0 -103
- /package/dist/storybook/assets/{list-heading-dR7AAq04.css → meta-content-dR7AAq04.css} +0 -0
package/dist/storybook/assets/{unit-input.stories-S31ymsIe.js → unit-input.stories-NxlXJaPc.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as m}from"./index-RfLt4OUa.js";import{d as r,r as rn}from"./index-qZmQ7nA9.js";import{c as sn}from"./index-VW3EWkuE.js";import{u as un}from"./use-previous-VKMmnaK7.js";import{M as we}from"./actions-AZ9fI-GM.js";import{I as on}from"./input-group-addon-BHVsW9mL.js";import{B as c}from"./button-rm22C2wf.js";import{T as dn}from"./tooltip-ZHdi6rl-.js";import{I as cn}from"./input-group-R8LoqKRn.js";import{S}from"./spacer-Yji9g2AW.js";import{T as mn}from"./text-6KQ6ntOV.js";import{I as pn}from"./input-iDZqV-2m.js";import{M as Ee}from"./types-VB5zD18b.js";import{l as E}from"./lodash-Bmg8FrMx.js";import{D as gn}from"./divider-RwW2f_N0.js";import{R as qt,C as pe}from"./row-vFUhHoz5.js";import{F as I}from"./field-9udMeZdr.js";import{a as ge}from"./message-p9VAXLNZ.js";import"./index-cCpkwrS5.js";import"./common-types-U65vzrrz.js";import"./disabled-context-urNQThQz.js";import"./icon-_m67DAr0.js";import"./objectWithoutPropertiesLoose-9Q1jwsKS.js";import"./inheritsLoose-Y9jOMJLd.js";import"./tslib.es6-OIsz3r9a.js";import"./index-4QtD-hFu.js";import"./types-5uVBABF4.js";import"./badge-23Ty_zBt.js";import"./spinner-R8Il4aRe.js";import"./index-miLrID2P.js";import"./styled-components.browser.esm-qIipjd6c.js";import"./label-J7MI85wD.js";import"./help-icon-yrJgkgdC.js";const hn=()=>{const t=m.useRef(null);return m.useLayoutEffect(()=>{t.current&&(t.current(),t.current=null)}),n=>{t.current=n}},vn=(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 b=(t=>(t.CUSTOM="custom",t.PREDEFINED="predefined",t))(b||{});const Wt=t=>t==="undefined"||t===void 0||t===""||t==="null"||t===null||t==="NaN"||isNaN(t),Tt=(t="",a,n="",s=!1)=>{if(s)return t;if(a&&!Wt(t))try{const u=r.isValueWithUnit(t)?t:r.withUnit(t,n),o=r.convertSamePrecision(u,a);return r.getValue(o)}catch{}return t},fn=t=>t?!!r.getUnit(t):!1,F=(t="",a,n,s)=>{if(s)return t;const u=fn(t)||r.isValueWithUnit(t),o=r.getValue(t);return Wt(o)?o:u?Tt(o,a,n,s):t},Ne=t=>E.isObject(t)&&!E.isArray(t)&&!E.isFunction(t)?E.get(t,"fieldName",""):typeof t=="string"?t:"",Cn=t=>E.isObjectLike(t)&&E.has(t,"message"),bn=t=>typeof t=="string"?t:Cn(t)?t.message:null;var Un=rn();const yn=t=>t.search(RegExp(/(^0{2}\.)|(^0+[1-9])/g))===0,Ae=(t,a)=>{var j;const{allowEmpty:n=!1,autoValue:s,placeholder:u,disabledValidation:o=!1}=a||{},i=String(t);if(o||s||u)return null;const g=Un.isValueWithUnit(i)?r.getValue(i):i;if(n&&g==="")return null;if(yn(g))return"Invalid number format due to leading zeroes";const h=r.validateNumber(g);if(!h.valid){const re=((j=h==null?void 0:h.errors)==null?void 0:j[0])??null;return bn(re)}return null},Pe=(t="")=>{var a;return(a=r.KNOWN_UNITS)==null?void 0:a.includes(t)},xn=(t,a)=>{const n=r.getUnit(t||"");return Pe(a)&&Pe(n)},Vn="_predefinedMenuActive_1yvt4_1",In={predefinedMenuActive:Vn},p=({name:t,placeholder:a="",disabled:n=!1,disabledUnit:s=!1,error:u=null,left:o=!1,small:i=!1,width:g="100%",value:h,unitkey:j="",initUnit:re,noConversion:Rt=!1,onChange:ie=()=>{},onClick:kn=()=>{},onFocus:Lt=()=>{},onSwitchUnit:he=()=>{},unitTemplate:ve,doNotConvertValue:A=!1,testId:w,warning:Kt=null,predefinedOptions:x,initialPredefinedOption:$t=!1,shouldLinkAutomaticly:fe=!0,selectedPredefinedOptionKey:Ce,validationCallback:be=()=>({name:"",error:null}),disabledValidation:Ue=!1,allowEmpty:ye=!1,autoValue:V})=>{typeof h=="number"&&(h=`${h}`);const Ht=hn(),[se="",P=""]=h!==void 0?r.split(h):[],xe=V?r.getUnit(V):"",Ve=m.useMemo(()=>vn(j,ve),[j,ve]),zt=xn(h,Ve),U=re||Ve||P,Jt=un(U),Ie=F(h,U,P,A),je=F(V,U,xe,A),Yt=Ie!==""?{value:Ie,unit:U}:je!==""?{value:je,unit:U}:{value:se,unit:P},[v,Y]=m.useState(Yt),[Zt,ue]=m.useState(null),[k,oe]=m.useState($t?b.PREDEFINED:b.CUSTOM),de=se===""&&V,D=x&&x.find(l=>{if(Ce)return Ce===l.valueKey;const d=r.isValueWithUnit(l.value)?r.getUnit(l.value):"";return r.withUnit(Tt(h,d),d)===l.value}),Gt=()=>{if(j)try{const l=de?V:h??"";let d=r.altUnitsList(l,j);return r.getValue(l)===""?d.map(f=>["",f[1]]):d}catch{return null}},Qt=l=>{const d=Ne(t),f=l.target,{value:y,selectionStart:X}=f,Se=r.cleanNumStr(y.replaceAll(" ","").replaceAll("|","")),ce=r.withUnit(Se,(v==null?void 0:v.unit)||""),nn=r.getValue(ce),me=Ae(nn,{allowEmpty:ye,autoValue:V,placeholder:a,disabledValidation:Ue});if(me===null){ie({target:{value:ce,name:d}});const[an,ln]=r.split(ce);Y({value:an,unit:ln}),ue(null),be(d,null)}else Y({value:Se,unit:v.unit}),ue(me),be(d,me);Ht(()=>{f.selectionStart=X,f.selectionEnd=X})},Xt=(l,d)=>{d===v.unit||isNaN(Number(l))||(Y({value:l,unit:d}),he&&he(d))};m.useEffect(()=>{if(U){let f,y="";Jt!==U?(f=F(h,U,P,A),y=U):r.withUnit(v.value,v.unit)!==h&&(f=F(h,v.unit,P,A),y=v.unit),f!==void 0&&Y({value:f,unit:y}),x&&oe(D&&fe?b.PREDEFINED:b.CUSTOM)}const l=r.checkAndCleanDecimalComma(se),d=Ae(l,{allowEmpty:ye,autoValue:V,placeholder:a,disabledValidation:Ue});ue(d)},[U,h,u,fe]);const Z=Gt(),G=r.label(v.unit)||v.unit||"",en=Rt||!Z||Z&&Z.length===1,ke=Ne(t);let Q;const tn=l=>{const[d,f=""]=r.isValueWithUnit(l.value)?r.split(l.value):[l.value];return{type:Ee.OPTION,inline:!0,onClick:()=>{r.validateNumber(d).valid&&!n&&(oe(b.PREDEFINED),ie({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(mn,{children:l.label}),e.jsx(S,{width:"20px",height:"0"})]}),description:r.isValueWithUnit(l.value)?`${d} ${f}`:l.value,selected:D===l&&k===b.PREDEFINED}};if(Q=[{type:Ee.OPTION,inline:!0,onClick:()=>{k!==b.CUSTOM&&!n&&ie({target:{value:r.withUnit(v.value,v.unit),name:typeof t=="string"?t:(t==null?void 0:t.fieldName)||""}})},label:"Custom",selected:k===b.CUSTOM}],x!=null&&x.length){const l=x.map(tn);Q=[...Q,...l]}return e.jsx("div",{className:k===b.PREDEFINED?sn(In.predefinedMenuActive):"",children:e.jsxs(cn,{small:i,width:g,children:[x&&e.jsx(dn,{text:k===b.PREDEFINED?D==null?void 0:D.label:"",children:e.jsx(we,{maxHeight:380,groupOrder:"first",testId:w&&`${w}-predefined-menu`,disabled:n,menu:{colored:!0,trigger:"Component",component:e.jsx(c,{groupOrder:"first",active:k===b.PREDEFINED,icon:k===b.PREDEFINED?"link":"unlink"}),small:i,sections:Q}})}),e.jsx(pn,{type:"text",name:ke,testId:w,disabled:n,placeholder:de?F(V,v.unit,xe,A):a,value:v.value,onChange:Qt,onFocus:Lt,error:u||Zt,warning:Kt,right:!o},ke),G&&(en||!zt?e.jsx(on,{groupOrder:"last",children:G}):e.jsx(we,{maxHeight:380,groupOrder:"last",disabled:s,testId:w&&`${w}-menu`,menu:{label:G,trigger:"DropDownButton",small:i,sections:Z.map(([l,d,f])=>{const y=f||d||"";return{type:"Option",label:isNaN(Number(l))?"":l,inline:!0,onClick:X=>{X.stopPropagation(),Xt(de?"":l,d)},description:y,selected:y===G,testId:`${w}-unit-${y}`}})}}))]})})};try{p.displayName="UnitInput",p.__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"}},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:jn}=__STORYBOOK_MODULE_ADDONS__,sa={title:"Basic/UnitInput",component:p,args:{name:"example",unitkey:"length",value:"123|m"}},C=t=>{const[a,n]=jn(),s=u=>{n({value:u.target.value})};return e.jsx(p,{...t,onChange:s})},ee=C.bind({}),M=C.bind({});M.args={initUnit:"ft",unitTemplate:{length:"ft"}};const _=C.bind({});_.args={value:'123|"',unitkey:'"'};const O=C.bind({});O.args={width:"180px"};const B=C.bind({});B.args={noConversion:!0};const q=C.bind({});q.args={small:!0};const W=C.bind({});W.args={error:"Error message goes here"};const T=C.bind({});T.args={value:"asas123asd|%"};const N=C.bind({});N.args={disabled:!0,disabledUnit:!0};N.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 R=C.bind({});R.args={disabled:!0,disabledUnit:!0,noConversion:!0};const L=C.bind({});L.args={disabledUnit:!0,unitkey:void 0};const K=C.bind({});K.args={disabledUnit:!0,unitkey:"length"};const $=C.bind({});$.args={disabledUnit:!1,disabled:!0};const H=t=>{const[a,n]=m.useState("123|m"),[s,u]=m.useState("223|m"),[o,i]=m.useState("ft");return e.jsxs(e.Fragment,{children:[e.jsx(c,{label:"Change initUnit",onClick:()=>i(o==="m"?"ft":"m")}),e.jsx(S,{}),e.jsx(c,{label:"Change value",onClick:()=>n(a==="123|m"?"456|m":"123|m")}),e.jsx(S,{}),e.jsx(p,{name:"example",onChange:g=>{n(g.target.value)},unitkey:"length",value:a,initUnit:o,onSwitchUnit:i}),e.jsx(S,{}),e.jsx(p,{name:"example2",onChange:g=>{u(g.target.value)},unitkey:"length",value:s,initUnit:o,onSwitchUnit:i}),e.jsx(gn,{}),e.jsx("h4",{children:"Without initUnit property (taken from the redux store)"}),e.jsx(p,{name:"example",onChange:g=>{n(g.target.value)},unitkey:"length",value:a,onSwitchUnit:i}),e.jsx(p,{name:"example2",onChange:g=>{u(g.target.value)},unitkey:"length",value:s,onSwitchUnit:i})]})};H.parameters={docs:{description:{story:"[OW-4380](https://oliasoft.atlassian.net/browse/OW-4380?atlOrigin=eyJpIjoiMmM1N2RkNWU3Mjk5NDYxY2E0YzhkMzk5ZTVmZTJhMjciLCJwIjoiaiJ9)"}}};const z=C.bind({});z.args={predefinedOptions:[{label:"bottom of casing",value:"12|km"},{label:"mud weight at shoe depth",value:"8|mm"}]};const J=()=>{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(qt,{children:[e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value infinity",onClick:()=>n(1/0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value -infinity",onClick:()=>n(-1/0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value null",onClick:()=>n(null)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - undefined",onClick:()=>n(void 0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - NaN",onClick:()=>n(NaN)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - nothing (empty)",onClick:()=>n(void 0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - empty string",onClick:()=>n("")})]}),e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value infinity|m",onClick:()=>n("Infinity|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value -infinity|m",onClick:()=>n("-Infinity|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value null|m",onClick:()=>n("null|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - undefined|m",onClick:()=>n("undefined|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - NaN|m",onClick:()=>n("NaN|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - nothing (empty)|m",onClick:()=>n("|m")})]})]}),e.jsx("br",{}),e.jsx(I,{label:"Normal PUI",children:e.jsx(p,{name:"example1",onChange:s=>n(s.target.value),value:a,unitkey:"length",width:t,placeholder:"value|unit"})}),e.jsx(I,{label:"Disabled validation",children:e.jsx(p,{name:"example2",onChange:s=>n(s.target.value),value:a,unitkey:"length",disabledValidation:!0,width:t})}),e.jsx(I,{label:"Disabled validation and manual error",children:e.jsx(p,{name:"example3",onChange:s=>n(s.target.value),value:a,unitkey:"length",error:"test",disabledValidation:!0,width:t})}),e.jsx(ge,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})},te=()=>{const t="500px",[a,n]=m.useState("1|m"),[s,u]=m.useState("|m"),o="123|km";return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different cases for automatic (placeholder) values:"}),e.jsx(qt,{children:e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value to ''",onClick:()=>n("")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to 1",onClick:()=>n("1")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to 1|m",onClick:()=>n("1|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to |m - empty value",onClick:()=>n("|m")})]})}),e.jsx("br",{}),e.jsx(I,{label:"Normal PUI (placeholder + auto)",children:e.jsx(p,{name:"example1",onChange:i=>n(i.target.value),value:a,unitkey:"length",width:t,placeholder:"value|unit",autoValue:o})}),e.jsx(I,{label:"Normal PUI (only auto)",children:e.jsx(p,{name:"example1",onChange:i=>n(i.target.value),value:a,unitkey:"length",width:t,autoValue:o})}),e.jsx(I,{label:"Empty PUI with autoValue",children:e.jsx(p,{name:"example1",onChange:i=>u(i.target.value),value:s,unitkey:"length",width:t,autoValue:o})}),e.jsx(I,{label:"Normal PUI (only placeholder)",children:e.jsx(p,{name:"example1",onChange:i=>n(i.target.value),value:a,unitkey:"length",width:t,placeholder:"Placeholder test"})}),e.jsx(I,{label:"Normal PUI (placeholder + allowEmpty)",children:e.jsx(p,{name:"example1",onChange:i=>n(i.target.value),value:a,unitkey:"length",width:t,placeholder:"Placeholder test",allowEmpty:!0})}),e.jsx(ge,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})};J.parameters={docs:{description:{story:"[OW-8884](https://oliasoft.atlassian.net/browse/OW-8884)"}}};const ne=()=>{const[t,a]=m.useState("123|%"),[n,s]=m.useState(null),u="This should be visible when an error appears",o=(i,g)=>(s(g),{name:i,error:g});return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"3rd party validation message when inputting invalid value:"}),e.jsx(p,{name:"example",onChange:i=>a(i.target.value),error:!n||u,validationCallback:o,value:t}),e.jsx("br",{}),e.jsx(S,{}),e.jsx("h4",{children:"Original validation message: "}),e.jsx(ge,{message:{heading:n,visible:!0}})]})},ae=()=>{const[t,a]=m.useState("123|m"),[n,s]=m.useState(""),[u,o]=m.useState("km"),i=()=>{o("ft"),s("placeholder"),a("|m")};return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Empty value case:"}),e.jsx(p,{name:"example",onChange:g=>a(g.target.value),value:t,allowEmpty:!0,placeholder:n,initUnit:u,unitkey:"length"}),e.jsx("br",{}),e.jsx(S,{}),e.jsx(c,{label:"Change value |m and unit ft",onClick:()=>i()})]})},le=()=>{const[t,a]=m.useState("123|m"),[n,s]=m.useState("m");return e.jsxs(e.Fragment,{children:[e.jsx(p,{name:"example",onChange:u=>a(u.target.value),value:t,initUnit:n,unitkey:"length",onSwitchUnit:s}),e.jsx(S,{}),e.jsx(p,{name:"example",onChange:u=>a(u.target.value),value:t,initUnit:n,unitkey:"length",onSwitchUnit:s})]})};var De,Fe,Me;ee.parameters={...ee.parameters,docs:{...(De=ee.parameters)==null?void 0:De.docs,source:{originalSource:`args => {
|
|
1
|
+
import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as m}from"./index-RfLt4OUa.js";import{d as r,r as it}from"./index-qZmQ7nA9.js";import{c as st}from"./index-VW3EWkuE.js";import{u as ut}from"./use-previous-VKMmnaK7.js";import{M as we}from"./actions-mOcj9IlF.js";import{I as ot}from"./input-group-addon-BHVsW9mL.js";import{B as c}from"./button-shH4xakS.js";import{T as dt}from"./tooltip-HEHiU__l.js";import{I as ct}from"./input-group-R8LoqKRn.js";import{S}from"./spacer-Yji9g2AW.js";import{T as mt}from"./text-6KQ6ntOV.js";import{I as pt}from"./input-2BhbKV-j.js";import{M as Ee}from"./types-VB5zD18b.js";import{l as E}from"./lodash-Bmg8FrMx.js";import{D as gt}from"./divider-RwW2f_N0.js";import{R as Wn,C as pe}from"./row-vFUhHoz5.js";import{F as I}from"./field-FZX0Z7IB.js";import{M as ge}from"./message-CRKuTfOl.js";import"./index-cCpkwrS5.js";import"./common-types-U65vzrrz.js";import"./disabled-context-urNQThQz.js";import"./icon-8EQazuuW.js";import"./objectWithoutPropertiesLoose-9Q1jwsKS.js";import"./inheritsLoose-8sb_A2v4.js";import"./tslib.es6-OIsz3r9a.js";import"./index-4QtD-hFu.js";import"./types-5uVBABF4.js";import"./badge-23Ty_zBt.js";import"./spinner-R8Il4aRe.js";import"./index-miLrID2P.js";import"./styled-components.browser.esm-qIipjd6c.js";import"./label-uCFEME1p.js";import"./help-icon-SKky6KLV.js";const ht=()=>{const n=m.useRef(null);return m.useLayoutEffect(()=>{n.current&&(n.current(),n.current=null)}),t=>{n.current=t}},vt=(n,a)=>{const t=a==null?void 0:a[n];return t||(console.log(`Warning: 'unitTemplate' does not define a preferred unit for '${n}'. Defaulting to standard unit.`),r.unitFromQuantity(n)??"")};var b=(n=>(n.CUSTOM="custom",n.PREDEFINED="predefined",n))(b||{});const Tn=n=>n==="undefined"||n===void 0||n===""||n==="null"||n===null||n==="NaN"||isNaN(n),Rn=(n="",a,t="",s=!1)=>{if(s)return n;if(a&&!Tn(n))try{const u=r.isValueWithUnit(n)?n:r.withUnit(n,t),o=r.convertSamePrecision(u,a);return r.getValue(o)}catch{}return n},ft=n=>n?!!r.getUnit(n):!1,F=(n="",a,t,s)=>{if(s)return n;const u=ft(n)||r.isValueWithUnit(n),o=r.getValue(n);return Tn(o)?o:u?Rn(o,a,t,s):n},Ne=n=>E.isObject(n)&&!E.isArray(n)&&!E.isFunction(n)?E.get(n,"fieldName",""):typeof n=="string"?n:"",Ct=n=>E.isObjectLike(n)&&E.has(n,"message"),bt=n=>typeof n=="string"?n:Ct(n)?n.message:null;var Ut=it();const yt=n=>n.search(RegExp(/(^0{2}\.)|(^0+[1-9])/g))===0,Ae=(n,a)=>{var j;const{allowEmpty:t=!1,autoValue:s,placeholder:u,disabledValidation:o=!1}=a||{},i=String(n);if(o||s||u)return null;const g=Ut.isValueWithUnit(i)?r.getValue(i):i;if(t&&g==="")return null;if(yt(g))return"Invalid number format due to leading zeroes";const h=r.validateNumber(g);if(!h.valid){const re=((j=h==null?void 0:h.errors)==null?void 0:j[0])??null;return bt(re)}return null},Pe=(n="")=>{var a;return(a=r.KNOWN_UNITS)==null?void 0:a.includes(n)},xt=(n,a)=>{const t=r.getUnit(n||"");return Pe(a)&&Pe(t)},Vt="_predefinedMenuActive_1yvt4_1",It={predefinedMenuActive:Vt},p=({name:n,placeholder:a="",disabled:t=!1,disabledUnit:s=!1,error:u=null,left:o=!1,small:i=!1,width:g="100%",value:h,unitkey:j="",initUnit:re,noConversion:Ln=!1,onChange:ie=()=>{},onClick:kt=()=>{},onFocus:Kn=()=>{},onSwitchUnit:he=()=>{},unitTemplate:ve,doNotConvertValue:A=!1,testId:w,warning:$n=null,predefinedOptions:x,initialPredefinedOption:Hn=!1,shouldLinkAutomaticly:fe=!0,selectedPredefinedOptionKey:Ce,validationCallback:be=()=>({name:"",error:null}),disabledValidation:Ue=!1,allowEmpty:ye=!1,autoValue:V})=>{typeof h=="number"&&(h=`${h}`);const zn=ht(),[se="",P=""]=h!==void 0?r.split(h):[],xe=V?r.getUnit(V):"",Ve=m.useMemo(()=>vt(j,ve),[j,ve]),Jn=xt(h,Ve),U=re||Ve||P,Yn=ut(U),Ie=F(h,U,P,A),je=F(V,U,xe,A),Zn=Ie!==""?{value:Ie,unit:U}:je!==""?{value:je,unit:U}:{value:se,unit:P},[v,Y]=m.useState(Zn),[Gn,ue]=m.useState(null),[k,oe]=m.useState(Hn?b.PREDEFINED:b.CUSTOM),de=se===""&&V,D=x&&x.find(l=>{if(Ce)return Ce===l.valueKey;const d=r.isValueWithUnit(l.value)?r.getUnit(l.value):"";return r.withUnit(Rn(h,d),d)===l.value}),Qn=()=>{if(j)try{const l=de?V:h??"";let d=r.altUnitsList(l,j);return r.getValue(l)===""?d.map(f=>["",f[1]]):d}catch{return null}},Xn=l=>{const d=Ne(n),f=l.target,{value:y,selectionStart:X}=f,Se=r.cleanNumStr(y.replaceAll(" ","").replaceAll("|","")),ce=r.withUnit(Se,(v==null?void 0:v.unit)||""),at=r.getValue(ce),me=Ae(at,{allowEmpty:ye,autoValue:V,placeholder:a,disabledValidation:Ue});if(me===null){ie({target:{value:ce,name:d}});const[lt,rt]=r.split(ce);Y({value:lt,unit:rt}),ue(null),be(d,null)}else Y({value:Se,unit:v.unit}),ue(me),be(d,me);zn(()=>{f.selectionStart=X,f.selectionEnd=X})},et=(l,d)=>{d===v.unit||isNaN(Number(l))||(Y({value:l,unit:d}),he&&he(d))};m.useEffect(()=>{if(U){let f,y="";Yn!==U?(f=F(h,U,P,A),y=U):r.withUnit(v.value,v.unit)!==h&&(f=F(h,v.unit,P,A),y=v.unit),f!==void 0&&Y({value:f,unit:y}),x&&oe(D&&fe?b.PREDEFINED:b.CUSTOM)}const l=r.checkAndCleanDecimalComma(se),d=Ae(l,{allowEmpty:ye,autoValue:V,placeholder:a,disabledValidation:Ue});ue(d)},[U,h,u,fe]);const Z=Qn(),G=r.label(v.unit)||v.unit||"",nt=Ln||!Z||Z&&Z.length===1,ke=Ne(n);let Q;const tt=l=>{const[d,f=""]=r.isValueWithUnit(l.value)?r.split(l.value):[l.value];return{type:Ee.OPTION,inline:!0,onClick:()=>{r.validateNumber(d).valid&&!t&&(oe(b.PREDEFINED),ie({target:{value:l.value,name:typeof n=="string"?n:(n==null?void 0:n.fieldName)||"",predefinedSelected:!0,predefinedOption:l}}))},label:e.jsxs(e.Fragment,{children:[e.jsx(mt,{children:l.label}),e.jsx(S,{width:"20px",height:"0"})]}),description:r.isValueWithUnit(l.value)?`${d} ${f}`:l.value,selected:D===l&&k===b.PREDEFINED}};if(Q=[{type:Ee.OPTION,inline:!0,onClick:()=>{k!==b.CUSTOM&&!t&&ie({target:{value:r.withUnit(v.value,v.unit),name:typeof n=="string"?n:(n==null?void 0:n.fieldName)||""}})},label:"Custom",selected:k===b.CUSTOM}],x!=null&&x.length){const l=x.map(tt);Q=[...Q,...l]}return e.jsx("div",{className:k===b.PREDEFINED?st(It.predefinedMenuActive):"",children:e.jsxs(ct,{small:i,width:g,children:[x&&e.jsx(dt,{text:k===b.PREDEFINED?D==null?void 0:D.label:"",children:e.jsx(we,{maxHeight:380,groupOrder:"first",testId:w&&`${w}-predefined-menu`,disabled:t,menu:{colored:!0,trigger:"Component",component:e.jsx(c,{groupOrder:"first",active:k===b.PREDEFINED,icon:k===b.PREDEFINED?"link":"unlink"}),small:i,sections:Q}})}),e.jsx(pt,{type:"text",name:ke,testId:w,disabled:t,placeholder:de?F(V,v.unit,xe,A):a,value:v.value,onChange:Xn,onFocus:Kn,error:u||Gn,warning:$n,right:!o},ke),G&&(nt||!Jn?e.jsx(ot,{groupOrder:"last",children:G}):e.jsx(we,{maxHeight:380,groupOrder:"last",disabled:s,testId:w&&`${w}-menu`,menu:{label:G,trigger:"DropDownButton",small:i,sections:Z.map(([l,d,f])=>{const y=f||d||"";return{type:"Option",label:isNaN(Number(l))?"":l,inline:!0,onClick:X=>{X.stopPropagation(),et(de?"":l,d)},description:y,selected:y===G,testId:`${w}-unit-${y}`}})}}))]})})};try{p.displayName="UnitInput",p.__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"}},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:jt}=__STORYBOOK_MODULE_ADDONS__,sa={title:"Basic/UnitInput",component:p,args:{name:"example",unitkey:"length",value:"123|m"}},C=n=>{const[a,t]=jt(),s=u=>{t({value:u.target.value})};return e.jsx(p,{...n,onChange:s})},ee=C.bind({}),M=C.bind({});M.args={initUnit:"ft",unitTemplate:{length:"ft"}};const _=C.bind({});_.args={value:'123|"',unitkey:'"'};const O=C.bind({});O.args={width:"180px"};const B=C.bind({});B.args={noConversion:!0};const q=C.bind({});q.args={small:!0};const W=C.bind({});W.args={error:"Error message goes here"};const T=C.bind({});T.args={value:"asas123asd|%"};const N=C.bind({});N.args={disabled:!0,disabledUnit:!0};N.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 R=C.bind({});R.args={disabled:!0,disabledUnit:!0,noConversion:!0};const L=C.bind({});L.args={disabledUnit:!0,unitkey:void 0};const K=C.bind({});K.args={disabledUnit:!0,unitkey:"length"};const $=C.bind({});$.args={disabledUnit:!1,disabled:!0};const H=n=>{const[a,t]=m.useState("123|m"),[s,u]=m.useState("223|m"),[o,i]=m.useState("ft");return e.jsxs(e.Fragment,{children:[e.jsx(c,{label:"Change initUnit",onClick:()=>i(o==="m"?"ft":"m")}),e.jsx(S,{}),e.jsx(c,{label:"Change value",onClick:()=>t(a==="123|m"?"456|m":"123|m")}),e.jsx(S,{}),e.jsx(p,{name:"example",onChange:g=>{t(g.target.value)},unitkey:"length",value:a,initUnit:o,onSwitchUnit:i}),e.jsx(S,{}),e.jsx(p,{name:"example2",onChange:g=>{u(g.target.value)},unitkey:"length",value:s,initUnit:o,onSwitchUnit:i}),e.jsx(gt,{}),e.jsx("h4",{children:"Without initUnit property (taken from the redux store)"}),e.jsx(p,{name:"example",onChange:g=>{t(g.target.value)},unitkey:"length",value:a,onSwitchUnit:i}),e.jsx(p,{name:"example2",onChange:g=>{u(g.target.value)},unitkey:"length",value:s,onSwitchUnit:i})]})};H.parameters={docs:{description:{story:"[OW-4380](https://oliasoft.atlassian.net/browse/OW-4380?atlOrigin=eyJpIjoiMmM1N2RkNWU3Mjk5NDYxY2E0YzhkMzk5ZTVmZTJhMjciLCJwIjoiaiJ9)"}}};const z=C.bind({});z.args={predefinedOptions:[{label:"bottom of casing",value:"12|km"},{label:"mud weight at shoe depth",value:"8|mm"}]};const J=()=>{const n="500px",[a,t]=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(Wn,{children:[e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value infinity",onClick:()=>t(1/0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value -infinity",onClick:()=>t(-1/0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value null",onClick:()=>t(null)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - undefined",onClick:()=>t(void 0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - NaN",onClick:()=>t(NaN)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - nothing (empty)",onClick:()=>t(void 0)}),e.jsx("br",{}),e.jsx(c,{label:"Change value - empty string",onClick:()=>t("")})]}),e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value infinity|m",onClick:()=>t("Infinity|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value -infinity|m",onClick:()=>t("-Infinity|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value null|m",onClick:()=>t("null|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - undefined|m",onClick:()=>t("undefined|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - NaN|m",onClick:()=>t("NaN|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value - nothing (empty)|m",onClick:()=>t("|m")})]})]}),e.jsx("br",{}),e.jsx(I,{label:"Normal PUI",children:e.jsx(p,{name:"example1",onChange:s=>t(s.target.value),value:a,unitkey:"length",width:n,placeholder:"value|unit"})}),e.jsx(I,{label:"Disabled validation",children:e.jsx(p,{name:"example2",onChange:s=>t(s.target.value),value:a,unitkey:"length",disabledValidation:!0,width:n})}),e.jsx(I,{label:"Disabled validation and manual error",children:e.jsx(p,{name:"example3",onChange:s=>t(s.target.value),value:a,unitkey:"length",error:"test",disabledValidation:!0,width:n})}),e.jsx(ge,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})},ne=()=>{const n="500px",[a,t]=m.useState("1|m"),[s,u]=m.useState("|m"),o="123|km";return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different cases for automatic (placeholder) values:"}),e.jsx(Wn,{children:e.jsxs(pe,{width:"25%",children:[e.jsx(c,{label:"Change value to ''",onClick:()=>t("")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to 1",onClick:()=>t("1")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to 1|m",onClick:()=>t("1|m")}),e.jsx("br",{}),e.jsx(c,{label:"Change value to |m - empty value",onClick:()=>t("|m")})]})}),e.jsx("br",{}),e.jsx(I,{label:"Normal PUI (placeholder + auto)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,placeholder:"value|unit",autoValue:o})}),e.jsx(I,{label:"Normal PUI (only auto)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,autoValue:o})}),e.jsx(I,{label:"Empty PUI with autoValue",children:e.jsx(p,{name:"example1",onChange:i=>u(i.target.value),value:s,unitkey:"length",width:n,autoValue:o})}),e.jsx(I,{label:"Normal PUI (only placeholder)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,placeholder:"Placeholder test"})}),e.jsx(I,{label:"Normal PUI (placeholder + allowEmpty)",children:e.jsx(p,{name:"example1",onChange:i=>t(i.target.value),value:a,unitkey:"length",width:n,placeholder:"Placeholder test",allowEmpty:!0})}),e.jsx(ge,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})};J.parameters={docs:{description:{story:"[OW-8884](https://oliasoft.atlassian.net/browse/OW-8884)"}}};const te=()=>{const[n,a]=m.useState("123|%"),[t,s]=m.useState(null),u="This should be visible when an error appears",o=(i,g)=>(s(g),{name:i,error:g});return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"3rd party validation message when inputting invalid value:"}),e.jsx(p,{name:"example",onChange:i=>a(i.target.value),error:!t||u,validationCallback:o,value:n}),e.jsx("br",{}),e.jsx(S,{}),e.jsx("h4",{children:"Original validation message: "}),e.jsx(ge,{message:{heading:t,visible:!0}})]})},ae=()=>{const[n,a]=m.useState("123|m"),[t,s]=m.useState(""),[u,o]=m.useState("km"),i=()=>{o("ft"),s("placeholder"),a("|m")};return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Empty value case:"}),e.jsx(p,{name:"example",onChange:g=>a(g.target.value),value:n,allowEmpty:!0,placeholder:t,initUnit:u,unitkey:"length"}),e.jsx("br",{}),e.jsx(S,{}),e.jsx(c,{label:"Change value |m and unit ft",onClick:()=>i()})]})},le=()=>{const[n,a]=m.useState("123|m"),[t,s]=m.useState("m");return e.jsxs(e.Fragment,{children:[e.jsx(p,{name:"example",onChange:u=>a(u.target.value),value:n,initUnit:t,unitkey:"length",onSwitchUnit:s}),e.jsx(S,{}),e.jsx(p,{name:"example",onChange:u=>a(u.target.value),value:n,initUnit:t,unitkey:"length",onSwitchUnit:s})]})};var De,Fe,Me;ee.parameters={...ee.parameters,docs:{...(De=ee.parameters)==null?void 0:De.docs,source:{originalSource:`args => {
|
|
2
2
|
const [_, updateArgs] = useArgs();
|
|
3
3
|
const handleChange = (evt: any) => {
|
|
4
4
|
updateArgs({
|
|
@@ -54,7 +54,7 @@ import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as m}from"./index-RfLt4OU
|
|
|
54
54
|
});
|
|
55
55
|
};
|
|
56
56
|
return <UnitInput {...args} onChange={handleChange} />;
|
|
57
|
-
}`,...(Xe=(Qe=W.parameters)==null?void 0:Qe.docs)==null?void 0:Xe.source}}};var
|
|
57
|
+
}`,...(Xe=(Qe=W.parameters)==null?void 0:Qe.docs)==null?void 0:Xe.source}}};var en,nn,tn;T.parameters={...T.parameters,docs:{...(en=T.parameters)==null?void 0:en.docs,source:{originalSource:`args => {
|
|
58
58
|
const [_, updateArgs] = useArgs();
|
|
59
59
|
const handleChange = (evt: any) => {
|
|
60
60
|
updateArgs({
|
|
@@ -62,7 +62,7 @@ import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as m}from"./index-RfLt4OU
|
|
|
62
62
|
});
|
|
63
63
|
};
|
|
64
64
|
return <UnitInput {...args} onChange={handleChange} />;
|
|
65
|
-
}`,...(
|
|
65
|
+
}`,...(tn=(nn=T.parameters)==null?void 0:nn.docs)==null?void 0:tn.source}}};var an,ln,rn;N.parameters={...N.parameters,docs:{...(an=N.parameters)==null?void 0:an.docs,source:{originalSource:`args => {
|
|
66
66
|
const [_, updateArgs] = useArgs();
|
|
67
67
|
const handleChange = (evt: any) => {
|
|
68
68
|
updateArgs({
|
|
@@ -70,7 +70,7 @@ import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as m}from"./index-RfLt4OU
|
|
|
70
70
|
});
|
|
71
71
|
};
|
|
72
72
|
return <UnitInput {...args} onChange={handleChange} />;
|
|
73
|
-
}`,...(
|
|
73
|
+
}`,...(rn=(ln=N.parameters)==null?void 0:ln.docs)==null?void 0:rn.source}}};var sn,un,on;R.parameters={...R.parameters,docs:{...(sn=R.parameters)==null?void 0:sn.docs,source:{originalSource:`args => {
|
|
74
74
|
const [_, updateArgs] = useArgs();
|
|
75
75
|
const handleChange = (evt: any) => {
|
|
76
76
|
updateArgs({
|
|
@@ -78,7 +78,7 @@ import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as m}from"./index-RfLt4OU
|
|
|
78
78
|
});
|
|
79
79
|
};
|
|
80
80
|
return <UnitInput {...args} onChange={handleChange} />;
|
|
81
|
-
}`,...(
|
|
81
|
+
}`,...(on=(un=R.parameters)==null?void 0:un.docs)==null?void 0:on.source}}};var dn,cn,mn;L.parameters={...L.parameters,docs:{...(dn=L.parameters)==null?void 0:dn.docs,source:{originalSource:`args => {
|
|
82
82
|
const [_, updateArgs] = useArgs();
|
|
83
83
|
const handleChange = (evt: any) => {
|
|
84
84
|
updateArgs({
|
|
@@ -86,7 +86,7 @@ import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as m}from"./index-RfLt4OU
|
|
|
86
86
|
});
|
|
87
87
|
};
|
|
88
88
|
return <UnitInput {...args} onChange={handleChange} />;
|
|
89
|
-
}`,...(
|
|
89
|
+
}`,...(mn=(cn=L.parameters)==null?void 0:cn.docs)==null?void 0:mn.source}}};var pn,gn,hn;K.parameters={...K.parameters,docs:{...(pn=K.parameters)==null?void 0:pn.docs,source:{originalSource:`args => {
|
|
90
90
|
const [_, updateArgs] = useArgs();
|
|
91
91
|
const handleChange = (evt: any) => {
|
|
92
92
|
updateArgs({
|
|
@@ -94,7 +94,7 @@ import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as m}from"./index-RfLt4OU
|
|
|
94
94
|
});
|
|
95
95
|
};
|
|
96
96
|
return <UnitInput {...args} onChange={handleChange} />;
|
|
97
|
-
}`,...(
|
|
97
|
+
}`,...(hn=(gn=K.parameters)==null?void 0:gn.docs)==null?void 0:hn.source}}};var vn,fn,Cn;$.parameters={...$.parameters,docs:{...(vn=$.parameters)==null?void 0:vn.docs,source:{originalSource:`args => {
|
|
98
98
|
const [_, updateArgs] = useArgs();
|
|
99
99
|
const handleChange = (evt: any) => {
|
|
100
100
|
updateArgs({
|
|
@@ -102,7 +102,7 @@ import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as m}from"./index-RfLt4OU
|
|
|
102
102
|
});
|
|
103
103
|
};
|
|
104
104
|
return <UnitInput {...args} onChange={handleChange} />;
|
|
105
|
-
}`,...(
|
|
105
|
+
}`,...(Cn=(fn=$.parameters)==null?void 0:fn.docs)==null?void 0:Cn.source}}};var bn,Un,yn;H.parameters={...H.parameters,docs:{...(bn=H.parameters)==null?void 0:bn.docs,source:{originalSource:`(args: IUnitInputProps) => {
|
|
106
106
|
const [value, setValue] = useState('123|m');
|
|
107
107
|
const [value2, setValue2] = useState('223|m');
|
|
108
108
|
const [initUnit, setInitUnit] = useState('ft');
|
|
@@ -127,7 +127,7 @@ import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as m}from"./index-RfLt4OU
|
|
|
127
127
|
setValue2(evt.target.value);
|
|
128
128
|
}} unitkey="length" value={value2} onSwitchUnit={setInitUnit} />
|
|
129
129
|
</>;
|
|
130
|
-
}`,...(
|
|
130
|
+
}`,...(yn=(Un=H.parameters)==null?void 0:Un.docs)==null?void 0:yn.source}}};var xn,Vn,In;z.parameters={...z.parameters,docs:{...(xn=z.parameters)==null?void 0:xn.docs,source:{originalSource:`args => {
|
|
131
131
|
const [_, updateArgs] = useArgs();
|
|
132
132
|
const handleChange = (evt: any) => {
|
|
133
133
|
updateArgs({
|
|
@@ -135,7 +135,7 @@ import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as m}from"./index-RfLt4OU
|
|
|
135
135
|
});
|
|
136
136
|
};
|
|
137
137
|
return <UnitInput {...args} onChange={handleChange} />;
|
|
138
|
-
}`,...(
|
|
138
|
+
}`,...(In=(Vn=z.parameters)==null?void 0:Vn.docs)==null?void 0:In.source}}};var jn,kn,Sn;J.parameters={...J.parameters,docs:{...(jn=J.parameters)==null?void 0:jn.docs,source:{originalSource:`() => {
|
|
139
139
|
const width = '500px';
|
|
140
140
|
const [value, setValue] = useState<any>(undefined);
|
|
141
141
|
return <>
|
|
@@ -185,7 +185,7 @@ import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as m}from"./index-RfLt4OU
|
|
|
185
185
|
visible: true
|
|
186
186
|
}} />
|
|
187
187
|
</>;
|
|
188
|
-
}`,...(
|
|
188
|
+
}`,...(Sn=(kn=J.parameters)==null?void 0:kn.docs)==null?void 0:Sn.source}}};var wn,En,Nn;ne.parameters={...ne.parameters,docs:{...(wn=ne.parameters)==null?void 0:wn.docs,source:{originalSource:`() => {
|
|
189
189
|
const width = '500px';
|
|
190
190
|
const [value, setValue] = useState<string>('1|m');
|
|
191
191
|
const [valueB, setValueB] = useState('|m');
|
|
@@ -224,7 +224,7 @@ import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as m}from"./index-RfLt4OU
|
|
|
224
224
|
visible: true
|
|
225
225
|
}} />
|
|
226
226
|
</>;
|
|
227
|
-
}`,...(
|
|
227
|
+
}`,...(Nn=(En=ne.parameters)==null?void 0:En.docs)==null?void 0:Nn.source}}};var An,Pn,Dn;te.parameters={...te.parameters,docs:{...(An=te.parameters)==null?void 0:An.docs,source:{originalSource:`() => {
|
|
228
228
|
const [value, setValue] = useState('123|%');
|
|
229
229
|
const [validation, setValidation] = useState<string | null>(null);
|
|
230
230
|
const predictedMessage = 'This should be visible when an error appears';
|
|
@@ -246,7 +246,7 @@ import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as m}from"./index-RfLt4OU
|
|
|
246
246
|
visible: true
|
|
247
247
|
}} />
|
|
248
248
|
</>;
|
|
249
|
-
}`,...(
|
|
249
|
+
}`,...(Dn=(Pn=te.parameters)==null?void 0:Pn.docs)==null?void 0:Dn.source}}};var Fn,Mn,_n;ae.parameters={...ae.parameters,docs:{...(Fn=ae.parameters)==null?void 0:Fn.docs,source:{originalSource:`() => {
|
|
250
250
|
const [value, setValue] = useState('123|m');
|
|
251
251
|
const [placeholder, setPlaceholder] = useState('');
|
|
252
252
|
const [initUnit, setInitUnit] = useState('km');
|
|
@@ -262,7 +262,7 @@ import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as m}from"./index-RfLt4OU
|
|
|
262
262
|
<Spacer />
|
|
263
263
|
<Button label="Change value |m and unit ft" onClick={() => setPlaceholderValue()} />
|
|
264
264
|
</>;
|
|
265
|
-
}`,...(
|
|
265
|
+
}`,...(_n=(Mn=ae.parameters)==null?void 0:Mn.docs)==null?void 0:_n.source}}};var On,Bn,qn;le.parameters={...le.parameters,docs:{...(On=le.parameters)==null?void 0:On.docs,source:{originalSource:`() => {
|
|
266
266
|
const [value, setValue] = useState('123|m');
|
|
267
267
|
const [unit, setUnit] = useState('m');
|
|
268
268
|
return <>
|
|
@@ -270,4 +270,4 @@ import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as m}from"./index-RfLt4OU
|
|
|
270
270
|
<Spacer />
|
|
271
271
|
<UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} initUnit={unit} unitkey="length" onSwitchUnit={setUnit} />
|
|
272
272
|
</>;
|
|
273
|
-
}`,...(
|
|
273
|
+
}`,...(qn=(Bn=le.parameters)==null?void 0:Bn.docs)==null?void 0:qn.source}}};const ua=["Default","InitUnit","notKnownUnit","Width","NoConversion","Small","Error","InternalValidationError","Disabled","DisabledNoConversion","DisabledUnitWithoutUnitKey","DisabledUnitWithUnitKey","DisabledWithEnabledUnitMenu","TestExternalStateChangeWithSynchronizedUnits","PredefinedOptionsMenu","TestEdgeCases","AutomaticValues","ValidationCallback","AllowEmptyPUI","onSwitchUnit"];export{ae as AllowEmptyPUI,ne as AutomaticValues,ee as Default,N as Disabled,R as DisabledNoConversion,K as DisabledUnitWithUnitKey,L as DisabledUnitWithoutUnitKey,$ as DisabledWithEnabledUnitMenu,W as Error,M as InitUnit,T as InternalValidationError,B as NoConversion,z as PredefinedOptionsMenu,q as Small,J as TestEdgeCases,H as TestExternalStateChangeWithSynchronizedUnits,te as ValidationCallback,O as Width,ua as __namedExportsOrder,sa as default,_ as notKnownUnit,le as onSwitchUnit};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import{j as i}from"./jsx-runtime-FsUICBgo.js";import{r as h}from"./index-RfLt4OUa.js";import{f as $}from"./immer.esm-bD7SSJ7T.js";import{d as U}from"./index-qZmQ7nA9.js";import{G as z}from"./grid-u1mZpaML.js";import{C as D}from"./card-0r8RRVk-.js";import{F as M}from"./field-FZX0Z7IB.js";import{H as R}from"./heading-jZsIIJF0.js";import{S as W}from"./select-DZdWUrCW.js";import{l as X}from"./lodash-Bmg8FrMx.js";import{u as Y}from"./use-previous-VKMmnaK7.js";import{T as Z,C as K}from"./table-033R9jUC.js";import"./index-cCpkwrS5.js";import"./styled-components.browser.esm-qIipjd6c.js";import"./tslib.es6-OIsz3r9a.js";import"./index-VW3EWkuE.js";import"./label-uCFEME1p.js";import"./common-types-U65vzrrz.js";import"./help-icon-SKky6KLV.js";import"./tooltip-HEHiU__l.js";import"./index-miLrID2P.js";import"./icon-8EQazuuW.js";import"./objectWithoutPropertiesLoose-9Q1jwsKS.js";import"./inheritsLoose-8sb_A2v4.js";import"./index-4QtD-hFu.js";import"./disabled-context-urNQThQz.js";import"./types-5uVBABF4.js";import"./assertThisInitialized-4q6YPdh3.js";import"./memoize-one.esm-hqe5SRxC.js";import"./types-VB5zD18b.js";import"./text-6KQ6ntOV.js";import"./actions-mOcj9IlF.js";import"./button-shH4xakS.js";import"./spinner-R8Il4aRe.js";import"./badge-23Ty_zBt.js";import"./select.input-zP5tW20f.js";import"./index.es-VXFRDikp.js";import"./redux-F5dueAP3.js";import"./objectSpread2-93s0nBry.js";import"./tiny-invariant-R4kOKlvx.js";import"./pagination-tnyyuMkB.js";import"./input-2BhbKV-j.js";import"./input-group-R8LoqKRn.js";import"./input-group-addon-BHVsW9mL.js";import"./number-input-CMhEMmUd.js";import"./check-box-2gxosI3y.js";import"./slider-MN9iDCsS.js";import"./index-ugi_ZH6T.js";import"./popover-cad2llTa.js";const ee=a=>a.reduce(({preferredUnits:n,storageUnits:t},{unitKey:o,preferredUnit:u,storageUnit:c})=>(n[o]=u,t[o]=c,{preferredUnits:n,storageUnits:t}),{preferredUnits:{},storageUnits:{}}),te=({headers:a,rows:n,selectedUnits:t,storageUnits:o,onChangeUnit:u,convertBackToStorageUnit:c,enableCosmeticRounding:r,enableDisplayRounding:d,roundDisplayValue:p})=>{const f=a?a.map(s=>({...s,cells:s.cells.map(l=>{if(l.type===K.AUTO_UNIT){const{unitKey:e}=l;return{value:t[e],type:K.SELECT,options:U.getUnitsForQuantity(e),native:!0,onChange:b=>u({unitKey:e,value:b.target.value})}}return l})})):[],m=n?n.map((s,l)=>({...s,cells:s.cells.map((e,b)=>{if("autoUnit"in e&&(e!=null&&e.autoUnit)&&(typeof(e==null?void 0:e.value)=="string"||typeof(e==null?void 0:e.value)=="number")){const{formatDisplayValue:g,unitKey:y,value:T}=e,x=t[y],v=o[y],S=x!==v,N=S?U.convertAndGetValue(T,x,v):e.value,B=U.isScientificStringNum(T),A=r&&(S||!B)?U.roundToPrecision(N,14):N,k=g?g(A):A;return{...e,value:k,enableCosmeticRounding:r,enableDisplayRounding:d,roundDisplayValue:p,onChange:w=>{const{value:_}=w.target,V=o[y],I=t[y],O=I!==V?U.convertAndGetValue(_,V,I):_,L=c?V:I;if("onChange"in e){const{onChange:Q}=e,J={...w,target:{...w.target,value:String(O),rowIndex:l,cellIndex:b,unit:L}};Q(J)}}}}return e})})):[];return{convertedHeaders:f,convertedRows:m}},j=({table:a,unitConfig:n,convertBackToStorageUnit:t=!0,enableCosmeticRounding:o=!0,enableDisplayRounding:u=!0,roundDisplayValue:c})=>{const{rows:r,headers:d,...p}=a,{storageUnits:f,preferredUnits:m}=ee(n),s=Y(m),[l,e]=h.useState(m),b=({unitKey:v,value:S})=>e({...l,[v]:S}),g=v=>te({headers:d,rows:r,selectedUnits:v,storageUnits:f,onChangeUnit:b,convertBackToStorageUnit:t,enableCosmeticRounding:o,enableDisplayRounding:u,roundDisplayValue:c}),y=g(l),[T,x]=h.useState(y);return h.useEffect(()=>{!X.isEqual(m,s)&&(e(m),x(g(m)))},[n]),h.useEffect(()=>{x(g(l))},[a,l]),i.jsx(Z,{table:{...p,headers:T.convertedHeaders,rows:T.convertedRows}})};try{j.displayName="UnitTable",j.__docgenInfo={description:"",displayName:"UnitTable",props:{table:{defaultValue:null,description:"",name:"table",required:!0,type:{name:"IUnitTable"}},unitConfig:{defaultValue:null,description:"",name:"unitConfig",required:!0,type:{name:"IUnitConfigItem[]"}},convertBackToStorageUnit:{defaultValue:{value:"true"},description:"",name:"convertBackToStorageUnit",required:!1,type:{name:"boolean"}},enableCosmeticRounding:{defaultValue:{value:"true"},description:"",name:"enableCosmeticRounding",required:!1,type:{name:"boolean"}},enableDisplayRounding:{defaultValue:{value:"true"},description:"",name:"enableDisplayRounding",required:!1,type:{name:"boolean"}},roundDisplayValue:{defaultValue:null,description:"",name:"roundDisplayValue",required:!1,type:{name:"((value: TStringNumberNull) => TStringNumberNull)"}},onListReorder:{defaultValue:null,description:"",name:"onListReorder",required:!1,type:{name:"((obj: { from: number; to: number; }) => void)"}}}}}catch{}const at={title:"Basic/UnitTable",args:{}},ne=!0,re=!0,G="m",ae=3,oe=(a,n)=>{const t=[n,n,n],o=[...Array(Number(a))].map((u,c)=>{const r=c,d=c+1.25,p=d-r;return[String(r),String(d),String(p)]});return[t].concat(o)},ie=oe(ae,G),se=({reduxTable:a,value:n,rowIndex:t,cellIndex:o})=>$(a,u=>{u[t+1][o]=n}),C=()=>{const[a,n]=h.useState(G),[t,o]=h.useState(ie),u=r=>{const{rowIndex:d,cellIndex:p,value:f,unit:m}=r.target,s=se({reduxTable:t,value:f,rowIndex:d,cellIndex:p});o(s)},c=t.reduce((r,d,p)=>(p===0?r.headers=[{cells:[{value:"From"},{value:"To"},{value:"Delta"}]},{cells:[{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"length"}]}]:r.rows=r.rows.concat({cells:d.map((f,m)=>{const s=p===1&&m===1;return{value:f,type:s?"Text":"NumberInput",unitKey:"length",onChange:u,formatDisplayValue:s?g=>`T* ${g}`:null,autoUnit:!0}})}),r),{headers:[],rows:[]});return i.jsxs(z,{columns:"1fr 1fr",gap:!0,children:[i.jsx(D,{heading:i.jsx(R,{children:"Global View Settings"}),children:i.jsx(M,{label:"Active Unit Template",children:i.jsx(W,{options:U.getUnitsForQuantity("length"),value:{value:a},onChange:r=>n(r.target.value),width:"100px"})})}),i.jsx(D,{heading:i.jsx(R,{children:"UnitTable"}),children:i.jsx(j,{table:c,unitConfig:[{unitKey:"length",storageUnit:t[0][0],preferredUnit:a}],convertBackToStorageUnit:ne,enableCosmeticRounding:re})}),i.jsx(D,{heading:i.jsx(R,{children:"Storage State (Redux)"}),children:i.jsx("pre",{children:i.jsx("code",{children:JSON.stringify(t,null,2)})})})]})};var E,H,F,P,q;C.parameters={...C.parameters,docs:{...(E=C.parameters)==null?void 0:E.docs,source:{originalSource:`() => {
|
|
2
|
+
const [preferredUnit, setPreferredUnit] = useState(initialUnit);
|
|
3
|
+
const [reduxTable, setReduxTable] = useState(initialTable);
|
|
4
|
+
|
|
5
|
+
/*********************************************************************************************************************
|
|
6
|
+
Cell onChange handler
|
|
7
|
+
*********************************************************************************************************************/
|
|
8
|
+
const onUpdateCell = (evt: IUnitTableOnChangeEvent) => {
|
|
9
|
+
const {
|
|
10
|
+
rowIndex,
|
|
11
|
+
cellIndex,
|
|
12
|
+
value,
|
|
13
|
+
unit
|
|
14
|
+
} = evt.target;
|
|
15
|
+
const nextTable = convertWholeTable ? convertStorageTable({
|
|
16
|
+
reduxTable,
|
|
17
|
+
value,
|
|
18
|
+
unit,
|
|
19
|
+
rowIndex,
|
|
20
|
+
cellIndex
|
|
21
|
+
}) : updateCell({
|
|
22
|
+
reduxTable,
|
|
23
|
+
value,
|
|
24
|
+
rowIndex,
|
|
25
|
+
cellIndex
|
|
26
|
+
});
|
|
27
|
+
setReduxTable(nextTable);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/*********************************************************************************************************************
|
|
31
|
+
Construct table view data (same as old Table component, with a new props)
|
|
32
|
+
*********************************************************************************************************************/
|
|
33
|
+
const tableViewData = reduxTable.reduce((acc, row, rowIndex) => {
|
|
34
|
+
if (rowIndex === 0) {
|
|
35
|
+
acc.headers = [{
|
|
36
|
+
cells: [{
|
|
37
|
+
value: 'From'
|
|
38
|
+
}, {
|
|
39
|
+
value: 'To'
|
|
40
|
+
}, {
|
|
41
|
+
value: 'Delta'
|
|
42
|
+
}]
|
|
43
|
+
}, {
|
|
44
|
+
cells: [{
|
|
45
|
+
type: 'AutoUnit',
|
|
46
|
+
unitKey: 'length'
|
|
47
|
+
}, {
|
|
48
|
+
type: 'AutoUnit',
|
|
49
|
+
unitKey: 'length'
|
|
50
|
+
}, {
|
|
51
|
+
type: 'AutoUnit',
|
|
52
|
+
unitKey: 'length'
|
|
53
|
+
}]
|
|
54
|
+
}];
|
|
55
|
+
} else {
|
|
56
|
+
acc.rows = acc.rows.concat({
|
|
57
|
+
cells: row.map((cell, cellIndex) => {
|
|
58
|
+
const specialCell = rowIndex === 1 && cellIndex === 1;
|
|
59
|
+
const type = specialCell ? 'Text' : 'NumberInput';
|
|
60
|
+
const formatDisplayValue = specialCell ? (value: number | string) => \`T* \${value}\` : null;
|
|
61
|
+
const value = cell;
|
|
62
|
+
return {
|
|
63
|
+
value,
|
|
64
|
+
type,
|
|
65
|
+
unitKey: 'length',
|
|
66
|
+
onChange: onUpdateCell,
|
|
67
|
+
formatDisplayValue,
|
|
68
|
+
autoUnit: true
|
|
69
|
+
};
|
|
70
|
+
})
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return acc;
|
|
74
|
+
}, {
|
|
75
|
+
headers: ([] as any[]),
|
|
76
|
+
rows: ([] as IUnitTableRow[])
|
|
77
|
+
});
|
|
78
|
+
return <Grid columns="1fr 1fr" gap>
|
|
79
|
+
<Card heading={<Heading>Global View Settings</Heading>}>
|
|
80
|
+
<Field label="Active Unit Template">
|
|
81
|
+
<Select options={getUnitsForQuantity('length')} value={{
|
|
82
|
+
value: preferredUnit
|
|
83
|
+
}} onChange={evt => setPreferredUnit(evt.target.value)} width="100px" />
|
|
84
|
+
</Field>
|
|
85
|
+
</Card>
|
|
86
|
+
<Card heading={<Heading>UnitTable</Heading>}>
|
|
87
|
+
<UnitTable table={tableViewData}
|
|
88
|
+
//New props:
|
|
89
|
+
unitConfig={[{
|
|
90
|
+
unitKey: 'length',
|
|
91
|
+
storageUnit: reduxTable[0][0],
|
|
92
|
+
preferredUnit
|
|
93
|
+
}]}
|
|
94
|
+
//Most tables should just use the default values here (true):
|
|
95
|
+
convertBackToStorageUnit={convertBackToStorageUnit} enableCosmeticRounding={enableCosmeticRounding} />
|
|
96
|
+
</Card>
|
|
97
|
+
<Card heading={<Heading>Storage State (Redux)</Heading>}>
|
|
98
|
+
<pre>
|
|
99
|
+
<code>{JSON.stringify(reduxTable, null, 2)}</code>
|
|
100
|
+
</pre>
|
|
101
|
+
</Card>
|
|
102
|
+
</Grid>;
|
|
103
|
+
}`,...(F=(H=C.parameters)==null?void 0:H.docs)==null?void 0:F.source},description:{story:"Story",...(q=(P=C.parameters)==null?void 0:P.docs)==null?void 0:q.description}}};const ot=["UnitTablePrototype"];export{C as UnitTablePrototype,ot as __namedExportsOrder,at as default};
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
window.STORIES = [{"titlePrefix":"","directory":"./src/components","files":"**/*.mdx","importPathMatcher":"^\\.[\\\\/](?:src\\/components(?:\\/(?!\\.)(?:(?:(?!(?:^|\\/)\\.).)*?)\\/|\\/|$)(?!\\.)(?=.)[^/]*?\\.mdx)$"},{"titlePrefix":"","directory":"./src","files":"**/*.stories.@(js|jsx|ts|tsx)","importPathMatcher":"^\\.[\\\\/](?:src(?:\\/(?!\\.)(?:(?:(?!(?:^|\\/)\\.).)*?)\\/|\\/|$)(?!\\.)(?=.)[^/]*?\\.stories\\.(js|jsx|ts|tsx))$"}];
|
|
23
23
|
window.DOCS_OPTIONS = {"defaultName":"Docs","autodocs":true};
|
|
24
24
|
|
|
25
|
+
|
|
26
|
+
|
|
25
27
|
// We do this so that "module && module.hot" etc. in Storybook source code
|
|
26
28
|
// doesn't fail (it will simply be disabled)
|
|
27
29
|
window.module = undefined;
|
|
@@ -357,7 +359,7 @@
|
|
|
357
359
|
}
|
|
358
360
|
</script>
|
|
359
361
|
|
|
360
|
-
<script type="module" crossorigin src="./assets/iframe-
|
|
362
|
+
<script type="module" crossorigin src="./assets/iframe-Z5bUT4O1.js"></script>
|
|
361
363
|
</head>
|
|
362
364
|
|
|
363
365
|
<body>
|