forked from Jigsaw-Code/outline-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor and improve popover element
- Loading branch information
1 parent
5854d2c
commit 2feeaea
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
x/examples/outline-connectivity-app/shared_frontend/pages/connectivity_test/popover_info.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { css, html, LitElement, nothing } from "lit"; | ||
import { property, customElement, query } from "lit/decorators.js"; | ||
import { unsafeHTML } from 'lit/directives/unsafe-html.js'; | ||
|
||
@customElement('info-popup') | ||
export class InfoPopup extends LitElement { | ||
@property({ type: Boolean }) isPopupVisible = false; | ||
@property({ type: String }) popupText = 'This is an <strong>info</strong> pop-up. Click the button to toggle visibility.' | ||
|
||
@query('#my-popover') | ||
popoverElement: HTMLElement; | ||
|
||
static styles = css` | ||
.popup { | ||
top: -50%; /* Position above the element */ | ||
font-family: var(--font-sans-serif); | ||
padding: 25px; | ||
max-width: 75%; | ||
box-sizing: border-box; | ||
border: 1px solid black; | ||
background-color: white; | ||
box-shadow: 0px 0px 10px rgba(0,0,0,0.7); | ||
} | ||
.close-button { | ||
position: absolute; | ||
top: 10px; | ||
right: 10px; | ||
cursor: pointer; | ||
font-size: 20px; /* Adjust size as needed */ | ||
} | ||
`; | ||
|
||
render() { | ||
return html` | ||
<div @click="${this.showPopover}" popovertarget="my-popover" popovertargetaction="show">ℹ️</div> | ||
<div popover="auto" class="popup" id="my-popover"> | ||
<span @click="${this.closePopover}" class="close-button" popovertargetaction="hide">×</span> | ||
${unsafeHTML(this.popupText)} | ||
</div> | ||
`; | ||
} | ||
|
||
showPopover() { | ||
this.popoverElement.showPopover(); | ||
} | ||
|
||
closePopover() { | ||
if (this.popoverElement) { | ||
this.popoverElement.hidePopover(); | ||
} | ||
} | ||
} |