Skip to content

fix(pf4): Add customization api to plain text #697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/pf4-component-mapper/src/files/plain-text.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { ReactNode } from "react";
import { TextProps, TextContentProps } from "@patternfly/react-core";

export interface PlainTextProps {
interface InternalPlainTextProps {
label: ReactNode;
name: string;
variant?: 'p'|'span'|'strong'|'b'|'cite'|'caption'|'code'|'em'|'i'|'h1'|'h2'|'h3'|'h4'|'h5'|'h6'|'h6'|'div'|'label'|'pre'|'q'|'samp'|'small'|'sub'|'sup';
TextContentProps: TextContentProps,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add it do docs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right its not generated yet.

}

export type PlainTextProps = InternalPlainTextProps & TextProps;

declare const PlainText: React.ComponentType<PlainTextProps>;

export default PlainText;
10 changes: 6 additions & 4 deletions packages/pf4-component-mapper/src/files/plain-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import PropTypes from 'prop-types';
import { TextContent, Text } from '@patternfly/react-core';
import validTextFields from '@data-driven-forms/common/src/utils/valid-text-fields';

const PlainText = ({ label, name, variant }) => (
<TextContent>
const PlainText = ({ component, label, name, variant, TextContentProps, ...rest }) => (
<TextContent {...TextContentProps}>
{typeof label === 'string'
? label.split('\n').map((paragraph, index) => (
<Text component={variant} key={`${name}-${index}`}>
<Text component={variant} {...rest} key={`${name}-${index}`}>
{paragraph}
</Text>
))
Expand All @@ -19,7 +19,9 @@ const PlainText = ({ label, name, variant }) => (
PlainText.propTypes = {
variant: PropTypes.oneOf(validTextFields),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should mention that component PF prop is mapped to variant prop in Docs.

label: PropTypes.node.isRequired,
name: PropTypes.string.isRequired
name: PropTypes.string.isRequired,
TextContentProps: PropTypes.object,
component: PropTypes.string
};

PlainText.defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
This a custom component with a custom design. Things can be changed, after official PF4 release.

**Props**

Plain text accepts all props defined in [PF4 Text component decoumentation](https://www.patternfly.org/v4/documentation/react/components/text#props).

**Due to a name conflict the Text component prop is mapped to variant key in schema.**

|Props|Type|Default|Description|
|-----|----|-------|-----------|
|label|string/node||Rendered text|
|TextContentProps|object||https://www.patternfly.org/v4/documentation/react/components/text#props|