@oliasoft-open-source/react-ui-library 4.6.15 → 4.6.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/global.css +11 -8
  2. package/dist/index.d.ts +15 -0
  3. package/dist/index.js +80 -9
  4. package/dist/index.js.map +1 -1
  5. package/dist/storybook/assets/{Color-6VNJS4EI--MtBZKKT.js → Color-6VNJS4EI-l_tkm4Ol.js} +1 -1
  6. package/dist/storybook/assets/{DocsRenderer-NNNQARDV-zWIDUW8s.js → DocsRenderer-NNNQARDV-pZpQmDez.js} +1 -1
  7. package/dist/storybook/assets/{WithTooltip-V3YHNWJZ-12HSM2HQ.js → WithTooltip-V3YHNWJZ-iEhMvku5.js} +1 -1
  8. package/dist/storybook/assets/{accordion.stories-TsMdBhhr.js → accordion.stories-lXs4IRds.js} +1 -1
  9. package/dist/storybook/assets/{buttons-and-links-EBr5j6Pb.js → buttons-and-links-kkzfA_fv.js} +1 -1
  10. package/dist/storybook/assets/{casing-loads.stories-cbxQQ8QL.js → casing-loads.stories-g4yBGv5b.js} +1 -1
  11. package/dist/storybook/assets/{cell.stories-S6RxEUZs.js → cell.stories-sVyam_bx.js} +1 -1
  12. package/dist/storybook/assets/{chunk-HLWAVYOI-olKL1DOp.js → chunk-HLWAVYOI-7EffY2hk.js} +1 -1
  13. package/dist/storybook/assets/{color-cEIYsWoC.js → color-0XY3ZHi2.js} +1 -1
  14. package/dist/storybook/assets/{file-input.stories-5kyAKS_C.js → file-input.stories-QbTMh_80.js} +1 -1
  15. package/dist/storybook/assets/{footer.stories-C10mdMff.js → footer.stories-ZEZ_We0f.js} +1 -1
  16. package/dist/storybook/assets/{form.stories-rXc4fhX5.js → form.stories-BaGSZHT3.js} +1 -1
  17. package/dist/storybook/assets/{formation.stories-SDrsEBR-.js → formation.stories-062BdtdZ.js} +1 -1
  18. package/dist/storybook/assets/{formatter-SWP5E3XI-lcnUpu9o.js → formatter-SWP5E3XI-rnZWn7Un.js} +1 -1
  19. package/dist/storybook/assets/{iframe-tFrL7OgV.js → iframe-fk3bQNFP.js} +2 -2
  20. package/dist/storybook/assets/{index-i7J9GoJM.js → index-L7u6rs_t.js} +5 -5
  21. package/dist/storybook/assets/{input-validation-PXF1N2vm.js → input-validation-SIWPb72t.js} +1 -1
  22. package/dist/storybook/assets/{inputs-WqrsreQN.js → inputs-ii5Lb3ZE.js} +1 -1
  23. package/dist/storybook/assets/{layout-forms-5QbjGxm5.js → layout-forms-lx7_nlWB.js} +1 -1
  24. package/dist/storybook/assets/{layout-general-6o2l_EdT.js → layout-general-6yMuf8qw.js} +1 -1
  25. package/dist/storybook/assets/{modal.stories-PLF80IYZ.js → modal.stories-aZGhb1Cl.js} +1 -1
  26. package/dist/storybook/assets/{padding-and-spacing-A6N16ujc.js → padding-and-spacing-Beocy83w.js} +1 -1
  27. package/dist/storybook/assets/{pop-confirm.stories-GmXpbAIC.js → pop-confirm.stories-6V_XrhKa.js} +1 -1
  28. package/dist/storybook/assets/popover-N9B8JT3G.js +1 -0
  29. package/dist/storybook/assets/popover.stories-goIrT_jy.js +10 -0
  30. package/dist/storybook/assets/{preview-xqKimQkP.js → preview-1W-XaElU.js} +2 -2
  31. package/dist/storybook/assets/{preview-jFWbYQuo.js → preview-4yh7mm39.js} +1 -1
  32. package/dist/storybook/assets/{row.stories-JJLYUXaO.js → row.stories-ZibxnXR9.js} +1 -1
  33. package/dist/storybook/assets/{syntaxhighlighter-B5GMVT5T-MZJdrJvC.js → syntaxhighlighter-B5GMVT5T-l5kiIEjw.js} +1 -1
  34. package/dist/storybook/assets/{table-38J6JCSb.js → table-kSTipYE0.js} +1 -1
  35. package/dist/storybook/assets/{table.stories-Sbzi__am.js → table.stories-zdRM5AV8.js} +1 -1
  36. package/dist/storybook/assets/{textarea-JE26Eekm.js → textarea-RrPYPGCC.js} +1 -1
  37. package/dist/storybook/assets/{textarea.stories-c1mkQU4s.js → textarea.stories-rqdJWVro.js} +1 -1
  38. package/dist/storybook/assets/{title.stories-qvk0Or3W.js → title.stories-tcfNoA6z.js} +1 -1
  39. package/dist/storybook/assets/unit-table.stories-Nry33G5L.js +150 -0
  40. package/dist/storybook/iframe.html +1 -1
  41. package/dist/storybook/index.json +1 -1
  42. package/dist/storybook/project.json +1 -1
  43. package/dist/storybook/stories.json +1 -1
  44. package/package.json +1 -1
  45. package/dist/storybook/assets/popover-Ioxe80BK.js +0 -1
  46. package/dist/storybook/assets/popover.stories-NbC7Zba8.js +0 -1
  47. package/dist/storybook/assets/unit-table.stories-0Wv_gCzq.js +0 -142
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oliasoft-open-source/react-ui-library",
3
- "version": "4.6.15",
3
+ "version": "4.6.17",
4
4
  "description": "Reusable UI components for React projects",
