pre-installations and preparations
This commit is contained in:
1 parent
3e5a0329cb
commit
201d621ac3
6977 files changed
+742826
No files matched your search
+2
@@ -0,0 +1,2 @@
|
||||
export { useBadge } from './useBadge';
|
||||
export * from './useBadge.types';
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
'use client';
|
||||
|
||||
export { useBadge } from './useBadge';
|
||||
export * from './useBadge.types';
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"sideEffects": false,
|
||||
"module": "./index.js",
|
||||
"main": "../node/useBadge/index.js",
|
||||
"types": "./index.d.ts"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
import { UseBadgeParameters, UseBadgeReturnValue } from './useBadge.types';
|
||||
/**
|
||||
*
|
||||
* Demos:
|
||||
*
|
||||
* - [Badge](https://mui.com/base-ui/react-badge/#hook)
|
||||
*
|
||||
* API:
|
||||
*
|
||||
* - [useBadge API](https://mui.com/base-ui/react-badge/hooks-api/#use-badge)
|
||||
*/
|
||||
export declare function useBadge(parameters: UseBadgeParameters): UseBadgeReturnValue;
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
'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)
|
||||
*/
|
||||
export 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
|
||||
};
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/// <reference types="react" />
|
||||
export interface UseBadgeParameters {
|
||||
/**
|
||||
* The content rendered within the badge.
|
||||
*/
|
||||
badgeContent?: React.ReactNode;
|
||||
/**
|
||||
* If `true`, the badge is invisible.
|
||||
* @default false
|
||||
*/
|
||||
invisible?: boolean;
|
||||
/**
|
||||
* Max count to show.
|
||||
* @default 99
|
||||
*/
|
||||
max?: number;
|
||||
/**
|
||||
* Controls whether the badge is hidden when `badgeContent` is zero.
|
||||
* @default false
|
||||
*/
|
||||
showZero?: boolean;
|
||||
}
|
||||
export interface UseBadgeReturnValue {
|
||||
/**
|
||||
* Defines the content that's displayed inside the badge.
|
||||
*/
|
||||
badgeContent: React.ReactNode;
|
||||
/**
|
||||
* If `true`, the component will not be visible.
|
||||
*/
|
||||
invisible: boolean;
|
||||
/**
|
||||
* Maximum number to be displayed in the badge.
|
||||
*/
|
||||
max: number;
|
||||
/**
|
||||
* Value to be displayed in the badge. If `badgeContent` is greater than `max`, it will return `max+`.
|
||||
*/
|
||||
displayValue: React.ReactNode;
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Reference in new issue
Block a user