@oliasoft-open-source/react-ui-library 4.10.7 → 4.11.0-beta-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +27 -31
- package/dist/index.js.map +1 -1
- package/dist/storybook/assets/{Color-KGDBMAHA-D26yaCjU.js → Color-KGDBMAHA-DNHJyTIW.js} +1 -1
- package/dist/storybook/assets/{DocsRenderer-PKQXORMH-vElC6boV.js → DocsRenderer-PKQXORMH-C9rr-9Kf.js} +1 -1
- package/dist/storybook/assets/{buttons-and-links-Bzw6sQEl.js → buttons-and-links-BR6gQ0FR.js} +1 -1
- package/dist/storybook/assets/{chunk-HLWAVYOI-Dub2zPy2.js → chunk-HLWAVYOI-xZeJ0r5F.js} +1 -1
- package/dist/storybook/assets/{color-sXpR2rDi.js → color-CL4Yvq6B.js} +1 -1
- package/dist/storybook/assets/{iframe-DfbvzuKW.js → iframe-DtGyYU7Y.js} +2 -2
- package/dist/storybook/assets/{index-CI3hSkVq.js → index-BLlJkNz-.js} +88 -88
- package/dist/storybook/assets/{index-Cj40cYYp.js → index-DOnfURi4.js} +1 -1
- package/dist/storybook/assets/initialize-context-ScheoYVG.js +1 -0
- package/dist/storybook/assets/{input-validation-5WW8MSTd.js → input-validation-e-lIRBH9.js} +1 -1
- package/dist/storybook/assets/{inputs-C6ZKc-en.js → inputs-i9oqcOde.js} +1 -1
- package/dist/storybook/assets/{layout-forms-Davxfa-B.js → layout-forms-CSDOaD98.js} +1 -1
- package/dist/storybook/assets/{layout-general-C4k_FsG1.js → layout-general-Ch_fXD34.js} +1 -1
- package/dist/storybook/assets/{padding-and-spacing-ChZ-7T_N.js → padding-and-spacing-CGADpYHw.js} +1 -1
- package/dist/storybook/assets/{preview-Dn1IHTmv.js → preview-BMsQEfL5.js} +1 -1
- package/dist/storybook/assets/{preview-Blwe7Q4Y.js → preview-DFAYoqIF.js} +2 -2
- package/dist/storybook/assets/{unit-input.stories-9b23SnFs.js → unit-input.stories-D-520BU0.js} +5 -5
- package/dist/storybook/assets/unit-table.stories-DT8GuYu8.js +152 -0
- package/dist/storybook/iframe.html +1 -1
- package/dist/storybook/project.json +1 -1
- package/package.json +1 -1
- package/dist/404.html +0 -1
- package/dist/storybook/assets/unit-table.stories-CEqyw4pW.js +0 -152
- package/dist/storybook/assets/use-previous-D775JrO6.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{o as n,X as T,m as l,a as c,A as H,l as L,u as B,s as b,b as S,J as u,O as C,w as h,c as d,p as g,d as y,f as F,h as I,e as k,g as x,D as A,v as P,i as R,B as W,j as f,q as D,k as E,y as N,n as q,z as v,r as w,C as O,x as U,_ as j,E as z,t as G,F as J,G as K,H as M,I as Q,K as V,L as X,S as Y,M as Z,N as _,P as $,Q as aa,R as sa,T as oa,U as ta,W as ra,V as ea,Y as ia}from"./index-
|
|
1
|
+
import{o as n,X as T,m as l,a as c,A as H,l as L,u as B,s as b,b as S,J as u,O as C,w as h,c as d,p as g,d as y,f as F,h as I,e as k,g as x,D as A,v as P,i as R,B as W,j as f,q as D,k as E,y as N,n as q,z as v,r as w,C as O,x as U,_ as j,E as z,t as G,F as J,G as K,H as M,I as Q,K as V,L as X,S as Y,M as Z,N as _,P as $,Q as aa,R as sa,T as oa,U as ta,W as ra,V as ea,Y as ia}from"./index-BLlJkNz-.js";import"./iframe-DtGyYU7Y.js";import"../sb-preview/runtime.js";import"./index-DhsZuJvc.js";import"./index-CUZDtIZe.js";import"./inheritsLoose-DP0QEDDI.js";import"./assertThisInitialized-B9jnkVVz.js";import"./index-D6rZ4wEC.js";export{n as A,T as ActionBar,l as Bar,c as Blockquote,H as Button,L as Code,B as DL,b as Div,S as EmptyTabContent,u as ErrorFormatter,C as FlexBar,h as Form,d as H1,g as H2,y as H3,F as H4,I as H5,k as H6,x as HR,A as IconButton,P as Img,R as LI,W as Link,f as ListItem,D as Loader,E as OL,N as P,q as Pre,v as ResetWrapper,w as ScrollArea,O as Separator,U as Span,j as SyntaxHighlighter,z as TT,G as TabBar,J as TabButton,K as Table,M as Tabs,Q as TabsState,V as TooltipLinkList,X as TooltipNote,Y as UL,Z as WithTooltip,_ as WithTooltipPure,$ as Zoom,aa as codeCommon,sa as components,oa as createCopyToClipboardFunction,ta as getStoryHref,ra as icons,ea as nameSpaceClassNames,ia as withReset};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r}from"./index-DhsZuJvc.js";import{d as o}from"./index-C0x1JmaP.js";const f=e=>{const t=r.useRef();return r.useEffect(()=>{t.current=e},[e]),t.current},l=({value:e,unitkey:t,toUnit:u})=>{var s;const n=o.ALT_UNITS[t];return!(!n||n.length===0||!((s=o.validateNumber(e))!=null&&s.valid)||!n.includes(u))};let a=r.createContext(null);const x=()=>r.useContext(a);export{x as a,l as c,f as u};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as e}from"./jsx-runtime-eps93zm2.js";import{useMDXComponents as r}from"./index-BcNHZKhG.js";import{Z as s,$ as n}from"./index-
|
|
1
|
+
import{j as e}from"./jsx-runtime-eps93zm2.js";import{useMDXComponents as r}from"./index-BcNHZKhG.js";import{Z as s,$ as n}from"./index-BLlJkNz-.js";import{NonExistentValue as a,Error as l}from"./select.stories-B9w9ONzj.js";import"./index-DhsZuJvc.js";import"./iframe-DtGyYU7Y.js";import"../sb-preview/runtime.js";import"./index-CUZDtIZe.js";import"./inheritsLoose-DP0QEDDI.js";import"./assertThisInitialized-B9jnkVVz.js";import"./index-D6rZ4wEC.js";import"./index-DMAnyMX5.js";import"./index-CF7H4eMJ.js";import"./select-DnRuRG_N.js";import"./lodash-c4VUpsOs.js";import"./index-Bk2sglWO.js";import"./common-types-Sih75Sav.js";import"./disabled-context-rmpd7YJS.js";import"./types-Dx2TtIG9.js";import"./tooltip-1V7clEnw.js";import"./index-CEuq6vkz.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"./icon-BSFY3vDO.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./badge-CLQ59MDF.js";import"./select.input-D0UkAPd9.js";import"./spacer-BWoNR27H.js";function o(t){const i={code:"code",h1:"h1",h2:"h2",h3:"h3",p:"p",strong:"strong",...r(),...t.components};return e.jsxs(e.Fragment,{children:[e.jsx(s,{title:"Input Validation"}),`
|
|
2
2
|
`,e.jsx(i.h1,{id:"input-validation",children:"Input Validation"}),`
|
|
3
3
|
`,e.jsx(i.h2,{id:"select",children:"Select"}),`
|
|
4
4
|
`,e.jsx(i.h3,{id:"invalid-states",children:"Invalid states"}),`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as e}from"./jsx-runtime-eps93zm2.js";import{useMDXComponents as s}from"./index-BcNHZKhG.js";import{Z as r,$ as o}from"./index-
|
|
1
|
+
import{j as e}from"./jsx-runtime-eps93zm2.js";import{useMDXComponents as s}from"./index-BcNHZKhG.js";import{Z as r,$ as o}from"./index-BLlJkNz-.js";import{Default as l}from"./button.stories-DA9DGYD2.js";import{Default as a}from"./check-box.stories-DfbWw6mD.js";import{Default as c}from"./file-input.stories-Cpd1NHbq.js";import{Default as d,Date as p}from"./input.stories-FKl0qVhm.js";import{Default as h}from"./number-input.stories-DMAU21wG.js";import{Default as m}from"./option-dropdown.stories-CIvqMhQ3.js";import{Default as u}from"./radio-button.stories-5gvV0LD0.js";import{Native as f,Default as x}from"./select.stories-B9w9ONzj.js";import{Default as j}from"./slider.stories-BzBb3PkP.js";import{Default as b}from"./textarea.stories-CJ-Oqytp.js";import{Default as g}from"./toggle.stories-qTHFTXxI.js";import"./index-DhsZuJvc.js";import"./iframe-DtGyYU7Y.js";import"../sb-preview/runtime.js";import"./index-CUZDtIZe.js";import"./inheritsLoose-DP0QEDDI.js";import"./assertThisInitialized-B9jnkVVz.js";import"./index-D6rZ4wEC.js";import"./react-router-dom-Ck2Y_Fzc.js";import"./index-CEuq6vkz.js";import"./tiny-invariant-DqLgxztJ.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./flex-EllkLxgO.js";import"./button-DHevvVBE.js";import"./index-Bk2sglWO.js";import"./common-types-Sih75Sav.js";import"./disabled-context-rmpd7YJS.js";import"./spinner-AWUe4xwQ.js";import"./icon-BSFY3vDO.js";import"./tooltip-1V7clEnw.js";import"./index-DMAnyMX5.js";import"./index-CF7H4eMJ.js";import"./check-box-DPLaOkRR.js";import"./help-icon-Buhx5nl6.js";import"./file-input-B0-ERX66.js";import"./lodash-c4VUpsOs.js";import"./input-group-BaRSJAEN.js";import"./input-DTXbDJaL.js";import"./types-Dx2TtIG9.js";import"./spacer-BWoNR27H.js";import"./message-Y48EomV-.js";import"./textarea-D6ltcKhz.js";import"./index-C0x1JmaP.js";import"./index-DRSy5Ssd.js";import"./grid-DRkC-bt8.js";import"./styled-components.browser.esm-BQ9GQzDc.js";import"./card-EcjmryU9.js";import"./heading-CRNoBc7q.js";import"./input-group-addon-D68iUKV2.js";import"./select-DnRuRG_N.js";import"./memoize-one.esm-CcMeOnPo.js";import"./types-BmbYqTX_.js";import"./text-B3-TSWok.js";import"./actions-D-uVCDzk.js";import"./badge-CLQ59MDF.js";import"./select.input-D0UkAPd9.js";import"./field-HrLaMLbx.js";import"./label-CqmyC9he.js";import"./toggle-BbFVf61v.js";import"./number-input-B5ReSBSL.js";import"./divider-DY9nJ_7N.js";import"./radio-button-DmDuw4DA.js";import"./slider-C7vnj_3M.js";import"./objectSpread2-DW4nTBoq.js";import"./index-BI4_Bp97.js";function i(n){const t={a:"a",code:"code",h1:"h1",h2:"h2",h3:"h3",li:"li",p:"p",strong:"strong",ul:"ul",...s(),...n.components};return e.jsxs(e.Fragment,{children:[e.jsx(r,{title:"Inputs"}),`
|
|
2
2
|
`,e.jsx(t.h1,{id:"inputs",children:"Inputs"}),`
|
|
3
3
|
`,e.jsx(t.p,{children:"React UI Library provides a comprehensive set of user input components."}),`
|
|
4
4
|
`,e.jsx(t.h2,{id:"button",children:"Button"}),`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as t}from"./jsx-runtime-eps93zm2.js";import{useMDXComponents as n}from"./index-BcNHZKhG.js";import{Z as s,$ as o}from"./index-
|
|
1
|
+
import{j as t}from"./jsx-runtime-eps93zm2.js";import{useMDXComponents as n}from"./index-BcNHZKhG.js";import{Z as s,$ as o}from"./index-BLlJkNz-.js";import{Default as l,LabelOnLeft as p}from"./field.stories-DUGMwi1O.js";import{Default as m,LabelsOnLeft as a,Row as h}from"./form.stories-BrUnmw7R.js";import"./index-DhsZuJvc.js";import"./iframe-DtGyYU7Y.js";import"../sb-preview/runtime.js";import"./index-CUZDtIZe.js";import"./inheritsLoose-DP0QEDDI.js";import"./assertThisInitialized-B9jnkVVz.js";import"./index-D6rZ4wEC.js";import"./field-HrLaMLbx.js";import"./index-Bk2sglWO.js";import"./label-CqmyC9he.js";import"./common-types-Sih75Sav.js";import"./help-icon-Buhx5nl6.js";import"./tooltip-1V7clEnw.js";import"./icon-BSFY3vDO.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./index-CEuq6vkz.js";import"./disabled-context-rmpd7YJS.js";import"./input-DTXbDJaL.js";import"./types-Dx2TtIG9.js";import"./lodash-c4VUpsOs.js";import"./text-B3-TSWok.js";import"./select-DnRuRG_N.js";import"./memoize-one.esm-CcMeOnPo.js";import"./types-BmbYqTX_.js";import"./actions-D-uVCDzk.js";import"./button-DHevvVBE.js";import"./spinner-AWUe4xwQ.js";import"./badge-CLQ59MDF.js";import"./select.input-D0UkAPd9.js";import"./check-box-DPLaOkRR.js";import"./button-group-1DEZPmxq.js";import"./toggle-BbFVf61v.js";import"./input-group-BaRSJAEN.js";import"./input-group-addon-D68iUKV2.js";import"./slider-C7vnj_3M.js";import"./objectSpread2-DW4nTBoq.js";import"./index-BI4_Bp97.js";import"./textarea-D6ltcKhz.js";import"./radio-button-DmDuw4DA.js";import"./form-row-CM112EYF.js";function r(i){const e={code:"code",h1:"h1",h2:"h2",p:"p",...n(),...i.components};return t.jsxs(t.Fragment,{children:[t.jsx(s,{title:"Layout (Forms)"}),`
|
|
2
2
|
`,t.jsx(e.h1,{id:"layout-forms",children:"Layout (Forms)"}),`
|
|
3
3
|
`,t.jsx(e.h2,{id:"field",children:"Field"}),`
|
|
4
4
|
`,t.jsxs(e.p,{children:["This is a wrapper for any form element with default bottom margin, and props like ",t.jsx(e.code,{children:"label"})," for other default styling."]}),`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as e}from"./jsx-runtime-eps93zm2.js";import{useMDXComponents as s}from"./index-BcNHZKhG.js";import{Z as r,$ as n}from"./index-
|
|
1
|
+
import{j as e}from"./jsx-runtime-eps93zm2.js";import{useMDXComponents as s}from"./index-BcNHZKhG.js";import{Z as r,$ as n}from"./index-BLlJkNz-.js";import{Center as d,SpaceBetween as l,JustifyEnd as a,Column as c}from"./flex.stories-BhvJpHpN.js";import{Default as h,CustomColumnWidth as p,DefaultGap as x,CustomGap as m,Responsive as u}from"./grid.stories-DqjhHHwX.js";import{Default as j,FixedWidth as f,NoPadding as w,ResponsiveWidth as g}from"./column.stories-DDTHFELF.js";import"./index-DhsZuJvc.js";import"./iframe-DtGyYU7Y.js";import"../sb-preview/runtime.js";import"./index-CUZDtIZe.js";import"./inheritsLoose-DP0QEDDI.js";import"./assertThisInitialized-B9jnkVVz.js";import"./index-D6rZ4wEC.js";import"./flex-EllkLxgO.js";import"./button-DHevvVBE.js";import"./index-Bk2sglWO.js";import"./common-types-Sih75Sav.js";import"./disabled-context-rmpd7YJS.js";import"./spinner-AWUe4xwQ.js";import"./icon-BSFY3vDO.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./index-CEuq6vkz.js";import"./tooltip-1V7clEnw.js";import"./text-B3-TSWok.js";import"./grid-DRkC-bt8.js";import"./styled-components.browser.esm-BQ9GQzDc.js";import"./card-EcjmryU9.js";import"./row-Bmiy2Lh0.js";import"./heading-CRNoBc7q.js";import"./help-icon-Buhx5nl6.js";function t(i){const o={code:"code",h1:"h1",h2:"h2",h3:"h3",p:"p",...s(),...i.components};return e.jsxs(e.Fragment,{children:[e.jsx(r,{title:"Layout (General)"}),`
|
|
2
2
|
`,e.jsx(o.h1,{id:"layout-general",children:"Layout (General)"}),`
|
|
3
3
|
`,e.jsx(o.h2,{id:"flex",children:"Flex"}),`
|
|
4
4
|
`,e.jsxs(o.p,{children:["The ",e.jsx(o.code,{children:"Flex"})," component is a basic flexbox wrapper with optional props for ",e.jsx(o.code,{children:"alignItems"}),", ",e.jsx(o.code,{children:"justifyContent"})," and ",e.jsx(o.code,{children:"flexDirection"}),". This is a conveninent way to center items vertically and/or horizontally, to align them to opposite edges, or align them to the far side."]}),`
|
package/dist/storybook/assets/{padding-and-spacing-ChZ-7T_N.js → padding-and-spacing-CGADpYHw.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as e}from"./jsx-runtime-eps93zm2.js";import{useMDXComponents as r}from"./index-BcNHZKhG.js";import{Z as t}from"./index-
|
|
1
|
+
import{j as e}from"./jsx-runtime-eps93zm2.js";import{useMDXComponents as r}from"./index-BcNHZKhG.js";import{Z as t}from"./index-BLlJkNz-.js";import"./index-DhsZuJvc.js";import"./iframe-DtGyYU7Y.js";import"../sb-preview/runtime.js";import"./index-CUZDtIZe.js";import"./inheritsLoose-DP0QEDDI.js";import"./assertThisInitialized-B9jnkVVz.js";import"./index-D6rZ4wEC.js";function i(s){const n={code:"code",h1:"h1",h2:"h2",li:"li",p:"p",strong:"strong",ul:"ul",...r(),...s.components};return e.jsxs(e.Fragment,{children:[e.jsx(t,{title:"Padding, Margin & Size"}),`
|
|
2
2
|
`,e.jsx(n.h1,{id:"padding-margin--size",children:"Padding, Margin & Size"}),`
|
|
3
3
|
`,e.jsx(n.h2,{id:"padding--margin",children:"Padding & Margin"}),`
|
|
4
4
|
`,e.jsx(n.p,{children:"There are standard CSS spacing variables for padding and margin."}),`
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{j as s}from"./jsx-runtime-eps93zm2.js";import{r as P,R as C}from"./index-DhsZuJvc.js";import{T as I}from"./toaster-7wnI6hqB.js";import"./message-Y48EomV-.js";import{a4 as d,a5 as M}from"./index-
|
|
1
|
+
import{j as s}from"./jsx-runtime-eps93zm2.js";import{r as P,R as C}from"./index-DhsZuJvc.js";import{T as I}from"./toaster-7wnI6hqB.js";import"./message-Y48EomV-.js";import{a4 as d,a5 as M}from"./index-BLlJkNz-.js";import{e as _}from"./index-DRSy5Ssd.js";import"./chunk-HLWAVYOI-xZeJ0r5F.js";import"./index-CUZDtIZe.js";import"./index-Bk2sglWO.js";import"./common-types-Sih75Sav.js";import"./icon-BSFY3vDO.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./inheritsLoose-DP0QEDDI.js";import"./index-CEuq6vkz.js";import"./disabled-context-rmpd7YJS.js";import"./iframe-DtGyYU7Y.js";import"../sb-preview/runtime.js";import"./assertThisInitialized-B9jnkVVz.js";import"./index-D6rZ4wEC.js";import"./react-16-DXAfArL2.js";var v="DARK_MODE";function f(r){"@babel/helpers - typeof";return f=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},f(r)}var b;function A(r,t){var e=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);t&&(n=n.filter(function(a){return Object.getOwnPropertyDescriptor(r,a).enumerable})),e.push.apply(e,n)}return e}function k(r){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?A(Object(e),!0).forEach(function(n){R(r,n,e[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(e)):A(Object(e)).forEach(function(n){Object.defineProperty(r,n,Object.getOwnPropertyDescriptor(e,n))})}return r}function R(r,t,e){return t=x(t),t in r?Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[t]=e,r}function x(r){var t=K(r,"string");return f(t)==="symbol"?t:String(t)}function K(r,t){if(f(r)!=="object"||r===null)return r;var e=r[Symbol.toPrimitive];if(e!==void 0){var n=e.call(r,t||"default");if(f(n)!=="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(r)}function p(r){return B(r)||U(r)||L(r)||N()}function N(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
2
2
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function L(r,t){if(r){if(typeof r=="string")return h(r,t);var e=Object.prototype.toString.call(r).slice(8,-1);if(e==="Object"&&r.constructor&&(e=r.constructor.name),e==="Map"||e==="Set")return Array.from(r);if(e==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return h(r,t)}}function U(r){if(typeof Symbol<"u"&&r[Symbol.iterator]!=null||r["@@iterator"]!=null)return Array.from(r)}function B(r){if(Array.isArray(r))return h(r)}function h(r,t){(t==null||t>r.length)&&(t=r.length);for(var e=0,n=new Array(t);e<t;e++)n[e]=r[e];return n}const{global:Y}=__STORYBOOK_MODULE_GLOBAL__;__STORYBOOK_MODULE_CORE_EVENTS__;var T=Y,$=T.document,g=T.window,j="sb-addon-themes-3";(b=g.matchMedia)===null||b===void 0||b.call(g,"(prefers-color-scheme: dark)");var O={classTarget:"body",dark:d.dark,darkClass:["dark"],light:d.light,lightClass:["light"],stylePreview:!1,userHasExplicitlySetTheTheme:!1},E=function(t){g.localStorage.setItem(j,JSON.stringify(t))},H=function(t,e){var n=e.current,a=e.darkClass,l=a===void 0?O.darkClass:a,o=e.lightClass,i=o===void 0?O.lightClass:o;if(n==="dark"){var u,c;(u=t.classList).remove.apply(u,p(y(i))),(c=t.classList).add.apply(c,p(y(l)))}else{var m,S;(m=t.classList).remove.apply(m,p(y(l))),(S=t.classList).add.apply(S,p(y(i)))}},y=function(t){var e=[];return e.concat(t).map(function(n){return n})},V=function(t){var e=$.querySelector(t.classTarget);e&&H(e,t)},D=function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=g.localStorage.getItem(j);if(typeof e=="string"){var n=JSON.parse(e);return t&&(t.dark&&!_(n.dark,t.dark)&&(n.dark=t.dark,E(n)),t.light&&!_(n.light,t.light)&&(n.light=t.light,E(n))),n}return k(k({},O),t)};V(D());function W(r,t){return F(r)||J(r,t)||G(r,t)||q()}function q(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
3
3
|
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function G(r,t){if(r){if(typeof r=="string")return w(r,t);var e=Object.prototype.toString.call(r).slice(8,-1);if(e==="Object"&&r.constructor&&(e=r.constructor.name),e==="Map"||e==="Set")return Array.from(r);if(e==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e))return w(r,t)}}function w(r,t){(t==null||t>r.length)&&(t=r.length);for(var e=0,n=new Array(t);e<t;e++)n[e]=r[e];return n}function J(r,t){var e=r==null?null:typeof Symbol<"u"&&r[Symbol.iterator]||r["@@iterator"];if(e!=null){var n,a,l,o,i=[],u=!0,c=!1;try{if(l=(e=e.call(r)).next,t!==0)for(;!(u=(n=l.call(e)).done)&&(i.push(n.value),i.length!==t);u=!0);}catch(m){c=!0,a=m}finally{try{if(!u&&e.return!=null&&(o=e.return(),Object(o)!==o))return}finally{if(c)throw a}}return i}}function F(r){if(Array.isArray(r))return r}const{addons:z,useState:Q,useEffect:X}=__STORYBOOK_MODULE_PREVIEW_API__;function Z(){var r=Q(D().current==="dark"),t=W(r,2),e=t[0],n=t[1];return X(function(){var a=z.getChannel();return a.on(v,n),function(){return a.off(v,n)}},[]),e}const Or=[r=>s.jsxs(s.Fragment,{children:[s.jsx(r,{}),s.jsx(I,{})]}),r=>{const t=Z();return P.useEffect(()=>document.documentElement.dataset.theme=t?"dark":"default",[t]),s.jsx(r,{})}],Sr={docs:{container:r=>{const[t,e]=C.useState(!1);r.context.channel.on(v,a=>e(a));const n={...r};return n.theme=t?d.dark:d.light,s.jsx(M,{...n})}},darkMode:{current:"light",stylePreview:!0}},_r=["autodocs"];export{Or as decorators,Sr as parameters,_r as tags};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./DocsRenderer-PKQXORMH-
|
|
2
|
-
import{_ as a}from"./iframe-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./DocsRenderer-PKQXORMH-C9rr-9Kf.js","./chunk-HLWAVYOI-xZeJ0r5F.js","./iframe-DtGyYU7Y.js","./index-DhsZuJvc.js","./react-16-DXAfArL2.js","./index-CUZDtIZe.js","./index-BLlJkNz-.js","./inheritsLoose-DP0QEDDI.js","./assertThisInitialized-B9jnkVVz.js","./index-D6rZ4wEC.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{_ as a}from"./iframe-DtGyYU7Y.js";import"../sb-preview/runtime.js";const{global:s}=__STORYBOOK_MODULE_GLOBAL__;var _=Object.entries(s.TAGS_OPTIONS??{}).reduce((e,r)=>{let[t,o]=r;return o.excludeFromDocsStories&&(e[t]=!0),e},{}),d={docs:{renderer:async()=>{let{DocsRenderer:e}=await a(()=>import("./DocsRenderer-PKQXORMH-C9rr-9Kf.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]),import.meta.url);return new e},stories:{filter:e=>{var r;return(e.tags||[]).filter(t=>_[t]).length===0&&!((r=e.parameters.docs)!=null&&r.disable)}}}};export{d as parameters};
|
package/dist/storybook/assets/{unit-input.stories-9b23SnFs.js → unit-input.stories-D-520BU0.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as e}from"./jsx-runtime-eps93zm2.js";import{r as u}from"./index-DhsZuJvc.js";import{d as r}from"./index-C0x1JmaP.js";import{w as he,u as f,e as w,f as yn,a as bn}from"./index-DMAnyMX5.js";import{c as Ln}from"./index-Bk2sglWO.js";import{u as Gn}from"./use-previous-D775JrO6.js";import{M as Oe}from"./actions-D-uVCDzk.js";import{I as Kn}from"./input-group-addon-D68iUKV2.js";import{B as p}from"./button-DHevvVBE.js";import{T as $n}from"./tooltip-1V7clEnw.js";import{I as zn}from"./input-group-BaRSJAEN.js";import{S as C}from"./spacer-BWoNR27H.js";import{T as Ue}from"./text-B3-TSWok.js";import{M as He}from"./types-BmbYqTX_.js";import{l as E}from"./lodash-c4VUpsOs.js";import{N as Jn,r as Yn}from"./number-input-B5ReSBSL.js";import{i as Qn}from"./select.input-D0UkAPd9.js";import{D as Zn}from"./divider-DY9nJ_7N.js";import{R as Cn,C as Be}from"./row-Bmiy2Lh0.js";import{F as V}from"./field-HrLaMLbx.js";import{M as xe}from"./message-Y48EomV-.js";import{G as Un}from"./grid-DRkC-bt8.js";import{C as F}from"./card-EcjmryU9.js";import{H as q}from"./heading-CRNoBc7q.js";import{T as Ne}from"./toggle-BbFVf61v.js";import{S as Xn}from"./select-DnRuRG_N.js";import{I as xn}from"./icon-BSFY3vDO.js";import"./index-DRSy5Ssd.js";import"./index-CF7H4eMJ.js";import"./common-types-Sih75Sav.js";import"./disabled-context-rmpd7YJS.js";import"./types-Dx2TtIG9.js";import"./badge-CLQ59MDF.js";import"./spinner-AWUe4xwQ.js";import"./index-CUZDtIZe.js";import"./input-DTXbDJaL.js";import"./styled-components.browser.esm-BQ9GQzDc.js";import"./label-CqmyC9he.js";import"./help-icon-Buhx5nl6.js";import"./index-CEuq6vkz.js";import"./inheritsLoose-DP0QEDDI.js";import"./assertThisInitialized-B9jnkVVz.js";import"./memoize-one.esm-CcMeOnPo.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";const ea=()=>{const t=u.useRef(null);return u.useLayoutEffect(()=>{t.current&&(t.current(),t.current=null)}),n=>{t.current=n}},ta=(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.`),r.unitFromQuantity(t)??"")};var I=(t=>(t.CUSTOM="custom",t.PREDEFINED="predefined",t))(I||{});const In=t=>t==="undefined"||t===void 0||t===""||t==="null"||t===null||t==="NaN"||isNaN(t),Tn=({value:t,unitkey:a,toUnit:n})=>{var i;const s=r.ALT_UNITS[a];return!(!s||s.length===0||!((i=r.validateNumber(t))!=null&&i.valid)||!s.includes(n))},wn=(t="",a,n,s="",i=!1)=>{var m;if(i)return t;if((m=r.validateNumber(t))!=null&&m.valid&&a&&!In(t))try{const l=r.isValueWithUnit(t)?t:r.withUnit(t,s);if(Tn({value:l,toUnit:a,unitkey:n})){const h=r.convertSamePrecision(l,a);return r.getValue(h)}return r.getValue(l)}catch{}},na=t=>t?!!r.getUnit(t):!1,J=({value:t="",toUnit:a,unitkey:n,defaultFromUnit:s,doNotConvertValue:i})=>{const m=na(t)||r.isValueWithUnit(t),l=r.getValue(t);return In(l)?l:m?wn(l,a,n,s,i):t},Le=t=>E.isObject(t)&&!E.isArray(t)&&!E.isFunction(t)?E.get(t,"fieldName",""):typeof t=="string"?t:"",Ge=(t="")=>{var a;return(a=r.KNOWN_UNITS)==null?void 0:a.includes(t)},aa=(t,a)=>{const n=r.getUnit(t||"");return Ge(a)&&Ge(n)};let ia=u.createContext(null);const ra=()=>u.useContext(ia),sa="_predefinedMenuActive_ye9w9_1",la="_inputWrapper_ye9w9_4",Ke={predefinedMenuActive:sa,inputWrapper:la},d=({name:t,placeholder:a="",disabled:n=!1,disabledUnit:s=!1,error:i=null,left:m=!1,small:l=!1,width:g="100%",value:h,unitkey:y="",initUnit:Ie,noConversion:K=!1,onChange:P=E.noop,onClick:Te=E.noop,onFocus:we=E.noop,onSwitchUnit:x=E.noop,unitTemplate:N,doNotConvertValue:$=!1,testId:_,warning:De=null,predefinedOptions:S,initialPredefinedOption:Vn=!1,shouldLinkAutomaticly:Ae=!0,selectedPredefinedOptionKey:Fe,validationCallback:kn=()=>({name:"",error:null}),disabledValidation:Sn=!1,allowEmpty:ua=!1,autoValue:B,convertBackToStorageUnit:jn=!1,enableCosmeticRounding:qe=!0,enableDisplayRounding:En=!1})=>{const R=ra(),Nn=ea();typeof h=="number"&&(h=`${h}`);const[Pe="",D=""]=h!==void 0?r.split(h):[],_e=B?r.getUnit(B):"",Re=u.useMemo(()=>ta(y,N||(R==null?void 0:R.unitTemplate)),[y,N,R==null?void 0:R.unitTemplate]),Bn=aa(h,Re),k=Ie||Re||D,Dn=Gn(k),Me=J({value:h,toUnit:k,unitkey:y,defaultFromUnit:D,doNotConvertValue:$}),We=J({value:B,toUnit:k,unitkey:y,defaultFromUnit:_e,doNotConvertValue:$}),An=Me!==""?{value:Me,unit:k}:We!==""?{value:We,unit:k}:{value:Pe,unit:D},[v,Ve]=u.useState(An),Fn=(v==null?void 0:v.value)===void 0,[A,ke]=u.useState(Vn?I.PREDEFINED:I.CUSTOM),Se=Pe===""&&B,qn=!!(Sn||B||a&&Qn(h)),z=S&&S.find(o=>{if(!(o!=null&&o.value))return;if(Fe)return Fe===o.valueKey;const c=r.isValueWithUnit(o.value)?r.getUnit(o.value):"";return r.withUnit(wn(h,c,y),c)===o.value}),Pn=()=>{const o=Se?B:h??"",c=v.unit;if(Tn({value:o,unitkey:y,toUnit:c})){if(y)try{let b=r.altUnitsList(o,y);return r.getValue(o)===""?b.map(T=>["",T[1]]):b}catch{return null}}else{let b=r.getAltUnitsListByQuantity(y);return b==null?void 0:b.map(T=>["",T==null?void 0:T.unit])}},_n=o=>{const c=Le(t),j=o.target,{value:b,selectionStart:T}=j,be=r.withUnit(b,(v==null?void 0:v.unit)||""),Ee=jn?r.withUnit(r.convertAndGetValue(be,D),D):be;P({target:{value:Ee,name:c}});const[On,Hn]=r.split(be);Ve({value:On,unit:Hn}),Nn(()=>{j.selectionStart=T,j.selectionEnd=T})},Rn=(o,c)=>{c===v.unit||isNaN(Number(o))||(Ve({value:o,unit:c}),x&&x(c))};u.useEffect(()=>{if(k){let o,c="";Dn!==k?(o=J({value:h,toUnit:k,unitkey:y,defaultFromUnit:D,doNotConvertValue:$}),c=k):r.withUnit(v.value,v.unit)!==h&&(o=J({value:h,toUnit:v.unit,unitkey:y,defaultFromUnit:D,doNotConvertValue:$}),c=v.unit),o!==void 0&&Ve({value:o,unit:c}),S&&ke(z&&Ae?I.PREDEFINED:I.CUSTOM)}},[k,h,i,Ae]);const ve=Pn(),fe=r.label(v.unit)||v.unit||"",Mn=K||!ve||ve&&ve.length===1,je=Le(t);let ye;const Wn=o=>{const c=o!=null&&o.value?o.value:"",[j="",b=""]=r.isValueWithUnit(c)?r.split(c):[c];return{type:He.OPTION,inline:!0,onClick:()=>{r.validateNumber(j).valid&&!n&&(ke(I.PREDEFINED),P({target:{value:c,name:typeof t=="string"?t:(t==null?void 0:t.fieldName)||"",predefinedSelected:!0,predefinedOption:o}}))},label:e.jsxs(e.Fragment,{children:[e.jsx(Ue,{children:o.label}),e.jsx(C,{width:"20px",height:"0"})]}),description:r.isValueWithUnit(c)?`${j} ${b}`:c,selected:z===o&&A===I.PREDEFINED}};if(ye=[{type:He.OPTION,inline:!0,onClick:()=>{A!==I.CUSTOM&&!n&&P({target:{value:r.withUnit(v.value,v.unit),name:typeof t=="string"?t:(t==null?void 0:t.fieldName)||""}})},label:"Custom",selected:A===I.CUSTOM}],S!=null&&S.length){const o=S.map(Wn);ye=[...ye,...o]}return e.jsx("div",{className:A===I.PREDEFINED?Ln(Ke.predefinedMenuActive):"",children:e.jsxs(zn,{small:l,width:g,children:[S&&e.jsx($n,{text:A===I.PREDEFINED?z==null?void 0:z.label:"",children:e.jsx(Oe,{maxHeight:380,groupOrder:"first",testId:_&&`${_}-predefined-menu`,disabled:n,menu:{colored:!0,trigger:"Component",component:e.jsx(p,{groupOrder:"first",active:A===I.PREDEFINED,icon:A===I.PREDEFINED?"link":"unlink"}),small:l,sections:ye}})}),e.jsx("div",{className:Ke.inputWrapper,children:e.jsx(Jn,{name:je,testId:_,disabled:n,placeholder:Se?J({value:B,toUnit:v.unit,unitkey:y,defaultFromUnit:_e,doNotConvertValue:$}):a,value:v.value,onChange:_n,onFocus:we,error:i===null?void 0:i,warning:De===null?void 0:De,left:m,allowEmpty:Fn,validationCallback:(o,c)=>kn(je,c),enableCosmeticRounding:qe,enableDisplayRounding:En,groupOrder:S?"middle":"first",disableInternalErrorValidationMessages:qn,small:l},je)}),fe&&(Mn||!Bn?e.jsx(Kn,{groupOrder:"last",children:fe}):e.jsx(Oe,{maxHeight:380,groupOrder:"last",disabled:s,testId:_&&`${_}-menu`,menu:{label:fe,trigger:"DropDownButton",small:l,sections:ve.map(([o,c,j])=>{const b=j||c||"",T=r.isValidNum(o)?o:"";return{type:"Option",label:qe?Yn(T):T,inline:!0,onClick:Ee=>{Ee.stopPropagation(),Rn(Se?"":o,c)},description:b,selected:b===fe,testId:`${_}-unit-${b}`}})}}))]})})};d.__docgenInfo={description:"",methods:[],displayName:"UnitInput",props:{name:{required:!0,tsType:{name:"union",raw:"string | { fieldName?: string }",elements:[{name:"string"},{name:"signature",type:"object",raw:"{ fieldName?: string }",signature:{properties:[{key:"fieldName",value:{name:"string",required:!1}}]}}]},description:""},placeholder:{required:!1,tsType:{name:"string"},description:"",defaultValue:{value:"''",computed:!1}},disabled:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},disabledUnit:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},error:{required:!1,tsType:{name:"union",raw:"string | null | boolean",elements:[{name:"string"},{name:"null"},{name:"boolean"}]},description:"",defaultValue:{value:"null",computed:!1}},left:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},small:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},width:{required:!1,tsType:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},description:"",defaultValue:{value:"'100%'",computed:!1}},value:{required:!1,tsType:{name:"string"},description:""},unitkey:{required:!1,tsType:{name:"string"},description:"",defaultValue:{value:"''",computed:!1}},initUnit:{required:!1,tsType:{name:"string"},description:""},noConversion:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},doNotConvertValue:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},testId:{required:!1,tsType:{name:"string"},description:""},warning:{required:!1,tsType:{name:"union",raw:"string | boolean | null",elements:[{name:"string"},{name:"boolean"},{name:"null"}]},description:"",defaultValue:{value:"null",computed:!1}},predefinedOptions:{required:!1,tsType:{name:"union",raw:"IPredefinedOption[] | null",elements:[{name:"Array",elements:[{name:"IPredefinedOption"}],raw:"IPredefinedOption[]"},{name:"null"}]},description:""},initialPredefinedOption:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},shouldLinkAutomaticly:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},selectedPredefinedOptionKey:{required:!1,tsType:{name:"string"},description:""},validationCallback:{required:!1,tsType:{name:"signature",type:"function",raw:"(name: string, error: string | null) => any",signature:{arguments:[{type:{name:"string"},name:"name"},{type:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}]},name:"error"}],return:{name:"any"}}},description:"",defaultValue:{value:"() => ({ name: '', error: null })",computed:!1}},disabledValidation:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},allowEmpty:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},autoValue:{required:!1,tsType:{name:"string"},description:""},onChange:{required:!1,tsType:{name:"signature",type:"function",raw:"(event: TChangeEvent | ICustomChangeEvent) => void",signature:{arguments:[{type:{name:"union",raw:"TChangeEvent | ICustomChangeEvent",elements:[{name:"intersection",raw:`ChangeEvent<T> & {
|
|
1
|
+
import{j as e}from"./jsx-runtime-eps93zm2.js";import{r as u}from"./index-DhsZuJvc.js";import{d as r}from"./index-C0x1JmaP.js";import{w as he,u as f,e as w,f as yn,a as bn}from"./index-DMAnyMX5.js";import{c as Ln}from"./index-Bk2sglWO.js";import{c as Cn,a as Gn,u as Kn}from"./initialize-context-ScheoYVG.js";import{M as Oe}from"./actions-D-uVCDzk.js";import{I as $n}from"./input-group-addon-D68iUKV2.js";import{B as p}from"./button-DHevvVBE.js";import{T as zn}from"./tooltip-1V7clEnw.js";import{I as Jn}from"./input-group-BaRSJAEN.js";import{S as C}from"./spacer-BWoNR27H.js";import{T as Ue}from"./text-B3-TSWok.js";import{M as He}from"./types-BmbYqTX_.js";import{l as E}from"./lodash-c4VUpsOs.js";import{N as Yn,r as Qn}from"./number-input-B5ReSBSL.js";import{i as Zn}from"./select.input-D0UkAPd9.js";import{D as Xn}from"./divider-DY9nJ_7N.js";import{R as Un,C as Be}from"./row-Bmiy2Lh0.js";import{F as V}from"./field-HrLaMLbx.js";import{M as xe}from"./message-Y48EomV-.js";import{G as xn}from"./grid-DRkC-bt8.js";import{C as A}from"./card-EcjmryU9.js";import{H as q}from"./heading-CRNoBc7q.js";import{T as Ne}from"./toggle-BbFVf61v.js";import{S as ea}from"./select-DnRuRG_N.js";import{I as In}from"./icon-BSFY3vDO.js";import"./index-DRSy5Ssd.js";import"./index-CF7H4eMJ.js";import"./common-types-Sih75Sav.js";import"./disabled-context-rmpd7YJS.js";import"./types-Dx2TtIG9.js";import"./badge-CLQ59MDF.js";import"./spinner-AWUe4xwQ.js";import"./index-CUZDtIZe.js";import"./input-DTXbDJaL.js";import"./styled-components.browser.esm-BQ9GQzDc.js";import"./label-CqmyC9he.js";import"./help-icon-Buhx5nl6.js";import"./index-CEuq6vkz.js";import"./inheritsLoose-DP0QEDDI.js";import"./assertThisInitialized-B9jnkVVz.js";import"./memoize-one.esm-CcMeOnPo.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";const ta=()=>{const t=u.useRef(null);return u.useLayoutEffect(()=>{t.current&&(t.current(),t.current=null)}),n=>{t.current=n}},na=(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.`),r.unitFromQuantity(t)??"")};var I=(t=>(t.CUSTOM="custom",t.PREDEFINED="predefined",t))(I||{});const Tn=t=>t==="undefined"||t===void 0||t===""||t==="null"||t===null||t==="NaN"||isNaN(t),wn=(t="",a,n,l="",i=!1)=>{var m;if(i)return t;if((m=r.validateNumber(t))!=null&&m.valid&&a&&!Tn(t))try{const s=r.isValueWithUnit(t)?t:r.withUnit(t,l);if(Cn({value:s,toUnit:a,unitkey:n})){const h=r.convertSamePrecision(s,a);return r.getValue(h)}return r.getValue(s)}catch{}},aa=t=>t?!!r.getUnit(t):!1,J=({value:t="",toUnit:a,unitkey:n,defaultFromUnit:l,doNotConvertValue:i})=>{const m=aa(t)||r.isValueWithUnit(t),s=r.getValue(t);return Tn(s)?s:m?wn(s,a,n,l,i):t},Le=t=>E.isObject(t)&&!E.isArray(t)&&!E.isFunction(t)?E.get(t,"fieldName",""):typeof t=="string"?t:"",Ge=(t="")=>{var a;return(a=r.KNOWN_UNITS)==null?void 0:a.includes(t)},ia=(t,a)=>{const n=r.getUnit(t||"");return Ge(a)&&Ge(n)},ra="_predefinedMenuActive_ye9w9_1",sa="_inputWrapper_ye9w9_4",Ke={predefinedMenuActive:ra,inputWrapper:sa},d=({name:t,placeholder:a="",disabled:n=!1,disabledUnit:l=!1,error:i=null,left:m=!1,small:s=!1,width:g="100%",value:h,unitkey:y="",initUnit:Ie,noConversion:K=!1,onChange:P=E.noop,onClick:Te=E.noop,onFocus:we=E.noop,onSwitchUnit:x=E.noop,unitTemplate:N,doNotConvertValue:$=!1,testId:_,warning:De=null,predefinedOptions:S,initialPredefinedOption:Vn=!1,shouldLinkAutomaticly:Fe=!0,selectedPredefinedOptionKey:Ae,validationCallback:kn=()=>({name:"",error:null}),disabledValidation:Sn=!1,allowEmpty:oa=!1,autoValue:B,convertBackToStorageUnit:jn=!1,enableCosmeticRounding:qe=!0,enableDisplayRounding:En=!1})=>{const R=Gn(),Nn=ta();typeof h=="number"&&(h=`${h}`);const[Pe="",D=""]=h!==void 0?r.split(h):[],_e=B?r.getUnit(B):"",Re=u.useMemo(()=>na(y,N||(R==null?void 0:R.unitTemplate)),[y,N,R==null?void 0:R.unitTemplate]),Bn=ia(h,Re),k=Ie||Re||D,Dn=Kn(k),Me=J({value:h,toUnit:k,unitkey:y,defaultFromUnit:D,doNotConvertValue:$}),We=J({value:B,toUnit:k,unitkey:y,defaultFromUnit:_e,doNotConvertValue:$}),Fn=Me!==""?{value:Me,unit:k}:We!==""?{value:We,unit:k}:{value:Pe,unit:D},[v,Ve]=u.useState(Fn),An=(v==null?void 0:v.value)===void 0,[F,ke]=u.useState(Vn?I.PREDEFINED:I.CUSTOM),Se=Pe===""&&B,qn=!!(Sn||B||a&&Zn(h)),z=S&&S.find(o=>{if(!(o!=null&&o.value))return;if(Ae)return Ae===o.valueKey;const c=r.isValueWithUnit(o.value)?r.getUnit(o.value):"";return r.withUnit(wn(h,c,y),c)===o.value}),Pn=()=>{const o=Se?B:h??"",c=v.unit;if(Cn({value:o,unitkey:y,toUnit:c})){if(y)try{let b=r.altUnitsList(o,y);return r.getValue(o)===""?b.map(T=>["",T[1]]):b}catch{return null}}else{let b=r.getAltUnitsListByQuantity(y);return b==null?void 0:b.map(T=>["",T==null?void 0:T.unit])}},_n=o=>{const c=Le(t),j=o.target,{value:b,selectionStart:T}=j,be=r.withUnit(b,(v==null?void 0:v.unit)||""),Ee=jn?r.withUnit(r.convertAndGetValue(be,D),D):be;P({target:{value:Ee,name:c}});const[On,Hn]=r.split(be);Ve({value:On,unit:Hn}),Nn(()=>{j.selectionStart=T,j.selectionEnd=T})},Rn=(o,c)=>{c===v.unit||isNaN(Number(o))||(Ve({value:o,unit:c}),x&&x(c))};u.useEffect(()=>{if(k){let o,c="";Dn!==k?(o=J({value:h,toUnit:k,unitkey:y,defaultFromUnit:D,doNotConvertValue:$}),c=k):r.withUnit(v.value,v.unit)!==h&&(o=J({value:h,toUnit:v.unit,unitkey:y,defaultFromUnit:D,doNotConvertValue:$}),c=v.unit),o!==void 0&&Ve({value:o,unit:c}),S&&ke(z&&Fe?I.PREDEFINED:I.CUSTOM)}},[k,h,i,Fe]);const ve=Pn(),fe=r.label(v.unit)||v.unit||"",Mn=K||!ve||ve&&ve.length===1,je=Le(t);let ye;const Wn=o=>{const c=o!=null&&o.value?o.value:"",[j="",b=""]=r.isValueWithUnit(c)?r.split(c):[c];return{type:He.OPTION,inline:!0,onClick:()=>{r.validateNumber(j).valid&&!n&&(ke(I.PREDEFINED),P({target:{value:c,name:typeof t=="string"?t:(t==null?void 0:t.fieldName)||"",predefinedSelected:!0,predefinedOption:o}}))},label:e.jsxs(e.Fragment,{children:[e.jsx(Ue,{children:o.label}),e.jsx(C,{width:"20px",height:"0"})]}),description:r.isValueWithUnit(c)?`${j} ${b}`:c,selected:z===o&&F===I.PREDEFINED}};if(ye=[{type:He.OPTION,inline:!0,onClick:()=>{F!==I.CUSTOM&&!n&&P({target:{value:r.withUnit(v.value,v.unit),name:typeof t=="string"?t:(t==null?void 0:t.fieldName)||""}})},label:"Custom",selected:F===I.CUSTOM}],S!=null&&S.length){const o=S.map(Wn);ye=[...ye,...o]}return e.jsx("div",{className:F===I.PREDEFINED?Ln(Ke.predefinedMenuActive):"",children:e.jsxs(Jn,{small:s,width:g,children:[S&&e.jsx(zn,{text:F===I.PREDEFINED?z==null?void 0:z.label:"",children:e.jsx(Oe,{maxHeight:380,groupOrder:"first",testId:_&&`${_}-predefined-menu`,disabled:n,menu:{colored:!0,trigger:"Component",component:e.jsx(p,{groupOrder:"first",active:F===I.PREDEFINED,icon:F===I.PREDEFINED?"link":"unlink"}),small:s,sections:ye}})}),e.jsx("div",{className:Ke.inputWrapper,children:e.jsx(Yn,{name:je,testId:_,disabled:n,placeholder:Se?J({value:B,toUnit:v.unit,unitkey:y,defaultFromUnit:_e,doNotConvertValue:$}):a,value:v.value,onChange:_n,onFocus:we,error:i===null?void 0:i,warning:De===null?void 0:De,left:m,allowEmpty:An,validationCallback:(o,c)=>kn(je,c),enableCosmeticRounding:qe,enableDisplayRounding:En,groupOrder:S?"middle":"first",disableInternalErrorValidationMessages:qn,small:s},je)}),fe&&(Mn||!Bn?e.jsx($n,{groupOrder:"last",children:fe}):e.jsx(Oe,{maxHeight:380,groupOrder:"last",disabled:l,testId:_&&`${_}-menu`,menu:{label:fe,trigger:"DropDownButton",small:s,sections:ve.map(([o,c,j])=>{const b=j||c||"",T=r.isValidNum(o)?o:"";return{type:"Option",label:qe?Qn(T):T,inline:!0,onClick:Ee=>{Ee.stopPropagation(),Rn(Se?"":o,c)},description:b,selected:b===fe,testId:`${_}-unit-${b}`}})}}))]})})};d.__docgenInfo={description:"",methods:[],displayName:"UnitInput",props:{name:{required:!0,tsType:{name:"union",raw:"string | { fieldName?: string }",elements:[{name:"string"},{name:"signature",type:"object",raw:"{ fieldName?: string }",signature:{properties:[{key:"fieldName",value:{name:"string",required:!1}}]}}]},description:""},placeholder:{required:!1,tsType:{name:"string"},description:"",defaultValue:{value:"''",computed:!1}},disabled:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},disabledUnit:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},error:{required:!1,tsType:{name:"union",raw:"string | null | boolean",elements:[{name:"string"},{name:"null"},{name:"boolean"}]},description:"",defaultValue:{value:"null",computed:!1}},left:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},small:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},width:{required:!1,tsType:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},description:"",defaultValue:{value:"'100%'",computed:!1}},value:{required:!1,tsType:{name:"string"},description:""},unitkey:{required:!1,tsType:{name:"string"},description:"",defaultValue:{value:"''",computed:!1}},initUnit:{required:!1,tsType:{name:"string"},description:""},noConversion:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},doNotConvertValue:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},testId:{required:!1,tsType:{name:"string"},description:""},warning:{required:!1,tsType:{name:"union",raw:"string | boolean | null",elements:[{name:"string"},{name:"boolean"},{name:"null"}]},description:"",defaultValue:{value:"null",computed:!1}},predefinedOptions:{required:!1,tsType:{name:"union",raw:"IPredefinedOption[] | null",elements:[{name:"Array",elements:[{name:"IPredefinedOption"}],raw:"IPredefinedOption[]"},{name:"null"}]},description:""},initialPredefinedOption:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},shouldLinkAutomaticly:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},selectedPredefinedOptionKey:{required:!1,tsType:{name:"string"},description:""},validationCallback:{required:!1,tsType:{name:"signature",type:"function",raw:"(name: string, error: string | null) => any",signature:{arguments:[{type:{name:"string"},name:"name"},{type:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}]},name:"error"}],return:{name:"any"}}},description:"",defaultValue:{value:"() => ({ name: '', error: null })",computed:!1}},disabledValidation:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},allowEmpty:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},autoValue:{required:!1,tsType:{name:"string"},description:""},onChange:{required:!1,tsType:{name:"signature",type:"function",raw:"(event: TChangeEvent | ICustomChangeEvent) => void",signature:{arguments:[{type:{name:"union",raw:"TChangeEvent | ICustomChangeEvent",elements:[{name:"intersection",raw:`ChangeEvent<T> & {
|
|
2
2
|
target:
|
|
3
3
|
| T
|
|
4
4
|
| { name: string; value: any; label?: string; files?: FileList | null };
|
|
@@ -7,7 +7,7 @@ import{j as e}from"./jsx-runtime-eps93zm2.js";import{r as u}from"./index-DhsZuJv
|
|
|
7
7
|
| T
|
|
8
8
|
| { name: string; value: any; label?: string; files?: FileList | null };
|
|
9
9
|
}`,signature:{properties:[{key:"target",value:{name:"union",raw:`| T
|
|
10
|
-
| { name: string; value: any; label?: string; files?: FileList | null }`,elements:[{name:"T"},{name:"signature",type:"object",raw:"{ name: string; value: any; label?: string; files?: FileList | null }",signature:{properties:[{key:"name",value:{name:"string",required:!0}},{key:"value",value:{name:"any",required:!0}},{key:"label",value:{name:"string",required:!1}},{key:"files",value:{name:"union",raw:"FileList | null",elements:[{name:"FileList"},{name:"null"}],required:!1}}]}}],required:!0}}]}}]},{name:"ICustomChangeEvent"}]},name:"event"}],return:{name:"void"}}},description:"",defaultValue:{value:"noop",computed:!0}},onSwitchUnit:{required:!1,tsType:{name:"signature",type:"function",raw:"(unit: string) => void",signature:{arguments:[{type:{name:"string"},name:"unit"}],return:{name:"void"}}},description:"",defaultValue:{value:"noop",computed:!0}},onClick:{required:!1,tsType:{name:"MouseEventHandler",elements:[{name:"HTMLInputElement"}],raw:"MouseEventHandler<HTMLInputElement>"},description:"",defaultValue:{value:"noop",computed:!0}},onFocus:{required:!1,tsType:{name:"FocusEventHandler",elements:[{name:"HTMLInputElement"}],raw:"FocusEventHandler<HTMLInputElement>"},description:"",defaultValue:{value:"noop",computed:!0}},unitTemplate:{required:!1,tsType:{name:"Record",elements:[{name:"string"},{name:"any"}],raw:"Record<string, any>"},description:""},convertBackToStorageUnit:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},enableCosmeticRounding:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},enableDisplayRounding:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}}}};const{useArgs:oa}=__STORYBOOK_MODULE_PREVIEW_API__,ei={title:"Forms/UnitInput",component:d,args:{name:"example",unitkey:"length",value:"123|m"}},U=t=>{const[a,n]=oa(),s=i=>{n({value:i.target.value})};return e.jsx(d,{...t,onChange:s})},Ce=U.bind({}),Y=U.bind({});Y.args={initUnit:"ft",unitTemplate:{length:"ft"}};const Q=U.bind({});Q.args={value:'123|"',unitkey:'"'};const Z=U.bind({});Z.args={width:"180px"};const X=U.bind({});X.args={noConversion:!0};const ee=U.bind({});ee.args={small:!0};const M=()=>{const[t,a]=u.useState("123|m");return e.jsx(d,{name:"example",onChange:n=>a(n.target.value),placeholder:"Type a value...",value:t,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"},testId:"testId"})};M.play=async({canvasElement:t,step:a})=>{const n=he(t),s=he(t.ownerDocument.body);await a("Shows validation error for non-numeric input",async()=>{const i=n.getByTestId("testId");await f.clear(i),await f.type(i,"123x45s6"),await w(n.getByDisplayValue("123x45s6")).toBeInTheDocument(),await yn.mouseOver(i),await bn(()=>{w(s.getByText("Must be a numerical value")).toBeInTheDocument()})})};const te=U.bind({});te.args={error:"Error message goes here"};const ne=U.bind({});ne.args={value:"asas123asd|%"};const W=U.bind({});W.args={disabled:!0,disabledUnit:!0};W.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 ae=U.bind({});ae.args={disabled:!0,disabledUnit:!0,noConversion:!0};const ie=U.bind({});ie.args={disabledUnit:!0,unitkey:void 0};const re=U.bind({});re.args={disabledUnit:!0,unitkey:"length"};const se=U.bind({});se.args={disabledUnit:!1,disabled:!0};const O=t=>{const[a,n]=u.useState("123|m"),[s,i]=u.useState("223|m"),[m,l]=u.useState("ft");return e.jsxs(e.Fragment,{children:[e.jsx(p,{label:"Change initUnit",onClick:()=>l(m==="m"?"ft":"m")}),e.jsx(C,{}),e.jsx(p,{label:"Change value",onClick:()=>n(a==="123|m"?"456|m":"123|m")}),e.jsx(C,{}),e.jsx(d,{name:"example",onChange:g=>{n(g.target.value)},unitkey:"length",value:a,initUnit:m,onSwitchUnit:l}),e.jsx(C,{}),e.jsx(d,{name:"example2",onChange:g=>{i(g.target.value)},unitkey:"length",value:s,initUnit:m,onSwitchUnit:l}),e.jsx(Zn,{}),e.jsx("h4",{children:"Without initUnit property (taken from the redux store)"}),e.jsx(d,{name:"example",onChange:g=>{n(g.target.value)},unitkey:"length",value:a,onSwitchUnit:l}),e.jsx(d,{name:"example2",onChange:g=>{i(g.target.value)},unitkey:"length",value:s,onSwitchUnit:l})]})};O.parameters={docs:{description:{story:"[OW-4380](https://oliasoft.atlassian.net/browse/OW-4380?atlOrigin=eyJpIjoiMmM1N2RkNWU3Mjk5NDYxY2E0YzhkMzk5ZTVmZTJhMjciLCJwIjoiaiJ9)"}}};const le=U.bind({});le.args={predefinedOptions:[{label:"bottom of casing",value:"12|km"},{label:"mud weight at shoe depth",value:"8|mm"}]};const H=()=>{const t="500px",[a,n]=u.useState(void 0);return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different edge cases such as +/- infinity, undefined, NaN, null:"}),e.jsxs(Cn,{children:[e.jsxs(Be,{width:"25%",children:[e.jsx(p,{label:"Change value infinity",onClick:()=>n(1/0)}),e.jsx("br",{}),e.jsx(p,{label:"Change value -infinity",onClick:()=>n(-1/0)}),e.jsx("br",{}),e.jsx(p,{label:"Change value null",onClick:()=>n(null)}),e.jsx("br",{}),e.jsx(p,{label:"Change value - undefined",onClick:()=>n(void 0)}),e.jsx("br",{}),e.jsx(p,{label:"Change value - NaN",onClick:()=>n(NaN)}),e.jsx("br",{}),e.jsx(p,{label:"Change value - nothing (empty)",onClick:()=>n(void 0)}),e.jsx("br",{}),e.jsx(p,{label:"Change value - empty string",onClick:()=>n("")})]}),e.jsxs(Be,{width:"25%",children:[e.jsx(p,{label:"Change value infinity|m",onClick:()=>n("Infinity|m")}),e.jsx("br",{}),e.jsx(p,{label:"Change value -infinity|m",onClick:()=>n("-Infinity|m")}),e.jsx("br",{}),e.jsx(p,{label:"Change value null|m",onClick:()=>n("null|m")}),e.jsx("br",{}),e.jsx(p,{label:"Change value - undefined|m",onClick:()=>n("undefined|m")}),e.jsx("br",{}),e.jsx(p,{label:"Change value - NaN|m",onClick:()=>n("NaN|m")}),e.jsx("br",{}),e.jsx(p,{label:"Change value - nothing (empty)|m",onClick:()=>n("|m")})]})]}),e.jsx("br",{}),e.jsx(V,{label:"Normal PUI",children:e.jsx(d,{name:"example1",onChange:s=>n(s.target.value),value:a,unitkey:"length",width:t,placeholder:"value|unit"})}),e.jsx(V,{label:"Disabled validation",children:e.jsx(d,{name:"example2",onChange:s=>n(s.target.value),value:a,unitkey:"length",disabledValidation:!0,width:t})}),e.jsx(V,{label:"Disabled validation and manual error",children:e.jsx(d,{name:"example3",onChange:s=>n(s.target.value),value:a,unitkey:"length",error:"test",disabledValidation:!0,width:t})}),e.jsx(xe,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})},oe=()=>{const t="500px",[a,n]=u.useState("1|m"),[s,i]=u.useState("|m"),m="123|km";return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different cases for automatic (placeholder) values:"}),e.jsx(Cn,{children:e.jsxs(Be,{width:"25%",children:[e.jsx(p,{label:"Change value to ''",onClick:()=>n("")}),e.jsx("br",{}),e.jsx(p,{label:"Change value to 1",onClick:()=>n("1")}),e.jsx("br",{}),e.jsx(p,{label:"Change value to 1|m",onClick:()=>n("1|m")}),e.jsx("br",{}),e.jsx(p,{label:"Change value to |m - empty value",onClick:()=>n("|m")})]})}),e.jsx("br",{}),e.jsx(V,{label:"Normal PUI (placeholder + auto)",children:e.jsx(d,{name:"example1",onChange:l=>n(l.target.value),value:a,unitkey:"length",width:t,placeholder:"value|unit",autoValue:m})}),e.jsx(V,{label:"Normal PUI (only auto)",children:e.jsx(d,{name:"example1",onChange:l=>n(l.target.value),value:a,unitkey:"length",width:t,autoValue:m})}),e.jsx(V,{label:"Empty PUI with autoValue",children:e.jsx(d,{name:"example1",onChange:l=>i(l.target.value),value:s,unitkey:"length",width:t,autoValue:m})}),e.jsx(V,{label:"Normal PUI (only placeholder)",children:e.jsx(d,{name:"example1",onChange:l=>n(l.target.value),value:a,unitkey:"length",width:t,placeholder:"Placeholder test"})}),e.jsx(V,{label:"Normal PUI (placeholder + allowEmpty)",children:e.jsx(d,{name:"example1",onChange:l=>n(l.target.value),value:a,unitkey:"length",width:t,placeholder:"Placeholder test",allowEmpty:!0})}),e.jsx(xe,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})};H.parameters={docs:{description:{story:"[OW-8884](https://oliasoft.atlassian.net/browse/OW-8884)"}}};const ue=()=>{const[t,a]=u.useState("123|%"),[n,s]=u.useState(null),i="This should be visible when an error appears",m=(l,g)=>(s(g),{name:l,error:g});return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"3rd party validation message when inputting invalid value:"}),e.jsx(d,{name:"example",onChange:l=>a(l.target.value),error:!n||i,validationCallback:m,value:t}),e.jsx("br",{}),e.jsx(C,{}),e.jsx("h4",{children:"Original validation message: "}),e.jsx(xe,{message:{heading:n,visible:!0}})]})},de=()=>{const[t,a]=u.useState("123|m"),[n,s]=u.useState(""),[i,m]=u.useState("km"),l=()=>{m("ft"),s("placeholder"),a("|m")};return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Empty value case:"}),e.jsx(d,{name:"example",onChange:g=>a(g.target.value),value:t,allowEmpty:!0,placeholder:n,initUnit:i,unitkey:"length"}),e.jsx("br",{}),e.jsx(C,{}),e.jsx(p,{label:"Change value |m and unit ft",onClick:()=>l()})]})},ce=()=>{const[t,a]=u.useState("123|m"),[n,s]=u.useState("m");return e.jsxs(e.Fragment,{children:[e.jsx(d,{name:"example",onChange:i=>a(i.target.value),value:t,initUnit:n,unitkey:"length",onSwitchUnit:s}),e.jsx(C,{}),e.jsx(d,{name:"example",onChange:i=>a(i.target.value),value:t,initUnit:n,unitkey:"length",onSwitchUnit:s})]})},me=()=>{const[t,a]=u.useState(!0),n=()=>{a(!1),setTimeout(()=>a(!0),0)},[s,i]=u.useState("123|ft");return e.jsxs(Un,{columns:"1fr 1fr",gap:!0,children:[e.jsxs(F,{heading:e.jsx(q,{children:"Storage State (Redux)"}),children:[s,e.jsx(C,{}),e.jsx(p,{label:"Change value",onClick:()=>i(r.withUnit(String(Math.floor(Math.random()*100)),"ft"))})]}),e.jsx(F,{heading:e.jsx(q,{icon:e.jsx(xn,{icon:"refresh",testId:"triggerRerenderTestId"}),onIconClick:n,children:"UnitInput"}),children:t&&e.jsx(d,{name:"example",onChange:m=>i(m.target.value),value:s,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"}})})]})},pe=()=>e.jsxs(e.Fragment,{children:[e.jsx(Ue,{faint:!0,children:"Reproduce OW-10614 rounding noise bug when storing values in a different unit to the display unit"}),e.jsx(C,{}),e.jsx(d,{name:"example",onChange:()=>{},value:r.withUnit(r.convertAndGetValue("9750|psi","bar"),"bar"),initUnit:"psi",unitkey:"pressure",unitTemplate:{pressure:"psi"}}),e.jsx(C,{}),e.jsx(d,{name:"example2",onChange:()=>{},value:r.withUnit(r.convertAndGetValue("8642|lbf","tonneForce"),"tonneForce"),initUnit:"lbf",unitkey:"force",unitTemplate:{force:"tonneForce"}})]}),L=()=>e.jsxs(e.Fragment,{children:[e.jsx(d,{name:"example",unitkey:"moleWeight",initUnit:"g/mol",doNotConvertValue:!0,value:"170|g/mol",unitTemplate:{moleWeight:"g/mol"},testId:"case1"}),e.jsx(C,{}),e.jsx(d,{name:"gor",unitkey:"moleWeight",initUnit:"gor",value:"Infinity|SCF/STB",testId:"case2"})]});L.play=async({canvasElement:t,step:a})=>{const n=he(t);await a("Can enter decimal values",async()=>{await w(n.getByDisplayValue("170")).toBeInTheDocument(),await w(n.getByDisplayValue("")).toBeInTheDocument()})};const ge=()=>{const[t,a]=u.useState(!0),n=()=>{a(!1),setTimeout(()=>a(!0),0)},[s,i]=u.useState("psi"),[m,l]=u.useState(!1),[g,h]=u.useState(!0),[y,Ie]=u.useState(!0),[K,P]=u.useState("672.2388357750001|bar"),[Te,we]=u.useState("");return e.jsxs(Un,{columns:"1fr 1fr",gap:!0,children:[e.jsxs(F,{heading:e.jsx(q,{children:"Settings"}),children:[e.jsx(V,{label:"Enable display rounding:",labelLeft:!0,labelWidth:200,children:e.jsx(Ne,{checked:m,onChange:x=>l(x.target.checked)})}),e.jsx(V,{label:"Enable cosmetic rounding:",labelLeft:!0,labelWidth:200,children:e.jsx(Ne,{checked:g,onChange:x=>h(x.target.checked)})}),e.jsx(V,{label:"Convert back to storage unit (onChange):",labelLeft:!0,labelWidth:200,children:e.jsx(Ne,{checked:y,onChange:x=>Ie(x.target.checked)})})]}),e.jsxs(F,{heading:e.jsx(q,{icon:e.jsx(xn,{icon:"refresh",testId:"triggerRerenderTestId"}),onIconClick:n,children:"UnitInput"}),children:[e.jsx(Ue,{faint:!0,children:"Cosmetic Rounding Test Case: type 9750 then return (compare with enableCosmeticRounding on and off)"}),e.jsx(C,{}),e.jsx(Ue,{warning:!0,children:"Note: UnitInput uses convertSamePrecision internally (decision prior to cosmetic value implementation). This means not all rounding noise occurrences seen in NumberInput will be reproducible in UnitInput, because they get rounded off by other logic."}),e.jsx(C,{}),t&&e.jsx(d,{name:"Example",unitkey:"pressure",initUnit:s,unitTemplate:{pressure:"psi"},value:K,onChange:x=>{const{value:N}=x.target;N&&P(N)},enableDisplayRounding:m,enableCosmeticRounding:g,error:r.convertAndGetValue(K,"bar")>=0?"":"Value must be positive",validationCallback:(x,N)=>{we(N??"")},convertBackToStorageUnit:y})]}),e.jsx(F,{heading:e.jsx(q,{children:"Unit Template"}),children:e.jsx(Xn,{options:[{label:"Bar",value:"bar"},{label:"psi",value:"psi"}],value:s,width:70,onChange:x=>i(x.target.value)})}),e.jsx(F,{heading:e.jsx(q,{children:"Test Validation Callback"}),children:Te&&e.jsx(xe,{message:{content:Te,icon:!0,type:"Error",visible:!0}})}),e.jsxs(F,{heading:e.jsx(q,{children:"Storage State / Redux"}),children:[K,e.jsx(C,{}),e.jsx(p,{label:"Change value",onClick:()=>P(r.withUnit(String(Math.floor(Math.random()*100)),"bar"))})]})]})},G=()=>{const[t,a]=u.useState("123|m");return e.jsx(d,{name:"example",onChange:n=>a(n.target.value),value:t,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"},testId:"testId"})};G.play=async({canvasElement:t,step:a})=>{const n=he(t),s=he(t.ownerDocument.body);await a("Can enter decimal values",async()=>{const i=n.getByTestId("testId");await f.clear(i),await f.type(i,"123.123456789"),await w(n.getByDisplayValue("123.123456789")).toBeInTheDocument()}),await a("Can enter scientific notation",async()=>{const i=n.getByTestId("testId");await f.clear(i),await f.type(i,"-1.12e3"),await w(n.getByDisplayValue("-1.12e3")).toBeInTheDocument()}),await a("Can enter comma decimals (converts to dot)",async()=>{const i=n.getByTestId("testId");await f.clear(i),await f.type(i,"123,456"),await w(n.getByDisplayValue("123.456")).toBeInTheDocument()}),await a("Can enter small numbers",async()=>{const i=n.getByTestId("testId");await f.clear(i),await f.type(i,"0.0000000023"),await w(n.getByDisplayValue("0.0000000023")).toBeInTheDocument()}),await a("Can enter large numbers",async()=>{const i=n.getByTestId("testId");await f.clear(i),await f.type(i,"999999999999"),await w(n.getByDisplayValue("999999999999")).toBeInTheDocument()}),await a("Can convert units",async()=>{const i=n.getByTestId("testId"),m=n.getByTestId("testId-menu");await f.clear(i),await f.type(i,"456.1"),await f.click(m),await f.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 f.clear(i),await f.type(i,"123x45s6"),await w(n.getByDisplayValue("123x45s6")).toBeInTheDocument(),await yn.mouseOver(i),await bn(()=>{w(s.getByText("Must be a numerical value")).toBeInTheDocument()})})};M.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"Placeholder"};O.__docgenInfo={description:"",methods:[],displayName:"TestExternalStateChangeWithSynchronizedUnits",props:{name:{required:!0,tsType:{name:"union",raw:"string | { fieldName?: string }",elements:[{name:"string"},{name:"signature",type:"object",raw:"{ fieldName?: string }",signature:{properties:[{key:"fieldName",value:{name:"string",required:!1}}]}}]},description:""},placeholder:{required:!1,tsType:{name:"string"},description:""},disabled:{required:!1,tsType:{name:"boolean"},description:""},disabledUnit:{required:!1,tsType:{name:"boolean"},description:""},error:{required:!1,tsType:{name:"union",raw:"string | null | boolean",elements:[{name:"string"},{name:"null"},{name:"boolean"}]},description:""},left:{required:!1,tsType:{name:"boolean"},description:""},small:{required:!1,tsType:{name:"boolean"},description:""},width:{required:!1,tsType:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},description:""},value:{required:!1,tsType:{name:"string"},description:""},unitkey:{required:!1,tsType:{name:"string"},description:""},initUnit:{required:!1,tsType:{name:"string"},description:""},noConversion:{required:!1,tsType:{name:"boolean"},description:""},doNotConvertValue:{required:!1,tsType:{name:"boolean"},description:""},testId:{required:!1,tsType:{name:"string"},description:""},warning:{required:!1,tsType:{name:"union",raw:"string | boolean | null",elements:[{name:"string"},{name:"boolean"},{name:"null"}]},description:""},predefinedOptions:{required:!1,tsType:{name:"union",raw:"IPredefinedOption[] | null",elements:[{name:"Array",elements:[{name:"IPredefinedOption"}],raw:"IPredefinedOption[]"},{name:"null"}]},description:""},initialPredefinedOption:{required:!1,tsType:{name:"boolean"},description:""},shouldLinkAutomaticly:{required:!1,tsType:{name:"boolean"},description:""},selectedPredefinedOptionKey:{required:!1,tsType:{name:"string"},description:""},validationCallback:{required:!1,tsType:{name:"signature",type:"function",raw:"(name: string, error: string | null) => any",signature:{arguments:[{type:{name:"string"},name:"name"},{type:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}]},name:"error"}],return:{name:"any"}}},description:""},disabledValidation:{required:!1,tsType:{name:"boolean"},description:""},allowEmpty:{required:!1,tsType:{name:"boolean"},description:""},autoValue:{required:!1,tsType:{name:"string"},description:""},onChange:{required:!1,tsType:{name:"signature",type:"function",raw:"(event: TChangeEvent | ICustomChangeEvent) => void",signature:{arguments:[{type:{name:"union",raw:"TChangeEvent | ICustomChangeEvent",elements:[{name:"intersection",raw:`ChangeEvent<T> & {
|
|
10
|
+
| { name: string; value: any; label?: string; files?: FileList | null }`,elements:[{name:"T"},{name:"signature",type:"object",raw:"{ name: string; value: any; label?: string; files?: FileList | null }",signature:{properties:[{key:"name",value:{name:"string",required:!0}},{key:"value",value:{name:"any",required:!0}},{key:"label",value:{name:"string",required:!1}},{key:"files",value:{name:"union",raw:"FileList | null",elements:[{name:"FileList"},{name:"null"}],required:!1}}]}}],required:!0}}]}}]},{name:"ICustomChangeEvent"}]},name:"event"}],return:{name:"void"}}},description:"",defaultValue:{value:"noop",computed:!0}},onSwitchUnit:{required:!1,tsType:{name:"signature",type:"function",raw:"(unit: string) => void",signature:{arguments:[{type:{name:"string"},name:"unit"}],return:{name:"void"}}},description:"",defaultValue:{value:"noop",computed:!0}},onClick:{required:!1,tsType:{name:"MouseEventHandler",elements:[{name:"HTMLInputElement"}],raw:"MouseEventHandler<HTMLInputElement>"},description:"",defaultValue:{value:"noop",computed:!0}},onFocus:{required:!1,tsType:{name:"FocusEventHandler",elements:[{name:"HTMLInputElement"}],raw:"FocusEventHandler<HTMLInputElement>"},description:"",defaultValue:{value:"noop",computed:!0}},unitTemplate:{required:!1,tsType:{name:"Record",elements:[{name:"string"},{name:"any"}],raw:"Record<string, any>"},description:""},convertBackToStorageUnit:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}},enableCosmeticRounding:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},enableDisplayRounding:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"false",computed:!1}}}};const{useArgs:la}=__STORYBOOK_MODULE_PREVIEW_API__,Xa={title:"Forms/UnitInput",component:d,args:{name:"example",unitkey:"length",value:"123|m"}},U=t=>{const[a,n]=la(),l=i=>{n({value:i.target.value})};return e.jsx(d,{...t,onChange:l})},Ce=U.bind({}),Y=U.bind({});Y.args={initUnit:"ft",unitTemplate:{length:"ft"}};const Q=U.bind({});Q.args={value:'123|"',unitkey:'"'};const Z=U.bind({});Z.args={width:"180px"};const X=U.bind({});X.args={noConversion:!0};const ee=U.bind({});ee.args={small:!0};const M=()=>{const[t,a]=u.useState("123|m");return e.jsx(d,{name:"example",onChange:n=>a(n.target.value),placeholder:"Type a value...",value:t,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"},testId:"testId"})};M.play=async({canvasElement:t,step:a})=>{const n=he(t),l=he(t.ownerDocument.body);await a("Shows validation error for non-numeric input",async()=>{const i=n.getByTestId("testId");await f.clear(i),await f.type(i,"123x45s6"),await w(n.getByDisplayValue("123x45s6")).toBeInTheDocument(),await yn.mouseOver(i),await bn(()=>{w(l.getByText("Must be a numerical value")).toBeInTheDocument()})})};const te=U.bind({});te.args={error:"Error message goes here"};const ne=U.bind({});ne.args={value:"asas123asd|%"};const W=U.bind({});W.args={disabled:!0,disabledUnit:!0};W.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 ae=U.bind({});ae.args={disabled:!0,disabledUnit:!0,noConversion:!0};const ie=U.bind({});ie.args={disabledUnit:!0,unitkey:void 0};const re=U.bind({});re.args={disabledUnit:!0,unitkey:"length"};const se=U.bind({});se.args={disabledUnit:!1,disabled:!0};const O=t=>{const[a,n]=u.useState("123|m"),[l,i]=u.useState("223|m"),[m,s]=u.useState("ft");return e.jsxs(e.Fragment,{children:[e.jsx(p,{label:"Change initUnit",onClick:()=>s(m==="m"?"ft":"m")}),e.jsx(C,{}),e.jsx(p,{label:"Change value",onClick:()=>n(a==="123|m"?"456|m":"123|m")}),e.jsx(C,{}),e.jsx(d,{name:"example",onChange:g=>{n(g.target.value)},unitkey:"length",value:a,initUnit:m,onSwitchUnit:s}),e.jsx(C,{}),e.jsx(d,{name:"example2",onChange:g=>{i(g.target.value)},unitkey:"length",value:l,initUnit:m,onSwitchUnit:s}),e.jsx(Xn,{}),e.jsx("h4",{children:"Without initUnit property (taken from the redux store)"}),e.jsx(d,{name:"example",onChange:g=>{n(g.target.value)},unitkey:"length",value:a,onSwitchUnit:s}),e.jsx(d,{name:"example2",onChange:g=>{i(g.target.value)},unitkey:"length",value:l,onSwitchUnit:s})]})};O.parameters={docs:{description:{story:"[OW-4380](https://oliasoft.atlassian.net/browse/OW-4380?atlOrigin=eyJpIjoiMmM1N2RkNWU3Mjk5NDYxY2E0YzhkMzk5ZTVmZTJhMjciLCJwIjoiaiJ9)"}}};const le=U.bind({});le.args={predefinedOptions:[{label:"bottom of casing",value:"12|km"},{label:"mud weight at shoe depth",value:"8|mm"}]};const H=()=>{const t="500px",[a,n]=u.useState(void 0);return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different edge cases such as +/- infinity, undefined, NaN, null:"}),e.jsxs(Un,{children:[e.jsxs(Be,{width:"25%",children:[e.jsx(p,{label:"Change value infinity",onClick:()=>n(1/0)}),e.jsx("br",{}),e.jsx(p,{label:"Change value -infinity",onClick:()=>n(-1/0)}),e.jsx("br",{}),e.jsx(p,{label:"Change value null",onClick:()=>n(null)}),e.jsx("br",{}),e.jsx(p,{label:"Change value - undefined",onClick:()=>n(void 0)}),e.jsx("br",{}),e.jsx(p,{label:"Change value - NaN",onClick:()=>n(NaN)}),e.jsx("br",{}),e.jsx(p,{label:"Change value - nothing (empty)",onClick:()=>n(void 0)}),e.jsx("br",{}),e.jsx(p,{label:"Change value - empty string",onClick:()=>n("")})]}),e.jsxs(Be,{width:"25%",children:[e.jsx(p,{label:"Change value infinity|m",onClick:()=>n("Infinity|m")}),e.jsx("br",{}),e.jsx(p,{label:"Change value -infinity|m",onClick:()=>n("-Infinity|m")}),e.jsx("br",{}),e.jsx(p,{label:"Change value null|m",onClick:()=>n("null|m")}),e.jsx("br",{}),e.jsx(p,{label:"Change value - undefined|m",onClick:()=>n("undefined|m")}),e.jsx("br",{}),e.jsx(p,{label:"Change value - NaN|m",onClick:()=>n("NaN|m")}),e.jsx("br",{}),e.jsx(p,{label:"Change value - nothing (empty)|m",onClick:()=>n("|m")})]})]}),e.jsx("br",{}),e.jsx(V,{label:"Normal PUI",children:e.jsx(d,{name:"example1",onChange:l=>n(l.target.value),value:a,unitkey:"length",width:t,placeholder:"value|unit"})}),e.jsx(V,{label:"Disabled validation",children:e.jsx(d,{name:"example2",onChange:l=>n(l.target.value),value:a,unitkey:"length",disabledValidation:!0,width:t})}),e.jsx(V,{label:"Disabled validation and manual error",children:e.jsx(d,{name:"example3",onChange:l=>n(l.target.value),value:a,unitkey:"length",error:"test",disabledValidation:!0,width:t})}),e.jsx(xe,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})},oe=()=>{const t="500px",[a,n]=u.useState("1|m"),[l,i]=u.useState("|m"),m="123|km";return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Different cases for automatic (placeholder) values:"}),e.jsx(Un,{children:e.jsxs(Be,{width:"25%",children:[e.jsx(p,{label:"Change value to ''",onClick:()=>n("")}),e.jsx("br",{}),e.jsx(p,{label:"Change value to 1",onClick:()=>n("1")}),e.jsx("br",{}),e.jsx(p,{label:"Change value to 1|m",onClick:()=>n("1|m")}),e.jsx("br",{}),e.jsx(p,{label:"Change value to |m - empty value",onClick:()=>n("|m")})]})}),e.jsx("br",{}),e.jsx(V,{label:"Normal PUI (placeholder + auto)",children:e.jsx(d,{name:"example1",onChange:s=>n(s.target.value),value:a,unitkey:"length",width:t,placeholder:"value|unit",autoValue:m})}),e.jsx(V,{label:"Normal PUI (only auto)",children:e.jsx(d,{name:"example1",onChange:s=>n(s.target.value),value:a,unitkey:"length",width:t,autoValue:m})}),e.jsx(V,{label:"Empty PUI with autoValue",children:e.jsx(d,{name:"example1",onChange:s=>i(s.target.value),value:l,unitkey:"length",width:t,autoValue:m})}),e.jsx(V,{label:"Normal PUI (only placeholder)",children:e.jsx(d,{name:"example1",onChange:s=>n(s.target.value),value:a,unitkey:"length",width:t,placeholder:"Placeholder test"})}),e.jsx(V,{label:"Normal PUI (placeholder + allowEmpty)",children:e.jsx(d,{name:"example1",onChange:s=>n(s.target.value),value:a,unitkey:"length",width:t,placeholder:"Placeholder test",allowEmpty:!0})}),e.jsx(xe,{message:{heading:"Current value inside PUI: "+a,visible:!0}})]})};H.parameters={docs:{description:{story:"[OW-8884](https://oliasoft.atlassian.net/browse/OW-8884)"}}};const ue=()=>{const[t,a]=u.useState("123|%"),[n,l]=u.useState(null),i="This should be visible when an error appears",m=(s,g)=>(l(g),{name:s,error:g});return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"3rd party validation message when inputting invalid value:"}),e.jsx(d,{name:"example",onChange:s=>a(s.target.value),error:!n||i,validationCallback:m,value:t}),e.jsx("br",{}),e.jsx(C,{}),e.jsx("h4",{children:"Original validation message: "}),e.jsx(xe,{message:{heading:n,visible:!0}})]})},de=()=>{const[t,a]=u.useState("123|m"),[n,l]=u.useState(""),[i,m]=u.useState("km"),s=()=>{m("ft"),l("placeholder"),a("|m")};return e.jsxs(e.Fragment,{children:[e.jsx("h4",{children:"Empty value case:"}),e.jsx(d,{name:"example",onChange:g=>a(g.target.value),value:t,allowEmpty:!0,placeholder:n,initUnit:i,unitkey:"length"}),e.jsx("br",{}),e.jsx(C,{}),e.jsx(p,{label:"Change value |m and unit ft",onClick:()=>s()})]})},ce=()=>{const[t,a]=u.useState("123|m"),[n,l]=u.useState("m");return e.jsxs(e.Fragment,{children:[e.jsx(d,{name:"example",onChange:i=>a(i.target.value),value:t,initUnit:n,unitkey:"length",onSwitchUnit:l}),e.jsx(C,{}),e.jsx(d,{name:"example",onChange:i=>a(i.target.value),value:t,initUnit:n,unitkey:"length",onSwitchUnit:l})]})},me=()=>{const[t,a]=u.useState(!0),n=()=>{a(!1),setTimeout(()=>a(!0),0)},[l,i]=u.useState("123|ft");return e.jsxs(xn,{columns:"1fr 1fr",gap:!0,children:[e.jsxs(A,{heading:e.jsx(q,{children:"Storage State (Redux)"}),children:[l,e.jsx(C,{}),e.jsx(p,{label:"Change value",onClick:()=>i(r.withUnit(String(Math.floor(Math.random()*100)),"ft"))})]}),e.jsx(A,{heading:e.jsx(q,{icon:e.jsx(In,{icon:"refresh",testId:"triggerRerenderTestId"}),onIconClick:n,children:"UnitInput"}),children:t&&e.jsx(d,{name:"example",onChange:m=>i(m.target.value),value:l,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"}})})]})},pe=()=>e.jsxs(e.Fragment,{children:[e.jsx(Ue,{faint:!0,children:"Reproduce OW-10614 rounding noise bug when storing values in a different unit to the display unit"}),e.jsx(C,{}),e.jsx(d,{name:"example",onChange:()=>{},value:r.withUnit(r.convertAndGetValue("9750|psi","bar"),"bar"),initUnit:"psi",unitkey:"pressure",unitTemplate:{pressure:"psi"}}),e.jsx(C,{}),e.jsx(d,{name:"example2",onChange:()=>{},value:r.withUnit(r.convertAndGetValue("8642|lbf","tonneForce"),"tonneForce"),initUnit:"lbf",unitkey:"force",unitTemplate:{force:"tonneForce"}})]}),L=()=>e.jsxs(e.Fragment,{children:[e.jsx(d,{name:"example",unitkey:"moleWeight",initUnit:"g/mol",doNotConvertValue:!0,value:"170|g/mol",unitTemplate:{moleWeight:"g/mol"},testId:"case1"}),e.jsx(C,{}),e.jsx(d,{name:"gor",unitkey:"moleWeight",initUnit:"gor",value:"Infinity|SCF/STB",testId:"case2"})]});L.play=async({canvasElement:t,step:a})=>{const n=he(t);await a("Can enter decimal values",async()=>{await w(n.getByDisplayValue("170")).toBeInTheDocument(),await w(n.getByDisplayValue("")).toBeInTheDocument()})};const ge=()=>{const[t,a]=u.useState(!0),n=()=>{a(!1),setTimeout(()=>a(!0),0)},[l,i]=u.useState("psi"),[m,s]=u.useState(!1),[g,h]=u.useState(!0),[y,Ie]=u.useState(!0),[K,P]=u.useState("672.2388357750001|bar"),[Te,we]=u.useState("");return e.jsxs(xn,{columns:"1fr 1fr",gap:!0,children:[e.jsxs(A,{heading:e.jsx(q,{children:"Settings"}),children:[e.jsx(V,{label:"Enable display rounding:",labelLeft:!0,labelWidth:200,children:e.jsx(Ne,{checked:m,onChange:x=>s(x.target.checked)})}),e.jsx(V,{label:"Enable cosmetic rounding:",labelLeft:!0,labelWidth:200,children:e.jsx(Ne,{checked:g,onChange:x=>h(x.target.checked)})}),e.jsx(V,{label:"Convert back to storage unit (onChange):",labelLeft:!0,labelWidth:200,children:e.jsx(Ne,{checked:y,onChange:x=>Ie(x.target.checked)})})]}),e.jsxs(A,{heading:e.jsx(q,{icon:e.jsx(In,{icon:"refresh",testId:"triggerRerenderTestId"}),onIconClick:n,children:"UnitInput"}),children:[e.jsx(Ue,{faint:!0,children:"Cosmetic Rounding Test Case: type 9750 then return (compare with enableCosmeticRounding on and off)"}),e.jsx(C,{}),e.jsx(Ue,{warning:!0,children:"Note: UnitInput uses convertSamePrecision internally (decision prior to cosmetic value implementation). This means not all rounding noise occurrences seen in NumberInput will be reproducible in UnitInput, because they get rounded off by other logic."}),e.jsx(C,{}),t&&e.jsx(d,{name:"Example",unitkey:"pressure",initUnit:l,unitTemplate:{pressure:"psi"},value:K,onChange:x=>{const{value:N}=x.target;N&&P(N)},enableDisplayRounding:m,enableCosmeticRounding:g,error:r.convertAndGetValue(K,"bar")>=0?"":"Value must be positive",validationCallback:(x,N)=>{we(N??"")},convertBackToStorageUnit:y})]}),e.jsx(A,{heading:e.jsx(q,{children:"Unit Template"}),children:e.jsx(ea,{options:[{label:"Bar",value:"bar"},{label:"psi",value:"psi"}],value:l,width:70,onChange:x=>i(x.target.value)})}),e.jsx(A,{heading:e.jsx(q,{children:"Test Validation Callback"}),children:Te&&e.jsx(xe,{message:{content:Te,icon:!0,type:"Error",visible:!0}})}),e.jsxs(A,{heading:e.jsx(q,{children:"Storage State / Redux"}),children:[K,e.jsx(C,{}),e.jsx(p,{label:"Change value",onClick:()=>P(r.withUnit(String(Math.floor(Math.random()*100)),"bar"))})]})]})},G=()=>{const[t,a]=u.useState("123|m");return e.jsx(d,{name:"example",onChange:n=>a(n.target.value),value:t,initUnit:"m",unitkey:"depth",unitTemplate:{depth:"m"},testId:"testId"})};G.play=async({canvasElement:t,step:a})=>{const n=he(t),l=he(t.ownerDocument.body);await a("Can enter decimal values",async()=>{const i=n.getByTestId("testId");await f.clear(i),await f.type(i,"123.123456789"),await w(n.getByDisplayValue("123.123456789")).toBeInTheDocument()}),await a("Can enter scientific notation",async()=>{const i=n.getByTestId("testId");await f.clear(i),await f.type(i,"-1.12e3"),await w(n.getByDisplayValue("-1.12e3")).toBeInTheDocument()}),await a("Can enter comma decimals (converts to dot)",async()=>{const i=n.getByTestId("testId");await f.clear(i),await f.type(i,"123,456"),await w(n.getByDisplayValue("123.456")).toBeInTheDocument()}),await a("Can enter small numbers",async()=>{const i=n.getByTestId("testId");await f.clear(i),await f.type(i,"0.0000000023"),await w(n.getByDisplayValue("0.0000000023")).toBeInTheDocument()}),await a("Can enter large numbers",async()=>{const i=n.getByTestId("testId");await f.clear(i),await f.type(i,"999999999999"),await w(n.getByDisplayValue("999999999999")).toBeInTheDocument()}),await a("Can convert units",async()=>{const i=n.getByTestId("testId"),m=n.getByTestId("testId-menu");await f.clear(i),await f.type(i,"456.1"),await f.click(m),await f.click(l.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 f.clear(i),await f.type(i,"123x45s6"),await w(n.getByDisplayValue("123x45s6")).toBeInTheDocument(),await yn.mouseOver(i),await bn(()=>{w(l.getByText("Must be a numerical value")).toBeInTheDocument()})})};M.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"Placeholder"};O.__docgenInfo={description:"",methods:[],displayName:"TestExternalStateChangeWithSynchronizedUnits",props:{name:{required:!0,tsType:{name:"union",raw:"string | { fieldName?: string }",elements:[{name:"string"},{name:"signature",type:"object",raw:"{ fieldName?: string }",signature:{properties:[{key:"fieldName",value:{name:"string",required:!1}}]}}]},description:""},placeholder:{required:!1,tsType:{name:"string"},description:""},disabled:{required:!1,tsType:{name:"boolean"},description:""},disabledUnit:{required:!1,tsType:{name:"boolean"},description:""},error:{required:!1,tsType:{name:"union",raw:"string | null | boolean",elements:[{name:"string"},{name:"null"},{name:"boolean"}]},description:""},left:{required:!1,tsType:{name:"boolean"},description:""},small:{required:!1,tsType:{name:"boolean"},description:""},width:{required:!1,tsType:{name:"union",raw:"string | number",elements:[{name:"string"},{name:"number"}]},description:""},value:{required:!1,tsType:{name:"string"},description:""},unitkey:{required:!1,tsType:{name:"string"},description:""},initUnit:{required:!1,tsType:{name:"string"},description:""},noConversion:{required:!1,tsType:{name:"boolean"},description:""},doNotConvertValue:{required:!1,tsType:{name:"boolean"},description:""},testId:{required:!1,tsType:{name:"string"},description:""},warning:{required:!1,tsType:{name:"union",raw:"string | boolean | null",elements:[{name:"string"},{name:"boolean"},{name:"null"}]},description:""},predefinedOptions:{required:!1,tsType:{name:"union",raw:"IPredefinedOption[] | null",elements:[{name:"Array",elements:[{name:"IPredefinedOption"}],raw:"IPredefinedOption[]"},{name:"null"}]},description:""},initialPredefinedOption:{required:!1,tsType:{name:"boolean"},description:""},shouldLinkAutomaticly:{required:!1,tsType:{name:"boolean"},description:""},selectedPredefinedOptionKey:{required:!1,tsType:{name:"string"},description:""},validationCallback:{required:!1,tsType:{name:"signature",type:"function",raw:"(name: string, error: string | null) => any",signature:{arguments:[{type:{name:"string"},name:"name"},{type:{name:"union",raw:"string | null",elements:[{name:"string"},{name:"null"}]},name:"error"}],return:{name:"any"}}},description:""},disabledValidation:{required:!1,tsType:{name:"boolean"},description:""},allowEmpty:{required:!1,tsType:{name:"boolean"},description:""},autoValue:{required:!1,tsType:{name:"string"},description:""},onChange:{required:!1,tsType:{name:"signature",type:"function",raw:"(event: TChangeEvent | ICustomChangeEvent) => void",signature:{arguments:[{type:{name:"union",raw:"TChangeEvent | ICustomChangeEvent",elements:[{name:"intersection",raw:`ChangeEvent<T> & {
|
|
11
11
|
target:
|
|
12
12
|
| T
|
|
13
13
|
| { name: string; value: any; label?: string; files?: FileList | null };
|
|
@@ -117,7 +117,7 @@ import{j as e}from"./jsx-runtime-eps93zm2.js";import{r as u}from"./index-DhsZuJv
|
|
|
117
117
|
});
|
|
118
118
|
};
|
|
119
119
|
return <UnitInput {...args} onChange={handleChange} />;
|
|
120
|
-
}`,...(Nt=(Et=re.parameters)==null?void 0:Et.docs)==null?void 0:Nt.source}}};var Bt,Dt,
|
|
120
|
+
}`,...(Nt=(Et=re.parameters)==null?void 0:Et.docs)==null?void 0:Nt.source}}};var Bt,Dt,Ft;se.parameters={...se.parameters,docs:{...(Bt=se.parameters)==null?void 0:Bt.docs,source:{originalSource:`args => {
|
|
121
121
|
const [_, updateArgs] = useArgs();
|
|
122
122
|
const handleChange = (evt: any) => {
|
|
123
123
|
updateArgs({
|
|
@@ -125,7 +125,7 @@ import{j as e}from"./jsx-runtime-eps93zm2.js";import{r as u}from"./index-DhsZuJv
|
|
|
125
125
|
});
|
|
126
126
|
};
|
|
127
127
|
return <UnitInput {...args} onChange={handleChange} />;
|
|
128
|
-
}`,...(
|
|
128
|
+
}`,...(Ft=(Dt=se.parameters)==null?void 0:Dt.docs)==null?void 0:Ft.source}}};var At,qt,Pt;O.parameters={...O.parameters,docs:{...(At=O.parameters)==null?void 0:At.docs,source:{originalSource:`(args: IUnitInputProps) => {
|
|
129
129
|
const [value, setValue] = useState('123|m');
|
|
130
130
|
const [value2, setValue2] = useState('223|m');
|
|
131
131
|
const [initUnit, setInitUnit] = useState('ft');
|
|
@@ -418,4 +418,4 @@ import{j as e}from"./jsx-runtime-eps93zm2.js";import{r as u}from"./index-DhsZuJv
|
|
|
418
418
|
return <UnitInput name="example" onChange={evt => setValue(evt.target.value)} value={value} initUnit="m" unitkey="depth" unitTemplate={{
|
|
419
419
|
depth: 'm'
|
|
420
420
|
}} testId="testId" />;
|
|
421
|
-
}`,...(fn=(vn=G.parameters)==null?void 0:vn.docs)==null?void 0:fn.source}}};const
|
|
421
|
+
}`,...(fn=(vn=G.parameters)==null?void 0:vn.docs)==null?void 0:fn.source}}};const ei=["Default","InitUnit","notKnownUnit","Width","NoConversion","Small","Placeholder","Error","InternalValidationError","Disabled","DisabledNoConversion","DisabledUnitWithoutUnitKey","DisabledUnitWithUnitKey","DisabledWithEnabledUnitMenu","TestExternalStateChangeWithSynchronizedUnits","PredefinedOptionsMenu","TestEdgeCases","AutomaticValues","ValidationCallback","AllowEmptyPUI","onSwitchUnit","ManagedTestCase","OW_10614TestCase","OW_17784TestCase","DemoCosmeticRounding","TestUserInput"];export{de as AllowEmptyPUI,oe as AutomaticValues,Ce as Default,ge as DemoCosmeticRounding,W as Disabled,ae as DisabledNoConversion,re as DisabledUnitWithUnitKey,ie as DisabledUnitWithoutUnitKey,se as DisabledWithEnabledUnitMenu,te as Error,Y as InitUnit,ne as InternalValidationError,me as ManagedTestCase,X as NoConversion,pe as OW_10614TestCase,L as OW_17784TestCase,M as Placeholder,le as PredefinedOptionsMenu,ee as Small,H as TestEdgeCases,O as TestExternalStateChangeWithSynchronizedUnits,G as TestUserInput,ue as ValidationCallback,Z as Width,ei as __namedExportsOrder,Xa as default,Q as notKnownUnit,ce as onSwitchUnit};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import{j as r}from"./jsx-runtime-eps93zm2.js";import{r as v}from"./index-DhsZuJvc.js";import{f as X}from"./immer.esm-BwVl9PS2.js";import{d as x}from"./index-C0x1JmaP.js";import{G as te}from"./grid-DRkC-bt8.js";import{S as ne}from"./spacer-BWoNR27H.js";import{w as O,u as g,e as j,f as ae,a as ie}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-DnRuRG_N.js";import{T as W}from"./toggle-BbFVf61v.js";import{l as re}from"./lodash-c4VUpsOs.js";import{u as oe,a as le,c as se}from"./initialize-context-ScheoYVG.js";import{T as ue,C as q}from"./table-DdpQxqOc.js";import"./index-DRSy5Ssd.js";import"./styled-components.browser.esm-BQ9GQzDc.js";import"./index-CF7H4eMJ.js";import"./index-Bk2sglWO.js";import"./label-CqmyC9he.js";import"./common-types-Sih75Sav.js";import"./help-icon-Buhx5nl6.js";import"./tooltip-1V7clEnw.js";import"./index-CUZDtIZe.js";import"./icon-BSFY3vDO.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./inheritsLoose-DP0QEDDI.js";import"./index-CEuq6vkz.js";import"./disabled-context-rmpd7YJS.js";import"./types-Dx2TtIG9.js";import"./assertThisInitialized-B9jnkVVz.js";import"./memoize-one.esm-CcMeOnPo.js";import"./types-BmbYqTX_.js";import"./text-B3-TSWok.js";import"./actions-D-uVCDzk.js";import"./button-DHevvVBE.js";import"./spinner-AWUe4xwQ.js";import"./badge-CLQ59MDF.js";import"./select.input-D0UkAPd9.js";import"./index.es-DazXb-ul.js";import"./redux-tRgGMjwY.js";import"./objectSpread2-DW4nTBoq.js";import"./tiny-invariant-DqLgxztJ.js";import"./pagination-CLt-kUlx.js";import"./input-DTXbDJaL.js";import"./input-group-BaRSJAEN.js";import"./input-group-addon-D68iUKV2.js";import"./number-input-B5ReSBSL.js";import"./check-box-DPLaOkRR.js";import"./slider-C7vnj_3M.js";import"./index-BI4_Bp97.js";import"./popover-rq33c1W2.js";const ce=a=>a.reduce(({preferredUnits:o,storageUnits:n},{unitKey:l,preferredUnit:e,storageUnit:b})=>{const{unitTemplate:u=null}=le()??{};return o[l]=e??(u==null?void 0:u[l]),n[l]=b,{preferredUnits:o,storageUnits:n}},{preferredUnits:{},storageUnits:{}}),G=(a,o,n,l)=>{if(se({value:a,unitkey:o,toUnit:n}))try{return x.convertAndGetValue(a,n,l)}catch{return a}return a},de=({headers:a,rows:o,selectedUnits:n,storageUnits:l,onChangeUnit:e,convertBackToStorageUnit:b,enableCosmeticRounding:u,enableDisplayRounding:T})=>{const d=a?a.map(p=>({...p,cells:p.cells.map(m=>{var i;if(m.type===q.AUTO_UNIT){const{testId:S,unitKey:c}=m;return{value:n[c],type:q.SELECT,searchable:!1,options:(i=x.getUnitsForQuantity(c))==null?void 0:i.map(U=>({label:x.label(U),value:U})),native:m.native,onChange:U=>e({unitKey:c,value:U.target.value}),testId:S}}return m})})):[],s=o?o.map((p,m)=>({...p,cells:p.cells.map((i,S)=>{if("autoUnit"in i&&(i!=null&&i.autoUnit)&&(typeof(i==null?void 0:i.value)=="string"||typeof(i==null?void 0:i.value)=="number")){const{unitKey:c,value:U,formatDisplayValue:I}=i,V=T&&"roundDisplayValue"in i?i==null?void 0:i.roundDisplayValue:null,h=n[c],y=l[c],t=h!==y,f=t?G(U,c,h,y):i.value,C=I?I(f):f;return{...i,value:C,enableCosmeticRounding:u&&t,enableDisplayRounding:T,roundDisplayValue:V,onChange:D=>{const{value:w}=D.target,k=l[c],E=n[c],N=E!==k,H=b?k:E,K=N?G(w,c,H,E):w;if("onChange"in i){const{onChange:B}=i,ee={...D,target:{...D.target,value:String(K),rowIndex:m,cellIndex:S,unit:H}};B(ee)}}}}return i})})):[];return{convertedHeaders:d,convertedRows:s}},Y=({table:a,unitConfig:o,convertBackToStorageUnit:n=!0,enableCosmeticRounding:l=!0,enableDisplayRounding:e=!0})=>{const{rows:b,headers:u,...T}=a,{storageUnits:d,preferredUnits:s}=ce(o),p=oe(s),[m,i]=v.useState(s),S=({unitKey:h,value:y})=>{i({...m,[h]:y});const t=o.find(f=>f.unitKey===h);t&&typeof t.onChange=="function"&&t.onChange({oldUnit:m[h],newUnit:y,unitKey:h})},c=h=>de({headers:u,rows:b,selectedUnits:h,storageUnits:d,onChangeUnit:S,convertBackToStorageUnit:n,enableCosmeticRounding:l,enableDisplayRounding:e}),U=c(m),[I,V]=v.useState(U);return v.useEffect(()=>{!re.isEqual(s,p)&&(Object.keys(s).forEach(y=>{const t=p==null?void 0:p[y],f=s[y];t!==f&&S({unitKey:y,value:f})}),V(c(s)))},[o]),v.useEffect(()=>{V(c(m))},[a,m]),r.jsx(ue,{table:{...T,headers:I.convertedHeaders,rows:I.convertedRows}})};Y.__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 vt={title:"Basic/UnitTable",args:{}},pe=!0,ge=!0,me=!0,he=!1,A="ft",Z="C",be=3,ye=(a,o,n)=>{const l=[o,o,n],e=[...Array(a)].map((b,u)=>{const T=u,d=u+1.25,s=4+u*.25;return[String(T),String(d),String(s)]});return[l,...e]},fe=ye(be,A,Z),ve=({reduxTable:a,value:o,unit:n,rowIndex:l,cellIndex:e})=>X(a,b=>{const u=b[0][e],T=(d,s)=>s===0;return b.forEach((d,s)=>{if(T(d,s)){d[e]=n;return}if(s===l+1){d[e]=String(o);return}const p=x.convertAndGetValue(d[e],n,u);d[e]=String(p)}),b}),Te=({reduxTable:a,value:o,rowIndex:n,cellIndex:l})=>X(a,e=>{e[n+1][l]=o}),L=()=>{var h,y;const[a,o]=v.useState(A),[n,l]=v.useState(Z),[e,b]=v.useState(fe),[u,T]=v.useState(pe),[d,s]=v.useState(me),[p,m]=v.useState(ge),[i,S]=v.useState(he),[c,U]=v.useState(A),I=t=>{const{rowIndex:f,cellIndex:C,value:D,unit:w}=t.target,k=i?ve({reduxTable:e,value:D,unit:w,rowIndex:f,cellIndex:C}):Te({reduxTable:e,value:D,rowIndex:f,cellIndex:C});b(k)},V=e.reduce((t,f,C)=>(C===0?t.headers=[{cells:[{value:"From"},{value:"To"},{value:"Temperature"}]},{cells:[{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"temperature",testId:"table-unit-selector-3"}]}]:t.rows=t.rows.concat({cells:f.map((D,w)=>{const k=C===1&&w===1;return{value:D,type:k?"Text":"NumberInput",unitKey:w===2?"temperature":"length",onChange:I,roundDisplayValue:C===3&&w===2?B=>x.roundByMagnitude(B,2):null,formatDisplayValue:k?B=>`T* ${B}`:null,autoUnit:!0,testId:`testId_${C}_${w}`}})}),t),{testId:"testId",headers:[],rows:[]});return r.jsxs(te,{columns:"1fr 1fr",gap:!0,children:[r.jsxs(F,{heading:r.jsx(_,{children:"Settings"}),children:[r.jsx(R,{label:"Convert back to storage unit:",labelLeft:!0,labelWidth:200,children:r.jsx(W,{checked:u,onChange:t=>T(t.target.checked)})}),r.jsx(R,{label:"Enable display rounding:",labelLeft:!0,labelWidth:200,children:r.jsx(W,{checked:d,onChange:t=>s(t.target.checked)})}),r.jsx(R,{label:"Enable cosmetic rounding:",labelLeft:!0,labelWidth:200,children:r.jsx(W,{checked:p,onChange:t=>m(t.target.checked)})}),r.jsx(R,{label:"Convert whole table:",labelLeft:!0,labelWidth:200,children:r.jsx(W,{checked:i,onChange:t=>S(t.target.checked)})})]}),r.jsxs(F,{heading:r.jsx(_,{children:"Unit template"}),children:[r.jsx(R,{label:"Length unit:",labelLeft:!0,labelWidth:120,children:r.jsx(P,{options:(h=x.getUnitsForQuantity("length"))==null?void 0:h.map(t=>({value:t,label:x.label(t)})),value:{value:a},onChange:t=>o(t.target.value),width:"100px"})}),r.jsx(R,{label:"Temperature unit:",labelLeft:!0,labelWidth:120,children:r.jsx(P,{options:(y=x.getUnitsForQuantity("temperature"))==null?void 0:y.map(t=>({value:t,label:x.label(t)})),value:{value:n},onChange:t=>l(t.target.value),width:"100px"})})]}),r.jsx(F,{heading:r.jsx(_,{children:"Storage State (Redux)"}),children:r.jsx("pre",{children:r.jsx("code",{children:JSON.stringify(e,null,2)})})}),r.jsxs(F,{heading:r.jsx(_,{children:"UnitTable"}),children:[r.jsx(Y,{table:V,unitConfig:[{unitKey:"length",storageUnit:e[0][0],preferredUnit:a,onChange:({newUnit:t})=>U(t)},{unitKey:"temperature",storageUnit:e[0][2],preferredUnit:n}],convertBackToStorageUnit:u,enableDisplayRounding:d,enableCosmeticRounding:p}),r.jsx(ne,{height:20}),r.jsx(R,{label:"Displayed length unit:",labelLeft:!0,labelWidth:150,children:c})]})]})};L.play=async({canvasElement:a,step:o})=>{const n=O(a),l=O(a.ownerDocument.body);await o("Can enter decimal values",async()=>{const e=n.getByTestId("testId_2_1");await g.clear(e),await g.type(e,"123.123456789"),await g.click(a),await j(n.getByDisplayValue("123.12")).toBeInTheDocument()}),await o("Can enter comma decimals (converts to dot)",async()=>{const e=n.getByTestId("testId_2_1");await g.clear(e),await g.type(e,"123,456"),await g.click(a),await j(n.getByDisplayValue("123.46")).toBeInTheDocument()}),await o("Can enter small numbers",async()=>{const e=n.getByTestId("testId_2_1");await g.clear(e),await g.type(e,"0.0000000023"),await g.click(a),await j(e).toHaveDisplayValue("0.00")}),await o("Can enter large numbers",async()=>{const e=n.getByTestId("testId_2_1");await g.clear(e),await g.type(e,"999999999999"),await g.click(a),await j(n.getByDisplayValue("999999999999.00")).toBeInTheDocument()}),await o("Shows validation error for non-numeric input",async()=>{const e=n.getByTestId("testId_2_1");await g.clear(e),await g.type(e,"123x45s6"),await g.click(a),await j(n.getByDisplayValue("123x45s6")).toBeInTheDocument(),await ae.mouseOver(e),await ie(()=>{j(l.getByText("Must be a numerical value")).toBeInTheDocument()})})};L.__docgenInfo={description:"",methods:[{name:"play",docblock:null,modifiers:["static"],params:[{name:"{ canvasElement, step }",optional:!1,type:null}],returns:null}],displayName:"UnitTableExample"};var $,Q,M,z,J;L.parameters={...L.parameters,docs:{...($=L.parameters)==null?void 0:$.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
|
+
}`,...(M=(Q=L.parameters)==null?void 0:Q.docs)==null?void 0:M.source},description:{story:"Story",...(J=(z=L.parameters)==null?void 0:z.docs)==null?void 0:J.description}}};const Tt=["UnitTableExample"];export{L as UnitTableExample,Tt as __namedExportsOrder,vt as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"generatedAt":
|
|
1
|
+
{"generatedAt":1724661568656,"hasCustomBabel":false,"hasCustomWebpack":false,"hasStaticDirs":false,"hasStorybookEslint":true,"refCount":0,"testPackages":{"@types/jest":"29.5.12","@vitest/coverage-c8":"0.31.4","eslint-plugin-vitest":null,"eslint-plugin-vitest-globals":"1.5.0","vitest":"1.6.0"},"packageManager":{"type":"yarn","version":"1.22.19"},"typescriptOptions":{"reactDocgen":"react-docgen"},"preview":{"usesGlobals":false},"framework":{"name":"@storybook/react-vite","options":{}},"builder":"@storybook/builder-vite","renderer":"@storybook/react","storybookVersion":"8.2.8","storybookVersionSpecifier":"^8.2.4","language":"typescript","storybookPackages":{"@storybook/addon-essentials":{"version":"8.2.8"},"@storybook/addon-links":{"version":"8.2.8"},"@storybook/preview-api":{"version":"8.2.8"},"@storybook/react":{"version":"8.2.8"},"@storybook/react-vite":{"version":"8.2.8"},"@storybook/test":{"version":"8.2.8"},"@storybook/test-runner":{"version":"0.19.1"},"eslint-plugin-storybook":{"version":"0.6.15"},"storybook":{"version":"8.2.8"}},"addons":{"@storybook/addon-actions":{"version":"8.2.8"},"@storybook/addon-docs":{"version":"8.2.8"},"@storybook/addon-interactions":{"version":"8.2.8"},"storybook-dark-mode":{"version":"4.0.2"}}}
|
package/package.json
CHANGED
package/dist/404.html
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<!doctype html><head><title>React UI Library</title><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1" user-scalable="no"><meta name="apple-mobile-web-app-capable" content="yes"><script type="module" crossorigin src="/react-ui-library/assets/index-DoFa61ar.js"></script><link rel="stylesheet" crossorigin href="/react-ui-library/assets/index-BpSdrNXy.css"></head><body><div id="content"></div></body>
|