5
5
  "homepage": "https://oliasoft-open-source.gitlab.io/react-ui-library",
6
6
  "bugs": {
@@ -1 +0,0 @@
1
- import{j as e}from"./jsx-runtime-FsUICBgo.js";import{r as i,R as d}from"./index-RfLt4OUa.js";import{u as j,A as B,i as V}from"./tooltip-dueTLnwA.js";import{c}from"./index-VW3EWkuE.js";import{I as q}from"./common-types-U65vzrrz.js";import{D as k}from"./disabled-context-urNQThQz.js";import{B as P}from"./button-BiJw0fB3.js";const W="_toggleBox_lhie5_1",w="_fullWidthStyleFix_lhie5_8",E="_dismiss_lhie5_13",l={toggleBox:W,fullWidthStyleFix:w,dismiss:E},f=({children:n,content:o,placement:m="top-center",closeOnOutsideClick:p=!0,fullWidth:v=!1,showCloseButton:g=!1,testId:x,disabled:a=!1,overflowContainer:y=!1})=>{const r=i.useContext(k),[s,u]=i.useState(!1),t=()=>u(!1),h=()=>{a||r||u(!s)};i.useEffect(()=>{a||r||t()},[a,r]);const{renderLayer:_,arrowProps:b,layerProps:C,triggerProps:O}=j({isOpen:s,placement:m,auto:!0,triggerOffset:6,onOutsideClick:p?t:void 0,ResizeObserver:V,overflowContainer:y});return e.jsxs(e.Fragment,{children:[e.jsx("div",{ref:O.ref,onClick:h,"data-testid":x,children:n}),s&&_(e.jsxs("div",{className:v?c(l.toggleBox,l.fullWidthStyleFix):c(l.toggleBox),...C,children:[e.jsxs("div",{children:[d.isValidElement(o)?d.cloneElement(o,{close:t}):o,g&&e.jsx("div",{className:l.dismiss,children:e.jsx(P,{small:!0,round:!0,onClick:t,icon:q.CLOSE})})]}),e.jsx(B,{...b,backgroundColor:"var(--color-background-layer)",borderColor:"var(--color-border)",borderWidth:1,size:6})]}))]})};try{f.displayName="Popover",f.__docgenInfo={description:"",displayName:"Popover",props:{content:{defaultValue:null,description:"",name:"content",required:!1,type:{name:"ReactNode"}},placement:{defaultValue:{value:"top-center"},description:"",name:"placement",required:!1,type:{name:"enum",value:[{value:'"top-center"'},{value:'"bottom-center"'},{value:'"center"'},{value:'"bottom-start"'},{value:'"bottom-end"'},{value:'"top-start"'},{value:'"top-end"'},{value:'"left-end"'},{value:'"left-center"'},{value:'"left-start"'},{value:'"right-end"'},{value:'"right-center"'},{value:'"right-start"'}]}},closeOnOutsideClick:{defaultValue:{value:"true"},description:"",name:"closeOnOutsideClick",required:!1,type:{name:"boolean"}},fullWidth:{defaultValue:{value:"false"},description:"",name:"fullWidth",required:!1,type:{name:"boolean"}},showCloseButton:{defaultValue:{value:"false"},description:"",name:"showCloseButton",required:!1,type:{name:"boolean"}},testId:{defaultValue:null,description:"",name:"testId",required:!1,type:{name:"string"}},disabled:{defaultValue:{value:"false"},description:"",name:"disabled",required:!1,type:{name:"boolean"}},overflowContainer:{defaultValue:{value:"false"},description:"",name:"overflowContainer",required:!1,type:{name:"boolean"}}}}}catch{}export{f as P};
@@ -1 +0,0 @@
1
- import{j as r}from"./jsx-runtime-FsUICBgo.js";import{P as C}from"./popover-Ioxe80BK.js";import{I as S}from"./input-fYKvBwPs.js";import{B as i}from"./button-BiJw0fB3.js";import{F as P}from"./flex-RYZsoWEN.js";import{S as B}from"./select-AcJYUY86.js";import"./index-RfLt4OUa.js";import"./tooltip-dueTLnwA.js";import"./index-miLrID2P.js";import"./index-VW3EWkuE.js";import"./common-types-U65vzrrz.js";import"./disabled-context-urNQThQz.js";import"./types-5uVBABF4.js";import"./lodash-Bmg8FrMx.js";import"./spinner-R8Il4aRe.js";import"./icon-8EQazuuW.js";import"./objectWithoutPropertiesLoose-9Q1jwsKS.js";import"./inheritsLoose-8sb_A2v4.js";import"./tslib.es6-OIsz3r9a.js";import"./index-4QtD-hFu.js";import"./assertThisInitialized-4q6YPdh3.js";import"./memoize-one.esm-hqe5SRxC.js";import"./types-VB5zD18b.js";import"./text-6KQ6ntOV.js";import"./actions-7PO9r8zE.js";import"./badge-23Ty_zBt.js";import"./select.input-zP5tW20f.js";const l=[{label:"Option 1",value:"1"},{label:"Option 2",value:"2"}],w=({close:e})=>r.jsxs(P,{gap:"var(--padding-xs)",children:[r.jsx(S,{value:"Value",width:"150px",small:!0}),r.jsx(B,{options:l,value:l[0],width:"auto",small:!0}),r.jsx(i,{colored:!0,label:"Save",onClick:()=>{},small:!0}),r.jsx(i,{label:"Cancel",onClick:e,small:!0})]}),$={title:"Basic/Popover",component:C,args:{overflowContainer:!0,content:r.jsx(w,{}),children:r.jsx(i,{label:"Toggle me"})},decorators:[e=>r.jsx("div",{style:{display:"flex"},children:e()})],parameters:{docs:{source:{excludeDecorators:!0}}}},p=e=>r.jsx(C,{...e}),a=p.bind({}),o=p.bind({});o.args={children:r.jsx(S,{value:"Value",width:"100%"})};const s=p.bind({});s.args={closeOnOutsideClick:!1,showCloseButton:!0};const t=p.bind({});t.args={disabled:!0};var m,c,n;a.parameters={...a.parameters,docs:{...(m=a.parameters)==null?void 0:m.docs,source:{originalSource:"args => <Popover {...args} />",...(n=(c=a.parameters)==null?void 0:c.docs)==null?void 0:n.source}}};var u,d,g;o.parameters={...o.parameters,docs:{...(u=o.parameters)==null?void 0:u.docs,source:{originalSource:"args => <Popover {...args} />",...(g=(d=o.parameters)==null?void 0:d.docs)==null?void 0:g.source}}};var x,v,b;s.parameters={...s.parameters,docs:{...(x=s.parameters)==null?void 0:x.docs,source:{originalSource:"args => <Popover {...args} />",...(b=(v=s.parameters)==null?void 0:v.docs)==null?void 0:b.source}}};var f,j,h;t.parameters={...t.parameters,docs:{...(f=t.parameters)==null?void 0:f.docs,source:{originalSource:"args => <Popover {...args} />",...(h=(j=t.parameters)==null?void 0:j.docs)==null?void 0:h.source}}};const rr=["Default","InputTrigger","CloseButton","Disabled"];export{s as CloseButton,a as Default,t as Disabled,o as InputTrigger,rr as __namedExportsOrder,$ as default};
@@ -1,142 +0,0 @@
1
- import{j as n}from"./jsx-runtime-FsUICBgo.js";import{r as v}from"./index-RfLt4OUa.js";import{f as Q}from"./immer.esm-bD7SSJ7T.js";import{d as b}from"./index-qZmQ7nA9.js";import{G as Z}from"./grid-u1mZpaML.js";import{C as L}from"./card-0r8RRVk-.js";import{F as V}from"./field-m7XXDdEG.js";import{H as E}from"./heading-4tVgoT7O.js";import{S as H}from"./select-AcJYUY86.js";import{T as F}from"./toggle-R__kwKym.js";import{l as ee}from"./lodash-Bmg8FrMx.js";import{u as te}from"./use-previous-VKMmnaK7.js";import{T as ne,C as P}from"./table-38J6JCSb.js";import"./index-cCpkwrS5.js";import"./styled-components.browser.esm-qIipjd6c.js";import"./tslib.es6-OIsz3r9a.js";import"./index-VW3EWkuE.js";import"./label-bLcoUwtK.js";import"./common-types-U65vzrrz.js";import"./help-icon-eelulTML.js";import"./tooltip-dueTLnwA.js";import"./index-miLrID2P.js";import"./icon-8EQazuuW.js";import"./objectWithoutPropertiesLoose-9Q1jwsKS.js";import"./inheritsLoose-8sb_A2v4.js";import"./index-4QtD-hFu.js";import"./disabled-context-urNQThQz.js";import"./types-5uVBABF4.js";import"./assertThisInitialized-4q6YPdh3.js";import"./memoize-one.esm-hqe5SRxC.js";import"./types-VB5zD18b.js";import"./text-6KQ6ntOV.js";import"./actions-7PO9r8zE.js";import"./button-BiJw0fB3.js";import"./spinner-R8Il4aRe.js";import"./badge-23Ty_zBt.js";import"./select.input-zP5tW20f.js";import"./index.es-VXFRDikp.js";import"./redux-F5dueAP3.js";import"./objectSpread2-93s0nBry.js";import"./tiny-invariant-R4kOKlvx.js";import"./pagination-DtJdggbI.js";import"./input-fYKvBwPs.js";import"./input-group-R8LoqKRn.js";import"./input-group-addon-BHVsW9mL.js";import"./number-input-ymd7m-s5.js";import"./check-box-KynSyTaY.js";import"./slider-n3IxC2iq.js";import"./index-ugi_ZH6T.js";import"./popover-Ioxe80BK.js";const ae=o=>o.reduce(({preferredUnits:i,storageUnits:r},{unitKey:s,preferredUnit:a,storageUnit:g})=>(i[s]=a,r[s]=g,{preferredUnits:i,storageUnits:r}),{preferredUnits:{},storageUnits:{}}),re=({headers:o,rows:i,selectedUnits:r,storageUnits:s,onChangeUnit:a,convertBackToStorageUnit:g,enableCosmeticRounding:c,enableDisplayRounding:f})=>{const u=o?o.map(m=>({...m,cells:m.cells.map(p=>{var t;if(p.type===P.AUTO_UNIT){const{testId:C,unitKey:d}=p;return{value:r[d],type:P.SELECT,searchable:!1,options:(t=b.getUnitsForQuantity(d))==null?void 0:t.map(h=>({label:b.label(h),value:h})),native:p.native,onChange:h=>a({unitKey:d,value:h.target.value}),testId:C}}return p})})):[],l=i?i.map((m,p)=>({...m,cells:m.cells.map((t,C)=>{if("autoUnit"in t&&(t!=null&&t.autoUnit)&&(typeof(t==null?void 0:t.value)=="string"||typeof(t==null?void 0:t.value)=="number")){const{unitKey:d,value:h,formatDisplayValue:U}=t,x=f&&"roundDisplayValue"in t?t==null?void 0:t.roundDisplayValue:null,e=r[d],T=s[d],y=e!==T,S=y?b.convertAndGetValue(h,e,T):t.value,R=b.isScientificStringNum(h),w=c&&(y||!R)?b.roundToPrecision(S,14):S,_=U?U(w):w;return{...t,value:_,enableCosmeticRounding:c,enableDisplayRounding:f,roundDisplayValue:x,onChange:j=>{const{value:W}=j.target,I=s[d],D=r[d],J=D!==I,K=g?I:D,$=J?b.convertAndGetValue(W,K,D):W;if("onChange"in t){const{onChange:X}=t,Y={...j,target:{...j.target,value:String($),rowIndex:p,cellIndex:C,unit:K}};X(Y)}}}}return t})})):[];return{convertedHeaders:u,convertedRows:l}},B=({table:o,unitConfig:i,convertBackToStorageUnit:r=!0,enableCosmeticRounding:s=!0,enableDisplayRounding:a=!0})=>{const{rows:g,headers:c,...f}=o,{storageUnits:u,preferredUnits:l}=ae(i),m=te(l),[p,t]=v.useState(l),C=({unitKey:e,value:T})=>t({...p,[e]:T}),d=e=>re({headers:c,rows:g,selectedUnits:e,storageUnits:u,onChangeUnit:C,convertBackToStorageUnit:r,enableCosmeticRounding:s,enableDisplayRounding:a}),h=d(p),[U,x]=v.useState(h);return v.useEffect(()=>{!ee.isEqual(l,m)&&(t(l),x(d(l)))},[i]),v.useEffect(()=>{x(d(p))},[o,p]),n.jsx(ne,{table:{...f,headers:U.convertedHeaders,rows:U.convertedRows}})};try{B.displayName="UnitTable",B.__docgenInfo={description:"",displayName:"UnitTable",props:{table:{defaultValue:null,description:"",name:"table",required:!0,type:{name:"IUnitTable"}},unitConfig:{defaultValue:null,description:"",name:"unitConfig",required:!0,type:{name:"IUnitConfigItem[]"}},convertBackToStorageUnit:{defaultValue:{value:"true"},description:"",name:"convertBackToStorageUnit",required:!1,type:{name:"boolean"}},enableCosmeticRounding:{defaultValue:{value:"true"},description:"",name:"enableCosmeticRounding",required:!1,type:{name:"boolean"}},enableDisplayRounding:{defaultValue:{value:"true"},description:"",name:"enableDisplayRounding",required:!1,type:{name:"boolean"}},onListReorder:{defaultValue:null,description:"",name:"onListReorder",required:!1,type:{name:"((obj: { from: number; to: number; }) => void)"}}}}}catch{}const dt={title:"Basic/UnitTable",args:{}},oe=!0,ie=!0,le=!0,se=!1,z="m",M="C",ue=3,de=(o,i,r)=>{const s=[i,i,r],a=[...Array(o)].map((g,c)=>{const f=c,u=c+1.25,l=4+c*.25;return[String(f),String(u),String(l)]});return[s,...a]},ce=de(ue,z,M),pe=({reduxTable:o,value:i,unit:r,rowIndex:s,cellIndex:a})=>Q(o,g=>{const c=g[0][a],f=(u,l)=>l===0;return g.forEach((u,l)=>{if(f(u,l)){u[a]=r;return}if(l===s+1){u[a]=String(i);return}const m=b.convertAndGetValue(u[a],r,c);u[a]=String(m)}),g}),ge=({reduxTable:o,value:i,rowIndex:r,cellIndex:s})=>Q(o,a=>{a[r+1][s]=i}),k=()=>{var U,x;const[o,i]=v.useState(z),[r,s]=v.useState(M),[a,g]=v.useState(ce),[c,f]=v.useState(oe),[u,l]=v.useState(le),[m,p]=v.useState(ie),[t,C]=v.useState(se),d=e=>{const{rowIndex:T,cellIndex:y,value:S,unit:R}=e.target,w=t?pe({reduxTable:a,value:S,unit:R,rowIndex:T,cellIndex:y}):ge({reduxTable:a,value:S,rowIndex:T,cellIndex:y});g(w)},h=a.reduce((e,T,y)=>(y===0?e.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"}]}]:e.rows=e.rows.concat({cells:T.map((S,R)=>{const w=y===1&&R===1;return{value:S,type:w?"Text":"NumberInput",unitKey:R===2?"temperature":"length",onChange:d,roundDisplayValue:y===3&&R===2?D=>b.roundByMagnitude(D,2):null,formatDisplayValue:w?D=>`T* ${D}`:null,autoUnit:!0}})}),e),{headers:[],rows:[]});return n.jsxs(Z,{columns:"1fr 1fr",gap:!0,children:[n.jsxs(L,{heading:n.jsx(E,{children:"Settings"}),children:[n.jsx(V,{label:"Convert back to storage unit:",labelLeft:!0,labelWidth:200,children:n.jsx(F,{checked:c,onChange:e=>f(e.target.checked)})}),n.jsx(V,{label:"Enable display rounding:",labelLeft:!0,labelWidth:200,children:n.jsx(F,{checked:u,onChange:e=>l(e.target.checked)})}),n.jsx(V,{label:"Enable cosmetic rounding:",labelLeft:!0,labelWidth:200,children:n.jsx(F,{checked:m,onChange:e=>p(e.target.checked)})}),n.jsx(V,{label:"Convert whole table:",labelLeft:!0,labelWidth:200,children:n.jsx(F,{checked:t,onChange:e=>C(e.target.checked)})})]}),n.jsxs(L,{heading:n.jsx(E,{children:"Unit template"}),children:[n.jsx(V,{label:"Length unit:",labelLeft:!0,labelWidth:120,children:n.jsx(H,{options:(U=b.getUnitsForQuantity("length"))==null?void 0:U.map(e=>({value:e,label:b.label(e)})),value:{value:o},onChange:e=>i(e.target.value),width:"100px"})}),n.jsx(V,{label:"Temperature unit:",labelLeft:!0,labelWidth:120,children:n.jsx(H,{options:(x=b.getUnitsForQuantity("temperature"))==null?void 0:x.map(e=>({value:e,label:b.label(e)})),value:{value:r},onChange:e=>s(e.target.value),width:"100px"})})]}),n.jsx(L,{heading:n.jsx(E,{children:"Storage State (Redux)"}),children:n.jsx("pre",{children:n.jsx("code",{children:JSON.stringify(a,null,2)})})}),n.jsx(L,{heading:n.jsx(E,{children:"UnitTable"}),children:n.jsx(B,{table:h,unitConfig:[{unitKey:"length",storageUnit:a[0][0],preferredUnit:o},{unitKey:"temperature",storageUnit:a[0][2],preferredUnit:r}],convertBackToStorageUnit:c,enableDisplayRounding:u,enableCosmeticRounding:m})})]})};var A,N,q,G,O;k.parameters={...k.parameters,docs:{...(A=k.parameters)==null?void 0:A.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
-
10
- /*********************************************************************************************************************
11
- Cell onChange handler
12
- *********************************************************************************************************************/
13
- const onUpdateCell = (evt: IUnitTableOnChangeEvent) => {
14
- const {
15
- rowIndex,
16
- cellIndex,
17
- value,
18
- unit
19
- } = evt.target;
20
- const nextTable = convertWholeTable ? convertStorageTable({
21
- reduxTable,
22
- value,
23
- unit,
24
- rowIndex,
25
- cellIndex
26
- }) : updateCell({
27
- reduxTable,
28
- value,
29
- rowIndex,
30
- cellIndex
31
- });
32
- setReduxTable(nextTable);
33
- };
34
-
35
- /*********************************************************************************************************************
36
- Construct table view data (same as old Table component, with a new props)
37
- *********************************************************************************************************************/
38
- const tableViewData = reduxTable.reduce((acc, row, rowIndex) => {
39
- if (rowIndex === 0) {
40
- acc.headers = [{
41
- cells: [{
42
- value: 'From'
43
- }, {
44
- value: 'To'
45
- }, {
46
- value: 'Temperature'
47
- }]
48
- }, {
49
- cells: [{
50
- type: 'AutoUnit',
51
- unitKey: 'length'
52
- }, {
53
- type: 'AutoUnit',
54
- unitKey: 'length'
55
- }, {
56
- type: 'AutoUnit',
57
- unitKey: 'temperature',
58
- testId: 'table-unit-selector-3'
59
- }]
60
- }];
61
- } else {
62
- acc.rows = acc.rows.concat({
63
- cells: row.map((cell, cellIndex) => {
64
- const specialCell = rowIndex === 1 && cellIndex === 1;
65
- const type = specialCell ? 'Text' : 'NumberInput';
66
- const formatDisplayValue = specialCell ? (value: number | string) => \`T* \${value}\` : null;
67
- const customDisplayRounding = rowIndex === 3 && cellIndex === 2 ? (value: TStringNumberNull) => roundByMagnitude(value, 2) : null;
68
- const value = cell;
69
- return {
70
- value,
71
- type,
72
- unitKey: cellIndex === 2 ? 'temperature' : 'length',
73
- onChange: onUpdateCell,
74
- roundDisplayValue: customDisplayRounding,
75
- // optionally customize the display rounding of specific columns/cells
76
- formatDisplayValue,
77
- // optionally extend/customize the display formatting of specific columns/cells
78
- autoUnit: true
79
- };
80
- })
81
- });
82
- }
83
- return acc;
84
- }, {
85
- headers: ([] as any[]),
86
- rows: ([] as IUnitTableRow[])
87
- });
88
- return <Grid columns="1fr 1fr" gap>
89
- <Card heading={<Heading>Settings</Heading>}>
90
- <Field label="Convert back to storage unit:" labelLeft labelWidth={200}>
91
- <Toggle checked={convertBackToStorageUnit} onChange={evt => setConvertBackToStorageUnit(evt.target.checked)} />
92
- </Field>
93
- <Field label="Enable display rounding:" labelLeft labelWidth={200}>
94
- <Toggle checked={enableDisplayRounding} onChange={evt => setEnableDisplayRounding(evt.target.checked)} />
95
- </Field>
96
- <Field label="Enable cosmetic rounding:" labelLeft labelWidth={200}>
97
- <Toggle checked={enableCosmeticRounding} onChange={evt => setEnableCosmeticRounding(evt.target.checked)} />
98
- </Field>
99
- <Field label="Convert whole table:" labelLeft labelWidth={200}>
100
- <Toggle checked={convertWholeTable} onChange={evt => setConvertWholeTable(evt.target.checked)} />
101
- </Field>
102
- </Card>
103
- <Card heading={<Heading>Unit template</Heading>}>
104
- <Field label="Length unit:" labelLeft labelWidth={120}>
105
- <Select options={getUnitsForQuantity('length')?.map(unit => ({
106
- value: unit,
107
- label: label(unit)
108
- }))} value={{
109
- value: preferredLengthUnit
110
- }} onChange={evt => setPreferredLengthUnit(evt.target.value)} width="100px" />
111
- </Field>
112
- <Field label="Temperature unit:" labelLeft labelWidth={120}>
113
- <Select options={getUnitsForQuantity('temperature')?.map(unit => ({
114
- value: unit,
115
- label: label(unit)
116
- }))} value={{
117
- value: preferredTemperatureUnit
118
- }} onChange={evt => setPreferredTemperatureUnit(evt.target.value)} width="100px" />
119
- </Field>
120
- </Card>
121
- <Card heading={<Heading>Storage State (Redux)</Heading>}>
122
- <pre>
123
- <code>{JSON.stringify(reduxTable, null, 2)}</code>
124
- </pre>
125
- </Card>
126
- <Card heading={<Heading>UnitTable</Heading>}>
127
- <UnitTable table={tableViewData}
128
- //New props:
129
- unitConfig={[{
130
- unitKey: 'length',
131
- storageUnit: reduxTable[0][0],
132
- preferredUnit: preferredLengthUnit
133
- }, {
134
- unitKey: 'temperature',
135
- storageUnit: reduxTable[0][2],
136
- preferredUnit: preferredTemperatureUnit
137
- }]}
138
- //Most tables should just use the default values here (true):
139
- convertBackToStorageUnit={convertBackToStorageUnit} enableDisplayRounding={enableDisplayRounding} enableCosmeticRounding={enableCosmeticRounding} />
140
- </Card>
141
- </Grid>;
142
- }`,...(q=(N=k.parameters)==null?void 0:N.docs)==null?void 0:q.source},description:{story:"Story",...(O=(G=k.parameters)==null?void 0:G.docs)==null?void 0:O.description}}};const ct=["UnitTablePrototype"];export{k as UnitTablePrototype,ct as __namedExportsOrder,dt as default};