paradiego
This commit is contained in:
41
node_modules/@mui/material/Badge/useBadge.js
generated
vendored
Normal file
41
node_modules/@mui/material/Badge/useBadge.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
'use client';
|
||||
|
||||
import { usePreviousProps } from '@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 = 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;
|
||||
Reference in New Issue
Block a user