From a1e8f1e4426ed3560ce1b76fb73a6969388ed253 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Thu, 7 Apr 2022 22:57:15 +0200 Subject: chore: add a SelectWithTooltip component --- .../molecules/forms/select-with-tooltip.tsx | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/components/molecules/forms/select-with-tooltip.tsx (limited to 'src/components/molecules/forms/select-with-tooltip.tsx') diff --git a/src/components/molecules/forms/select-with-tooltip.tsx b/src/components/molecules/forms/select-with-tooltip.tsx new file mode 100644 index 0000000..5e48d62 --- /dev/null +++ b/src/components/molecules/forms/select-with-tooltip.tsx @@ -0,0 +1,58 @@ +import Select, { SelectProps } from '@components/atoms/forms/select'; +import { FC, useState } from 'react'; +import HelpButton from '../buttons/help-button'; +import Tooltip, { TooltipProps } from '../modals/tooltip'; +import styles from './select-with-tooltip.module.scss'; + +export type SelectWithTooltipProps = SelectProps & + Pick & { + /** + * The select label. + */ + label: string; + /** + * Set additional classes to the tooltip wrapper. + */ + tooltipClasses?: string; + }; + +/** + * SelectWithTooltip component + * + * Render a select with a button to display a tooltip about options. + */ +const SelectWithTooltip: FC = ({ + title, + content, + id, + label, + tooltipClasses = '', + ...props +}) => { + const [isTooltipOpened, setIsTooltipOpened] = useState(false); + const buttonModifier = isTooltipOpened ? styles['btn--activated'] : ''; + const tooltipModifier = isTooltipOpened + ? styles['tooltip--visible'] + : styles['tooltip--hidden']; + + return ( +
+ +