@oliasoft-open-source/react-ui-library 4.8.2 → 4.9.0-beta-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +7 -2
- package/dist/index.js +44 -29
- package/dist/index.js.map +1 -1
- package/dist/storybook/assets/{Color-KGDBMAHA-CLI1j7TM.js → Color-KGDBMAHA-9iiZ9sw8.js} +1 -1
- package/dist/storybook/assets/{DocsRenderer-PKQXORMH-C-VGLian.js → DocsRenderer-PKQXORMH-ypxq1WaK.js} +1 -1
- package/dist/storybook/assets/{accordion.stories-CjdOndbq.js → accordion.stories-D8Jb5lRq.js} +2 -2
- package/dist/storybook/assets/{afe.stories-D-uQj_IO.js → afe.stories-Dxdcf-Wr.js} +2 -2
- package/dist/storybook/assets/{buttons-and-links-DLCyz4fu.js → buttons-and-links-CtCO9I4x.js} +1 -1
- package/dist/storybook/assets/{casing-loads.stories-Cb2t61c-.js → casing-loads.stories-Bo9VN-h1.js} +2 -2
- package/dist/storybook/assets/{cell.stories-B6XrqnOz.js → cell.stories-BRIh_VqD.js} +2 -2
- package/dist/storybook/assets/{chunk-HLWAVYOI-B-NqvPla.js → chunk-HLWAVYOI-pVr_pd7U.js} +1 -1
- package/dist/storybook/assets/{color-DFh0-vFc.js → color-DRpLnJug.js} +1 -1
- package/dist/storybook/assets/{footer.stories-BxFhNGsz.js → footer.stories-Cghb-yfM.js} +2 -2
- package/dist/storybook/assets/form.stories-Bs1kjjd-.js +49 -0
- package/dist/storybook/assets/{formation.stories-r9JrQX7d.js → formation.stories-DqRntQtC.js} +2 -2
- package/dist/storybook/assets/iframe-Dl9kSAK_.js +2 -0
- package/dist/storybook/assets/{index-BIH3zom3.js → index-B-vN3mVN.js} +1 -1
- package/dist/storybook/assets/{index-MQZw3-wz.js → index-BtLaQIRR.js} +88 -88
- package/dist/storybook/assets/{input-group.stories-dQnx3QX0.js → input-group.stories-CCXx8SUE.js} +3 -3
- package/dist/storybook/assets/{input-validation-BhTmzA8C.js → input-validation-CipliMS4.js} +2 -2
- package/dist/storybook/assets/{inputs-BZwMYCXB.js → inputs-CfCos_Do.js} +1 -1
- package/dist/storybook/assets/layout-forms-BQ06Ufkz.js +16 -0
- package/dist/storybook/assets/{layout-general-hZ1fwnpl.js → layout-general-BSEz3PKo.js} +1 -1
- package/dist/storybook/assets/{modal.stories-B-4WKtnM.js → modal.stories-BZHVz3SN.js} +2 -2
- package/dist/storybook/assets/number-input-CKbeoN5B.js +16 -0
- package/dist/storybook/assets/number-input.stories-XP0NZg9d.js +166 -0
- package/dist/storybook/assets/{padding-and-spacing-DZHdCzCJ.js → padding-and-spacing-BJI9HaUS.js} +1 -1
- package/dist/storybook/assets/{pagination-bLx5-m9c.js → pagination-CUucuCPT.js} +1 -1
- package/dist/storybook/assets/{pagination.stories-BHPRfynZ.js → pagination.stories-CN4-LYyQ.js} +2 -2
- package/dist/storybook/assets/popover.stories-Cxaq0SAc.js +10 -0
- package/dist/storybook/assets/{preview-_veCKVNG.js → preview-1dyDpjfs.js} +2 -2
- package/dist/storybook/assets/{preview-nWTzJqHS.js → preview-I-_KBbaH.js} +1 -1
- package/dist/storybook/assets/{projects.stories-CdvyNFKw.js → projects.stories-B1J-8EYu.js} +2 -2
- package/dist/storybook/assets/{radio-button-C3RuBqEf.js → radio-button-YWkXh8yt.js} +1 -1
- package/dist/storybook/assets/{radio-button.stories-CAHs1mr6.js → radio-button.stories-DB127127.js} +2 -2
- package/dist/storybook/assets/{reservoirs.stories-C98Z9kS0.js → reservoirs.stories-B2mJ74TZ.js} +2 -2
- package/dist/storybook/assets/{rich-text-input.stories-B2p90wTh.js → rich-text-input.stories-B3O7b7-u.js} +3 -3
- package/dist/storybook/assets/{row.stories-BRVnImTl.js → row.stories-D014hMyd.js} +2 -2
- package/dist/storybook/assets/select-BEc_mNg5.js +61 -0
- package/dist/storybook/assets/select.input-D0UkAPd9.js +1 -0
- package/dist/storybook/assets/{select.stories-B0d_sE6g.js → select.stories-DXD4AYSk.js} +2 -2
- package/dist/storybook/assets/{site.stories-lIyAWOdt.js → site.stories-CbJ0phLn.js} +2 -2
- package/dist/storybook/assets/{table-DWBe_npR.js → table-CsEdIPXW.js} +1 -1
- package/dist/storybook/assets/{table.stories-Cb7lE3nF.js → table.stories-B5frb4W9.js} +2 -2
- package/dist/storybook/assets/{tabs-BoToLVEP.js → tabs-C3NG6m9W.js} +1 -1
- package/dist/storybook/assets/tabs.stories-dsXjRHJy.js +30 -0
- package/dist/storybook/assets/{title.stories-TUTSNdwJ.js → title.stories-BisMTHc8.js} +3 -3
- package/dist/storybook/assets/unit-input.stories-DiZlUE9e.js +380 -0
- package/dist/storybook/assets/unit-table.stories-DPghKtFI.js +152 -0
- package/dist/storybook/iframe.html +1 -1
- package/dist/storybook/index.json +1 -1
- package/dist/storybook/project.json +1 -1
- package/package.json +3 -3
- package/dist/404.html +0 -1
- package/dist/storybook/assets/enum-Bnn40S8Q.js +0 -1
- package/dist/storybook/assets/form.stories-C_zflIAj.js +0 -49
- package/dist/storybook/assets/helpers-JJxzGegQ.js +0 -1
- package/dist/storybook/assets/iframe-DOgYbEjR.js +0 -2
- package/dist/storybook/assets/layout-forms-j_hFXArR.js +0 -16
- package/dist/storybook/assets/number-input-C8O0lnql.js +0 -16
- package/dist/storybook/assets/number-input.stories-e-MRb-7_.js +0 -124
- package/dist/storybook/assets/popover.stories-DyTPnA5y.js +0 -10
- package/dist/storybook/assets/select-BpALjE__.js +0 -61
- package/dist/storybook/assets/select.input-CJed_LLR.js +0 -1
- package/dist/storybook/assets/tabs.stories-B52iEaHf.js +0 -30
- package/dist/storybook/assets/unit-input.stories-CRAsgJro.js +0 -316
- package/dist/storybook/assets/unit-table.stories-BdTJv4W-.js +0 -152
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import{j as i}from"./jsx-runtime-eps93zm2.js";import{r as v}from"./index-DhsZuJvc.js";import{f as J}from"./immer.esm-BwVl9PS2.js";import{d as C}from"./index-C0x1JmaP.js";import{G as ee}from"./grid-DRkC-bt8.js";import{S as te}from"./spacer-BWoNR27H.js";import{w as O,u as d,e as j,f as ne,a as ae}from"./index-DMAnyMX5.js";import{C as F}from"./card-EcjmryU9.js";import{F as k}from"./field-C5_fLDpy.js";import{H as _}from"./heading-NkLgQYoP.js";import{S as G}from"./select-BEc_mNg5.js";import{T as W}from"./toggle-C0zvrIOF.js";import{l as ie}from"./lodash-c4VUpsOs.js";import{u as oe}from"./use-previous-D775JrO6.js";import{T as re,C as P}from"./table-CsEdIPXW.js";import"./index-DRSy5Ssd.js";import"./styled-components.browser.esm-BQ9GQzDc.js";import"./index-CF7H4eMJ.js";import"./index-Bk2sglWO.js";import"./label-hiSz3I8H.js";import"./common-types-Sih75Sav.js";import"./help-icon-41R-Z9N1.js";import"./tooltip-1V7clEnw.js";import"./index-CUZDtIZe.js";import"./icon-BP4BO6-k.js";import"./objectWithoutPropertiesLoose-CAYKN5F1.js";import"./inheritsLoose-DR8r8Ogv.js";import"./index-CEuq6vkz.js";import"./disabled-context-rmpd7YJS.js";import"./types-Dx2TtIG9.js";import"./extends-CF3RwP-h.js";import"./assertThisInitialized-B9jnkVVz.js";import"./memoize-one.esm-CcMeOnPo.js";import"./types-BmbYqTX_.js";import"./text-B3-TSWok.js";import"./actions-Tr0wIZve.js";import"./button-CzvLc2io.js";import"./spinner-AWUe4xwQ.js";import"./badge-CLQ59MDF.js";import"./select.input-D0UkAPd9.js";import"./index.es-D2piFfFj.js";import"./redux-tRgGMjwY.js";import"./objectSpread2-DW4nTBoq.js";import"./tiny-invariant-DqLgxztJ.js";import"./pagination-CUucuCPT.js";import"./input-DTXbDJaL.js";import"./input-group-BaRSJAEN.js";import"./input-group-addon-D68iUKV2.js";import"./number-input-CKbeoN5B.js";import"./check-box-wCvXxtCz.js";import"./slider-CBE03NwD.js";import"./index-BI4_Bp97.js";import"./popover-9ZnEm5Hy.js";const le=o=>o.reduce(({preferredUnits:r,storageUnits:n},{unitKey:l,preferredUnit:e,storageUnit:h})=>(r[l]=e,n[l]=h,{preferredUnits:r,storageUnits:n}),{preferredUnits:{},storageUnits:{}}),se=({headers:o,rows:r,selectedUnits:n,storageUnits:l,onChangeUnit:e,convertBackToStorageUnit:h,enableCosmeticRounding:b,enableDisplayRounding:T})=>{const u=o?o.map(c=>({...c,cells:c.cells.map(p=>{var a;if(p.type===P.AUTO_UNIT){const{testId:S,unitKey:g}=p;return{value:n[g],type:P.SELECT,searchable:!1,options:(a=C.getUnitsForQuantity(g))==null?void 0:a.map(U=>({label:C.label(U),value:U})),native:p.native,onChange:U=>e({unitKey:g,value:U.target.value}),testId:S}}return p})})):[],s=r?r.map((c,p)=>({...c,cells:c.cells.map((a,S)=>{if("autoUnit"in a&&(a!=null&&a.autoUnit)&&(typeof(a==null?void 0:a.value)=="string"||typeof(a==null?void 0:a.value)=="number")){const{unitKey:g,value:U,formatDisplayValue:I}=a,V=T&&"roundDisplayValue"in a?a==null?void 0:a.roundDisplayValue:null,m=n[g],y=l[g],t=m!==y,f=t?C.convertAndGetValue(U,m,y):a.value,w=I?I(f):f;return{...a,value:w,enableCosmeticRounding:b&&t,enableDisplayRounding:T,roundDisplayValue:V,onChange:D=>{const{value:x}=D.target,R=l[g],E=n[g],N=E!==R,H=h?R:E,K=N?C.convertAndGetValue(x,H,E):x;if("onChange"in a){const{onChange:B}=a,Z={...D,target:{...D.target,value:String(K),rowIndex:p,cellIndex:S,unit:H}};B(Z)}}}}return a})})):[];return{convertedHeaders:u,convertedRows:s}},X=({table:o,unitConfig:r,convertBackToStorageUnit:n=!0,enableCosmeticRounding:l=!0,enableDisplayRounding:e=!0})=>{const{rows:h,headers:b,...T}=o,{storageUnits:u,preferredUnits:s}=le(r),c=oe(s),[p,a]=v.useState(s),S=({unitKey:m,value:y})=>{a({...p,[m]:y});const t=r.find(f=>f.unitKey===m);t&&typeof t.onChange=="function"&&t.onChange({oldUnit:p[m],newUnit:y,unitKey:m})},g=m=>se({headers:b,rows:h,selectedUnits:m,storageUnits:u,onChangeUnit:S,convertBackToStorageUnit:n,enableCosmeticRounding:l,enableDisplayRounding:e}),U=g(p),[I,V]=v.useState(U);return v.useEffect(()=>{!ie.isEqual(s,c)&&(Object.keys(s).forEach(y=>{const t=c==null?void 0:c[y],f=s[y];t!==f&&S({unitKey:y,value:f})}),V(g(s)))},[r]),v.useEffect(()=>{V(g(p))},[o,p]),i.jsx(re,{table:{...T,headers:I.convertedHeaders,rows:I.convertedRows}})};X.__docgenInfo={description:"",methods:[],displayName:"UnitTable",props:{table:{required:!0,tsType:{name:"IUnitTable"},description:""},unitConfig:{required:!0,tsType:{name:"Array",elements:[{name:"IUnitConfigItem"}],raw:"IUnitConfigItem[]"},description:""},convertBackToStorageUnit:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},enableCosmeticRounding:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}},enableDisplayRounding:{required:!1,tsType:{name:"boolean"},description:"",defaultValue:{value:"true",computed:!1}}},composes:["Omit"]};const yt={title:"Basic/UnitTable",args:{}},ue=!0,ce=!0,de=!0,pe=!1,A="ft",Y="C",ge=3,me=(o,r,n)=>{const l=[r,r,n],e=[...Array(o)].map((h,b)=>{const T=b,u=b+1.25,s=4+b*.25;return[String(T),String(u),String(s)]});return[l,...e]},he=me(ge,A,Y),be=({reduxTable:o,value:r,unit:n,rowIndex:l,cellIndex:e})=>J(o,h=>{const b=h[0][e],T=(u,s)=>s===0;return h.forEach((u,s)=>{if(T(u,s)){u[e]=n;return}if(s===l+1){u[e]=String(r);return}const c=C.convertAndGetValue(u[e],n,b);u[e]=String(c)}),h}),ye=({reduxTable:o,value:r,rowIndex:n,cellIndex:l})=>J(o,e=>{e[n+1][l]=r}),L=()=>{var m,y;const[o,r]=v.useState(A),[n,l]=v.useState(Y),[e,h]=v.useState(he),[b,T]=v.useState(ue),[u,s]=v.useState(de),[c,p]=v.useState(ce),[a,S]=v.useState(pe),[g,U]=v.useState(A),I=t=>{const{rowIndex:f,cellIndex:w,value:D,unit:x}=t.target,R=a?be({reduxTable:e,value:D,unit:x,rowIndex:f,cellIndex:w}):ye({reduxTable:e,value:D,rowIndex:f,cellIndex:w});h(R)},V=e.reduce((t,f,w)=>(w===0?t.headers=[{cells:[{value:"From"},{value:"To"},{value:"Temperature"}]},{cells:[{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"temperature",testId:"table-unit-selector-3"}]}]:t.rows=t.rows.concat({cells:f.map((D,x)=>{const R=w===1&&x===1;return{value:D,type:R?"Text":"NumberInput",unitKey:x===2?"temperature":"length",onChange:I,roundDisplayValue:w===3&&x===2?B=>C.roundByMagnitude(B,2):null,formatDisplayValue:R?B=>`T* ${B}`:null,autoUnit:!0,testId:`testId_${w}_${x}`}})}),t),{testId:"testId",headers:[],rows:[]});return i.jsxs(ee,{columns:"1fr 1fr",gap:!0,children:[i.jsxs(F,{heading:i.jsx(_,{children:"Settings"}),children:[i.jsx(k,{label:"Convert back to storage unit:",labelLeft:!0,labelWidth:200,children:i.jsx(W,{checked:b,onChange:t=>T(t.target.checked)})}),i.jsx(k,{label:"Enable display rounding:",labelLeft:!0,labelWidth:200,children:i.jsx(W,{checked:u,onChange:t=>s(t.target.checked)})}),i.jsx(k,{label:"Enable cosmetic rounding:",labelLeft:!0,labelWidth:200,children:i.jsx(W,{checked:c,onChange:t=>p(t.target.checked)})}),i.jsx(k,{label:"Convert whole table:",labelLeft:!0,labelWidth:200,children:i.jsx(W,{checked:a,onChange:t=>S(t.target.checked)})})]}),i.jsxs(F,{heading:i.jsx(_,{children:"Unit template"}),children:[i.jsx(k,{label:"Length unit:",labelLeft:!0,labelWidth:120,children:i.jsx(G,{options:(m=C.getUnitsForQuantity("length"))==null?void 0:m.map(t=>({value:t,label:C.label(t)})),value:{value:o},onChange:t=>r(t.target.value),width:"100px"})}),i.jsx(k,{label:"Temperature unit:",labelLeft:!0,labelWidth:120,children:i.jsx(G,{options:(y=C.getUnitsForQuantity("temperature"))==null?void 0:y.map(t=>({value:t,label:C.label(t)})),value:{value:n},onChange:t=>l(t.target.value),width:"100px"})})]}),i.jsx(F,{heading:i.jsx(_,{children:"Storage State (Redux)"}),children:i.jsx("pre",{children:i.jsx("code",{children:JSON.stringify(e,null,2)})})}),i.jsxs(F,{heading:i.jsx(_,{children:"UnitTable"}),children:[i.jsx(X,{table:V,unitConfig:[{unitKey:"length",storageUnit:e[0][0],preferredUnit:o,onChange:({newUnit:t})=>U(t)},{unitKey:"temperature",storageUnit:e[0][2],preferredUnit:n}],convertBackToStorageUnit:b,enableDisplayRounding:u,enableCosmeticRounding:c}),i.jsx(te,{height:20}),i.jsx(k,{label:"Displayed length unit:",labelLeft:!0,labelWidth:150,children:g})]})]})};L.play=async({canvasElement:o,step:r})=>{const n=O(o),l=O(o.ownerDocument.body);await r("Can enter decimal values",async()=>{const e=n.getByTestId("testId_2_1");await d.clear(e),await d.type(e,"123.123456789"),await d.click(o),await j(n.getByDisplayValue("123.12")).toBeInTheDocument()}),await r("Can enter comma decimals (converts to dot)",async()=>{const e=n.getByTestId("testId_2_1");await d.clear(e),await d.type(e,"123,456"),await d.click(o),await j(n.getByDisplayValue("123.46")).toBeInTheDocument()}),await r("Can enter small numbers",async()=>{const e=n.getByTestId("testId_2_1");await d.clear(e),await d.type(e,"0.0000000023"),await d.click(o),await j(e).toHaveDisplayValue("0.00")}),await r("Can enter large numbers",async()=>{const e=n.getByTestId("testId_2_1");await d.clear(e),await d.type(e,"999999999999"),await d.click(o),await j(n.getByDisplayValue("999999999999.00")).toBeInTheDocument()}),await r("Shows validation error for non-numeric input",async()=>{const e=n.getByTestId("testId_2_1");await d.clear(e),await d.type(e,"123x45s6"),await d.click(o),await j(n.getByDisplayValue("123x45s6")).toBeInTheDocument(),await ne.mouseOver(e),await ae(()=>{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,$,Q,M,z;L.parameters={...L.parameters,docs:{...(q=L.parameters)==null?void 0:q.docs,source:{originalSource:`() => {
|
|
2
|
+
const [preferredLengthUnit, setPreferredLengthUnit] = useState(initialLengthUnit);
|
|
3
|
+
const [preferredTemperatureUnit, setPreferredTemperatureUnit] = useState(initialTemperatureUnit);
|
|
4
|
+
const [reduxTable, setReduxTable] = useState<TTable>(initialTable);
|
|
5
|
+
const [convertBackToStorageUnit, setConvertBackToStorageUnit] = useState(initialConvertBackToStorageUnit);
|
|
6
|
+
const [enableDisplayRounding, setEnableDisplayRounding] = useState(initialEnableDisplayRounding);
|
|
7
|
+
const [enableCosmeticRounding, setEnableCosmeticRounding] = useState(initialEnableCosmeticRounding);
|
|
8
|
+
const [convertWholeTable, setConvertWholeTable] = useState(initialConvertWholeTable);
|
|
9
|
+
const [displayedLengthUnit, setDisplayedLengthUnit] = useState(initialLengthUnit);
|
|
10
|
+
|
|
11
|
+
/*********************************************************************************************************************
|
|
12
|
+
Cell onChange handler
|
|
13
|
+
*********************************************************************************************************************/
|
|
14
|
+
const onUpdateCell = (evt: IUnitTableOnChangeEvent) => {
|
|
15
|
+
const {
|
|
16
|
+
rowIndex,
|
|
17
|
+
cellIndex,
|
|
18
|
+
value,
|
|
19
|
+
unit
|
|
20
|
+
} = evt.target;
|
|
21
|
+
const nextTable = convertWholeTable ? convertStorageTable({
|
|
22
|
+
reduxTable,
|
|
23
|
+
value,
|
|
24
|
+
unit,
|
|
25
|
+
rowIndex,
|
|
26
|
+
cellIndex
|
|
27
|
+
}) : updateCell({
|
|
28
|
+
reduxTable,
|
|
29
|
+
value,
|
|
30
|
+
rowIndex,
|
|
31
|
+
cellIndex
|
|
32
|
+
});
|
|
33
|
+
setReduxTable(nextTable);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/*********************************************************************************************************************
|
|
37
|
+
Construct table view data (same as old Table component, with a new props)
|
|
38
|
+
*********************************************************************************************************************/
|
|
39
|
+
const tableViewData = reduxTable.reduce((acc, row, rowIndex) => {
|
|
40
|
+
if (rowIndex === 0) {
|
|
41
|
+
acc.headers = [{
|
|
42
|
+
cells: [{
|
|
43
|
+
value: 'From'
|
|
44
|
+
}, {
|
|
45
|
+
value: 'To'
|
|
46
|
+
}, {
|
|
47
|
+
value: 'Temperature'
|
|
48
|
+
}]
|
|
49
|
+
}, {
|
|
50
|
+
cells: [{
|
|
51
|
+
type: 'AutoUnit',
|
|
52
|
+
unitKey: 'length'
|
|
53
|
+
}, {
|
|
54
|
+
type: 'AutoUnit',
|
|
55
|
+
unitKey: 'length'
|
|
56
|
+
}, {
|
|
57
|
+
type: 'AutoUnit',
|
|
58
|
+
unitKey: 'temperature',
|
|
59
|
+
testId: 'table-unit-selector-3'
|
|
60
|
+
}]
|
|
61
|
+
}];
|
|
62
|
+
} else {
|
|
63
|
+
acc.rows = acc.rows.concat({
|
|
64
|
+
cells: row.map((cell, cellIndex) => {
|
|
65
|
+
const specialCell = rowIndex === 1 && cellIndex === 1;
|
|
66
|
+
const type = specialCell ? 'Text' : 'NumberInput';
|
|
67
|
+
const formatDisplayValue = specialCell ? (value: number | string) => \`T* \${value}\` : null;
|
|
68
|
+
const customDisplayRounding = rowIndex === 3 && cellIndex === 2 ? (value: TStringNumberNull) => roundByMagnitude(value, 2) : null;
|
|
69
|
+
const value = cell;
|
|
70
|
+
return {
|
|
71
|
+
value,
|
|
72
|
+
type,
|
|
73
|
+
unitKey: cellIndex === 2 ? 'temperature' : 'length',
|
|
74
|
+
onChange: onUpdateCell,
|
|
75
|
+
roundDisplayValue: customDisplayRounding,
|
|
76
|
+
// optionally customize the display rounding of specific columns/cells
|
|
77
|
+
formatDisplayValue,
|
|
78
|
+
// optionally extend/customize the display formatting of specific columns/cells
|
|
79
|
+
autoUnit: true,
|
|
80
|
+
testId: \`testId_\${rowIndex}_\${cellIndex}\`
|
|
81
|
+
};
|
|
82
|
+
})
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return acc;
|
|
86
|
+
}, {
|
|
87
|
+
testId: 'testId',
|
|
88
|
+
headers: ([] as any[]),
|
|
89
|
+
rows: ([] as IUnitTableRow[])
|
|
90
|
+
});
|
|
91
|
+
return <Grid columns="1fr 1fr" gap>
|
|
92
|
+
<Card heading={<Heading>Settings</Heading>}>
|
|
93
|
+
<Field label="Convert back to storage unit:" labelLeft labelWidth={200}>
|
|
94
|
+
<Toggle checked={convertBackToStorageUnit} onChange={evt => setConvertBackToStorageUnit(evt.target.checked)} />
|
|
95
|
+
</Field>
|
|
96
|
+
<Field label="Enable display rounding:" labelLeft labelWidth={200}>
|
|
97
|
+
<Toggle checked={enableDisplayRounding} onChange={evt => setEnableDisplayRounding(evt.target.checked)} />
|
|
98
|
+
</Field>
|
|
99
|
+
<Field label="Enable cosmetic rounding:" labelLeft labelWidth={200}>
|
|
100
|
+
<Toggle checked={enableCosmeticRounding} onChange={evt => setEnableCosmeticRounding(evt.target.checked)} />
|
|
101
|
+
</Field>
|
|
102
|
+
<Field label="Convert whole table:" labelLeft labelWidth={200}>
|
|
103
|
+
<Toggle checked={convertWholeTable} onChange={evt => setConvertWholeTable(evt.target.checked)} />
|
|
104
|
+
</Field>
|
|
105
|
+
</Card>
|
|
106
|
+
<Card heading={<Heading>Unit template</Heading>}>
|
|
107
|
+
<Field label="Length unit:" labelLeft labelWidth={120}>
|
|
108
|
+
<Select options={getUnitsForQuantity('length')?.map(unit => ({
|
|
109
|
+
value: unit,
|
|
110
|
+
label: label(unit)
|
|
111
|
+
}))} value={{
|
|
112
|
+
value: preferredLengthUnit
|
|
113
|
+
}} onChange={evt => setPreferredLengthUnit(evt.target.value)} width="100px" />
|
|
114
|
+
</Field>
|
|
115
|
+
<Field label="Temperature unit:" labelLeft labelWidth={120}>
|
|
116
|
+
<Select options={getUnitsForQuantity('temperature')?.map(unit => ({
|
|
117
|
+
value: unit,
|
|
118
|
+
label: label(unit)
|
|
119
|
+
}))} value={{
|
|
120
|
+
value: preferredTemperatureUnit
|
|
121
|
+
}} onChange={evt => setPreferredTemperatureUnit(evt.target.value)} width="100px" />
|
|
122
|
+
</Field>
|
|
123
|
+
</Card>
|
|
124
|
+
<Card heading={<Heading>Storage State (Redux)</Heading>}>
|
|
125
|
+
<pre>
|
|
126
|
+
<code>{JSON.stringify(reduxTable, null, 2)}</code>
|
|
127
|
+
</pre>
|
|
128
|
+
</Card>
|
|
129
|
+
<Card heading={<Heading>UnitTable</Heading>}>
|
|
130
|
+
<UnitTable table={tableViewData}
|
|
131
|
+
//New props:
|
|
132
|
+
unitConfig={[{
|
|
133
|
+
unitKey: 'length',
|
|
134
|
+
storageUnit: reduxTable[0][0],
|
|
135
|
+
preferredUnit: preferredLengthUnit,
|
|
136
|
+
onChange: ({
|
|
137
|
+
newUnit
|
|
138
|
+
}) => setDisplayedLengthUnit(newUnit)
|
|
139
|
+
}, {
|
|
140
|
+
unitKey: 'temperature',
|
|
141
|
+
storageUnit: reduxTable[0][2],
|
|
142
|
+
preferredUnit: preferredTemperatureUnit
|
|
143
|
+
}]}
|
|
144
|
+
//Most tables should just use the default values here (true):
|
|
145
|
+
convertBackToStorageUnit={convertBackToStorageUnit} enableDisplayRounding={enableDisplayRounding} enableCosmeticRounding={enableCosmeticRounding} />
|
|
146
|
+
<Spacer height={20} />
|
|
147
|
+
<Field label="Displayed length unit:" labelLeft labelWidth={150}>
|
|
148
|
+
{displayedLengthUnit}
|
|
149
|
+
</Field>
|
|
150
|
+
</Card>
|
|
151
|
+
</Grid>;
|
|
152
|
+
}`,...(Q=($=L.parameters)==null?void 0:$.docs)==null?void 0:Q.source},description:{story:"Story",...(z=(M=L.parameters)==null?void 0:M.docs)==null?void 0:z.description}}};const ft=["UnitTableExample"];export{L as UnitTableExample,ft as __namedExportsOrder,yt as default};
|