-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8994ce8
commit be9718a
Showing
10 changed files
with
77 additions
and
14 deletions.
There are no files selected for viewing
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
15 changes: 13 additions & 2 deletions
15
src/components/hover-card/components/hover-card-trigger.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
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,13 +1,36 @@ | ||
import { useControllableState } from '@/components/_shared/hooks/use-controllable-state' | ||
import { HoverCardProvider } from '@/components/hover-card/contexts/hover-card-context' | ||
import type { HoverCardProps } from '@/components/hover-card/types/hover-card' | ||
import { HoverCard as HoverCardPrimitive } from '@radix-ui/react-hover-card' | ||
import React from 'react' | ||
|
||
// @TODO add controllable state and and manipulation for open close on trigger | ||
|
||
const HoverCard = (props: HoverCardProps) => { | ||
const { openDelay = 300, closeDelay = 300, ...restProps } = props | ||
const { | ||
defaultOpen, | ||
open: openProp, | ||
onOpenChange, | ||
children, | ||
shouldTriggerToggleOpen = false, | ||
openDelay = 0, | ||
closeDelay = 300, | ||
} = props | ||
|
||
const [open, setOpen] = useControllableState({ | ||
defaultProp: defaultOpen, | ||
prop: openProp, | ||
onChange: onOpenChange, | ||
}) | ||
|
||
return <HoverCardPrimitive openDelay={openDelay} closeDelay={closeDelay} {...restProps} /> | ||
return ( | ||
<HoverCardPrimitive | ||
open={open} | ||
onOpenChange={setOpen} | ||
openDelay={openDelay} | ||
closeDelay={closeDelay} | ||
> | ||
<HoverCardProvider value={{ shouldTriggerToggleOpen, setOpen }}>{children}</HoverCardProvider> | ||
</HoverCardPrimitive> | ||
) | ||
} | ||
|
||
export { HoverCard } |
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,4 @@ | ||
const DEFAULT_HOVER_CARD_CONTENT_CLASSNAME = | ||
'render-ui-hover-card-content data-[state=closed]:data-[side=bottom]:animate-popover-exit-from-top-and-fade-out data-[state=closed]:data-[side=top]:animate-popover-exit-from-bottom-and-fade-out data-[state=closed]:data-[side=right]:animate-popover-exit-from-left-and-fade-out data-[state=closed]:data-[side=left]:animate-popover-exit-from-right-and-fade-out data-[state=open]:data-[side=bottom]:animate-popover-enter-to-top-and-fade-in data-[state=open]:data-[side=left]:animate-popover-enter-to-right-and-fade-in data-[state=open]:data-[side=right]:animate-popover-enter-to-left-and-fade-in data-[state=open]:data-[side=top]:animate-popover-enter-to-bottom-and-fade-in z-50 box-border w-fit rounded-md border bg-background border-mode-accent text-mode-contrast p-4 shadow-md outline-none will-change-[transform,opacity] data-[side=bottom]:origin-top data-[side=left]:origin-right data-[side=right]:origin-left data-[side=top]:origin-bottom' | ||
|
||
export { DEFAULT_HOVER_CARD_CONTENT_CLASSNAME } |
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,12 @@ | ||
import { initializeContext } from '@renderui/utils' | ||
|
||
import type { HoverCardContext } from '@/components/hover-card/types/hover-card-context' | ||
|
||
const [HoverCardProvider, useHoverCardContext] = initializeContext<HoverCardContext>({ | ||
errorMessage: 'Components using hoverCard context must be wrapped in a <HoverCard />.', | ||
providerName: 'HoverCardProvider', | ||
hookName: 'useHoverCardContext', | ||
name: 'HoverCardContext', | ||
}) | ||
|
||
export { HoverCardProvider, useHoverCardContext } |
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,6 @@ | ||
type HoverCardContext = { | ||
shouldTriggerToggleOpen: boolean | ||
setOpen: React.Dispatch<React.SetStateAction<boolean>> | ||
} | ||
|
||
export type { HoverCardContext } |
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 +1,7 @@ | ||
export type { HoverCardProps } from '@radix-ui/react-hover-card' | ||
import type { Simplify } from '@/components/_shared/types/simplify' | ||
|
||
import type { HoverCardProps as HoverCardPrimitiveProps } from '@radix-ui/react-hover-card' | ||
|
||
type HoverCardProps = Simplify<HoverCardPrimitiveProps & { shouldTriggerToggleOpen?: boolean }> | ||
|
||
export type { HoverCardProps } |