forked from mui/mui-x
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderPnl.tsx
More file actions
52 lines (45 loc) · 1.2 KB
/
renderPnl.tsx
File metadata and controls
52 lines (45 loc) · 1.2 KB
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
import * as React from 'react';
import clsx from 'clsx';
import { styled } from '@mui/material/styles';
import type { GridRenderCellParams } from '@mui/x-data-grid-premium';
const Value = styled('div')(({ theme }) => ({
width: '100%',
fontVariantNumeric: 'tabular-nums',
'&.positive': {
color: (theme.vars || theme).palette.success.light,
...theme.applyStyles('light', {
color: (theme.vars || theme).palette.success.dark,
}),
},
'&.negative': {
color: (theme.vars || theme).palette.error.light,
...theme.applyStyles('light', {
color: (theme.vars || theme).palette.error.dark,
}),
},
}));
function pnlFormatter(value: number) {
return value < 0 ? `(${Math.abs(value).toLocaleString()})` : value.toLocaleString();
}
interface PnlProps {
value: number;
}
const Pnl = React.memo(function Pnl(props: PnlProps) {
const { value } = props;
return (
<Value
className={clsx({
positive: value > 0,
negative: value < 0,
})}
>
{pnlFormatter(value)}
</Value>
);
});
export function renderPnl(params: GridRenderCellParams<any, number, any>) {
if (params.value == null) {
return '';
}
return <Pnl value={params.value} />;
}