31 lines
No EOL
765 B
JavaScript
31 lines
No EOL
765 B
JavaScript
'use client';
|
|
|
|
import usePreviousProps from '@mui/utils/usePreviousProps';
|
|
function useBadge(parameters) {
|
|
const {
|
|
badgeContent: badgeContentProp,
|
|
invisible: invisibleProp = false,
|
|
max: maxProp = 99,
|
|
showZero = false
|
|
} = parameters;
|
|
const prevProps = usePreviousProps({
|
|
badgeContent: badgeContentProp,
|
|
max: maxProp
|
|
});
|
|
let invisible = invisibleProp;
|
|
if (invisibleProp === false && badgeContentProp === 0 && !showZero) {
|
|
invisible = true;
|
|
}
|
|
const {
|
|
badgeContent,
|
|
max = maxProp
|
|
} = invisible ? prevProps : parameters;
|
|
const displayValue = badgeContent && Number(badgeContent) > max ? `${max}+` : badgeContent;
|
|
return {
|
|
badgeContent,
|
|
invisible,
|
|
max,
|
|
displayValue
|
|
};
|
|
}
|
|
export default useBadge; |