@mui/material
Version:
Material UI is an open-source React component library that implements Google's Material Design. It's comprehensive and can be used in production out of the box.
46 lines (45 loc) • 1.05 kB
JavaScript
'use client';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _utils = require("@mui/utils");
/**
*
* Demos:
*
* - [Badge](https://mui.com/base-ui/react-badge/#hook)
*
* API:
*
* - [useBadge API](https://mui.com/base-ui/react-badge/hooks-api/#use-badge)
*/
function useBadge(parameters) {
const {
badgeContent: badgeContentProp,
invisible: invisibleProp = false,
max: maxProp = 99,
showZero = false
} = parameters;
const prevProps = (0, _utils.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
};
}
var _default = exports.default = useBadge;
;