UNPKG

5.22 kBTypeScriptView Raw
1import * as React from 'react';
2import { SxProps } from '@mui/system';
3import { OverridableStringUnion, Simplify } from '@mui/types';
4import { SlotComponentProps } from '../utils/types';
5import { Theme } from '../styles';
6import { OverridableComponent, OverrideProps } from '../OverridableComponent';
7import { BadgeClasses } from './badgeClasses';
8
9export interface BadgePropsVariantOverrides {}
10export interface BadgePropsColorOverrides {}
11export interface BadgeRootSlotPropsOverrides {}
12export interface BadgeBadgeSlotPropsOverrides {}
13
14export type BadgeOwnerState = Simplify<
15 BadgeOwnProps & {
16 badgeContent: React.ReactNode;
17 invisible: boolean;
18 max: number;
19 displayValue: React.ReactNode;
20 showZero: boolean;
21 anchorOrigin: BadgeOrigin;
22 color: OverridableStringUnion<
23 'primary' | 'secondary' | 'default' | 'error' | 'info' | 'success' | 'warning',
24 BadgePropsColorOverrides
25 >;
26 overlap: 'rectangular' | 'circular';
27 variant: OverridableStringUnion<'standard' | 'dot', BadgePropsVariantOverrides>;
28 }
29>;
30
31export interface BadgeOrigin {
32 vertical?: 'top' | 'bottom';
33 horizontal?: 'left' | 'right';
34}
35
36export interface BadgeOwnProps {
37 /**
38 * The anchor of the badge.
39 * @default {
40 * vertical: 'top',
41 * horizontal: 'right',
42 * }
43 */
44 anchorOrigin?: BadgeOrigin;
45 /**
46 * The content rendered within the badge.
47 */
48 badgeContent?: React.ReactNode;
49 /**
50 * The badge will be added relative to this node.
51 */
52 children?: React.ReactNode;
53 /**
54 * Override or extend the styles applied to the component.
55 */
56 classes?: Partial<BadgeClasses>;
57 /**
58 * @ignore
59 */
60 className?: string;
61 /**
62 * The color of the component.
63 * It supports both default and custom theme colors, which can be added as shown in the
64 * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
65 * @default 'default'
66 */
67 color?: OverridableStringUnion<
68 'primary' | 'secondary' | 'default' | 'error' | 'info' | 'success' | 'warning',
69 BadgePropsColorOverrides
70 >;
71 /**
72 * The extra props for the slot components.
73 * You can override the existing props or add new ones.
74 *
75 * @deprecated use the `slotProps` prop instead. This prop will be removed in v7. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details.
76 *
77 * @default {}
78 */
79 componentsProps?: BadgeOwnProps['slotProps'];
80 /**
81 * The components used for each slot inside.
82 *
83 * @deprecated use the `slots` prop instead. This prop will be removed in v7. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details.
84 *
85 * @default {}
86 */
87 components?: {
88 Root?: React.ElementType;
89 Badge?: React.ElementType;
90 };
91 /**
92 * If `true`, the badge is invisible.
93 * @default false
94 */
95 invisible?: boolean;
96 /**
97 * Max count to show.
98 * @default 99
99 */
100 max?: number;
101 /**
102 * Wrapped shape the badge should overlap.
103 * @default 'rectangular'
104 */
105 overlap?: 'rectangular' | 'circular';
106 /**
107 * The props used for each slot inside the Badge.
108 * @default {}
109 */
110 slotProps?: {
111 root?: SlotComponentProps<'span', BadgeRootSlotPropsOverrides, BadgeOwnerState>;
112 badge?: SlotComponentProps<'span', BadgeBadgeSlotPropsOverrides, BadgeOwnerState>;
113 };
114 /**
115 * The components used for each slot inside the Badge.
116 * Either a string to use a HTML element or a component.
117 * @default {}
118 */
119 slots?: {
120 /**
121 * The component that renders the root.
122 * @default 'span'
123 */
124 root?: React.ElementType;
125 /**
126 * The component that renders the badge.
127 * @default 'span'
128 */
129 badge?: React.ElementType;
130 };
131 /**
132 * Controls whether the badge is hidden when `badgeContent` is zero.
133 * @default false
134 */
135 showZero?: boolean;
136 /**
137 * The system prop that allows defining system overrides as well as additional CSS styles.
138 */
139 sx?: SxProps<Theme>;
140 /**
141 * The variant to use.
142 * @default 'standard'
143 */
144 variant?: OverridableStringUnion<'standard' | 'dot', BadgePropsVariantOverrides>;
145}
146
147export interface BadgeTypeMap<
148 RootComponent extends React.ElementType = 'span',
149 AdditionalProps = {},
150> {
151 props: AdditionalProps & BadgeOwnProps;
152 defaultComponent: RootComponent;
153}
154
155type BadgeRootProps = NonNullable<BadgeTypeMap['props']['slotProps']>['root'];
156type BadgeBadgeProps = NonNullable<BadgeTypeMap['props']['slotProps']>['badge'];
157
158export declare const BadgeRoot: React.FC<BadgeRootProps>;
159export declare const BadgeMark: React.FC<BadgeBadgeProps>;
160
161/**
162 *
163 * Demos:
164 *
165 * - [Avatar](https://mui.com/material-ui/react-avatar/)
166 * - [Badge](https://mui.com/material-ui/react-badge/)
167 *
168 * API:
169 *
170 * - [Badge API](https://mui.com/material-ui/api/badge/)
171 */
172declare const Badge: OverridableComponent<BadgeTypeMap>;
173
174export type BadgeProps<
175 RootComponent extends React.ElementType = BadgeTypeMap['defaultComponent'],
176 AdditionalProps = {},
177> = OverrideProps<BadgeTypeMap<RootComponent, AdditionalProps>, RootComponent> & {
178 component?: React.ElementType;
179};
180
181export default Badge;