UNPKG

8.36 kBJavaScriptView Raw
1'use client';
2
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import composeClasses from '@mui/utils/composeClasses';
6import Typography, { typographyClasses } from "../Typography/index.js";
7import { styled } from "../zero-styled/index.js";
8import { useDefaultProps } from "../DefaultPropsProvider/index.js";
9import cardHeaderClasses, { getCardHeaderUtilityClass } from "./cardHeaderClasses.js";
10import useSlot from "../utils/useSlot.js";
11import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12const 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};
26const CardHeaderRoot = styled('div', {
27 name: 'MuiCardHeader',
28 slot: 'Root',
29 overridesResolver: (props, styles) => {
30 return [{
31 [`& .${cardHeaderClasses.title}`]: styles.title
32 }, {
33 [`& .${cardHeaderClasses.subheader}`]: styles.subheader
34 }, styles.root];
35 }
36})({
37 display: 'flex',
38 alignItems: 'center',
39 padding: 16
40});
41const CardHeaderAvatar = styled('div', {
42 name: 'MuiCardHeader',
43 slot: 'Avatar',
44 overridesResolver: (props, styles) => styles.avatar
45})({
46 display: 'flex',
47 flex: '0 0 auto',
48 marginRight: 16
49});
50const CardHeaderAction = styled('div', {
51 name: 'MuiCardHeader',
52 slot: 'Action',
53 overridesResolver: (props, styles) => styles.action
54})({
55 flex: '0 0 auto',
56 alignSelf: 'flex-start',
57 marginTop: -4,
58 marginRight: -8,
59 marginBottom: -4
60});
61const CardHeaderContent = styled('div', {
62 name: 'MuiCardHeader',
63 slot: 'Content',
64 overridesResolver: (props, styles) => styles.content
65})({
66 flex: '1 1 auto',
67 [`.${typographyClasses.root}:where(& .${cardHeaderClasses.title})`]: {
68 display: 'block'
69 },
70 [`.${typographyClasses.root}:where(& .${cardHeaderClasses.subheader})`]: {
71 display: 'block'
72 }
73});
74const CardHeader = /*#__PURE__*/React.forwardRef(function CardHeader(inProps, ref) {
75 const props = useDefaultProps({
76 props: inProps,
77 name: 'MuiCardHeader'
78 });
79 const {
80 action,
81 avatar,
82 component = 'div',
83 disableTypography = false,
84 subheader: subheaderProp,
85 subheaderTypographyProps,
86 title: titleProp,
87 titleTypographyProps,
88 slots = {},
89 slotProps = {},
90 ...other
91 } = props;
92 const ownerState = {
93 ...props,
94 component,
95 disableTypography
96 };
97 const classes = useUtilityClasses(ownerState);
98 const externalForwardedProps = {
99 slots,
100 slotProps: {
101 title: titleTypographyProps,
102 subheader: subheaderTypographyProps,
103 ...slotProps
104 }
105 };
106 let title = titleProp;
107 const [TitleSlot, titleSlotProps] = useSlot('title', {
108 className: classes.title,
109 elementType: Typography,
110 externalForwardedProps,
111 ownerState,
112 additionalProps: {
113 variant: avatar ? 'body2' : 'h5',
114 component: 'span'
115 }
116 });
117 if (title != null && title.type !== Typography && !disableTypography) {
118 title = /*#__PURE__*/_jsx(TitleSlot, {
119 ...titleSlotProps,
120 children: title
121 });
122 }
123 let subheader = subheaderProp;
124 const [SubheaderSlot, subheaderSlotProps] = useSlot('subheader', {
125 className: classes.subheader,
126 elementType: Typography,
127 externalForwardedProps,
128 ownerState,
129 additionalProps: {
130 variant: avatar ? 'body2' : 'body1',
131 color: 'textSecondary',
132 component: 'span'
133 }
134 });
135 if (subheader != null && subheader.type !== Typography && !disableTypography) {
136 subheader = /*#__PURE__*/_jsx(SubheaderSlot, {
137 ...subheaderSlotProps,
138 children: subheader
139 });
140 }
141 const [RootSlot, rootSlotProps] = useSlot('root', {
142 ref,
143 className: classes.root,
144 elementType: CardHeaderRoot,
145 externalForwardedProps: {
146 ...externalForwardedProps,
147 ...other,
148 component
149 },
150 ownerState
151 });
152 const [AvatarSlot, avatarSlotProps] = useSlot('avatar', {
153 className: classes.avatar,
154 elementType: CardHeaderAvatar,
155 externalForwardedProps,
156 ownerState
157 });
158 const [ContentSlot, contentSlotProps] = useSlot('content', {
159 className: classes.content,
160 elementType: CardHeaderContent,
161 externalForwardedProps,
162 ownerState
163 });
164 const [ActionSlot, actionSlotProps] = useSlot('action', {
165 className: classes.action,
166 elementType: CardHeaderAction,
167 externalForwardedProps,
168 ownerState
169 });
170 return /*#__PURE__*/_jsxs(RootSlot, {
171 ...rootSlotProps,
172 children: [avatar && /*#__PURE__*/_jsx(AvatarSlot, {
173 ...avatarSlotProps,
174 children: avatar
175 }), /*#__PURE__*/_jsxs(ContentSlot, {
176 ...contentSlotProps,
177 children: [title, subheader]
178 }), action && /*#__PURE__*/_jsx(ActionSlot, {
179 ...actionSlotProps,
180 children: action
181 })]
182 });
183});
184process.env.NODE_ENV !== "production" ? CardHeader.propTypes /* remove-proptypes */ = {
185 // ┌────────────────────────────── Warning ──────────────────────────────┐
186 // │ These PropTypes are generated from the TypeScript type definitions. │
187 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
188 // └─────────────────────────────────────────────────────────────────────┘
189 /**
190 * The action to display in the card header.
191 */
192 action: PropTypes.node,
193 /**
194 * The Avatar element to display.
195 */
196 avatar: PropTypes.node,
197 /**
198 * @ignore
199 */
200 children: PropTypes.node,
201 /**
202 * Override or extend the styles applied to the component.
203 */
204 classes: PropTypes.object,
205 /**
206 * The component used for the root node.
207 * Either a string to use a HTML element or a component.
208 */
209 component: PropTypes.elementType,
210 /**
211 * If `true`, `subheader` and `title` won't be wrapped by a Typography component.
212 * This can be useful to render an alternative Typography variant by wrapping
213 * the `title` text, and optional `subheader` text
214 * with the Typography component.
215 * @default false
216 */
217 disableTypography: PropTypes.bool,
218 /**
219 * The props used for each slot inside.
220 * @default {}
221 */
222 slotProps: PropTypes.shape({
223 action: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
224 avatar: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
225 content: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
226 root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
227 subheader: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
228 title: PropTypes.oneOfType([PropTypes.func, PropTypes.object])
229 }),
230 /**
231 * The components used for each slot inside.
232 * @default {}
233 */
234 slots: PropTypes.shape({
235 action: PropTypes.elementType,
236 avatar: PropTypes.elementType,
237 content: PropTypes.elementType,
238 root: PropTypes.elementType,
239 subheader: PropTypes.elementType,
240 title: PropTypes.elementType
241 }),
242 /**
243 * The content of the component.
244 */
245 subheader: PropTypes.node,
246 /**
247 * These props will be forwarded to the subheader
248 * (as long as disableTypography is not `true`).
249 * @deprecated Use `slotProps.subheader` instead. This prop will be removed in v7. See [Migrating from deprecated APIs](/material-ui/migration/migrating-from-deprecated-apis/) for more details.
250 */
251 subheaderTypographyProps: PropTypes.object,
252 /**
253 * The system prop that allows defining system overrides as well as additional CSS styles.
254 */
255 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
256 /**
257 * The content of the component.
258 */
259 title: PropTypes.node,
260 /**
261 * These props will be forwarded to the title
262 * (as long as disableTypography is not `true`).
263 * @deprecated Use `slotProps.title` instead. This prop will be removed in v7. See [Migrating from deprecated APIs](/material-ui/migration/migrating-from-deprecated-apis/) for more details.
264 */
265 titleTypographyProps: PropTypes.object
266} : void 0;
267export default CardHeader;
\No newline at end of file