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 { styled, internal_createExtendSxProp } from "../zero-styled/index.js";
|
8 | import memoTheme from "../utils/memoTheme.js";
|
9 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
10 | import capitalize from "../utils/capitalize.js";
|
11 | import createSimplePaletteValueFilter from "../utils/createSimplePaletteValueFilter.js";
|
12 | import { getTypographyUtilityClass } from "./typographyClasses.js";
|
13 | import { jsx as _jsx } from "react/jsx-runtime";
|
14 | const v6Colors = {
|
15 | primary: true,
|
16 | secondary: true,
|
17 | error: true,
|
18 | info: true,
|
19 | success: true,
|
20 | warning: true,
|
21 | textPrimary: true,
|
22 | textSecondary: true,
|
23 | textDisabled: true
|
24 | };
|
25 | const extendSxProp = internal_createExtendSxProp();
|
26 | const useUtilityClasses = ownerState => {
|
27 | const {
|
28 | align,
|
29 | gutterBottom,
|
30 | noWrap,
|
31 | paragraph,
|
32 | variant,
|
33 | classes
|
34 | } = ownerState;
|
35 | const slots = {
|
36 | root: ['root', variant, ownerState.align !== 'inherit' && `align${capitalize(align)}`, gutterBottom && 'gutterBottom', noWrap && 'noWrap', paragraph && 'paragraph']
|
37 | };
|
38 | return composeClasses(slots, getTypographyUtilityClass, classes);
|
39 | };
|
40 | export const TypographyRoot = styled('span', {
|
41 | name: 'MuiTypography',
|
42 | slot: 'Root',
|
43 | overridesResolver: (props, styles) => {
|
44 | const {
|
45 | ownerState
|
46 | } = props;
|
47 | return [styles.root, ownerState.variant && styles[ownerState.variant], ownerState.align !== 'inherit' && styles[`align${capitalize(ownerState.align)}`], ownerState.noWrap && styles.noWrap, ownerState.gutterBottom && styles.gutterBottom, ownerState.paragraph && styles.paragraph];
|
48 | }
|
49 | })(memoTheme(({
|
50 | theme
|
51 | }) => ({
|
52 | margin: 0,
|
53 | variants: [{
|
54 | props: {
|
55 | variant: 'inherit'
|
56 | },
|
57 | style: {
|
58 |
|
59 | font: 'inherit',
|
60 | lineHeight: 'inherit',
|
61 | letterSpacing: 'inherit'
|
62 | }
|
63 | }, ...Object.entries(theme.typography).filter(([variant, value]) => variant !== 'inherit' && value && typeof value === 'object').map(([variant, value]) => ({
|
64 | props: {
|
65 | variant
|
66 | },
|
67 | style: value
|
68 | })), ...Object.entries(theme.palette).filter(createSimplePaletteValueFilter()).map(([color]) => ({
|
69 | props: {
|
70 | color
|
71 | },
|
72 | style: {
|
73 | color: (theme.vars || theme).palette[color].main
|
74 | }
|
75 | })), ...Object.entries(theme.palette?.text || {}).filter(([, value]) => typeof value === 'string').map(([color]) => ({
|
76 | props: {
|
77 | color: `text${capitalize(color)}`
|
78 | },
|
79 | style: {
|
80 | color: (theme.vars || theme).palette.text[color]
|
81 | }
|
82 | })), {
|
83 | props: ({
|
84 | ownerState
|
85 | }) => ownerState.align !== 'inherit',
|
86 | style: {
|
87 | textAlign: 'var(--Typography-textAlign)'
|
88 | }
|
89 | }, {
|
90 | props: ({
|
91 | ownerState
|
92 | }) => ownerState.noWrap,
|
93 | style: {
|
94 | overflow: 'hidden',
|
95 | textOverflow: 'ellipsis',
|
96 | whiteSpace: 'nowrap'
|
97 | }
|
98 | }, {
|
99 | props: ({
|
100 | ownerState
|
101 | }) => ownerState.gutterBottom,
|
102 | style: {
|
103 | marginBottom: '0.35em'
|
104 | }
|
105 | }, {
|
106 | props: ({
|
107 | ownerState
|
108 | }) => ownerState.paragraph,
|
109 | style: {
|
110 | marginBottom: 16
|
111 | }
|
112 | }]
|
113 | })));
|
114 | const defaultVariantMapping = {
|
115 | h1: 'h1',
|
116 | h2: 'h2',
|
117 | h3: 'h3',
|
118 | h4: 'h4',
|
119 | h5: 'h5',
|
120 | h6: 'h6',
|
121 | subtitle1: 'h6',
|
122 | subtitle2: 'h6',
|
123 | body1: 'p',
|
124 | body2: 'p',
|
125 | inherit: 'p'
|
126 | };
|
127 | const Typography = React.forwardRef(function Typography(inProps, ref) {
|
128 | const {
|
129 | color,
|
130 | ...themeProps
|
131 | } = useDefaultProps({
|
132 | props: inProps,
|
133 | name: 'MuiTypography'
|
134 | });
|
135 | const isSxColor = !v6Colors[color];
|
136 |
|
137 | const props = extendSxProp({
|
138 | ...themeProps,
|
139 | ...(isSxColor && {
|
140 | color
|
141 | })
|
142 | });
|
143 | const {
|
144 | align = 'inherit',
|
145 | className,
|
146 | component,
|
147 | gutterBottom = false,
|
148 | noWrap = false,
|
149 | paragraph = false,
|
150 | variant = 'body1',
|
151 | variantMapping = defaultVariantMapping,
|
152 | ...other
|
153 | } = props;
|
154 | const ownerState = {
|
155 | ...props,
|
156 | align,
|
157 | color,
|
158 | className,
|
159 | component,
|
160 | gutterBottom,
|
161 | noWrap,
|
162 | paragraph,
|
163 | variant,
|
164 | variantMapping
|
165 | };
|
166 | const Component = component || (paragraph ? 'p' : variantMapping[variant] || defaultVariantMapping[variant]) || 'span';
|
167 | const classes = useUtilityClasses(ownerState);
|
168 | return _jsx(TypographyRoot, {
|
169 | as: Component,
|
170 | ref: ref,
|
171 | className: clsx(classes.root, className),
|
172 | ...other,
|
173 | ownerState: ownerState,
|
174 | style: {
|
175 | ...(align !== 'inherit' && {
|
176 | '--Typography-textAlign': align
|
177 | }),
|
178 | ...other.style
|
179 | }
|
180 | });
|
181 | });
|
182 | process.env.NODE_ENV !== "production" ? Typography.propTypes = {
|
183 |
|
184 |
|
185 |
|
186 |
|
187 | |
188 |
|
189 |
|
190 |
|
191 | align: PropTypes.oneOf(['center', 'inherit', 'justify', 'left', 'right']),
|
192 | |
193 |
|
194 |
|
195 | children: PropTypes.node,
|
196 | |
197 |
|
198 |
|
199 | classes: PropTypes.object,
|
200 | |
201 |
|
202 |
|
203 | className: PropTypes.string,
|
204 | |
205 |
|
206 |
|
207 |
|
208 |
|
209 | color: PropTypes .oneOfType([PropTypes.oneOf(['primary', 'secondary', 'success', 'error', 'info', 'warning', 'textPrimary', 'textSecondary', 'textDisabled']), PropTypes.string]),
|
210 | |
211 |
|
212 |
|
213 |
|
214 | component: PropTypes.elementType,
|
215 | |
216 |
|
217 |
|
218 |
|
219 | gutterBottom: PropTypes.bool,
|
220 | |
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 | noWrap: PropTypes.bool,
|
228 | |
229 |
|
230 |
|
231 |
|
232 |
|
233 | paragraph: PropTypes.bool,
|
234 | |
235 |
|
236 |
|
237 | style: PropTypes.object,
|
238 | |
239 |
|
240 |
|
241 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
242 | |
243 |
|
244 |
|
245 |
|
246 | variant: PropTypes .oneOfType([PropTypes.oneOf(['body1', 'body2', 'button', 'caption', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'inherit', 'overline', 'subtitle1', 'subtitle2']), PropTypes.string]),
|
247 | |
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 | variantMapping: PropTypes .object
|
267 | } : void 0;
|
268 | export default Typography; |
\ | No newline at end of file |