diff --git a/package.json b/package.json index 3ea1e41e8..806ff7189 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,6 @@ "prop-types": "15.7.2", "raf": "3.4.1", "react": "16.13.0", - "react-children-utilities": "2.0.12", "react-dates": "21.8.0", "react-dom": "16.13.0", "react-error-boundary": "1.2.5", diff --git a/src/components/Form/FormDatePicker.tsx b/src/components/Form/FormDatePicker.tsx index 012c94098..9257431ba 100644 --- a/src/components/Form/FormDatePicker.tsx +++ b/src/components/Form/FormDatePicker.tsx @@ -7,6 +7,7 @@ import Media from 'react-media' import { Col, FormGroup, Row } from 'reactstrap' import FormLabel from './FormLabel' +import { HelpProps } from './FormHelpButton' import { DateRange } from '../../algorithms/types/Param.types' @@ -21,7 +22,7 @@ function getNumberOfMonthsCount(media: { tiny: boolean; small: boolean; medium: export interface FormDatePickerProps { identifier: string label: string - help?: string | React.ReactNode + help?: HelpProps allowPast?: boolean } diff --git a/src/components/Form/FormDropdown.tsx b/src/components/Form/FormDropdown.tsx index a6fdf5f54..78a6e383c 100644 --- a/src/components/Form/FormDropdown.tsx +++ b/src/components/Form/FormDropdown.tsx @@ -3,6 +3,8 @@ import React from 'react' import { Field, FieldProps, FormikErrors, FormikTouched, FormikValues } from 'formik' import FormDropdownStateless from './FormDropdownStateless' +import { HelpProps } from './FormHelpButton' + export interface FormDropdownOption { value: ValueType label: string @@ -11,7 +13,7 @@ export interface FormDropdownOption { export interface FormDropdownProps { identifier: string label: string - help?: string | React.ReactNode + help?: HelpProps options: FormDropdownOption[] errors?: FormikErrors touched?: FormikTouched diff --git a/src/components/Form/FormDropdownStateless.tsx b/src/components/Form/FormDropdownStateless.tsx index 93f5ff60e..630f2a75f 100644 --- a/src/components/Form/FormDropdownStateless.tsx +++ b/src/components/Form/FormDropdownStateless.tsx @@ -5,11 +5,12 @@ import { Col, FormGroup, Row } from 'reactstrap' import { FormDropdownOption } from './FormDropdownOption' import FormLabel from './FormLabel' +import { HelpProps } from './FormHelpButton' export interface FormDropdownProps { identifier: string label: string | React.ReactNode - help?: string | React.ReactNode + help?: HelpProps options: FormDropdownOption[] defaultOption?: FormDropdownOption value?: FormDropdownOption diff --git a/src/components/Form/FormHelpButton.test.tsx b/src/components/Form/FormHelpButton.test.tsx index be79d4714..c1fba65e2 100644 --- a/src/components/Form/FormHelpButton.test.tsx +++ b/src/components/Form/FormHelpButton.test.tsx @@ -1,22 +1,24 @@ import React from 'react' import { render, fireEvent, waitForElementToBeRemoved } from '@testing-library/react' -import FormHelpButton from './FormHelpButton' +import FormHelpButton, { help } from './FormHelpButton' describe('FormHelpButton', () => { it('renders', () => { - const { getByLabelText } = render() + const { getByLabelText } = render() expect(getByLabelText('help')).not.toBeNull() }) it('initially hides help', () => { - const { queryByText } = render() + const { queryByText } = render() expect(queryByText('def')).toBeNull() }) it('opens', async () => { - const { getByLabelText, findByText, queryByText } = render() + const { getByLabelText, findByText, queryByText } = render( + , + ) fireEvent.click(getByLabelText('help')) @@ -26,7 +28,7 @@ describe('FormHelpButton', () => { it('displays help', async () => { const { getByLabelText, findByText, queryByText } = render( - , + , ) fireEvent.click(getByLabelText('help')) @@ -35,8 +37,21 @@ describe('FormHelpButton', () => { expect(queryByText('some help')).toBeTruthy() }) + it('it displays a ReactNode', async () => { + const { getByLabelText, findByText, queryByText } = render( + Hello, ReactNode)} />, + ) + + fireEvent.click(getByLabelText('help')) + + await findByText('Hello, ReactNode') + expect(queryByText('Hello, ReactNode')).toBeTruthy() + }) + it('closes inside', async () => { - const { getByLabelText, findByText, queryByText } = render() + const { getByLabelText, findByText, queryByText } = render( + , + ) fireEvent.click(getByLabelText('help')) await findByText('def') expect(queryByText('def')).not.toBeNull() @@ -50,7 +65,7 @@ describe('FormHelpButton', () => { it('closes outside', async () => { const { getByLabelText, findByText, getByText, queryByText } = render(
- + click outside
, ) diff --git a/src/components/Form/FormHelpButton.tsx b/src/components/Form/FormHelpButton.tsx index 9edacb4a7..e80c6aa06 100644 --- a/src/components/Form/FormHelpButton.tsx +++ b/src/components/Form/FormHelpButton.tsx @@ -2,8 +2,6 @@ import React from 'react' import { Button, Card, CardBody, UncontrolledPopover } from 'reactstrap' -import { onlyText } from 'react-children-utilities' - import { FaQuestion } from 'react-icons/fa' import './FormHelpButton.scss' @@ -12,13 +10,21 @@ function safeId(id: string) { return id.replace('.', '-') } +export interface HelpProps { + label: string + content: string | React.ReactNode +} + +export function help(label: string, content: string | React.ReactNode): HelpProps { + return { label, content } +} + export interface FormHelpButtonProps { identifier: string - label: string | React.ReactNode - help?: string | React.ReactNode + help?: HelpProps } -export default function FormHelpButton({ identifier, label, help }: FormHelpButtonProps) { +export default function FormHelpButton({ identifier, help }: FormHelpButtonProps) { return ( <>