Skip to content
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
10 changes: 10 additions & 0 deletions apps/website/screens/components/popover/code/PopoverCodePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ const sections = [
<td>Controlled open state of the popover. If it is left undefined, it will be uncontrolled.</td>
<td>-</td>
</tr>
<tr>
<td>offset</td>
<td>
<TableCode>number</TableCode>
</td>
<td>Distance in pixels from the trigger element to the popover.</td>
<td>
<TableCode>4</TableCode>
</td>
</tr>
<tr>
<td>onClose</td>
<td>
Expand Down
14 changes: 9 additions & 5 deletions packages/lib/src/popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import { useEffect, useId, useRef, useState } from "react";
import * as Popover from "@radix-ui/react-popover";
import { PopoverPropsType } from "./types";

const PopoverWrapper = styled.div`
width: fit-content;
`;

const PopoverContent = styled.div`
box-sizing: border-box;
border-radius: var(--border-radius-m);
box-shadow: var(--shadow-400);
padding: var(--spacing-gap-s);
padding: var(--spacing-padding-xs);
background-color: var(--color-bg-neutral-lightest);
`;

Expand All @@ -33,6 +37,7 @@ const DxcPopover = ({
children,
hasTip = false,
isOpen,
offset = 4,
onOpen,
onClose,
popoverContent,
Expand All @@ -55,9 +60,8 @@ const DxcPopover = ({
{asChild ? (
children
) : (
<div
<PopoverWrapper
role="button"
style={{ width: "fit-content" }}
onClick={
actionToOpen === "click"
? () => handleTrigger(isControlled.current, setOpened, true, onOpen)
Expand All @@ -75,15 +79,15 @@ const DxcPopover = ({
}
>
{children}
</div>
</PopoverWrapper>
)}
</Popover.Trigger>
<Popover.Portal container={portalContainer}>
<Popover.Content
aria-label="Popover content"
align={align}
side={side}
sideOffset={4}
sideOffset={offset}
onInteractOutside={() => handleTrigger(isControlled.current, setOpened, false, onClose)}
onEscapeKeyDown={() => handleTrigger(isControlled.current, setOpened, false, onClose)}
onMouseEnter={
Expand Down
2 changes: 2 additions & 0 deletions packages/lib/src/popover/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export type PopoverPropsType = {
hasTip?: boolean;
/** Controlled open state of the popover. If it is left undefined, it will be uncontrolled. */
isOpen?: boolean;
/** Distance in pixels from the trigger element to the popover. */
offset?: number;
/** Callback function when the popover is opened.
* Used only in controlled mode and if the trigger lacks the events to manage the controlled behavior. */
onOpen?: () => void;
Expand Down
Loading