mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-24 06:14:41 +00:00
e79c805804
## Description: migrate tailwindcss v3 to v4 ## 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: wraith4081 --------- Co-authored-by: iamlewis <lewismmmm@gmail.com> Co-authored-by: Ryan <7389646+ryanbarlow97@users.noreply.github.com>
115 lines
2.8 KiB
TypeScript
115 lines
2.8 KiB
TypeScript
import { LitElement, css, html } from "lit";
|
|
import { customElement, state } from "lit/decorators.js";
|
|
import { renderPlayerFlag } from "../core/CustomFlag";
|
|
import { FlagSchema } from "../core/Schemas";
|
|
import { translateText } from "./Utils";
|
|
|
|
const flagKey: string = "flag";
|
|
|
|
@customElement("flag-input")
|
|
export class FlagInput extends LitElement {
|
|
@state() public flag: string = "";
|
|
|
|
static styles = css`
|
|
@media (max-width: 768px) {
|
|
.flag-modal {
|
|
width: 80vw;
|
|
}
|
|
|
|
.dropdown-item {
|
|
width: calc(100% / 3 - 15px);
|
|
}
|
|
}
|
|
`;
|
|
|
|
public getCurrentFlag(): string {
|
|
return this.flag;
|
|
}
|
|
|
|
private getStoredFlag(): string {
|
|
const storedFlag = localStorage.getItem(flagKey);
|
|
if (storedFlag) {
|
|
return storedFlag;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
private dispatchFlagEvent() {
|
|
this.dispatchEvent(
|
|
new CustomEvent("flag-change", {
|
|
detail: { flag: this.flag },
|
|
bubbles: true,
|
|
composed: true,
|
|
}),
|
|
);
|
|
}
|
|
|
|
private updateFlag = (ev: Event) => {
|
|
const e = ev as CustomEvent<{ flag: string }>;
|
|
if (!FlagSchema.safeParse(e.detail.flag).success) return;
|
|
if (this.flag !== e.detail.flag) {
|
|
this.flag = e.detail.flag;
|
|
}
|
|
};
|
|
|
|
connectedCallback() {
|
|
super.connectedCallback();
|
|
this.flag = this.getStoredFlag();
|
|
this.dispatchFlagEvent();
|
|
window.addEventListener("flag-change", this.updateFlag as EventListener);
|
|
}
|
|
|
|
disconnectedCallback() {
|
|
super.disconnectedCallback();
|
|
window.removeEventListener("flag-change", this.updateFlag as EventListener);
|
|
}
|
|
|
|
createRenderRoot() {
|
|
return this;
|
|
}
|
|
|
|
render() {
|
|
return html`
|
|
<div class="flex relative">
|
|
<button
|
|
id="flag-input_"
|
|
class="w-full border rounded-lg flex cursor-pointer border-black/30
|
|
dark:border-gray-300/60 bg-white/70 dark:bg-[rgba(55,65,81,0.7)]
|
|
justify-center aspect-square"
|
|
title=${translateText("flag_input.button_title")}
|
|
>
|
|
<span
|
|
id="flag-preview"
|
|
class="block w-full aspect-3/2 bg-[#333] overflow-hidden rounded-md"
|
|
></span>
|
|
</button>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
updated() {
|
|
const preview = this.renderRoot.querySelector(
|
|
"#flag-preview",
|
|
) as HTMLElement;
|
|
if (!preview) return;
|
|
|
|
preview.innerHTML = "";
|
|
|
|
if (this.flag?.startsWith("!")) {
|
|
renderPlayerFlag(this.flag, preview);
|
|
} else {
|
|
const img = document.createElement("img");
|
|
img.src = this.flag ? `/flags/${this.flag}.svg` : `/flags/xx.svg`;
|
|
img.style.width = "100%";
|
|
img.style.height = "100%";
|
|
img.style.objectFit = "contain";
|
|
img.onerror = () => {
|
|
if (!img.src.endsWith("/flags/xx.svg")) {
|
|
img.src = "/flags/xx.svg";
|
|
}
|
|
};
|
|
preview.appendChild(img);
|
|
}
|
|
}
|
|
}
|