From 238307940d9b5b329a13e475d1cff75643207974 Mon Sep 17 00:00:00 2001 From: Rachel Killackey Date: Fri, 13 Apr 2018 12:45:11 -0500 Subject: [PATCH 1/7] add hideLabel prop, story --- docs.md | 3 +++ src/forms/helpers/omit-label-props.js | 3 +++ src/forms/labels/input-label.js | 18 ++++++++++++++++-- src/forms/labels/labeled-field.js | 3 ++- stories/forms/inputs/input.story.js | 2 +- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/docs.md b/docs.md index 86c90488..3e2d0225 100644 --- a/docs.md +++ b/docs.md @@ -872,6 +872,7 @@ For instance: `'person.firstName'` becomes `'First Name'` **Parameters** - `name` **[String][48]** The name of the associated input +- `hideLabel` **[Boolean][50]** A boolean representing hiding or showing the label element (optional, default `false`) - `hint` **[String][48]?** A usage hint for the associated input - `label` **([String][48] \| [Boolean][50])?** Custom text for the label - `tooltip` **[String][48]?** A message to display in a tooltip @@ -993,6 +994,7 @@ Created in order to prevent these props from being passed down to the input comp Omits the following props: +- `hideLabel` - `hint` - `tooltip` - `label` @@ -1006,6 +1008,7 @@ Omits the following props: ```javascript const props = { label: 'Biography', + hideLabel: true, hint: 'A short biography', tooltip: 'Help us learn more about you!', maxLength: 1000 diff --git a/src/forms/helpers/omit-label-props.js b/src/forms/helpers/omit-label-props.js index ea4202cc..b7f176bd 100644 --- a/src/forms/helpers/omit-label-props.js +++ b/src/forms/helpers/omit-label-props.js @@ -6,6 +6,7 @@ import { omit } from '../../utils' * Created in order to prevent these props from being passed down to the input component through `...rest`. * * Omits the following props: + * - `hideLabel` * - `hint` * - `tooltip` * - `label` @@ -18,6 +19,7 @@ import { omit } from '../../utils' * * const props = { * label: 'Biography', + * hideLabel: true, * hint: 'A short biography', * tooltip: 'Help us learn more about you!', * maxLength: 1000 @@ -46,6 +48,7 @@ import { omit } from '../../utils' function omitLabelProps (props) { return omit([ + 'hideLabel', 'hint', 'tooltip', 'label' diff --git a/src/forms/labels/input-label.js b/src/forms/labels/input-label.js index b564c7fc..ed0e82d7 100644 --- a/src/forms/labels/input-label.js +++ b/src/forms/labels/input-label.js @@ -3,6 +3,7 @@ import PropTypes from 'prop-types' import classnames from 'classnames' import { convertNameToLabel } from '../helpers' import { toggle, togglePropTypes } from '../../utils' +import { hide } from 'redux-modal'; /** * @@ -22,6 +23,7 @@ import { toggle, togglePropTypes } from '../../utils' * @name InputLabel * @type Function * @param {String} name - The name of the associated input + * @param {Boolean} [hideLabel=false] - A boolean representing hiding or showing the label element * @param {String} [hint] - A usage hint for the associated input * @param {String|Boolean} [label] - Custom text for the label * @param {String} [tooltip] - A message to display in a tooltip @@ -51,6 +53,7 @@ import { toggle, togglePropTypes } from '../../utils' **/ const propTypes = { + hideLabel: PropTypes.bool, hint: PropTypes.string, label: PropTypes.oneOfType([ PropTypes.string, PropTypes.bool ]), name: PropTypes.string.isRequired, @@ -59,13 +62,24 @@ const propTypes = { } const defaultProps = { + hideLabel: false, hint: '', label: '', tooltip: '', } -function InputLabel ({ hint, label, name, tooltip, tooltipShown, toggleTooltipShown }) { - const labelText = label || convertNameToLabel(name) +function InputLabel ({ + hideLabel, + hint, + label, + name, + tooltip, + tooltipShown, + toggleTooltipShown, +}) { + const showLabel = (hideLabel !== true) || (label !== false) + console.log(label !== false) + const labelText = showLabel || convertNameToLabel(name) return ( { diff --git a/src/forms/labels/labeled-field.js b/src/forms/labels/labeled-field.js index c169295a..0f7cc0fb 100644 --- a/src/forms/labels/labeled-field.js +++ b/src/forms/labels/labeled-field.js @@ -58,6 +58,7 @@ function LabeledField ({ input: { name }, meta: { error, touched, invalid }, className, + hideLabel, hint, label, tooltip, @@ -66,7 +67,7 @@ function LabeledField ({ }) { return (
- + { children } { !hideErrorLabel && }
diff --git a/stories/forms/inputs/input.story.js b/stories/forms/inputs/input.story.js index 02d3fb3a..33242bb9 100644 --- a/stories/forms/inputs/input.story.js +++ b/stories/forms/inputs/input.story.js @@ -31,7 +31,7 @@ storiesOf('Input', module) )) .add('with error', () => ( From 33b4ae2efa5900bb30b927414ddf285305333402 Mon Sep 17 00:00:00 2001 From: Rachel Killackey Date: Fri, 13 Apr 2018 12:53:43 -0500 Subject: [PATCH 2/7] update showLabel logic, add new story --- docs.md | 2 +- src/forms/labels/input-label.js | 9 ++++----- stories/forms/inputs/input.story.js | 7 +++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs.md b/docs.md index 3e2d0225..d2d6ab67 100644 --- a/docs.md +++ b/docs.md @@ -872,7 +872,7 @@ For instance: `'person.firstName'` becomes `'First Name'` **Parameters** - `name` **[String][48]** The name of the associated input -- `hideLabel` **[Boolean][50]** A boolean representing hiding or showing the label element (optional, default `false`) +- `hideLabel` **[Boolean][50]** A boolean representing whether or not to display the label element (optional, default `false`) - `hint` **[String][48]?** A usage hint for the associated input - `label` **([String][48] \| [Boolean][50])?** Custom text for the label - `tooltip` **[String][48]?** A message to display in a tooltip diff --git a/src/forms/labels/input-label.js b/src/forms/labels/input-label.js index ed0e82d7..9667bb40 100644 --- a/src/forms/labels/input-label.js +++ b/src/forms/labels/input-label.js @@ -23,7 +23,7 @@ import { hide } from 'redux-modal'; * @name InputLabel * @type Function * @param {String} name - The name of the associated input - * @param {Boolean} [hideLabel=false] - A boolean representing hiding or showing the label element + * @param {Boolean} [hideLabel=false] - A boolean representing whether or not to display the label element * @param {String} [hint] - A usage hint for the associated input * @param {String|Boolean} [label] - Custom text for the label * @param {String} [tooltip] - A message to display in a tooltip @@ -77,13 +77,12 @@ function InputLabel ({ tooltipShown, toggleTooltipShown, }) { - const showLabel = (hideLabel !== true) || (label !== false) - console.log(label !== false) - const labelText = showLabel || convertNameToLabel(name) + const showLabel = !(hideLabel === true || label === false) + const labelText = !showLabel || convertNameToLabel(name) return ( { - label !== false && + showLabel &&