Files
OpenFrontIO/src/client/components/baseComponents/Modal.ts
T
Ryan 70f2abb181 Homepage update & add 3 public lobbies (#3191)
## Description:

Update UI 
check https://homepageupdate.openfront.dev/ 

Improved mobile UI (now fills whole screen for all modals) e.g.:
<img width="432" height="852" alt="image"
src="https://github.com/user-attachments/assets/56de40af-4137-4c57-96b7-3910c9a665b8"
/>

Converted PublicLobby to be "GameModeSelector" to get a nicer 4x4 grid
div, where <GameModeSelector> now handles all the username validation
now (removed redundant code from modals such as matchmaking) also fixed
a bug where someone could have "[XX] X" as thier username (when the
minimum should be 3 chars for their name)

Now visually displays the 3 lobbies ffa/team/special (which is a
continuation from the work done in: #3196 )
<img width="818" height="563" alt="image"
src="https://github.com/user-attachments/assets/a15cd31b-6061-4fb8-83ee-ffde6225cfa7"
/>

updated the background:
<img width="1919" height="807" alt="image"
src="https://github.com/user-attachments/assets/358a7434-51b8-4540-baf2-d1be05053c44"
/>



slightly updated the glassy-look to be less glassy:
<img width="825" height="729" alt="image"
src="https://github.com/user-attachments/assets/1801871b-bbf8-43db-ac53-489337ae80a5"
/>



## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

## Please put your Discord username so you can be contacted if a bug or
regression is found:

w.o.n
2026-02-18 23:11:01 -06:00

115 lines
3.5 KiB
TypeScript

import { LitElement, html, unsafeCSS } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import tailwindStyles from "../../styles.css?inline";
@customElement("o-modal")
export class OModal extends LitElement {
static styles = [unsafeCSS(tailwindStyles)];
@state() public isModalOpen = false;
static openCount = 0;
@property({ type: Boolean })
public inline = false;
@property({ type: Boolean })
public alwaysMaximized = false;
@property({ type: Boolean })
public hideCloseButton = false;
@property({ type: String })
public title = "";
@property({ type: Boolean })
public hideHeader = false;
@property({ type: String })
public maxWidth = "";
public onClose?: () => void;
public open() {
if (!this.isModalOpen) {
if (!this.inline) {
OModal.openCount = OModal.openCount + 1;
if (OModal.openCount === 1) document.body.style.overflow = "hidden";
}
this.isModalOpen = true;
}
}
public close() {
if (this.isModalOpen) {
this.isModalOpen = false;
this.onClose?.();
if (!this.inline) {
OModal.openCount = Math.max(0, OModal.openCount - 1);
if (OModal.openCount === 0) document.body.style.overflow = "";
}
}
}
disconnectedCallback() {
// Ensure global counter is decremented if this modal is removed while open.
if (this.isModalOpen && !this.inline) {
OModal.openCount = Math.max(0, OModal.openCount - 1);
if (OModal.openCount === 0) document.body.style.overflow = "";
}
super.disconnectedCallback();
}
render() {
const backdropClass = this.inline
? "relative z-10 w-full h-full flex items-stretch bg-transparent"
: "fixed inset-0 z-[9999] bg-black/60 flex items-center justify-center overflow-hidden";
const wrapperClass = this.inline
? "relative flex flex-col w-full h-full m-0 max-w-full max-h-none shadow-none"
: `relative flex flex-col w-full h-full lg:w-[90%] lg:h-auto lg:min-w-[400px] lg:max-w-[900px] lg:m-8 lg:rounded-lg shadow-[0_20px_60px_rgba(0,0,0,0.8)] lg:max-h-[calc(100vh-4rem)] ${
this.alwaysMaximized ? "h-auto" : ""
}`;
const wrapperStyle =
!this.inline && this.maxWidth ? `max-width: ${this.maxWidth};` : "";
return html`
${this.isModalOpen
? html`
<aside
class="${backdropClass}"
@click=${this.inline ? null : () => this.close()}
>
<div
@click=${(e: Event) => e.stopPropagation()}
class="${wrapperClass}"
style="${wrapperStyle}"
>
${this.inline || this.hideCloseButton
? html``
: html`<div
class="absolute top-5 right-5 z-10 text-white cursor-pointer"
@click=${() => this.close()}
>
</div>`}
${!this.hideHeader && this.title
? html`<div
class="px-[1.4rem] py-[1rem] text-2xl font-bold text-white"
>
${this.title}
</div>`
: html``}
<section
class="relative flex-1 min-h-0 p-0 lg:p-[1.4rem] text-white bg-[#23232382] backdrop-blur-md lg:rounded-lg overflow-y-auto"
>
<slot></slot>
</section>
</div>
</aside>
`
: html``}
`;
}
}