From c27b761e871c2b90b475cd5c8a6358389d5c4608 Mon Sep 17 00:00:00 2001 From: Prabhdip Gill Date: Thu, 9 Jul 2026 16:34:08 -0700 Subject: [PATCH 1/7] Add tooltip to checkboxes --- src/components/Checkbox/Checkbox.stories.tsx | 6 +++ src/components/Checkbox/Checkbox.tsx | 38 +++++++++++++++---- .../__snapshots__/Checkbox.spec.tsx.snap | 16 ++++---- .../Tree/__snapshots__/Tree.spec.tsx.snap | 4 +- 4 files changed, 46 insertions(+), 18 deletions(-) diff --git a/src/components/Checkbox/Checkbox.stories.tsx b/src/components/Checkbox/Checkbox.stories.tsx index 248c2190b..513e7cbed 100644 --- a/src/components/Checkbox/Checkbox.stories.tsx +++ b/src/components/Checkbox/Checkbox.stories.tsx @@ -46,3 +46,9 @@ export const Disabled = () => <> {renderDisabledCheckboxes('light', 1.6)} {renderDisabledCheckboxes('light', 2)} + +export const WithTooltip = () => + Checkbox label + Disabled label with tooltip + Disabled checked label with tooltip +; diff --git a/src/components/Checkbox/Checkbox.tsx b/src/components/Checkbox/Checkbox.tsx index 55dbe89b5..2ca993082 100644 --- a/src/components/Checkbox/Checkbox.tsx +++ b/src/components/Checkbox/Checkbox.tsx @@ -1,7 +1,10 @@ -import { LabelHTMLAttributes, PropsWithChildren } from "react"; +import React, { LabelHTMLAttributes, PropsWithChildren } from "react"; import { checkboxLabelStyles, checkboxInputStyles, CheckboxVariant, CheckboxSize } from "./sharedCheckboxStyles"; import styled from "styled-components"; import { InputHTMLAttributes } from "react"; +import {useTooltipTriggerState} from 'react-stately'; +import {useTooltipTrigger} from 'react-aria'; +import { CustomTooltip } from '../Tooltip'; const StyledLabel = styled.label<{ bold: boolean; variant: CheckboxVariant; isDisabled?: boolean; }>` ${checkboxLabelStyles} @@ -12,19 +15,38 @@ const StyledInput = styled.input<{ variant: CheckboxVariant; checkboxSize: Check ${checkboxInputStyles} `; +const LabelWithTooltipWrapper = styled.div` + display: inline-block; + position: relative; +`; + type CheckboxProps = PropsWithChildren< Omit, 'type'> & { variant?: CheckboxVariant; size?: CheckboxSize; bold?: boolean; labelProps?: LabelHTMLAttributes; + tooltipText?: string; }>; -export const Checkbox = ({ children, disabled, variant = 'primary', bold = false, size = 1.6, labelProps, ...props }: CheckboxProps) => { - return ( - - - {children} - - ); +export const Checkbox = ({ children, disabled, variant = 'primary', bold = false, size = 1.6, labelProps, tooltipText, ...props }: CheckboxProps) => { + const state = useTooltipTriggerState({delay: 0}); + const ref = React.useRef(null); + + const { triggerProps, tooltipProps } = useTooltipTrigger({delay: 0}, state, ref); + + return tooltipText + ? + + state.open()} variant={variant} checkboxSize={size} isDisabled={disabled} disabled={disabled} /> + {children} + {state.isOpen && ( + {tooltipText} + )} + + + : + + {children} + ; }; diff --git a/src/components/Checkbox/__snapshots__/Checkbox.spec.tsx.snap b/src/components/Checkbox/__snapshots__/Checkbox.spec.tsx.snap index 3669d188f..fef9c1890 100644 --- a/src/components/Checkbox/__snapshots__/Checkbox.spec.tsx.snap +++ b/src/components/Checkbox/__snapshots__/Checkbox.spec.tsx.snap @@ -3,10 +3,10 @@ exports[`Checkbox allows setting props on label 1`] = `