Skip to content
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

fix: Moved field descriptions into tooltip #1858

Merged
merged 6 commits into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import get from 'lodash/get';
import classnames from 'classnames';

import { FormContext } from '../types';
import { WidgetLabel } from '../widgets/WidgetLabel';

import { RootField } from './RootField';

Expand Down Expand Up @@ -75,23 +76,13 @@ export function BaseField<T = any>(props: BaseFieldProps<T>): JSX.Element {
) : (
<div className={classnames({ BaseField: !displayInline }, className)} key={key} id={key.replace(/\.|#/g, '')}>
{!hideDescription && (
<div>
<h3 className="BaseFieldTitle">{getTitle()}</h3>
{descriptionOverride !== false && (descriptionOverride || description || schema.description) && (
<p className="BaseFieldDescription">
{getDescription()}
{helpLink && helpLinkText && (
<>
<br />
<br />
<a href={helpLink} target="_blank" rel="noopener noreferrer">
{helpLinkText}
</a>
</>
)}
</p>
)}
</div>
<WidgetLabel
label={getTitle()}
description={getDescription()}
helpLink={helpLink}
helpLinkText={helpLinkText}
{...props.schema}
tdurnford marked this conversation as resolved.
Show resolved Hide resolved
/>
)}
<div className={classnames({ BaseFieldInline: displayInline })}>{children}</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ interface DescriptionCalloutProps {
title: string;
description?: string;
id?: string;
helpLink?: string;
helpLinkText?: string;
}

const DescriptionCallout: React.FC<DescriptionCalloutProps> = props => {
const { description, title, id } = props;
const { description, title, id, helpLink, helpLinkText } = props;

if (!description) {
return null;
Expand All @@ -27,7 +29,18 @@ const DescriptionCallout: React.FC<DescriptionCalloutProps> = props => {
onRenderContent: () => (
<div>
<h3 style={{ fontSize: '20px', margin: '0', marginBottom: '10px' }}>{title}</h3>
<p>{description}</p>
<p>
{description}
{helpLink && helpLinkText && (
<>
<br />
<br />
<a href={helpLink} target="_blank" rel="noopener noreferrer">
{helpLinkText}
</a>
</>
)}
</p>
</div>
),
}}
Expand Down Expand Up @@ -57,10 +70,12 @@ interface WidgetLabelProps {
label?: string;
description?: string;
inline?: boolean;
helpLink?: string;
helpLinkText?: string;
}

export const WidgetLabel: React.FC<WidgetLabelProps> = props => {
const { label, description, id, inline } = props;
const { label, description, id, inline, helpLink, helpLinkText } = props;

if (!label) {
return null;
Expand All @@ -79,7 +94,13 @@ export const WidgetLabel: React.FC<WidgetLabelProps> = props => {
}}
>
{label}
<DescriptionCallout description={description} title={label} id={id} />
<DescriptionCallout
description={description}
title={label}
id={id}
helpLink={helpLink}
helpLinkText={helpLinkText}
/>
</Label>
);
};