From f4479064deccbefbc77c4f150151a6fd1df716ba Mon Sep 17 00:00:00 2001 From: Shawn Date: Tue, 16 May 2023 09:54:27 -0400 Subject: [PATCH] feat: update radio button style, add HintExpander to FormRadioButton --- .../FormRadioButton/FormRadioButton.js | 113 +++++++++++++----- .../FormRadioButton.stories.js | 22 ++++ src/components/HintExpander/HintExpander.tsx | 4 +- 3 files changed, 108 insertions(+), 31 deletions(-) diff --git a/src/components/FormRadioButton/FormRadioButton.js b/src/components/FormRadioButton/FormRadioButton.js index 3d130d24..2e433ced 100644 --- a/src/components/FormRadioButton/FormRadioButton.js +++ b/src/components/FormRadioButton/FormRadioButton.js @@ -2,6 +2,7 @@ import PropTypes from "prop-types"; import React from "react"; import { FormError } from "../FormError/FormError"; import { FormLabel } from "../FormLabel/FormLabel"; +import { HintExpander } from "../HintExpander/HintExpander"; export function FormRadioButton(props) { const validationClass = props.hasError @@ -19,38 +20,58 @@ export function FormRadioButton(props) { infoText={props.infoText} describedBy={props.describedBy} helpText={props.helpText} + hasHint={props.hasHint} + hintProps={props.hintProps} /> )} - {props.options.map(({ id, label, checked, value }, index) => ( - - ))} + {props.options.map( + ({ id, label, checked, value, hasHint, hintProps }, index) => ( + + ) + )} {props.hasError && } ); @@ -86,9 +107,41 @@ FormRadioButton.propTypes = { * the label for the radio button */ label: PropTypes.string.isRequired, + /** + * show hint for radio button + */ + hasHint: PropTypes.bool, + /** + * Hint Expander props + */ + hintProps: PropTypes.shape({ + linkText: PropTypes.string, + description: PropTypes.string, + withLink: PropTypes.bool, + externalLinkText: PropTypes.string, + optionalLinkText: PropTypes.string, + className: PropTypes.string, + }), }) ), + /** + * Option to show and custom Hint Expander + */ + hasHint: PropTypes.bool, + + /** + * Hint Expander props + */ + hintProps: PropTypes.shape({ + textLink: PropTypes.string, + description: PropTypes.string, + withLink: PropTypes.bool, + externalLinkText: PropTypes.string, + optionalLinkText: PropTypes.string, + className: PropTypes.string, + }), + /** * whether the radio button is checked or not */ diff --git a/src/components/FormRadioButton/FormRadioButton.stories.js b/src/components/FormRadioButton/FormRadioButton.stories.js index e44f8973..a2d2e623 100644 --- a/src/components/FormRadioButton/FormRadioButton.stories.js +++ b/src/components/FormRadioButton/FormRadioButton.stories.js @@ -21,6 +21,17 @@ const optionsList = [ id: "option_1", value: "Option 1", label: "Options 1: Some Value to show", + hasHint: true, + hintProps: { + linkText: "Why are we asking about [topic]?", + description: + "We need to know this because your partner’s annual net income...", + withLink: false, + externalLinkText: "", + optionalLinkText: "", + url: "", + className: "", + }, }, { id: "option_2", @@ -47,6 +58,17 @@ withLabelHelpText.args = { options: optionsList, label: "I am a text field", infoText: "Help Text", + hasHint: true, + hintProps: { + linkText: "Why are we asking about [topic]?", + description: + "We need to know this because your partner’s annual net income...", + withLink: false, + externalLinkText: "", + optionalLinkText: "", + url: "", + className: "", + }, helpText: "Help text that is always visible under the label to provide users with primary information needed to fill in the form field. Limit of 2 sentences", }; diff --git a/src/components/HintExpander/HintExpander.tsx b/src/components/HintExpander/HintExpander.tsx index de2a0361..4e57d4e1 100644 --- a/src/components/HintExpander/HintExpander.tsx +++ b/src/components/HintExpander/HintExpander.tsx @@ -11,6 +11,7 @@ export interface HintExpanderProps { optionalLinkText: string; url: string; children: React.ReactNode; + className: string; } export const HintExpander: React.FC = ({ @@ -20,6 +21,7 @@ export const HintExpander: React.FC = ({ optionalLinkText, url, children, + className, }) => { const [expanded, setExpanded] = useState(false); @@ -28,7 +30,7 @@ export const HintExpander: React.FC = ({ }; return ( -
+