@universal-tennis/ui-shared 0.1.29 → 0.1.30
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/stories/organisms/Tables/DrawCardTable.js +23 -3
- package/dist/stories/organisms/Tables/DrawCardTable.js.map +1 -1
- package/dist/stories/utlis/useScreenSize.d.ts +4 -0
- package/dist/stories/utlis/useScreenSize.js +28 -0
- package/dist/stories/utlis/useScreenSize.js.map +1 -0
- package/package.json +1 -1
- package/src/stories/organisms/Tables/DrawCardTable.tsx +44 -4
- package/src/stories/utlis/useScreenSize.js +28 -0
|
@@ -13,7 +13,10 @@ import React from 'react';
|
|
|
13
13
|
import Box from '@mui/material/Box';
|
|
14
14
|
import { styled } from '@mui/material/styles';
|
|
15
15
|
import Grid from '@mui/material/Grid';
|
|
16
|
+
import { useWindowSize } from 'stories/utlis/useScreenSize';
|
|
16
17
|
import Typography from '../../atoms/Typography/Typography';
|
|
18
|
+
const MOBILE_SCREEN_SIZE = 768;
|
|
19
|
+
const MOBILE_TABLET_SCREEN_SIZE = 1200;
|
|
17
20
|
const StyledHeader = styled(Grid)({
|
|
18
21
|
alignItems: 'center',
|
|
19
22
|
justifyContent: 'center',
|
|
@@ -24,19 +27,36 @@ const GridSections = styled(Box)({
|
|
|
24
27
|
alignItems: 'center',
|
|
25
28
|
padding: '8px'
|
|
26
29
|
});
|
|
30
|
+
const TableMobileSection = styled(Grid) `
|
|
31
|
+
flex-direction: column;
|
|
32
|
+
`;
|
|
27
33
|
export default function DrawCardTable(_a) {
|
|
28
34
|
var { headerRows, tableRows } = _a, props = __rest(_a, ["headerRows", "tableRows"]);
|
|
35
|
+
const size = useWindowSize();
|
|
36
|
+
const isMobileAndTablet = (size === null || size === void 0 ? void 0 : size.width) && (size === null || size === void 0 ? void 0 : size.width) < MOBILE_TABLET_SCREEN_SIZE;
|
|
29
37
|
const totalColumns = Math.floor(12 / headerRows.length);
|
|
30
38
|
const formatTableRows = tableRows.map((row, index) => {
|
|
31
39
|
if (index > 2)
|
|
32
40
|
return; // Table can only support 3 columns
|
|
33
|
-
const
|
|
41
|
+
const rowSectionsHeight = `${100 / tableRows[index].length}%`;
|
|
34
42
|
const sectionAmount = tableRows[index].length;
|
|
35
|
-
return (React.createElement(Grid, { key: index, xs: totalColumns }, [...Array(sectionAmount)].map((section, idx) => (React.createElement(GridSections, { key: idx, sx: { height:
|
|
43
|
+
return (React.createElement(Grid, { key: index, xs: totalColumns }, [...Array(sectionAmount)].map((section, idx) => (React.createElement(GridSections, { key: idx, sx: { height: rowSectionsHeight } }, row[idx])))));
|
|
36
44
|
});
|
|
37
|
-
|
|
45
|
+
const formatMobileRows = tableRows.map((row, index) => {
|
|
46
|
+
if (index > 2)
|
|
47
|
+
return; // Table can only support 3 columns
|
|
48
|
+
const headerRow = headerRows[index];
|
|
49
|
+
const sectionAmount = tableRows[index].length;
|
|
50
|
+
return (React.createElement(React.Fragment, null,
|
|
51
|
+
React.createElement(Grid, { container: true, sx: { height: '60px' } },
|
|
52
|
+
React.createElement(StyledHeader, null,
|
|
53
|
+
React.createElement(Typography, { category: "secondary", size: "small-medium-cap" }, headerRow.name))),
|
|
54
|
+
React.createElement(TableMobileSection, { container: true }, [...Array(sectionAmount)].map((section, idx) => (React.createElement(GridSections, { key: idx }, row[idx]))))));
|
|
55
|
+
});
|
|
56
|
+
const formatDesktopRows = (React.createElement(React.Fragment, null,
|
|
38
57
|
React.createElement(Grid, { container: true, sx: { height: '60px' } }, headerRows.map((row) => (React.createElement(StyledHeader, { key: row.name, xs: totalColumns },
|
|
39
58
|
React.createElement(Typography, { category: "secondary", size: "small-medium-cap" }, row.name))))),
|
|
40
59
|
React.createElement(Grid, { container: true }, formatTableRows)));
|
|
60
|
+
return (React.createElement(Box, Object.assign({}, props, { sx: { flexGrow: 1 }, "aria-label": "draw table" }), isMobileAndTablet ? formatMobileRows : formatDesktopRows));
|
|
41
61
|
}
|
|
42
62
|
//# sourceMappingURL=DrawCardTable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DrawCardTable.js","sourceRoot":"","sources":["../../../../src/stories/organisms/Tables/DrawCardTable.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,MAAM,mBAAmB,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,IAAI,MAAM,oBAAoB,CAAC;AACtC,OAAO,UAAU,MAAM,mCAAmC,CAAC;AAG3D,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAChC,UAAU,EAAE,QAAQ;IACpB,cAAc,EAAE,QAAQ;IACxB,OAAO,EAAE,MAAM;CAChB,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC/B,OAAO,EAAE,MAAM;IACf,UAAU,EAAE,QAAQ;IACpB,OAAO,EAAE,KAAK;CACf,CAAC,CAAC;AAEH,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EAIjB;QAJiB,EACpC,UAAU,EACV,SAAS,OAEU,EADhB,KAAK,cAH4B,2BAIrC,CADS;IAER,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IAExD,MAAM,eAAe,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QACnD,IAAI,KAAK,GAAG,CAAC;YAAE,OAAO,CAAC,oCAAoC;QAC3D,MAAM,
|
|
1
|
+
{"version":3,"file":"DrawCardTable.js","sourceRoot":"","sources":["../../../../src/stories/organisms/Tables/DrawCardTable.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,MAAM,mBAAmB,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAs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tB;QACI,oBAAC,IAAI,IAAC,SAAS,QAAC,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,IACjC,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CACrB,oBAAC,YAAY,IAAC,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,EAAE,EAAE,YAAY;YACzC,oBAAC,UAAU,IAAC,QAAQ,EAAC,WAAW,EAAC,IAAI,EAAC,kBAAkB,IAAE,GAAG,CAAC,IAAI,CAAc,CACrE,CAClB,CAAC,CACC;QACP,oBAAC,IAAI,IAAC,SAAS,UACV,eAAe,CACb,CACR,CACN,CAAC;IAEF,OAAO,CACH,oBAAC,GAAG,oBAAK,KAAK,IAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,gBAAa,YAAY,KACvD,iBAAiB,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,iBAAiB,CACvD,CACT,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
// Hook
|
|
3
|
+
export function useWindowSize() {
|
|
4
|
+
// Initialize state with undefined width/height so server and client renders match
|
|
5
|
+
// Learn more here: https://joshwcomeau.com/react/the-perils-of-rehydration/
|
|
6
|
+
const [windowSize, setWindowSize] = useState({
|
|
7
|
+
width: undefined,
|
|
8
|
+
height: undefined,
|
|
9
|
+
});
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
// Handler to call on window resize
|
|
12
|
+
function handleResize() {
|
|
13
|
+
// Set window width/height to state
|
|
14
|
+
setWindowSize({
|
|
15
|
+
width: window.innerWidth,
|
|
16
|
+
height: window.innerHeight,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
// Add event listener
|
|
20
|
+
window.addEventListener("resize", handleResize);
|
|
21
|
+
// Call handler right away so state gets updated with initial window size
|
|
22
|
+
handleResize();
|
|
23
|
+
// Remove event listener on cleanup
|
|
24
|
+
return () => window.removeEventListener("resize", handleResize);
|
|
25
|
+
}, []); // Empty array ensures that effect is only run on mount
|
|
26
|
+
return windowSize;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=useScreenSize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useScreenSize.js","sourceRoot":"","sources":["../../../src/stories/utlis/useScreenSize.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO;AACP,MAAM,UAAU,aAAa;IAC3B,kFAAkF;IAClF,4EAA4E;IAC5E,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC;QAC3C,KAAK,EAAE,SAAS;QAChB,MAAM,EAAE,SAAS;KAClB,CAAC,CAAC;IACH,SAAS,CAAC,GAAG,EAAE;QACb,mCAAmC;QACnC,SAAS,YAAY;YACnB,mCAAmC;YACnC,aAAa,CAAC;gBACZ,KAAK,EAAE,MAAM,CAAC,UAAU;gBACxB,MAAM,EAAE,MAAM,CAAC,WAAW;aAC3B,CAAC,CAAC;QACL,CAAC;QACD,qBAAqB;QACrB,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;QAChD,yEAAyE;QACzE,YAAY,EAAE,CAAC;QACf,mCAAmC;QACnC,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAClE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,uDAAuD;IAC/D,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,9 +2,13 @@ import React from 'react';
|
|
|
2
2
|
import Box from '@mui/material/Box';
|
|
3
3
|
import { styled } from '@mui/material/styles';
|
|
4
4
|
import Grid from '@mui/material/Grid';
|
|
5
|
+
import { useWindowSize } from 'stories/utlis/useScreenSize';
|
|
5
6
|
import Typography from '../../atoms/Typography/Typography';
|
|
6
7
|
import { DrawCardTableProps } from './sharedTypes';
|
|
7
8
|
|
|
9
|
+
const MOBILE_SCREEN_SIZE = 768;
|
|
10
|
+
const MOBILE_TABLET_SCREEN_SIZE = 1200;
|
|
11
|
+
|
|
8
12
|
const StyledHeader = styled(Grid)({
|
|
9
13
|
alignItems: 'center',
|
|
10
14
|
justifyContent: 'center',
|
|
@@ -17,22 +21,29 @@ const GridSections = styled(Box)({
|
|
|
17
21
|
padding: '8px'
|
|
18
22
|
});
|
|
19
23
|
|
|
24
|
+
const TableMobileSection = styled(Grid)`
|
|
25
|
+
flex-direction: column;
|
|
26
|
+
`;
|
|
27
|
+
|
|
20
28
|
export default function DrawCardTable({
|
|
21
29
|
headerRows,
|
|
22
30
|
tableRows,
|
|
23
31
|
...props
|
|
24
32
|
}: DrawCardTableProps) {
|
|
33
|
+
const size = useWindowSize();
|
|
34
|
+
const isMobileAndTablet = size?.width && size?.width < MOBILE_TABLET_SCREEN_SIZE;
|
|
35
|
+
|
|
25
36
|
const totalColumns = Math.floor(12 / headerRows.length);
|
|
26
37
|
|
|
27
38
|
const formatTableRows = tableRows.map((row, index) => {
|
|
28
39
|
if (index > 2) return; // Table can only support 3 columns
|
|
29
|
-
const
|
|
40
|
+
const rowSectionsHeight = `${100 / tableRows[index].length}%`;
|
|
30
41
|
const sectionAmount = tableRows[index].length;
|
|
31
42
|
|
|
32
43
|
return (
|
|
33
44
|
<Grid key={index} xs={totalColumns}>
|
|
34
45
|
{[...Array(sectionAmount)].map((section, idx) => (
|
|
35
|
-
<GridSections key={idx} sx={{ height:
|
|
46
|
+
<GridSections key={idx} sx={{ height: rowSectionsHeight }}>
|
|
36
47
|
{row[idx]}
|
|
37
48
|
</GridSections>
|
|
38
49
|
))}
|
|
@@ -40,8 +51,31 @@ export default function DrawCardTable({
|
|
|
40
51
|
);
|
|
41
52
|
});
|
|
42
53
|
|
|
43
|
-
|
|
44
|
-
|
|
54
|
+
const formatMobileRows = tableRows.map((row, index) => {
|
|
55
|
+
if (index > 2) return; // Table can only support 3 columns
|
|
56
|
+
|
|
57
|
+
const headerRow = headerRows[index];
|
|
58
|
+
const sectionAmount = tableRows[index].length;
|
|
59
|
+
return (
|
|
60
|
+
<>
|
|
61
|
+
<Grid container sx={{ height: '60px' }}>
|
|
62
|
+
<StyledHeader>
|
|
63
|
+
<Typography category="secondary" size="small-medium-cap">{headerRow.name}</Typography>
|
|
64
|
+
</StyledHeader>
|
|
65
|
+
</Grid>
|
|
66
|
+
<TableMobileSection container>
|
|
67
|
+
{[...Array(sectionAmount)].map((section, idx) => (
|
|
68
|
+
<GridSections key={idx}>
|
|
69
|
+
{row[idx]}
|
|
70
|
+
</GridSections>
|
|
71
|
+
))}
|
|
72
|
+
</TableMobileSection>
|
|
73
|
+
</>
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const formatDesktopRows = (
|
|
78
|
+
<>
|
|
45
79
|
<Grid container sx={{ height: '60px' }}>
|
|
46
80
|
{headerRows.map((row) => (
|
|
47
81
|
<StyledHeader key={row.name} xs={totalColumns}>
|
|
@@ -52,6 +86,12 @@ export default function DrawCardTable({
|
|
|
52
86
|
<Grid container>
|
|
53
87
|
{formatTableRows}
|
|
54
88
|
</Grid>
|
|
89
|
+
</>
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<Box {...props} sx={{ flexGrow: 1 }} aria-label="draw table">
|
|
94
|
+
{isMobileAndTablet ? formatMobileRows : formatDesktopRows}
|
|
55
95
|
</Box>
|
|
56
96
|
);
|
|
57
97
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
// Hook
|
|
4
|
+
export function useWindowSize() {
|
|
5
|
+
// Initialize state with undefined width/height so server and client renders match
|
|
6
|
+
// Learn more here: https://joshwcomeau.com/react/the-perils-of-rehydration/
|
|
7
|
+
const [windowSize, setWindowSize] = useState({
|
|
8
|
+
width: undefined,
|
|
9
|
+
height: undefined,
|
|
10
|
+
});
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
// Handler to call on window resize
|
|
13
|
+
function handleResize() {
|
|
14
|
+
// Set window width/height to state
|
|
15
|
+
setWindowSize({
|
|
16
|
+
width: window.innerWidth,
|
|
17
|
+
height: window.innerHeight,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
// Add event listener
|
|
21
|
+
window.addEventListener("resize", handleResize);
|
|
22
|
+
// Call handler right away so state gets updated with initial window size
|
|
23
|
+
handleResize();
|
|
24
|
+
// Remove event listener on cleanup
|
|
25
|
+
return () => window.removeEventListener("resize", handleResize);
|
|
26
|
+
}, []); // Empty array ensures that effect is only run on mount
|
|
27
|
+
return windowSize;
|
|
28
|
+
}
|