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 | var _slots$root, _slots$badge;
|
35 | const {
|
36 | children,
|
37 | max: maxProp = 99,
|
38 | slotProps = {},
|
39 | slots = {},
|
40 | showZero = false
|
41 | } = props,
|
42 | other = _objectWithoutPropertiesLoose(props, _excluded);
|
43 | const {
|
44 | badgeContent,
|
45 | max,
|
46 | displayValue,
|
47 | invisible
|
48 | } = useBadge(_extends({}, props, {
|
49 | max: maxProp
|
50 | }));
|
51 | const ownerState = _extends({}, props, {
|
52 | badgeContent,
|
53 | invisible,
|
54 | max,
|
55 | showZero
|
56 | });
|
57 | const classes = useUtilityClasses(ownerState);
|
58 | const Root = (_slots$root = slots.root) != null ? _slots$root : 'span';
|
59 | const rootProps = useSlotProps({
|
60 | elementType: Root,
|
61 | externalSlotProps: slotProps.root,
|
62 | externalForwardedProps: other,
|
63 | additionalProps: {
|
64 | ref: forwardedRef
|
65 | },
|
66 | ownerState,
|
67 | className: classes.root
|
68 | });
|
69 | const BadgeComponent = (_slots$badge = slots.badge) != null ? _slots$badge : 'span';
|
70 | const badgeProps = useSlotProps({
|
71 | elementType: BadgeComponent,
|
72 | externalSlotProps: slotProps.badge,
|
73 | ownerState,
|
74 | className: classes.badge
|
75 | });
|
76 | return _jsxs(Root, _extends({}, rootProps, {
|
77 | children: [children, _jsx(BadgeComponent, _extends({}, badgeProps, {
|
78 | children: displayValue
|
79 | }))]
|
80 | }));
|
81 | });
|
82 | process.env.NODE_ENV !== "production" ? Badge.propTypes = {
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | |
88 |
|
89 |
|
90 | badgeContent: PropTypes.node,
|
91 | |
92 |
|
93 |
|
94 | children: PropTypes.node,
|
95 | |
96 |
|
97 |
|
98 |
|
99 | invisible: PropTypes.bool,
|
100 | |
101 |
|
102 |
|
103 |
|
104 | max: PropTypes.number,
|
105 | |
106 |
|
107 |
|
108 |
|
109 | showZero: PropTypes.bool,
|
110 | |
111 |
|
112 |
|
113 |
|
114 | slotProps: PropTypes.shape({
|
115 | badge: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
|
116 | root: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
|
117 | }),
|
118 | |
119 |
|
120 |
|
121 |
|
122 |
|
123 | slots: PropTypes.shape({
|
124 | badge: PropTypes.elementType,
|
125 | root: PropTypes.elementType
|
126 | })
|
127 | } : void 0;
|
128 | export default Badge; |
\ | No newline at end of file |