1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | const _excluded = ["badgeContent", "children", "invisible", "max", "slotProps", "slots", "showZero"];
|
4 | import * as React from 'react';
|
5 | import PropTypes from 'prop-types';
|
6 | import composeClasses from '../composeClasses';
|
7 | import useBadge from '../useBadge';
|
8 | import { getBadgeUtilityClass } from './badgeClasses';
|
9 | import { useSlotProps } from '../utils';
|
10 | import { useClassNamesOverride } from '../utils/ClassNameConfigurator';
|
11 | import { jsx as _jsx } from "react/jsx-runtime";
|
12 | import { jsxs as _jsxs } from "react/jsx-runtime";
|
13 | const useUtilityClasses = ownerState => {
|
14 | const {
|
15 | invisible
|
16 | } = ownerState;
|
17 | const slots = {
|
18 | root: ['root'],
|
19 | badge: ['badge', invisible && 'invisible']
|
20 | };
|
21 | return composeClasses(slots, useClassNamesOverride(getBadgeUtilityClass));
|
22 | };
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | const Badge = React.forwardRef(function Badge(props, forwardedRef) {
|
34 | const {
|
35 | children,
|
36 | max: maxProp = 99,
|
37 | slotProps = {},
|
38 | slots = {},
|
39 | showZero = false
|
40 | } = props,
|
41 | other = _objectWithoutPropertiesLoose(props, _excluded);
|
42 | const {
|
43 | badgeContent,
|
44 | max,
|
45 | displayValue,
|
46 | invisible
|
47 | } = useBadge(_extends({}, props, {
|
48 | max: maxProp
|
49 | }));
|
50 | const ownerState = _extends({}, props, {
|
51 | badgeContent,
|
52 | invisible,
|
53 | max,
|
54 | showZero
|
55 | });
|
56 | const classes = useUtilityClasses(ownerState);
|
57 | const Root = slots.root ?? 'span';
|
58 | const rootProps = useSlotProps({
|
59 | elementType: Root,
|
60 | externalSlotProps: slotProps.root,
|
61 | externalForwardedProps: other,
|
62 | additionalProps: {
|
63 | ref: forwardedRef
|
64 | },
|
65 | ownerState,
|
66 | className: classes.root
|
67 | });
|
68 | const BadgeComponent = slots.badge ?? 'span';
|
69 | const badgeProps = useSlotProps({
|
70 | elementType: BadgeComponent,
|
71 | externalSlotProps: slotProps.badge,
|
72 | ownerState,
|
73 | className: classes.badge
|
74 | });
|
75 | return _jsxs(Root, _extends({}, rootProps, {
|
76 | children: [children, _jsx(BadgeComponent, _extends({}, badgeProps, {
|
77 | children: displayValue
|
78 | }))]
|
79 | }));
|
80 | });
|
81 | process.env.NODE_ENV !== "production" ? Badge.propTypes = {
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | |
87 |
|
88 |
|
89 | badgeContent: PropTypes.node,
|
90 | |
91 |
|
92 |
|
93 | children: PropTypes.node,
|
94 | |
95 |
|
96 |
|
97 |
|
98 | invisible: PropTypes.bool,
|
99 | |
100 |
|
101 |
|
102 |
|
103 | max: PropTypes.number,
|
104 | |
105 |
|
106 |
|
107 |
|
108 | showZero: PropTypes.bool,
|
109 | |
110 |
|
111 |
|
112 |
|
113 | slotProps: PropTypes.shape({
|
114 | badge: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
115 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
116 | }),
|
117 | |
118 |
|
119 |
|
120 |
|
121 |
|
122 | slots: PropTypes.shape({
|
123 | badge: PropTypes.elementType,
|
124 | root: PropTypes.elementType
|
125 | })
|
126 | } : void 0;
|
127 | export default Badge; |
\ | No newline at end of file |