@oliasoft-open-source/react-ui-library 4.6.4 → 4.6.5
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.js +13 -4
- package/dist/index.js.map +1 -1
- package/dist/storybook/assets/{Color-6VNJS4EI-H6GX9JuX.js → Color-6VNJS4EI-6QyiStBx.js} +1 -1
- package/dist/storybook/assets/{DocsRenderer-NNNQARDV-61WZ2ztU.js → DocsRenderer-NNNQARDV-2upuKe-y.js} +1 -1
- package/dist/storybook/assets/{WithTooltip-V3YHNWJZ-6RntR6-_.js → WithTooltip-V3YHNWJZ-sasadf5B.js} +1 -1
- package/dist/storybook/assets/{buttons-and-links-UD3PzaIj.js → buttons-and-links-5qDA5c0M.js} +1 -1
- package/dist/storybook/assets/{chunk-HLWAVYOI-xPY5mnsO.js → chunk-HLWAVYOI-2WzL7lNK.js} +1 -1
- package/dist/storybook/assets/{color-jPK0xr4E.js → color-oYWpjfqe.js} +1 -1
- package/dist/storybook/assets/{formatter-SWP5E3XI-zYzBeB0L.js → formatter-SWP5E3XI-NZzQKsls.js} +1 -1
- package/dist/storybook/assets/{iframe-ru6_7CpQ.js → iframe-GxJzSQlX.js} +2 -2
- package/dist/storybook/assets/{index-vSKvx_iy.js → index-NMzKYhDm.js} +5 -5
- package/dist/storybook/assets/{input-validation-QodABrdN.js → input-validation-0WooNvL8.js} +1 -1
- package/dist/storybook/assets/{inputs-B4UxTeyT.js → inputs-ZnQpWnaa.js} +1 -1
- package/dist/storybook/assets/{layout-forms-nWVwatRI.js → layout-forms-MHOKZcG9.js} +1 -1
- package/dist/storybook/assets/{layout-general-m9TinthY.js → layout-general-X0JNgpR0.js} +1 -1
- package/dist/storybook/assets/{padding-and-spacing-ee-3aL0o.js → padding-and-spacing-hLcWI3R8.js} +1 -1
- package/dist/storybook/assets/{preview-_J8ZmGOb.js → preview-TQVrQPI_.js} +1 -1
- package/dist/storybook/assets/{preview-oostgEjZ.js → preview-r7HHhykG.js} +2 -2
- package/dist/storybook/assets/{syntaxhighlighter-B5GMVT5T-Ebq1wDzX.js → syntaxhighlighter-B5GMVT5T-gFlfxFDl.js} +1 -1
- package/dist/storybook/assets/unit-table.stories-ZHWCQMuq.js +142 -0
- package/dist/storybook/iframe.html +1 -1
- package/dist/storybook/project.json +1 -1
- package/package.json +1 -1
- package/dist/storybook/assets/unit-table.stories-lZ4MjpDy.js +0 -108
|
@@ -0,0 +1,142 @@
|
|
|
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-FZX0Z7IB.js";import{H as E}from"./heading-jZsIIJF0.js";import{S as H}from"./select-DZdWUrCW.js";import{T as F}from"./toggle-M_66MP8X.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-033R9jUC.js";import"./index-cCpkwrS5.js";import"./styled-components.browser.esm-qIipjd6c.js";import"./tslib.es6-OIsz3r9a.js";import"./index-VW3EWkuE.js";import"./label-uCFEME1p.js";import"./common-types-U65vzrrz.js";import"./help-icon-SKky6KLV.js";import"./tooltip-HEHiU__l.js";import"./index-miLrID2P.js";import"./icon-8EQazuuW.js";import"./objectWithoutPropertiesLoose-9Q1jwsKS.js";import"./inheritsLoose-8sb_A2v4.js";import"./index-4QtD-hFu.js";import"./disabled-context-urNQThQz.js";import"./types-5uVBABF4.js";import"./assertThisInitialized-4q6YPdh3.js";import"./memoize-one.esm-hqe5SRxC.js";import"./types-VB5zD18b.js";import"./text-6KQ6ntOV.js";import"./actions-mOcj9IlF.js";import"./button-shH4xakS.js";import"./spinner-R8Il4aRe.js";import"./badge-23Ty_zBt.js";import"./select.input-zP5tW20f.js";import"./index.es-VXFRDikp.js";import"./redux-F5dueAP3.js";import"./objectSpread2-93s0nBry.js";import"./tiny-invariant-R4kOKlvx.js";import"./pagination-tnyyuMkB.js";import"./input-2BhbKV-j.js";import"./input-group-R8LoqKRn.js";import"./input-group-addon-BHVsW9mL.js";import"./number-input-CMhEMmUd.js";import"./check-box-2gxosI3y.js";import"./slider-MN9iDCsS.js";import"./index-ugi_ZH6T.js";import"./popover-cad2llTa.js";const 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,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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"generatedAt":
|
|
1
|
+
{"generatedAt":1718222257851,"hasCustomBabel":false,"hasCustomWebpack":false,"hasStaticDirs":false,"hasStorybookEslint":true,"refCount":0,"packageManager":{"type":"yarn","version":"1.22.19"},"features":{"storyStoreV7":true},"preview":{"usesGlobals":false},"framework":{"name":"@storybook/react-vite","options":{}},"builder":"@storybook/builder-vite","renderer":"@storybook/react","storybookVersion":"7.6.19","storybookVersionSpecifier":"^7.6.19","language":"typescript","storybookPackages":{"@storybook/addon-essentials":{"version":"7.6.19"},"@storybook/addon-links":{"version":"7.6.19"},"@storybook/addons":{"version":"7.6.19"},"@storybook/react":{"version":"7.6.19"},"@storybook/react-vite":{"version":"7.6.19"},"eslint-plugin-storybook":{"version":"0.6.15"},"storybook":{"version":"7.5.3"}},"addons":{"@storybook/addon-actions":{"version":"7.6.19"},"@storybook/addon-docs":{"version":"7.6.19"},"storybook-dark-mode":{"version":"3.0.3"}}}
|
package/package.json
CHANGED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import{j as s}from"./jsx-runtime-FsUICBgo.js";import{r as h}from"./index-RfLt4OUa.js";import{f as Q}from"./immer.esm-bD7SSJ7T.js";import{d as v}from"./index-qZmQ7nA9.js";import{G as J}from"./grid-u1mZpaML.js";import{C as D}from"./card-0r8RRVk-.js";import{F as $}from"./field-FZX0Z7IB.js";import{H as I}from"./heading-jZsIIJF0.js";import{S as W}from"./select-DZdWUrCW.js";import{l as X}from"./lodash-Bmg8FrMx.js";import{u as Y}from"./use-previous-VKMmnaK7.js";import{T as Z,C as K}from"./table-033R9jUC.js";import"./index-cCpkwrS5.js";import"./styled-components.browser.esm-qIipjd6c.js";import"./tslib.es6-OIsz3r9a.js";import"./index-VW3EWkuE.js";import"./label-uCFEME1p.js";import"./common-types-U65vzrrz.js";import"./help-icon-SKky6KLV.js";import"./tooltip-HEHiU__l.js";import"./index-miLrID2P.js";import"./icon-8EQazuuW.js";import"./objectWithoutPropertiesLoose-9Q1jwsKS.js";import"./inheritsLoose-8sb_A2v4.js";import"./index-4QtD-hFu.js";import"./disabled-context-urNQThQz.js";import"./types-5uVBABF4.js";import"./assertThisInitialized-4q6YPdh3.js";import"./memoize-one.esm-hqe5SRxC.js";import"./types-VB5zD18b.js";import"./text-6KQ6ntOV.js";import"./actions-mOcj9IlF.js";import"./button-shH4xakS.js";import"./spinner-R8Il4aRe.js";import"./badge-23Ty_zBt.js";import"./select.input-zP5tW20f.js";import"./index.es-VXFRDikp.js";import"./redux-F5dueAP3.js";import"./objectSpread2-93s0nBry.js";import"./tiny-invariant-R4kOKlvx.js";import"./pagination-tnyyuMkB.js";import"./input-2BhbKV-j.js";import"./input-group-R8LoqKRn.js";import"./input-group-addon-BHVsW9mL.js";import"./number-input-CMhEMmUd.js";import"./check-box-2gxosI3y.js";import"./slider-MN9iDCsS.js";import"./index-ugi_ZH6T.js";import"./popover-cad2llTa.js";const ee=o=>o.reduce(({preferredUnits:n,storageUnits:t},{unitKey:i,preferredUnit:m,storageUnit:g})=>(n[i]=m,t[i]=g,{preferredUnits:n,storageUnits:t}),{preferredUnits:{},storageUnits:{}}),te=({headers:o,rows:n,selectedUnits:t,storageUnits:i,onChangeUnit:m,convertBackToStorageUnit:g,enableCosmeticRounding:a,enableDisplayRounding:l})=>{const u=o?o.map(c=>({...c,cells:c.cells.map(r=>{if(r.type===K.AUTO_UNIT){const{testId:e,unitKey:y}=r;return{value:t[y],type:K.SELECT,options:v.getUnitsForQuantity(y),native:!0,onChange:p=>m({unitKey:y,value:p.target.value}),testId:e}}return r})})):[],d=n?n.map((c,r)=>({...c,cells:c.cells.map((e,y)=>{if("autoUnit"in e&&(e!=null&&e.autoUnit)&&(typeof(e==null?void 0:e.value)=="string"||typeof(e==null?void 0:e.value)=="number")){const{unitKey:p,value:U,formatDisplayValue:f}=e,T=l&&"roundDisplayValue"in e?e==null?void 0:e.roundDisplayValue:null,b=t[p],C=i[p],j=b!==C,A=j?v.convertAndGetValue(U,b,C):e.value,q=v.isScientificStringNum(U),N=a&&(j||!q)?v.roundToPrecision(A,14):A,k=f?f(N):N;return{...e,value:k,enableCosmeticRounding:a,enableDisplayRounding:l,roundDisplayValue:T,onChange:w=>{const{value:_}=w.target,S=i[p],V=t[p],O=V!==S?v.convertAndGetValue(_,S,V):_,z=g?S:V;if("onChange"in e){const{onChange:L}=e,M={...w,target:{...w.target,value:String(O),rowIndex:r,cellIndex:y,unit:z}};L(M)}}}}return e})})):[];return{convertedHeaders:u,convertedRows:d}},R=({table:o,unitConfig:n,convertBackToStorageUnit:t=!0,enableCosmeticRounding:i=!0,enableDisplayRounding:m=!0})=>{const{rows:g,headers:a,...l}=o,{storageUnits:u,preferredUnits:d}=ee(n),c=Y(d),[r,e]=h.useState(d),y=({unitKey:b,value:C})=>e({...r,[b]:C}),p=b=>te({headers:a,rows:g,selectedUnits:b,storageUnits:u,onChangeUnit:y,convertBackToStorageUnit:t,enableCosmeticRounding:i,enableDisplayRounding:m}),U=p(r),[f,T]=h.useState(U);return h.useEffect(()=>{!X.isEqual(d,c)&&(e(d),T(p(d)))},[n]),h.useEffect(()=>{T(p(r))},[o,r]),s.jsx(Z,{table:{...l,headers:f.convertedHeaders,rows:f.convertedRows}})};try{R.displayName="UnitTable",R.__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 rt={title:"Basic/UnitTable",args:{}},ne=!0,ae=!0,oe=!0,G="m",re=3,ie=(o,n)=>{const t=[n,n,n],i=[...Array(Number(o))].map((m,g)=>{const a=g,l=g+1.25,u=l-a;return[String(a),String(l),String(u)]});return[t].concat(i)},se=ie(re,G),le=({reduxTable:o,value:n,rowIndex:t,cellIndex:i})=>Q(o,m=>{m[t+1][i]=n}),x=()=>{const[o,n]=h.useState(G),[t,i]=h.useState(se),m=a=>{const{rowIndex:l,cellIndex:u,value:d,unit:c}=a.target,r=le({reduxTable:t,value:d,rowIndex:l,cellIndex:u});i(r)},g=t.reduce((a,l,u)=>(u===0?a.headers=[{cells:[{value:"From"},{value:"To"},{value:"Delta"}]},{cells:[{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"length"},{type:"AutoUnit",unitKey:"length",testId:"table-unit-selector-3"}]}]:a.rows=a.rows.concat({cells:l.map((d,c)=>{const r=u===1&&c===1;return{value:d,type:r?"Text":"NumberInput",unitKey:"length",onChange:m,roundDisplayValue:u===3&&c===2?f=>v.roundByMagnitude(f,2):null,formatDisplayValue:r?f=>`T* ${f}`:null,autoUnit:!0}})}),a),{headers:[],rows:[]});return s.jsxs(J,{columns:"1fr 1fr",gap:!0,children:[s.jsx(D,{heading:s.jsx(I,{children:"Global View Settings"}),children:s.jsx($,{label:"Active Unit Template",children:s.jsx(W,{options:v.getUnitsForQuantity("length"),value:{value:o},onChange:a=>n(a.target.value),width:"100px"})})}),s.jsx(D,{heading:s.jsx(I,{children:"UnitTable"}),children:s.jsx(R,{table:g,unitConfig:[{unitKey:"length",storageUnit:t[0][0],preferredUnit:o}],convertBackToStorageUnit:ne,enableDisplayRounding:oe,enableCosmeticRounding:ae})}),s.jsx(D,{heading:s.jsx(I,{children:"Storage State (Redux)"}),children:s.jsx("pre",{children:s.jsx("code",{children:JSON.stringify(t,null,2)})})})]})};var E,H,F,P,B;x.parameters={...x.parameters,docs:{...(E=x.parameters)==null?void 0:E.docs,source:{originalSource:`() => {
|
|
2
|
-
const [preferredUnit, setPreferredUnit] = useState(initialUnit);
|
|
3
|
-
const [reduxTable, setReduxTable] = useState(initialTable);
|
|
4
|
-
|
|
5
|
-
/*********************************************************************************************************************
|
|
6
|
-
Cell onChange handler
|
|
7
|
-
*********************************************************************************************************************/
|
|
8
|
-
const onUpdateCell = (evt: IUnitTableOnChangeEvent) => {
|
|
9
|
-
const {
|
|
10
|
-
rowIndex,
|
|
11
|
-
cellIndex,
|
|
12
|
-
value,
|
|
13
|
-
unit
|
|
14
|
-
} = evt.target;
|
|
15
|
-
const nextTable = convertWholeTable ? convertStorageTable({
|
|
16
|
-
reduxTable,
|
|
17
|
-
value,
|
|
18
|
-
unit,
|
|
19
|
-
rowIndex,
|
|
20
|
-
cellIndex
|
|
21
|
-
}) : updateCell({
|
|
22
|
-
reduxTable,
|
|
23
|
-
value,
|
|
24
|
-
rowIndex,
|
|
25
|
-
cellIndex
|
|
26
|
-
});
|
|
27
|
-
setReduxTable(nextTable);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/*********************************************************************************************************************
|
|
31
|
-
Construct table view data (same as old Table component, with a new props)
|
|
32
|
-
*********************************************************************************************************************/
|
|
33
|
-
const tableViewData = reduxTable.reduce((acc, row, rowIndex) => {
|
|
34
|
-
if (rowIndex === 0) {
|
|
35
|
-
acc.headers = [{
|
|
36
|
-
cells: [{
|
|
37
|
-
value: 'From'
|
|
38
|
-
}, {
|
|
39
|
-
value: 'To'
|
|
40
|
-
}, {
|
|
41
|
-
value: 'Delta'
|
|
42
|
-
}]
|
|
43
|
-
}, {
|
|
44
|
-
cells: [{
|
|
45
|
-
type: 'AutoUnit',
|
|
46
|
-
unitKey: 'length'
|
|
47
|
-
}, {
|
|
48
|
-
type: 'AutoUnit',
|
|
49
|
-
unitKey: 'length'
|
|
50
|
-
}, {
|
|
51
|
-
type: 'AutoUnit',
|
|
52
|
-
unitKey: 'length',
|
|
53
|
-
testId: 'table-unit-selector-3'
|
|
54
|
-
}]
|
|
55
|
-
}];
|
|
56
|
-
} else {
|
|
57
|
-
acc.rows = acc.rows.concat({
|
|
58
|
-
cells: row.map((cell, cellIndex) => {
|
|
59
|
-
const specialCell = rowIndex === 1 && cellIndex === 1;
|
|
60
|
-
const type = specialCell ? 'Text' : 'NumberInput';
|
|
61
|
-
const formatDisplayValue = specialCell ? (value: number | string) => \`T* \${value}\` : null;
|
|
62
|
-
const customDisplayRounding = rowIndex === 3 && cellIndex === 2 ? (value: TStringNumberNull) => roundByMagnitude(value, 2) : null;
|
|
63
|
-
const value = cell;
|
|
64
|
-
return {
|
|
65
|
-
value,
|
|
66
|
-
type,
|
|
67
|
-
unitKey: 'length',
|
|
68
|
-
onChange: onUpdateCell,
|
|
69
|
-
roundDisplayValue: customDisplayRounding,
|
|
70
|
-
// optionally customize the display rounding of specific columns/cells
|
|
71
|
-
formatDisplayValue,
|
|
72
|
-
// optionally extend/customize the display formatting of specific columns/cells
|
|
73
|
-
autoUnit: true
|
|
74
|
-
};
|
|
75
|
-
})
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
return acc;
|
|
79
|
-
}, {
|
|
80
|
-
headers: ([] as any[]),
|
|
81
|
-
rows: ([] as IUnitTableRow[])
|
|
82
|
-
});
|
|
83
|
-
return <Grid columns="1fr 1fr" gap>
|
|
84
|
-
<Card heading={<Heading>Global View Settings</Heading>}>
|
|
85
|
-
<Field label="Active Unit Template">
|
|
86
|
-
<Select options={getUnitsForQuantity('length')} value={{
|
|
87
|
-
value: preferredUnit
|
|
88
|
-
}} onChange={evt => setPreferredUnit(evt.target.value)} width="100px" />
|
|
89
|
-
</Field>
|
|
90
|
-
</Card>
|
|
91
|
-
<Card heading={<Heading>UnitTable</Heading>}>
|
|
92
|
-
<UnitTable table={tableViewData}
|
|
93
|
-
//New props:
|
|
94
|
-
unitConfig={[{
|
|
95
|
-
unitKey: 'length',
|
|
96
|
-
storageUnit: reduxTable[0][0],
|
|
97
|
-
preferredUnit
|
|
98
|
-
}]}
|
|
99
|
-
//Most tables should just use the default values here (true):
|
|
100
|
-
convertBackToStorageUnit={convertBackToStorageUnit} enableDisplayRounding={enableDisplayRounding} enableCosmeticRounding={enableCosmeticRounding} />
|
|
101
|
-
</Card>
|
|
102
|
-
<Card heading={<Heading>Storage State (Redux)</Heading>}>
|
|
103
|
-
<pre>
|
|
104
|
-
<code>{JSON.stringify(reduxTable, null, 2)}</code>
|
|
105
|
-
</pre>
|
|
106
|
-
</Card>
|
|
107
|
-
</Grid>;
|
|
108
|
-
}`,...(F=(H=x.parameters)==null?void 0:H.docs)==null?void 0:F.source},description:{story:"Story",...(B=(P=x.parameters)==null?void 0:P.docs)==null?void 0:B.description}}};const it=["UnitTablePrototype"];export{x as UnitTablePrototype,it as __namedExportsOrder,rt as default};
|