UNPKG

6.08 kBJavaScriptView Raw
1'use client';
2
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import composeClasses from '@mui/utils/composeClasses';
7import Typography, { typographyClasses } from "../Typography/index.js";
8import { styled } from "../zero-styled/index.js";
9import { useDefaultProps } from "../DefaultPropsProvider/index.js";
10import cardHeaderClasses, { getCardHeaderUtilityClass } from "./cardHeaderClasses.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 [`& .${cardHeaderClasses.title}`]: styles.title,
31 [`& .${cardHeaderClasses.subheader}`]: styles.subheader,
32 ...styles.root
33 })
34})({
35 display: 'flex',
36 alignItems: 'center',
37 padding: 16
38});
39const 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});
48const 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});
59const 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});
72const CardHeader = /*#__PURE__*/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 = /*#__PURE__*/_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 = /*#__PURE__*/_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 /*#__PURE__*/_jsxs(CardHeaderRoot, {
117 className: clsx(classes.root, className),
118 as: component,
119 ref: ref,
120 ownerState: ownerState,
121 ...other,
122 children: [avatar && /*#__PURE__*/_jsx(CardHeaderAvatar, {
123 className: classes.avatar,
124 ownerState: ownerState,
125 children: avatar
126 }), /*#__PURE__*/_jsxs(CardHeaderContent, {
127 className: classes.content,
128 ownerState: ownerState,
129 children: [title, subheader]
130 }), action && /*#__PURE__*/_jsx(CardHeaderAction, {
131 className: classes.action,
132 ownerState: ownerState,
133 children: action
134 })]
135 });
136});
137process.env.NODE_ENV !== "production" ? CardHeader.propTypes /* remove-proptypes */ = {
138 // ┌────────────────────────────── Warning ──────────────────────────────┐
139 // │ These PropTypes are generated from the TypeScript type definitions. │
140 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
141 // └─────────────────────────────────────────────────────────────────────┘
142 /**
143 * The action to display in the card header.
144 */
145 action: PropTypes.node,
146 /**
147 * The Avatar element to display.
148 */
149 avatar: PropTypes.node,
150 /**
151 * @ignore
152 */
153 children: PropTypes.node,
154 /**
155 * Override or extend the styles applied to the component.
156 */
157 classes: PropTypes.object,
158 /**
159 * @ignore
160 */
161 className: PropTypes.string,
162 /**
163 * The component used for the root node.
164 * Either a string to use a HTML element or a component.
165 */
166 component: PropTypes.elementType,
167 /**
168 * If `true`, `subheader` and `title` won't be wrapped by a Typography component.
169 * This can be useful to render an alternative Typography variant by wrapping
170 * the `title` text, and optional `subheader` text
171 * with the Typography component.
172 * @default false
173 */
174 disableTypography: PropTypes.bool,
175 /**
176 * The content of the component.
177 */
178 subheader: PropTypes.node,
179 /**
180 * These props will be forwarded to the subheader
181 * (as long as disableTypography is not `true`).
182 */
183 subheaderTypographyProps: PropTypes.object,
184 /**
185 * The system prop that allows defining system overrides as well as additional CSS styles.
186 */
187 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
188 /**
189 * The content of the component.
190 */
191 title: PropTypes.node,
192 /**
193 * These props will be forwarded to the title
194 * (as long as disableTypography is not `true`).
195 */
196 titleTypographyProps: PropTypes.object
197} : void 0;
198export default CardHeader;
\No newline at end of file