@oliasoft-open-source/react-ui-library 4.11.0-beta-3 → 4.11.0
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/404.html +1 -0
- package/dist/index.js +78 -58
- package/dist/index.js.map +1 -1
- package/dist/storybook/assets/{Color-KGDBMAHA-DeGjmgTY.js → Color-KGDBMAHA-C4DMqLTk.js} +1 -1
- package/dist/storybook/assets/{DocsRenderer-PKQXORMH-DJIj_qEG.js → DocsRenderer-PKQXORMH-4sK5I5fh.js} +1 -1
- package/dist/storybook/assets/{accordion.stories-BTxV-ybU.js → accordion.stories-BSRBp5Mg.js} +2 -2
- package/dist/storybook/assets/{afe.stories-DFQsvqIV.js → afe.stories-DM18uTAa.js} +2 -2
- package/dist/storybook/assets/{buttons-and-links-BHGzZGPV.js → buttons-and-links-BAJT7RF7.js} +1 -1
- package/dist/storybook/assets/{casing-loads.stories-CJpnsmsZ.js → casing-loads.stories-CE6GJ021.js} +2 -2
- package/dist/storybook/assets/{cell.stories-Bpl0Squh.js → cell.stories-BkZwSf40.js} +2 -2
- package/dist/storybook/assets/check-box.stories-BJ0ShmeC.js +97 -0
- package/dist/storybook/assets/check-box.test-case.stories-CzuYZkUh.js +30 -0
- package/dist/storybook/assets/{chunk-HLWAVYOI-D2p4xoma.js → chunk-HLWAVYOI-wyESLsMA.js} +1 -1
- package/dist/storybook/assets/{color-D9KYOiNh.js → color-CXm-Xks7.js} +1 -1
- package/dist/storybook/assets/enum-Bnn40S8Q.js +1 -0
- package/dist/storybook/assets/footer.stories-C1SojIiD.js +3 -0
- package/dist/storybook/assets/form.stories-BLcmnfy8.js +49 -0
- package/dist/storybook/assets/{formation.stories-BT8VrcqV.js → formation.stories-DZ9-Ct5F.js} +2 -2
- package/dist/storybook/assets/helpers-JJxzGegQ.js +1 -0
- package/dist/storybook/assets/iframe-DGCZgYKU.js +2 -0
- package/dist/storybook/assets/{index-C0Iaso0O.js → index-D-ApmKaY.js} +88 -88
- package/dist/storybook/assets/{index-CNkaN_wz.js → index-DHATsyTR.js} +1 -1
- package/dist/storybook/assets/{input-group.stories-CElwRt3p.js → input-group.stories-EhmORqH9.js} +3 -3
- package/dist/storybook/assets/{input-validation-Ccgprl1C.js → input-validation-BdnKKR1J.js} +2 -2
- package/dist/storybook/assets/{inputs-DtQ245kS.js → inputs-Cpi6xZLB.js} +2 -2
- package/dist/storybook/assets/{layout-forms-Bm7FYA3V.js → layout-forms-DxC0zO_Y.js} +5 -5
- package/dist/storybook/assets/{layout-general-V7ekuEG7.js → layout-general-Be4RMwPl.js} +1 -1
- package/dist/storybook/assets/menu.stories-DLJSzJa-.js +82 -0
- package/dist/storybook/assets/menu.test-case.stories-DyrNbGBs.js +3 -0
- package/dist/storybook/assets/modal.stories-DOgeTuHT.js +200 -0
- package/dist/storybook/assets/modal.test-case.stories-DQ1Izuq6.js +21 -0
- package/dist/storybook/assets/{number-input-Bpg4Yqmo.js → number-input-CJJvhIIv.js} +1 -1
- package/dist/storybook/assets/number-input.stories-CKVq60XH.js +89 -0
- package/dist/storybook/assets/number-input.test-case.stories-Dh1F7N8M.js +92 -0
- package/dist/storybook/assets/{padding-and-spacing-IKi7rvQ-.js → padding-and-spacing-BZdh5XRo.js} +1 -1
- package/dist/storybook/assets/{pagination-CLt-kUlx.js → pagination-DWc8zp3k.js} +1 -1
- package/dist/storybook/assets/{pagination.stories-CTRM0Xou.js → pagination.stories-B5cOvzik.js} +2 -2
- package/dist/storybook/assets/popover.stories-p9_-pH_Q.js +10 -0
- package/dist/storybook/assets/{preview-ZgLLfBPl.js → preview-B3bzTGOp.js} +2 -2
- package/dist/storybook/assets/{preview-CtQzjqBP.js → preview-NGnahGuq.js} +1 -1
- package/dist/storybook/assets/{projects.stories-BQswWVCx.js → projects.stories-Co_WnKSx.js} +2 -2
- package/dist/storybook/assets/{radio-button-DmDuw4DA.js → radio-button-C4ljBRED.js} +1 -1
- package/dist/storybook/assets/radio-button.stories-D1rWr6ms.js +61 -0
- package/dist/storybook/assets/radio-button.test-case.stories-DglmHlWs.js +11 -0
- package/dist/storybook/assets/{reservoirs.stories-B12tIrmZ.js → reservoirs.stories-UW_8sofe.js} +2 -2
- package/dist/storybook/assets/{rich-text-input.stories-DkaOBgbE.js → rich-text-input.stories-CK_OTGiV.js} +3 -3
- package/dist/storybook/assets/{row.stories-msEoNdGI.js → row.stories-D11wLSt6.js} +2 -2
- package/dist/storybook/assets/select-03uRbc4I.js +61 -0
- package/dist/storybook/assets/select.input-CJed_LLR.js +1 -0
- package/dist/storybook/assets/select.stories-Bpffz9TF.js +498 -0
- package/dist/storybook/assets/select.stories-data-DxgWKlU6.js +1 -0
- package/dist/storybook/assets/select.test-case.stories-DwDNDHax.js +82 -0
- package/dist/storybook/assets/{site.stories-umpPYjkq.js → site.stories-ZGohyW6Z.js} +2 -2
- package/dist/storybook/assets/{table-5Y5KPNSk.js → table-DyOsClUv.js} +1 -1
- package/dist/storybook/assets/{table.stories-Clltxls0.js → table.stories-C1GgZCCR.js} +2 -2
- package/dist/storybook/assets/{tabs-C3NG6m9W.js → tabs-BoToLVEP.js} +1 -1
- package/dist/storybook/assets/tabs.stories-B52iEaHf.js +30 -0
- package/dist/storybook/assets/{title.stories-CsrYTGde.js → title.stories-jatDyjoM.js} +3 -3
- package/dist/storybook/assets/toaster.stories-G6nKp3uV.js +84 -0
- package/dist/storybook/assets/toaster.test-case.stories-CCHTh_U1.js +6 -0
- package/dist/storybook/assets/toggle.stories-BAislK3I.js +106 -0
- package/dist/storybook/assets/toggle.test-case.stories-CeUwdhGD.js +36 -0
- package/dist/storybook/assets/{tooltip.test-case.stories-CHibN8rC.js → tooltip.test-case.stories-C0wxGvKJ.js} +1 -1
- package/dist/storybook/assets/unit-input-CooRJQnF.js +10 -0
- package/dist/storybook/assets/unit-input.stories-zmSrl6iW.js +198 -0
- package/dist/storybook/assets/unit-input.test-case.stories-C1xRJ1EZ.js +220 -0
- package/dist/storybook/assets/unit-table.stories-Bl2gHPKG.js +152 -0
- package/dist/storybook/assets/unit-table.test-case.stories-DpSewGv4.js +1 -0
- package/dist/storybook/assets/use-previous-D775JrO6.js +1 -0
- package/dist/storybook/iframe.html +1 -1
- package/dist/storybook/index.json +1 -1
- package/dist/storybook/project.json +1 -1
- package/package.json +1 -1
- package/dist/storybook/assets/check-box.stories-DfbWw6mD.js +0 -126
- package/dist/storybook/assets/footer.stories-DgjDE_JR.js +0 -3
- package/dist/storybook/assets/form.stories-BrUnmw7R.js +0 -49
- package/dist/storybook/assets/iframe-B8VgeFPT.js +0 -2
- package/dist/storybook/assets/initialize-context-DOqEe1Xq.js +0 -1
- package/dist/storybook/assets/menu.stories-xWX80Eh2.js +0 -84
- package/dist/storybook/assets/modal.stories-LhoWfDE6.js +0 -220
- package/dist/storybook/assets/number-input.stories-DhCjZ37u.js +0 -180
- package/dist/storybook/assets/popover.stories-CGm0M5fv.js +0 -10
- package/dist/storybook/assets/radio-button.stories-5gvV0LD0.js +0 -71
- package/dist/storybook/assets/select-DnRuRG_N.js +0 -61
- package/dist/storybook/assets/select.input-D0UkAPd9.js +0 -1
- package/dist/storybook/assets/select.stories-B9w9ONzj.js +0 -579
- package/dist/storybook/assets/tabs.stories-dsXjRHJy.js +0 -30
- package/dist/storybook/assets/toaster.stories-HO4VBTy-.js +0 -89
- package/dist/storybook/assets/toggle.stories-qTHFTXxI.js +0 -141
- package/dist/storybook/assets/unit-input.stories-QnEpR0rY.js +0 -426
- package/dist/storybook/assets/unit-table.stories-BZCc0yfc.js +0 -152
|
@@ -1,152 +0,0 @@
|
|
|
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 p,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,g as se,c as ue}from"./initialize-context-DOqEe1Xq.js";import{T as ce,C as q}from"./table-5Y5KPNSk.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-Bpg4Yqmo.js";import"./check-box-DPLaOkRR.js";import"./slider-C7vnj_3M.js";import"./index-BI4_Bp97.js";import"./popover-rq33c1W2.js";const de=a=>a.reduce(({preferredUnits:o,storageUnits:n},{unitKey:l,preferredUnit:e,storageUnit:b})=>{const{unitTemplate:g=null}=le()??{};return o[l]=e??se(l,g),n[l]=b,{preferredUnits:o,storageUnits:n}},{preferredUnits:{},storageUnits:{}}),G=(a,o,n,l)=>{if(ue({value:a,unitkey:o,toUnit:n}))try{return x.convertAndGetValue(a,n,l)}catch{return a}return a},pe=({headers:a,rows:o,selectedUnits:n,storageUnits:l,onChangeUnit:e,convertBackToStorageUnit:b,enableCosmeticRounding:g,enableDisplayRounding:T})=>{const c=a?a.map(d=>({...d,cells:d.cells.map(m=>{var i;if(m.type===q.AUTO_UNIT){const{testId:S,unitKey:u}=m;return{value:n[u],type:q.SELECT,searchable:!1,options:(i=x.getUnitsForQuantity(u))==null?void 0:i.map(U=>({label:x.label(U),value:U})),native:m.native,onChange:U=>e({unitKey:u,value:U.target.value}),testId:S}}return m})})):[],s=o?o.map((d,m)=>({...d,cells:d.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:u,value:U,formatDisplayValue:I}=i,V=T&&"roundDisplayValue"in i?i==null?void 0:i.roundDisplayValue:null,h=n[u],y=l[u],t=h!==y,f=t?G(U,u,h,y):i.value,C=I?I(f):f;return{...i,value:C,enableCosmeticRounding:g&&t,enableDisplayRounding:T,roundDisplayValue:V,onChange:D=>{const{value:w}=D.target,k=l[u],E=n[u],N=E!==k,H=b?k:E,K=N?G(w,u,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:c,convertedRows:s}},Y=({table:a,unitConfig:o,convertBackToStorageUnit:n=!0,enableCosmeticRounding:l=!0,enableDisplayRounding:e=!0})=>{const{rows:b,headers:g,...T}=a,{storageUnits:c,preferredUnits:s}=de(o),d=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})},u=h=>pe({headers:g,rows:b,selectedUnits:h,storageUnits:c,onChangeUnit:S,convertBackToStorageUnit:n,enableCosmeticRounding:l,enableDisplayRounding:e}),U=u(m),[I,V]=v.useState(U);return v.useEffect(()=>{!re.isEqual(s,d)&&(Object.keys(s).forEach(y=>{const t=d==null?void 0:d[y],f=s[y];t!==f&&S({unitKey:y,value:f})}),V(u(s)))},[o]),v.useEffect(()=>{V(u(m))},[a,m]),r.jsx(ce,{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 Tt={title:"Basic/UnitTable",args:{}},ge=!0,me=!0,he=!0,be=!1,A="ft",Z="C",ye=3,fe=(a,o,n)=>{const l=[o,o,n],e=[...Array(a)].map((b,g)=>{const T=g,c=g+1.25,s=4+g*.25;return[String(T),String(c),String(s)]});return[l,...e]},ve=fe(ye,A,Z),Te=({reduxTable:a,value:o,unit:n,rowIndex:l,cellIndex:e})=>X(a,b=>{const g=b[0][e],T=(c,s)=>s===0;return b.forEach((c,s)=>{if(T(c,s)){c[e]=n;return}if(s===l+1){c[e]=String(o);return}const d=x.convertAndGetValue(c[e],n,g);c[e]=String(d)}),b}),Ue=({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(ve),[g,T]=v.useState(ge),[c,s]=v.useState(he),[d,m]=v.useState(me),[i,S]=v.useState(be),[u,U]=v.useState(A),I=t=>{const{rowIndex:f,cellIndex:C,value:D,unit:w}=t.target,k=i?Te({reduxTable:e,value:D,unit:w,rowIndex:f,cellIndex:C}):Ue({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:g,onChange:t=>T(t.target.checked)})}),r.jsx(R,{label:"Enable display rounding:",labelLeft:!0,labelWidth:200,children:r.jsx(W,{checked:c,onChange:t=>s(t.target.checked)})}),r.jsx(R,{label:"Enable cosmetic rounding:",labelLeft:!0,labelWidth:200,children:r.jsx(W,{checked:d,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:g,enableDisplayRounding:c,enableCosmeticRounding:d}),r.jsx(ne,{height:20}),r.jsx(R,{label:"Displayed length unit:",labelLeft:!0,labelWidth:150,children:u})]})]})};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 p.clear(e),await p.type(e,"123.123456789"),await p.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 p.clear(e),await p.type(e,"123,456"),await p.click(a),await j(n.getByDisplayValue("123.46")).toBeInTheDocument()}),await o("Can enter small numbers",async()=>{const e=n.getByTestId("testId_2_1");await p.clear(e),await p.type(e,"0.0000000023"),await p.click(a),await j(e).toHaveDisplayValue("0.00")}),await o("Can enter large numbers",async()=>{const e=n.getByTestId("testId_2_1");await p.clear(e),await p.type(e,"999999999999"),await p.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 p.clear(e),await p.type(e,"123x45s6"),await p.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 Ut=["UnitTableExample"];export{L as UnitTableExample,Ut as __namedExportsOrder,Tt as default};
|