-
Notifications
You must be signed in to change notification settings - Fork 69
Exports Tooltip event handler utils #2910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
530b369
feat(tooltip): implement event handler utils for hover and click inte…
TheSonOfThomp c1ef609
changesets
TheSonOfThomp 5420b98
LG-5139: optional icon in chart titles (#2899)
charcoalyy 3be1113
Adds missing `./static` directory to SB addon (#2905)
TheSonOfThomp c24fe7d
Merge branch 'main' into a/tooltip-utils
TheSonOfThomp e14515f
clean up handlers. mv types
TheSonOfThomp 7397bb0
simplifies hook
TheSonOfThomp debb0e3
adds tests
TheSonOfThomp beb7cbe
adds DEFAULT_HOVER_DELAY
TheSonOfThomp ffefe0f
update triggerEventHandlers
TheSonOfThomp 040fc71
tsdoc
TheSonOfThomp b712f35
Merge branch 'main' into a/tooltip-utils
TheSonOfThomp 227531d
only hook
TheSonOfThomp 422b5ab
Merge branch 'main' into a/tooltip-utils
TheSonOfThomp bbab87b
Merge branch 'main' into a/tooltip-utils
TheSonOfThomp de62b44
Update useTooltipTriggerEventHandlers.spec.tsx
TheSonOfThomp 6a3e3be
Merge branch 'a/tooltip-utils' of https://github.com/mongodb/leafygre…
TheSonOfThomp 6243c75
memoize
TheSonOfThomp b1ef563
Merge branch 'main' into a/tooltip-utils
TheSonOfThomp 9e5c696
Merge branch 'main' into a/tooltip-utils
TheSonOfThomp c946b3e
Update packages/tooltip/src/Tooltip/utils/useTooltipTriggerEventHandl…
TheSonOfThomp 712760e
SA feedback 👍
TheSonOfThomp abbefea
Merge branch 'a/tooltip-utils' of https://github.com/mongodb/leafygre…
TheSonOfThomp d697951
Merge branch 'main' into a/tooltip-utils
TheSonOfThomp 94b1976
Update useTooltipTriggerEventHandlers.spec.tsx
TheSonOfThomp f9e12d3
Merge branch 'a/tooltip-utils' of https://github.com/mongodb/leafygre…
TheSonOfThomp 9ce40cf
type names
TheSonOfThomp faafb16
rm delay escape hatch
TheSonOfThomp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@leafygreen-ui/tooltip': minor | ||
--- | ||
|
||
Exports `Tooltip` as a named export (as well as default) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
'@leafygreen-ui/tooltip': minor | ||
--- | ||
|
||
Exports `useTooltipTriggerEventHandlers` to enable handling external tooltip triggers. | ||
|
||
```tsx | ||
const [open, setOpen] = useState(false); | ||
const tooltipEventHandlers = useTooltipTriggerEventHandlers({ | ||
triggerEvent: TriggerEvent.Hover, | ||
setState: setOpen, | ||
onFocus: (e) => { console.log(e) } // side effects called on focus of the trigger | ||
}); | ||
|
||
return ( | ||
<> | ||
<Button ref={triggerRef} {...tooltipEventHandlers}> | ||
Button | ||
</Button> | ||
<Tooltip | ||
refEl={triggerRef} | ||
open={open} | ||
setOpen={setOpen} | ||
>Content</Tooltip> | ||
</> | ||
) | ||
``` | ||
TheSonOfThomp marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
packages/tooltip/src/Tooltip/utils/tooltipHandlers.types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { FocusEventHandler, MouseEventHandler, RefObject } from 'react'; | ||
|
||
import type { TriggerEvent } from '../Tooltip.types'; | ||
|
||
export interface UseTooltipEventsBaseArgs { | ||
/** | ||
* The `useState` dispatch method to toggle the tooltip state | ||
*/ | ||
setState: React.Dispatch<React.SetStateAction<boolean>>; | ||
|
||
/** | ||
* Whether the tooltip event handlers should be enabled | ||
*/ | ||
isEnabled?: boolean; | ||
|
||
/** | ||
* The delay in milliseconds before the tooltip opens on hover. | ||
*/ | ||
delay?: number; | ||
TheSonOfThomp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
export interface CreateTooltipEventsArgsHover { | ||
TheSonOfThomp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* Whether the tooltip will open/close on `hover` or `click` events. | ||
* Note: must match the value passed onto `tooltip` | ||
*/ | ||
triggerEvent: typeof TriggerEvent.Hover; | ||
|
||
/** | ||
* A ref to the Tooltip element. | ||
* Optional when the trigger event is `hover` | ||
*/ | ||
tooltipRef?: RefObject<HTMLElement>; | ||
|
||
/** Additional side effects to run on this event */ | ||
onMouseEnter?: MouseEventHandler<HTMLElement>; | ||
|
||
/** Additional side effects to run on this event */ | ||
onMouseLeave?: MouseEventHandler<HTMLElement>; | ||
|
||
/** Additional side effects to run on this event */ | ||
onFocus?: FocusEventHandler<HTMLElement>; | ||
|
||
/** Additional side effects to run on this event */ | ||
onBlur?: FocusEventHandler<HTMLElement>; | ||
} | ||
|
||
export interface CreateTooltipEventsArgsClick { | ||
/** | ||
* Whether the tooltip will open/close on `hover` or `click` events. | ||
* Note: must match the value passed onto `tooltip` | ||
*/ | ||
triggerEvent: typeof TriggerEvent.Click; | ||
|
||
/** | ||
* A ref to the Tooltip element. | ||
* Optional when the trigger event is `hover` | ||
*/ | ||
tooltipRef: RefObject<HTMLElement>; | ||
|
||
/** | ||
* Additional side effects to run on this event | ||
*/ | ||
onClick?: MouseEventHandler<HTMLElement>; | ||
} | ||
|
||
export type CreateTooltipEventsArgs<Trigger extends TriggerEvent> = | ||
UseTooltipEventsBaseArgs & | ||
(Trigger extends 'hover' | ||
? CreateTooltipEventsArgsHover | ||
: Trigger extends 'click' | ||
? CreateTooltipEventsArgsClick | ||
: never); | ||
|
||
export interface TooltipHoverEvents { | ||
onMouseEnter: MouseEventHandler<HTMLElement>; | ||
onMouseLeave: MouseEventHandler<HTMLElement>; | ||
onFocus: FocusEventHandler<HTMLElement>; | ||
onBlur: FocusEventHandler<HTMLElement>; | ||
onClick: undefined; | ||
} | ||
export interface TooltipClickEvents { | ||
onClick: MouseEventHandler<HTMLElement>; | ||
onMouseEnter: undefined; | ||
onMouseLeave: undefined; | ||
onFocus: undefined; | ||
onBlur: undefined; | ||
} | ||
|
||
export type TooltipEventHandlers<Trigger extends TriggerEvent> = | ||
Trigger extends 'hover' | ||
? TooltipHoverEvents | ||
: Trigger extends 'click' | ||
? TooltipClickEvents | ||
: never; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.