-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
GridRowCount.tsx
83 lines (70 loc) · 2.56 KB
/
GridRowCount.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { unstable_composeClasses as composeClasses } from '@mui/utils';
import { styled, SxProps, Theme } from '@mui/material/styles';
import { useGridApiContext } from '../hooks/utils/useGridApiContext';
import { getDataGridUtilityClass } from '../constants/gridClasses';
import { useGridRootProps } from '../hooks/utils/useGridRootProps';
import { DataGridProcessedProps } from '../models/props/DataGridProps';
interface RowCountProps {
rowCount: number;
visibleRowCount: number;
}
type GridRowCountProps = React.HTMLAttributes<HTMLDivElement> &
RowCountProps & {
sx?: SxProps<Theme>;
};
type OwnerState = { classes: DataGridProcessedProps['classes'] };
const useUtilityClasses = (ownerState: OwnerState) => {
const { classes } = ownerState;
const slots = {
root: ['rowCount'],
};
return composeClasses(slots, getDataGridUtilityClass, classes);
};
const GridRowCountRoot = styled('div', {
name: 'MuiDataGrid',
slot: 'RowCount',
overridesResolver: (props, styles) => styles.rowCount,
})(({ theme }) => ({
alignItems: 'center',
display: 'flex',
margin: theme.spacing(0, 2),
}));
const GridRowCount = React.forwardRef<HTMLDivElement, GridRowCountProps>(function GridRowCount(
props,
ref,
) {
const { className, rowCount, visibleRowCount, ...other } = props;
const apiRef = useGridApiContext();
const rootProps = useGridRootProps();
const ownerState = { classes: rootProps.classes };
const classes = useUtilityClasses(ownerState);
if (rowCount === 0) {
return null;
}
const text =
visibleRowCount < rowCount
? apiRef.current.getLocaleText('footerTotalVisibleRows')(visibleRowCount, rowCount)
: rowCount.toLocaleString();
return (
<GridRowCountRoot ref={ref} className={clsx(classes.root, className)} {...other}>
{apiRef.current.getLocaleText('footerTotalRows')} {text}
</GridRowCountRoot>
);
});
GridRowCount.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
rowCount: PropTypes.number.isRequired,
sx: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])),
PropTypes.func,
PropTypes.object,
]),
visibleRowCount: PropTypes.number.isRequired,
} as any;
export { GridRowCount };