UNPKG

9.24 kBJavaScriptView Raw
1"use strict";
2'use client';
3
4var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
6Object.defineProperty(exports, "__esModule", {
7 value: true
8});
9exports.default = exports.TypographyRoot = void 0;
10var React = _interopRequireWildcard(require("react"));
11var _propTypes = _interopRequireDefault(require("prop-types"));
12var _clsx = _interopRequireDefault(require("clsx"));
13var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
14var _zeroStyled = require("../zero-styled");
15var _memoTheme = _interopRequireDefault(require("../utils/memoTheme"));
16var _DefaultPropsProvider = require("../DefaultPropsProvider");
17var _capitalize = _interopRequireDefault(require("../utils/capitalize"));
18var _createSimplePaletteValueFilter = _interopRequireDefault(require("../utils/createSimplePaletteValueFilter"));
19var _typographyClasses = require("./typographyClasses");
20var _jsxRuntime = require("react/jsx-runtime");
21const v6Colors = {
22 primary: true,
23 secondary: true,
24 error: true,
25 info: true,
26 success: true,
27 warning: true,
28 textPrimary: true,
29 textSecondary: true,
30 textDisabled: true
31};
32const extendSxProp = (0, _zeroStyled.internal_createExtendSxProp)();
33const useUtilityClasses = ownerState => {
34 const {
35 align,
36 gutterBottom,
37 noWrap,
38 paragraph,
39 variant,
40 classes
41 } = ownerState;
42 const slots = {
43 root: ['root', variant, ownerState.align !== 'inherit' && `align${(0, _capitalize.default)(align)}`, gutterBottom && 'gutterBottom', noWrap && 'noWrap', paragraph && 'paragraph']
44 };
45 return (0, _composeClasses.default)(slots, _typographyClasses.getTypographyUtilityClass, classes);
46};
47const TypographyRoot = exports.TypographyRoot = (0, _zeroStyled.styled)('span', {
48 name: 'MuiTypography',
49 slot: 'Root',
50 overridesResolver: (props, styles) => {
51 const {
52 ownerState
53 } = props;
54 return [styles.root, ownerState.variant && styles[ownerState.variant], ownerState.align !== 'inherit' && styles[`align${(0, _capitalize.default)(ownerState.align)}`], ownerState.noWrap && styles.noWrap, ownerState.gutterBottom && styles.gutterBottom, ownerState.paragraph && styles.paragraph];
55 }
56})((0, _memoTheme.default)(({
57 theme
58}) => ({
59 margin: 0,
60 variants: [{
61 props: {
62 variant: 'inherit'
63 },
64 style: {
65 // Some elements, like <button> on Chrome have default font that doesn't inherit, reset this.
66 font: 'inherit',
67 lineHeight: 'inherit',
68 letterSpacing: 'inherit'
69 }
70 }, ...Object.entries(theme.typography).filter(([variant, value]) => variant !== 'inherit' && value && typeof value === 'object').map(([variant, value]) => ({
71 props: {
72 variant
73 },
74 style: value
75 })), ...Object.entries(theme.palette).filter((0, _createSimplePaletteValueFilter.default)()).map(([color]) => ({
76 props: {
77 color
78 },
79 style: {
80 color: (theme.vars || theme).palette[color].main
81 }
82 })), ...Object.entries(theme.palette?.text || {}).filter(([, value]) => typeof value === 'string').map(([color]) => ({
83 props: {
84 color: `text${(0, _capitalize.default)(color)}`
85 },
86 style: {
87 color: (theme.vars || theme).palette.text[color]
88 }
89 })), {
90 props: ({
91 ownerState
92 }) => ownerState.align !== 'inherit',
93 style: {
94 textAlign: 'var(--Typography-textAlign)'
95 }
96 }, {
97 props: ({
98 ownerState
99 }) => ownerState.noWrap,
100 style: {
101 overflow: 'hidden',
102 textOverflow: 'ellipsis',
103 whiteSpace: 'nowrap'
104 }
105 }, {
106 props: ({
107 ownerState
108 }) => ownerState.gutterBottom,
109 style: {
110 marginBottom: '0.35em'
111 }
112 }, {
113 props: ({
114 ownerState
115 }) => ownerState.paragraph,
116 style: {
117 marginBottom: 16
118 }
119 }]
120})));
121const defaultVariantMapping = {
122 h1: 'h1',
123 h2: 'h2',
124 h3: 'h3',
125 h4: 'h4',
126 h5: 'h5',
127 h6: 'h6',
128 subtitle1: 'h6',
129 subtitle2: 'h6',
130 body1: 'p',
131 body2: 'p',
132 inherit: 'p'
133};
134const Typography = /*#__PURE__*/React.forwardRef(function Typography(inProps, ref) {
135 const {
136 color,
137 ...themeProps
138 } = (0, _DefaultPropsProvider.useDefaultProps)({
139 props: inProps,
140 name: 'MuiTypography'
141 });
142 const isSxColor = !v6Colors[color];
143 // TODO: Remove `extendSxProp` in v7
144 const props = extendSxProp({
145 ...themeProps,
146 ...(isSxColor && {
147 color
148 })
149 });
150 const {
151 align = 'inherit',
152 className,
153 component,
154 gutterBottom = false,
155 noWrap = false,
156 paragraph = false,
157 variant = 'body1',
158 variantMapping = defaultVariantMapping,
159 ...other
160 } = props;
161 const ownerState = {
162 ...props,
163 align,
164 color,
165 className,
166 component,
167 gutterBottom,
168 noWrap,
169 paragraph,
170 variant,
171 variantMapping
172 };
173 const Component = component || (paragraph ? 'p' : variantMapping[variant] || defaultVariantMapping[variant]) || 'span';
174 const classes = useUtilityClasses(ownerState);
175 return /*#__PURE__*/(0, _jsxRuntime.jsx)(TypographyRoot, {
176 as: Component,
177 ref: ref,
178 className: (0, _clsx.default)(classes.root, className),
179 ...other,
180 ownerState: ownerState,
181 style: {
182 ...(align !== 'inherit' && {
183 '--Typography-textAlign': align
184 }),
185 ...other.style
186 }
187 });
188});
189process.env.NODE_ENV !== "production" ? Typography.propTypes /* remove-proptypes */ = {
190 // ┌────────────────────────────── Warning ──────────────────────────────┐
191 // │ These PropTypes are generated from the TypeScript type definitions. │
192 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
193 // └─────────────────────────────────────────────────────────────────────┘
194 /**
195 * Set the text-align on the component.
196 * @default 'inherit'
197 */
198 align: _propTypes.default.oneOf(['center', 'inherit', 'justify', 'left', 'right']),
199 /**
200 * The content of the component.
201 */
202 children: _propTypes.default.node,
203 /**
204 * Override or extend the styles applied to the component.
205 */
206 classes: _propTypes.default.object,
207 /**
208 * @ignore
209 */
210 className: _propTypes.default.string,
211 /**
212 * The color of the component.
213 * It supports both default and custom theme colors, which can be added as shown in the
214 * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
215 */
216 color: _propTypes.default /* @typescript-to-proptypes-ignore */.oneOfType([_propTypes.default.oneOf(['primary', 'secondary', 'success', 'error', 'info', 'warning', 'textPrimary', 'textSecondary', 'textDisabled']), _propTypes.default.string]),
217 /**
218 * The component used for the root node.
219 * Either a string to use a HTML element or a component.
220 */
221 component: _propTypes.default.elementType,
222 /**
223 * If `true`, the text will have a bottom margin.
224 * @default false
225 */
226 gutterBottom: _propTypes.default.bool,
227 /**
228 * If `true`, the text will not wrap, but instead will truncate with a text overflow ellipsis.
229 *
230 * Note that text overflow can only happen with block or inline-block level elements
231 * (the element needs to have a width in order to overflow).
232 * @default false
233 */
234 noWrap: _propTypes.default.bool,
235 /**
236 * If `true`, the element will be a paragraph element.
237 * @default false
238 * @deprecated Use the `component` prop instead. This prop will be removed in v7. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details.
239 */
240 paragraph: _propTypes.default.bool,
241 /**
242 * @ignore
243 */
244 style: _propTypes.default.object,
245 /**
246 * The system prop that allows defining system overrides as well as additional CSS styles.
247 */
248 sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
249 /**
250 * Applies the theme typography styles.
251 * @default 'body1'
252 */
253 variant: _propTypes.default /* @typescript-to-proptypes-ignore */.oneOfType([_propTypes.default.oneOf(['body1', 'body2', 'button', 'caption', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'inherit', 'overline', 'subtitle1', 'subtitle2']), _propTypes.default.string]),
254 /**
255 * The component maps the variant prop to a range of different HTML element types.
256 * For instance, subtitle1 to `<h6>`.
257 * If you wish to change that mapping, you can provide your own.
258 * Alternatively, you can use the `component` prop.
259 * @default {
260 * h1: 'h1',
261 * h2: 'h2',
262 * h3: 'h3',
263 * h4: 'h4',
264 * h5: 'h5',
265 * h6: 'h6',
266 * subtitle1: 'h6',
267 * subtitle2: 'h6',
268 * body1: 'p',
269 * body2: 'p',
270 * inherit: 'p',
271 * }
272 */
273 variantMapping: _propTypes.default /* @typescript-to-proptypes-ignore */.object
274} : void 0;
275var _default = exports.default = Typography;
\No newline at end of file