From e6628a6a66963fec522cd86a7caebda252b52c88 Mon Sep 17 00:00:00 2001 From: Dong Kyun David Kim Date: Sun, 25 Apr 2021 15:34:17 -0700 Subject: [PATCH 1/5] Adding support for help text -> error text conversion --- .../Form/Documentation/Form.stories.tsx | 1 + src/Components/Form/Form.scss | 7 ++++++ src/Components/Form/FormElementError.tsx | 25 ++++++++++++------- src/Components/Form/FormValidationElement.tsx | 8 ++++-- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/Components/Form/Documentation/Form.stories.tsx b/src/Components/Form/Documentation/Form.stories.tsx index f0a80372d..c76adb344 100644 --- a/src/Components/Form/Documentation/Form.stories.tsx +++ b/src/Components/Form/Documentation/Form.stories.tsx @@ -234,6 +234,7 @@ formStories.add(
diff --git a/src/Components/Form/Form.scss b/src/Components/Form/Form.scss index 658b6cd09..c1cedf640 100644 --- a/src/Components/Form/Form.scss +++ b/src/Components/Form/Form.scss @@ -36,6 +36,12 @@ @extend %no-user-select; } +.cf-form--element-error-container { + position: relative; + height: 0px; + width: 100%; +} + .cf-form--label { width: 100%; color: $cf-label--default; @@ -60,6 +66,7 @@ } .cf-form--element-error { + position: absolute; line-height: 16px; color: $c-dreamsicle; margin: $cf-marg-a 0 0 0; diff --git a/src/Components/Form/FormElementError.tsx b/src/Components/Form/FormElementError.tsx index 193097286..f8eee3aef 100644 --- a/src/Components/Form/FormElementError.tsx +++ b/src/Components/Form/FormElementError.tsx @@ -8,6 +8,7 @@ import {StandardFunctionProps} from '../../Types' export interface FormElementErrorProps extends StandardFunctionProps { /** Text to be displayed on error */ message?: string + withHelper?: boolean } export type FormElementErrorRef = HTMLSpanElement @@ -23,6 +24,7 @@ export const FormElementError = forwardRef< className, message = '\u00a0\u00a0', testID = 'form--element-error', + withHelper = false, }, ref ) => { @@ -30,16 +32,21 @@ export const FormElementError = forwardRef< [`${className}`]: className, }) + //When Helper text exists, we want error message to take up as much height as the helper text. When Helper text does not exist, we want error message to not shift spaces. + const withHelperStyle = withHelper ? {height: '20px'} : {} + return ( - - {message} - +
+ + {message} + +
) } ) diff --git a/src/Components/Form/FormValidationElement.tsx b/src/Components/Form/FormValidationElement.tsx index b30cad251..aef473677 100644 --- a/src/Components/Form/FormValidationElement.tsx +++ b/src/Components/Form/FormValidationElement.tsx @@ -80,6 +80,8 @@ export const FormValidationElement = forwardRef< onStatusChange(status) } + const withHelper = helpText ? true : false + const formValidationElementClass = classnames('cf-form--element', { [`${className}`]: className, }) @@ -99,8 +101,10 @@ export const FormValidationElement = forwardRef< )} {children(status)} - {!!errorMessage && } - {!!helpText && } + {!!errorMessage && ( + + )} + {!!helpText && !errorMessage && } ) } From 6a5e2479839d4af57b8aa4c084989a8563392f7b Mon Sep 17 00:00:00 2001 From: Dong Kyun David Kim Date: Thu, 6 May 2021 18:44:27 -0700 Subject: [PATCH 2/5] allocate built in space --- src/Components/Form/Form.scss | 2 +- src/Components/Form/FormElementError.tsx | 4 +--- src/Components/Form/FormValidationElement.tsx | 3 +++ 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Components/Form/Form.scss b/src/Components/Form/Form.scss index c1cedf640..e6ecdf57e 100644 --- a/src/Components/Form/Form.scss +++ b/src/Components/Form/Form.scss @@ -38,7 +38,7 @@ .cf-form--element-error-container { position: relative; - height: 0px; + height: 20px; width: 100%; } diff --git a/src/Components/Form/FormElementError.tsx b/src/Components/Form/FormElementError.tsx index f8eee3aef..25af65330 100644 --- a/src/Components/Form/FormElementError.tsx +++ b/src/Components/Form/FormElementError.tsx @@ -33,10 +33,9 @@ export const FormElementError = forwardRef< }) //When Helper text exists, we want error message to take up as much height as the helper text. When Helper text does not exist, we want error message to not shift spaces. - const withHelperStyle = withHelper ? {height: '20px'} : {} + //const withHelperStyle = withHelper ? {height: '20px'} : {} return ( -
{message} -
) } ) diff --git a/src/Components/Form/FormValidationElement.tsx b/src/Components/Form/FormValidationElement.tsx index aef473677..105d0c6ab 100644 --- a/src/Components/Form/FormValidationElement.tsx +++ b/src/Components/Form/FormValidationElement.tsx @@ -86,6 +86,7 @@ export const FormValidationElement = forwardRef< [`${className}`]: className, }) + return ( ) } From b760def25864105126be167a31cc4c203c4b0d78 Mon Sep 17 00:00:00 2001 From: Dong Kyun David Kim Date: Tue, 18 May 2021 20:16:49 -0700 Subject: [PATCH 3/5] lint and prettier --- src/Components/Form/Form.scss | 2 +- src/Components/Form/FormElement.tsx | 2 ++ src/Components/Form/FormElementError.tsx | 19 +++++++++---------- src/Components/Form/FormValidationElement.tsx | 11 +++++------ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Components/Form/Form.scss b/src/Components/Form/Form.scss index e6ecdf57e..eabbfd10e 100644 --- a/src/Components/Form/Form.scss +++ b/src/Components/Form/Form.scss @@ -18,7 +18,7 @@ display: flex; flex-direction: column; align-items: stretch; - margin-bottom: $cf-marg-b; + margin-bottom: $cf-marg-a; } /* diff --git a/src/Components/Form/FormElement.tsx b/src/Components/Form/FormElement.tsx index 87a02a866..3fb59a00d 100644 --- a/src/Components/Form/FormElement.tsx +++ b/src/Components/Form/FormElement.tsx @@ -80,6 +80,7 @@ export const FormElement = forwardRef( className={formElementClass} > {formElementElements} +
) } @@ -93,6 +94,7 @@ export const FormElement = forwardRef( className={formElementClass} > {formElementElements} +
) } diff --git a/src/Components/Form/FormElementError.tsx b/src/Components/Form/FormElementError.tsx index 25af65330..c1796ab1f 100644 --- a/src/Components/Form/FormElementError.tsx +++ b/src/Components/Form/FormElementError.tsx @@ -24,7 +24,6 @@ export const FormElementError = forwardRef< className, message = '\u00a0\u00a0', testID = 'form--element-error', - withHelper = false, }, ref ) => { @@ -36,15 +35,15 @@ export const FormElementError = forwardRef< //const withHelperStyle = withHelper ? {height: '20px'} : {} return ( - - {message} - + + {message} + ) } ) diff --git a/src/Components/Form/FormValidationElement.tsx b/src/Components/Form/FormValidationElement.tsx index 105d0c6ab..ccc2e0cde 100644 --- a/src/Components/Form/FormValidationElement.tsx +++ b/src/Components/Form/FormValidationElement.tsx @@ -86,7 +86,6 @@ export const FormValidationElement = forwardRef< [`${className}`]: className, }) - return (