1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import clsx from 'clsx';
|
6 | import composeClasses from '@mui/utils/composeClasses';
|
7 | import Typography, { typographyClasses } from "../Typography/index.js";
|
8 | import { styled } from "../zero-styled/index.js";
|
9 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
10 | import cardHeaderClasses, { getCardHeaderUtilityClass } from "./cardHeaderClasses.js";
|
11 | import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
12 | const useUtilityClasses = ownerState => {
|
13 | const {
|
14 | classes
|
15 | } = ownerState;
|
16 | const slots = {
|
17 | root: ['root'],
|
18 | avatar: ['avatar'],
|
19 | action: ['action'],
|
20 | content: ['content'],
|
21 | title: ['title'],
|
22 | subheader: ['subheader']
|
23 | };
|
24 | return composeClasses(slots, getCardHeaderUtilityClass, classes);
|
25 | };
|
26 | const CardHeaderRoot = styled('div', {
|
27 | name: 'MuiCardHeader',
|
28 | slot: 'Root',
|
29 | overridesResolver: (props, styles) => ({
|
30 | [`& .${cardHeaderClasses.title}`]: styles.title,
|
31 | [`& .${cardHeaderClasses.subheader}`]: styles.subheader,
|
32 | ...styles.root
|
33 | })
|
34 | })({
|
35 | display: 'flex',
|
36 | alignItems: 'center',
|
37 | padding: 16
|
38 | });
|
39 | const CardHeaderAvatar = styled('div', {
|
40 | name: 'MuiCardHeader',
|
41 | slot: 'Avatar',
|
42 | overridesResolver: (props, styles) => styles.avatar
|
43 | })({
|
44 | display: 'flex',
|
45 | flex: '0 0 auto',
|
46 | marginRight: 16
|
47 | });
|
48 | const CardHeaderAction = styled('div', {
|
49 | name: 'MuiCardHeader',
|
50 | slot: 'Action',
|
51 | overridesResolver: (props, styles) => styles.action
|
52 | })({
|
53 | flex: '0 0 auto',
|
54 | alignSelf: 'flex-start',
|
55 | marginTop: -4,
|
56 | marginRight: -8,
|
57 | marginBottom: -4
|
58 | });
|
59 | const CardHeaderContent = styled('div', {
|
60 | name: 'MuiCardHeader',
|
61 | slot: 'Content',
|
62 | overridesResolver: (props, styles) => styles.content
|
63 | })({
|
64 | flex: '1 1 auto',
|
65 | [`.${typographyClasses.root}:where(& .${cardHeaderClasses.title})`]: {
|
66 | display: 'block'
|
67 | },
|
68 | [`.${typographyClasses.root}:where(& .${cardHeaderClasses.subheader})`]: {
|
69 | display: 'block'
|
70 | }
|
71 | });
|
72 | const CardHeader = React.forwardRef(function CardHeader(inProps, ref) {
|
73 | const props = useDefaultProps({
|
74 | props: inProps,
|
75 | name: 'MuiCardHeader'
|
76 | });
|
77 | const {
|
78 | action,
|
79 | avatar,
|
80 | className,
|
81 | component = 'div',
|
82 | disableTypography = false,
|
83 | subheader: subheaderProp,
|
84 | subheaderTypographyProps,
|
85 | title: titleProp,
|
86 | titleTypographyProps,
|
87 | ...other
|
88 | } = props;
|
89 | const ownerState = {
|
90 | ...props,
|
91 | component,
|
92 | disableTypography
|
93 | };
|
94 | const classes = useUtilityClasses(ownerState);
|
95 | let title = titleProp;
|
96 | if (title != null && title.type !== Typography && !disableTypography) {
|
97 | title = _jsx(Typography, {
|
98 | variant: avatar ? 'body2' : 'h5',
|
99 | className: classes.title,
|
100 | component: "span",
|
101 | ...titleTypographyProps,
|
102 | children: title
|
103 | });
|
104 | }
|
105 | let subheader = subheaderProp;
|
106 | if (subheader != null && subheader.type !== Typography && !disableTypography) {
|
107 | subheader = _jsx(Typography, {
|
108 | variant: avatar ? 'body2' : 'body1',
|
109 | className: classes.subheader,
|
110 | color: "textSecondary",
|
111 | component: "span",
|
112 | ...subheaderTypographyProps,
|
113 | children: subheader
|
114 | });
|
115 | }
|
116 | return _jsxs(CardHeaderRoot, {
|
117 | className: clsx(classes.root, className),
|
118 | as: component,
|
119 | ref: ref,
|
120 | ownerState: ownerState,
|
121 | ...other,
|
122 | children: [avatar && _jsx(CardHeaderAvatar, {
|
123 | className: classes.avatar,
|
124 | ownerState: ownerState,
|
125 | children: avatar
|
126 | }), _jsxs(CardHeaderContent, {
|
127 | className: classes.content,
|
128 | ownerState: ownerState,
|
129 | children: [title, subheader]
|
130 | }), action && _jsx(CardHeaderAction, {
|
131 | className: classes.action,
|
132 | ownerState: ownerState,
|
133 | children: action
|
134 | })]
|
135 | });
|
136 | });
|
137 | process.env.NODE_ENV !== "production" ? CardHeader.propTypes = {
|
138 |
|
139 |
|
140 |
|
141 |
|
142 | |
143 |
|
144 |
|
145 | action: PropTypes.node,
|
146 | |
147 |
|
148 |
|
149 | avatar: PropTypes.node,
|
150 | |
151 |
|
152 |
|
153 | children: PropTypes.node,
|
154 | |
155 |
|
156 |
|
157 | classes: PropTypes.object,
|
158 | |
159 |
|
160 |
|
161 | className: PropTypes.string,
|
162 | |
163 |
|
164 |
|
165 |
|
166 | component: PropTypes.elementType,
|
167 | |
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 | disableTypography: PropTypes.bool,
|
175 | |
176 |
|
177 |
|
178 | subheader: PropTypes.node,
|
179 | |
180 |
|
181 |
|
182 |
|
183 | subheaderTypographyProps: PropTypes.object,
|
184 | |
185 |
|
186 |
|
187 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
188 | |
189 |
|
190 |
|
191 | title: PropTypes.node,
|
192 | |
193 |
|
194 |
|
195 |
|
196 | titleTypographyProps: PropTypes.object
|
197 | } : void 0;
|
198 | export default CardHeader; |
\ | No newline at end of file |