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