Save months of design and development work for your team with the full design system setup and source code
export { default } from "./Popover";
export type { Props as PopoverProps, Instance as PopoverInstance } from "./Popover.types";
import { classNames } from "utilities/helpers";
import Flyout, { useFlyoutContext, type FlyoutProps } from "components/_private/Flyout";
import Dismissible, { type DismissibleProps } from "components/Dismissible";
import type * as T from "./Popover.types";
import s from "./Popover.module.css";
import getPaddingStyles from "styles/padding";
const Popover = (props: T.Props) => {
const {
width,
variant = "elevated",
triggerType = "click",
position = "bottom",
...flyoutProps
} = props;
const padding = props.padding ?? (variant === "headless" ? 0 : 4);
const trapFocusMode =
props.trapFocusMode || (triggerType === "hover" ? "content-menu" : undefined);
const paddingStyles = getPaddingStyles(padding);
const contentClassName = classNames(
s.content,
!!width && s["content--has-width"],
variant && s[`content--variant-${variant}`]
);
return (
<Flyout
{...(flyoutProps as FlyoutProps)}
position={position}
trapFocusMode={trapFocusMode}
triggerType={triggerType}
width={width}
contentClassName={contentClassName}
contentAttributes={{ style: { ...paddingStyles?.variables } }}
/>
);
};
const PopoverDismissible = (props: DismissibleProps) => {
const { handleClose } = useFlyoutContext();
return <Dismissible {...props} onClose={handleClose} />;
};
Popover.Dismissible = PopoverDismissible;
Popover.Trigger = Flyout.Trigger;
Popover.Content = Flyout.Content;
export default Popover;
.content {
max-width: 360px;
}
.content--variant-elevated {
border-radius: var(--rs-radius-medium);
background: var(--rs-color-background-elevation-overlay);
color: var(--rs-color-foreground-neutral);
border: 1px solid var(--rs-color-border-neutral-faded);
box-shadow: var(--rs-shadow-overlay);
overflow: hidden;
min-width: 220px;
}
.content.content--has-width {
max-width: none;
min-width: 0;
}
@media (--rs-viewport-s) {
.content {
max-width: none;
}
}
import type React from "react";
import type { FlyoutProps, FlyoutInstance } from "components/_private/Flyout";
export type Instance = FlyoutInstance;
export type Props = Pick<
FlyoutProps,
| "id"
| "position"
| "forcePosition"
| "fallbackPositions"
| "onOpen"
| "onClose"
| "width"
| "trapFocusMode"
| "active"
| "defaultActive"
| "contentGap"
| "contentShift"
| "instanceRef"
| "triggerType"
| "disableHideAnimation"
| "disableContentHover"
| "disableCloseOnOutsideClick"
| "containerRef"
| "initialFocusRef"
| "originCoordinates"
> & {
children?: React.ReactNode;
padding?: number;
variant?: "elevated" | "headless";
};
Mo | Tu | We | Th | Fr | Sa | Su |
---|---|---|---|---|---|---|