UNPKG

1.05 kBJavaScriptView Raw
1"use strict";
2'use client';
3
4Object.defineProperty(exports, "__esModule", {
5 value: true
6});
7exports.default = void 0;
8var _utils = require("@mui/utils");
9/**
10 *
11 * Demos:
12 *
13 * - [Badge](https://mui.com/base-ui/react-badge/#hook)
14 *
15 * API:
16 *
17 * - [useBadge API](https://mui.com/base-ui/react-badge/hooks-api/#use-badge)
18 */
19function useBadge(parameters) {
20 const {
21 badgeContent: badgeContentProp,
22 invisible: invisibleProp = false,
23 max: maxProp = 99,
24 showZero = false
25 } = parameters;
26 const prevProps = (0, _utils.usePreviousProps)({
27 badgeContent: badgeContentProp,
28 max: maxProp
29 });
30 let invisible = invisibleProp;
31 if (invisibleProp === false && badgeContentProp === 0 && !showZero) {
32 invisible = true;
33 }
34 const {
35 badgeContent,
36 max = maxProp
37 } = invisible ? prevProps : parameters;
38 const displayValue = badgeContent && Number(badgeContent) > max ? `${max}+` : badgeContent;
39 return {
40 badgeContent,
41 invisible,
42 max,
43 displayValue
44 };
45}
46var _default = exports.default = useBadge;
\No newline at end of file