Skip to content

Commit 990f33f

Browse files
committed
Add example of adding a border to popup
This shows the use of the --popup-border-width parameter along with how to add matching border to the arrow itself.
1 parent 6277b6e commit 990f33f

File tree

1 file changed

+84
-0
lines changed
  • packages/webawesome/docs/docs/components

1 file changed

+84
-0
lines changed

packages/webawesome/docs/docs/components/popup.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,90 @@ By default, the arrow will be aligned as close to the center of the _anchor_ as
426426
</div>
427427
```
428428

429+
### Adding a border
430+
431+
Borders can also be added to the popup element by targetting the contents of the `wa-popup` element. This styling can also be extended to the arrow itself by targetting `.arrow` class in the popup.
432+
433+
When adding borders to the popup element which has an arrow, make sure to set the `--popup-border-width` custom property to match the width of the border of the popup. Setting this will allow the arrow to overlap the border of the popup so that they visually appear connected.
434+
435+
```html {.example}
436+
<div class="popup-border">
437+
<wa-popup placement="top" arrow arrow-placement="anchor" distance="8" active>
438+
<span slot="anchor"></span>
439+
<div class="box"></div>
440+
</wa-popup>
441+
442+
<div class="popup-border-options">
443+
<wa-combobox label="Placement" name="placement" placeholder="Select placement..." class="popup-overview-select"></wa-combobox>
444+
</div>
445+
446+
<style>
447+
448+
.popup-border span[slot='anchor'] {
449+
display: inline-block;
450+
width: 150px;
451+
height: 150px;
452+
border: dashed 2px var(--wa-color-neutral-fill-loud);
453+
margin: 50px;
454+
}
455+
456+
.popup-border .box {
457+
width: 100px;
458+
height: 50px;
459+
background: var(--wa-color-brand-on-loud);
460+
border-radius: var(--wa-border-radius-m);
461+
border: var(--wa-panel-border-width) solid var(--wa-color-brand-border-loud);
462+
border-style: var(--wa-panel-border-style);
463+
box-shadow: var(--wa-shadow-l);
464+
}
465+
466+
.popup-border wa-popup {
467+
--arrow-color: var(--wa-color-brand-on-loud);
468+
--popup-border-width: var(--wa-panel-border-width);
469+
470+
&::part(arrow) {
471+
border-bottom: var(--wa-panel-border-width) var(--wa-panel-border-style) var(--wa-color-brand-border-loud);
472+
border-right: var(--wa-panel-border-width) var(--wa-panel-border-style) var(--wa-color-brand-border-loud);
473+
}
474+
}
475+
476+
.popup-border-options {
477+
display: flex;
478+
flex-wrap: wrap;
479+
align-items: end;
480+
gap: 1rem;
481+
}
482+
483+
.popup-border-options wa-combobox {
484+
width: 160px;
485+
}
486+
</style>
487+
488+
<script type="module">
489+
await customElements.whenDefined('wa-combobox');
490+
491+
const container = document.querySelector('.popup-border');
492+
const popup = container.querySelector('wa-popup');
493+
const placement = container.querySelector('wa-combobox[name="placement"]');
494+
495+
const placements = ['top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end', 'right', 'right-start', 'right-end', 'left', 'left-start', 'left-end'];
496+
497+
placements.forEach(value => {
498+
const option = document.createElement('wa-option');
499+
option.value = value;
500+
option.textContent = value;
501+
placement.append(option);
502+
});
503+
504+
await placement.updateComplete;
505+
506+
placement.value = 'top';
507+
508+
placement.addEventListener('change', () => (popup.placement = placement.value));
509+
</script>
510+
</div>
511+
```
512+
429513
{# TODO: this example totally destroys browsers. Needs investigation.
430514

431515
### Syncing with the Anchor's Dimensions

0 commit comments

Comments
 (0)