Skip to content

Commit 99cd63c

Browse files
committed
fix(mui): map component prop to element in plain text
1 parent 5c7e7ca commit 99cd63c

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

packages/mui-component-mapper/src/files/plain-text.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { TypographyProps } from "@material-ui/core";
2-
import { ReactNode } from "react";
2+
import { ElementType, ReactNode } from "react";
33

4-
export interface PlainTextProps extends TypographyProps {
4+
export interface PlainTextProps extends Omit<TypographyProps, 'component'> {
55
label: ReactNode;
66
name: string;
7+
element?: ElementType;
78
}
89

910
declare const PlainText: React.ComponentType<PlainTextProps>;

packages/mui-component-mapper/src/files/plain-text.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@ import React from 'react';
22
import { Typography } from '@material-ui/core';
33
import PropTypes from 'prop-types';
44

5-
const PlainText = ({ label, name, component, ...props }) =>
5+
const PlainText = ({ label, name, component, element, ...props }) =>
66
typeof label === 'string' ? (
77
label.split('\n').map((paragraph, index) => (
8-
<Typography key={`${index}-${name}`} {...props}>
8+
<Typography key={`${index}-${name}`} {...props} {...(element && { component: element })}>
99
{paragraph}
1010
</Typography>
1111
))
1212
) : (
13-
<Typography {...props}>{label}</Typography>
13+
<Typography {...props} {...(element && { component: element })}>
14+
{label}
15+
</Typography>
1416
);
1517

1618
PlainText.propTypes = {
1719
label: PropTypes.node.isRequired,
1820
name: PropTypes.string.isRequired,
19-
component: PropTypes.any
21+
component: PropTypes.any,
22+
element: PropTypes.elementType
2023
};
2124

2225
PlainText.defaultProps = {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
PlainText is just a `Typography` component. It accepts all the [same props](https://material-ui.com/api/typography/).
2+
3+
## component prop
4+
5+
Due to conficting props names, `component` prop is not available, use `element` prop.
6+
7+
```jsx
8+
{
9+
component: 'plain-text',
10+
name: 'plain-text',
11+
label: 'Header',
12+
element: 'h1'
13+
}
14+
```

0 commit comments

Comments
 (0)