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