Skip to content
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

[NO JIRA][BpkPopover]: Make popover hoverable #3581

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/bpk-component-popover/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ const WithCustomRenderTargetExample = () => (
</Spacer>
);

const HoverExample = () => (
<Spacer>
<PopoverContainer id="my-popover-1" hoverable />
</Spacer>
);

const WithoutArrowExample = () => (
<Spacer>
<PopoverContainer id="my-popover-2" displayArrow={false} />
Expand Down Expand Up @@ -196,6 +202,7 @@ const VisualExample = () => (
export {
DefaultExample,
WithCustomRenderTargetExample,
HoverExample,
WithoutArrowExample,
WithLabelAsTitleExample,
WithNoCloseButtonIconExample,
Expand Down
2 changes: 2 additions & 0 deletions examples/bpk-component-popover/stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import BpkPopover from '../../packages/bpk-component-popover';
import {
DefaultExample,
WithCustomRenderTargetExample,
HoverExample,
WithoutArrowExample,
WithLabelAsTitleExample,
OnTheSideExample,
Expand All @@ -38,6 +39,7 @@ export default {

export const Default = DefaultExample;
export const WithCustomRenderTarget = WithCustomRenderTargetExample;
export const Hover = HoverExample;
export const WithoutArrow = WithoutArrowExample;
export const WithLabelAsTitle = WithLabelAsTitleExample;
export const WithNoCloseButtonIcon =
Expand Down
16 changes: 12 additions & 4 deletions packages/bpk-component-popover/src/BpkPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import {
arrow,
FloatingArrow,
shift,
useHover,
safePolygon,
} from '@floating-ui/react';

import { surfaceHighlightDay } from '@skyscanner/bpk-foundations-web/tokens/base.es6';
Expand Down Expand Up @@ -98,6 +100,7 @@ export type Props = CloseButtonProps & {
className?: string | null;
closeButtonIcon?: boolean;
closeButtonProps?: Object;
hoverable?: boolean;
isOpen?: boolean;
labelAsTitle?: boolean;
padded?: boolean;
Expand All @@ -118,6 +121,7 @@ const BpkPopover = ({
closeButtonLabel,
closeButtonProps = {},
closeButtonText,
hoverable = false,
id,
isOpen = false,
label,
Expand Down Expand Up @@ -155,12 +159,16 @@ const BpkPopover = ({

const click = useClick(context);
const dismiss = useDismiss(context);
const hover = useHover(context, {
enabled: hoverable,
mouseOnly: true,
handleClose: safePolygon({
requireIntent: false,
}),
});

// Merge all the interactions into prop getters
const { getFloatingProps, getReferenceProps } = useInteractions([
click,
dismiss,
]);
const { getFloatingProps, getReferenceProps } = useInteractions([click, dismiss, hover]);

const targetClick = target?.props?.onClick;
const referenceProps = targetClick ? getReferenceProps({
Expand Down
Loading