Skip to content

Commit

Permalink
[NO JIRA]: Make popover hoverable (#3581)
Browse files Browse the repository at this point in the history
Co-authored-by: James Ronald <[email protected]>
  • Loading branch information
olliecurtis and jronald01 authored Nov 29, 2024
1 parent f1c97b7 commit bf0d774
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
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

0 comments on commit bf0d774

Please sign in to comment.