-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tooltip fixes and added PassiveTrigger
- Loading branch information
1 parent
f9f2f9f
commit fbc46e5
Showing
10 changed files
with
266 additions
and
42 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
packages/components/src/Tooltip/src/PassiveTrigger.module.css
This file contains 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 @@ | ||
.hop-PassiveTrigger { | ||
--hop-PassiveTrigger-inline-size: max-content; | ||
|
||
inline-size: var(--hop-PassiveTrigger-inline-size); | ||
} |
This file contains 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,80 @@ | ||
import { useStyledSystem, type StyledSystemProps } from "@hopper-ui/styled-system"; | ||
import clsx from "clsx"; | ||
import { forwardRef, useRef, type ForwardedRef, type ReactNode } from "react"; | ||
import { useFocusable } from "react-aria"; | ||
import { useContextProps } from "react-aria-components"; | ||
|
||
import { cssModule, type BaseComponentDOMProps } from "../../utils/index.ts"; | ||
|
||
import { PassiveTriggerContext } from "./PassiveTriggerContext.ts"; | ||
|
||
import styles from "./PassiveTrigger.module.css"; | ||
|
||
export const GlobalPassiveTriggerCssSelector = "hop-PassiveTrigger"; | ||
|
||
export interface PassiveTriggerProps extends StyledSystemProps, BaseComponentDOMProps { | ||
/** | ||
* The children of the PassiveTrigger. | ||
*/ | ||
children?: ReactNode; | ||
} | ||
/** | ||
* A PassiveTrigger wraps a trigger element and Tooltip, handling visibility and positioning. | ||
* | ||
* [View Documentation](TODO) | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
function PassiveTrigger(props: PassiveTriggerProps, ref: ForwardedRef<HTMLDivElement>) { | ||
[props, ref] = useContextProps(props, ref, PassiveTriggerContext); | ||
|
||
const { stylingProps, ...ownProps } = useStyledSystem(props); | ||
const backupRef = useRef<HTMLDivElement>(null); | ||
const determinedRef = (ref ?? backupRef); | ||
const { focusableProps } = useFocusable(ownProps, determinedRef); | ||
const { | ||
children, | ||
className, | ||
slot, | ||
style: styleProp, | ||
...otherProps | ||
} = ownProps; | ||
|
||
const classNames = clsx( | ||
className, | ||
GlobalPassiveTriggerCssSelector, | ||
cssModule( | ||
styles, | ||
"hop-FloatingBadge" | ||
), | ||
stylingProps.className | ||
); | ||
|
||
const style = { | ||
...stylingProps.style, | ||
...styleProp | ||
}; | ||
|
||
return ( | ||
<div | ||
ref={determinedRef} | ||
slot={slot ?? undefined} | ||
className={classNames} | ||
style={style} | ||
{...focusableProps} | ||
{...otherProps} | ||
> | ||
{children} | ||
</div> | ||
); | ||
} | ||
|
||
/** | ||
* Wraps a tooltip trigger that is not normally focusable. | ||
* | ||
* [View Documentation](TODO) | ||
*/ | ||
const _PassiveTrigger = forwardRef<HTMLDivElement, PassiveTriggerProps>(PassiveTrigger); | ||
_PassiveTrigger.displayName = "PassiveTrigger"; | ||
|
||
export { _PassiveTrigger as PassiveTrigger }; | ||
|
This file contains 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,8 @@ | ||
import { createContext } from "react"; | ||
import type { ContextValue } from "react-aria-components"; | ||
|
||
import type { PassiveTriggerProps } from "./PassiveTrigger.tsx"; | ||
|
||
export const PassiveTriggerContext = createContext<ContextValue<PassiveTriggerProps, HTMLDivElement>>({}); | ||
|
||
PassiveTriggerContext.displayName = "PassiveTriggerContext"; |
This file contains 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 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 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 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 |
---|---|---|
@@ -1,2 +1,6 @@ | ||
export * from "./PassiveTrigger.tsx"; | ||
export * from "./PassiveTriggerContext.ts"; | ||
export * from "./Tooltip.tsx"; | ||
export * from "./TooltipContext.ts"; | ||
export * from "./TooltipTrigger.tsx"; | ||
|
This file contains 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
Oops, something went wrong.