sp-popover

Examples API

Attributes and Properties #

Property Attribute Type Default Description dialog dialog boolean false Whether the popover should manage the application of padding to its content or not. open open boolean false Whether the popover is visible or not. placement placement "auto" | "auto-start" | "auto-end" | "top" | "bottom" | "right" | "left" | "top-start" | "top-end" | "bottom-start" | "bottom-end" | "right-start" | "right-end" | "left-start" | "left-end" | "none" 'none' tip tip boolean false

Slots #

Name Description default slot content to display within the Popover

Description #

An <sp-popover> is used to display transient content (menus, options, additional actions etc.) and appears when clicking/tapping on a source (tools, buttons, etc.) It stands out via its visual style (stroke and drop shadow) and floats on top of the rest of the interface. This component does not implement the actual overlay behavior and interactions. This is handled by the Overlay system.

Usage #

See it on NPM! How big is this package in your project? Try it on webcomponents.dev

yarn add @spectrum-web-components/popover

Import the side effectful registration of <sp-popover> via:

import '@spectrum-web-components/popover/sp-popover.js';

When looking to leverage the Popover base class as a type and/or for extension purposes, do so via:

import { Popover } from '@spectrum-web-components/popover';

Example #

<div
style="
color: var(--spectrum-gray-800);
height: 200px;
position: relative;
width: 320px;
max-width: 100%;
"

>

<sp-popover open style="--spectrum-popover-dialog-min-width: 0;">
<sp-dialog>
<h3 slot="heading">Popover title</h3>
Cupcake ipsum dolor sit amet jelly beans. Chocolate jelly caramels.
Icing soufflé chupa chups donut cheesecake. Jelly-o chocolate cake
sweet roll cake danish candy biscuit halvah
</sp-dialog>
</sp-popover>
</div>

Variants #

Default with no tip #

Default popover with no tip and no placement. Popovers will fill up the space of they're containing element by default. The default popover has no padding by default

<div
style="
color: var(--spectrum-gray-800);
height: 200px;
position: relative;
width: 320px;
max-width: 100%;
"

>

<sp-popover
variant="default"
open
style="max-width: 320px; --spectrum-popover-dialog-min-width: 0;"
>

<div style="font-size: 14px; padding: 10px">
<div
style="
font-size: 18px;
font-weight: 700;
padding-bottom: 30px;
"

>

Popover title
</div>
<div style="font-size: 14px">
Cupcake ipsum dolor sit amet jelly beans. Chocolate jelly
caramels. Icing soufflé chupa chups donut cheesecake. Jelly-o
chocolate cake sweet roll cake danish candy biscuit halvah
</div>
</div>
</sp-popover>
</div>

Dialog popovers #

To apply a managed about of padding within your <sp-popover> you may choose to wrap you slotted content with an <sp-dialog> element, as seen below:

<div
style="
color: var(--spectrum-gray-800);
height: 200px;
position: relative;
width: 320px;
max-width: 100%;
"

>

<sp-popover open style="--spectrum-popover-dialog-min-width: 0;">
<div
style="
font-size: 18px;
font-weight: 700;
padding-bottom: 30px;
"

>

Popover title
</div>
<div style="font-size: 14px">
Cupcake ipsum dolor sit amet jelly beans. Chocolate jelly caramels.
Icing soufflé chupa chups donut cheesecake. Jelly-o chocolate cake
sweet roll cake danish candy biscuit halvah
</div>
</sp-popover>
</div>

Popover with tip #

The placement attribute can be used to customize from where the <sp-popover> points to content to which it is related. placement="top" will point down to the related content from the top, etc.

Top
<div
style="
color: var(--spectrum-gray-800);
height: 200px;
position: relative;
width: 320px;
max-width: 100%;
"

>

<sp-popover
placement="top"
tip
open
style="--spectrum-popover-dialog-min-width: 0;"
>

<sp-dialog>
<h3 slot="heading">Popover title</h3>
Cupcake ipsum dolor sit amet jelly beans. Chocolate jelly caramels.
Icing soufflé chupa chups donut cheesecake. Jelly-o chocolate cake
sweet roll cake danish candy biscuit halvah
</sp-dialog>
</sp-popover>
</div>
Right
<div
style="
color: var(--spectrum-gray-800);
height: 200px;
position: relative;
width: 320px;
max-width: 100%;
"

>

<sp-popover
placement="right"
tip
open
style="--spectrum-popover-dialog-min-width: 0;"
>

<sp-dialog>
<h3 slot="heading">Popover title</h3>
Cupcake ipsum dolor sit amet jelly beans. Chocolate jelly caramels.
Icing soufflé chupa chups donut cheesecake. Jelly-o chocolate cake
sweet roll cake danish candy biscuit halvah
</sp-dialog>
</sp-popover>
</div>
Bottom
<div
style="
color: var(--spectrum-gray-800);
height: 200px;
position: relative;
width: 320px;
max-width: 100%;
"

>

<sp-popover
placement="bottom"
tip
open
style="--spectrum-popover-dialog-min-width: 0;"
>

<sp-dialog>
<h3 slot="heading">Popover title</h3>
Cupcake ipsum dolor sit amet jelly beans. Chocolate jelly caramels.
Icing soufflé chupa chups donut cheesecake. Jelly-o chocolate cake
sweet roll cake danish candy biscuit halvah
</sp-dialog>
</sp-popover>
</div>
Left
<div
style="
color: var(--spectrum-gray-800);
height: 200px;
position: relative;
width: 320px;
max-width: 100%;
"

>

<sp-popover
placement="left"
tip
open
style="--spectrum-popover-dialog-min-width: 0;"
>

<sp-dialog>
<h3 slot="heading">Popover title</h3>
Cupcake ipsum dolor sit amet jelly beans. Chocolate jelly caramels.
Icing soufflé chupa chups donut cheesecake. Jelly-o chocolate cake
sweet roll cake danish candy biscuit halvah
</sp-dialog>
</sp-popover>
</div>