Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Add help tips to labels to explain what their icon means [#85]
Browse files Browse the repository at this point in the history
  • Loading branch information
nataliemt committed Feb 23, 2021
1 parent d8250f7 commit d5657ad
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
15 changes: 6 additions & 9 deletions src/js/components/PropertyPicker.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const React = require('react');
const classNames = require('classnames');
const DateTimeFormatPicker = require('./DateTimeFormatPicker.react.js');
const SelectorPicker = require('./SelectorPicker.react.js');
const LabelIcon = require('./common/LabelIcon.react.js');
import type { RuleProperty } from '../models/RuleProperty';
import RulePropertyTypes from '../models/RulePropertyTypes';
import RuleActions from '../data/RuleActions';
Expand Down Expand Up @@ -122,16 +123,12 @@ class PropertyPicker extends React.Component<Props> {
[propertyClass]: true,
})}
>
<label>
{RulePropertyUtils.isValid(this.props.property) ? (
<span></span>
) : this.props.property.definition.required ? (
<span></span>
) : (
<span></span>
)}{' '}
<LabelIcon
valid={RulePropertyUtils.isValid(this.props.property)}
required={this.props.property.definition.required}
>
{this.props.property.definition.displayName}
</label>
</LabelIcon>
<label className="sub-label selector-label">Selector</label>
<SelectorPicker {...this.props} field={this.props.property} />
{attributePicker}
Expand Down
8 changes: 4 additions & 4 deletions src/js/components/RulePicker.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
const React = require('react');
const PropertyPicker = require('./PropertyPicker.react.js');
const SelectorPicker = require('./SelectorPicker.react');
const LabelIcon = require('./common/LabelIcon.react.js');
const classNames = require('classnames');
const RuleActions = require('../data/RuleActions');

Expand Down Expand Up @@ -47,7 +48,7 @@ class RulePicker extends React.Component<Props, State> {
const toggler = this.state.collapsed
? '\u25B6' // right triangle
: '\u25BC'; // down triangle

const hasSelector = this.props.rule.selector != '';
return (
<div
className={classNames({
Expand Down Expand Up @@ -87,10 +88,9 @@ class RulePicker extends React.Component<Props, State> {
valid: this.props.rule.selector != '',
})}
>
<label>
{this.props.rule.selector != '' ? <span></span> : <span></span>}{' '}
<LabelIcon valid={hasSelector} required={!hasSelector}>
Selector
</label>
</LabelIcon>
<SelectorPicker {...this.props} field={this.props.rule} />
</div>
{this.props.rule.properties
Expand Down
38 changes: 38 additions & 0 deletions src/js/components/common/LabelIcon.react.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import React from 'react';

interface Props {
children: string;
required: ?boolean;
valid: ?boolean;
}

const LabelIcon = ({ children, required = false, valid = false }: Props) => {
let icon = '•';
let tooltip = 'Field is optional';
if (required) {
icon = '✘';
tooltip = 'Field is required';
}
if (valid) {
icon = '✔';
tooltip = 'Field is valid';
}
return (
<label>
<span data-tooltip={tooltip} data-position="bottom left">{icon}</span>
{` ${children}`}
</label>
);
}

module.exports = LabelIcon;

0 comments on commit d5657ad

Please sign in to comment.