1 | 'use client';
|
2 |
|
3 | import { usePreviousProps } from '@mui/utils';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export function useBadge(parameters) {
|
15 | const {
|
16 | badgeContent: badgeContentProp,
|
17 | invisible: invisibleProp = false,
|
18 | max: maxProp = 99,
|
19 | showZero = false
|
20 | } = parameters;
|
21 | const prevProps = usePreviousProps({
|
22 | badgeContent: badgeContentProp,
|
23 | max: maxProp
|
24 | });
|
25 | let invisible = invisibleProp;
|
26 | if (invisibleProp === false && badgeContentProp === 0 && !showZero) {
|
27 | invisible = true;
|
28 | }
|
29 | const {
|
30 | badgeContent,
|
31 | max = maxProp
|
32 | } = invisible ? prevProps : parameters;
|
33 | const displayValue = badgeContent && Number(badgeContent) > max ? `${max}+` : badgeContent;
|
34 | return {
|
35 | badgeContent,
|
36 | invisible,
|
37 | max,
|
38 | displayValue
|
39 | };
|
40 | } |
\ | No newline at end of file |