mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 23:11:55 +00:00
c63b304a97
## Description: Various changes, applied more styling from the homewrecker branch * dimmed background * Content width: expands to 24cm on 2xl screens * game card ocean color: French blue → sky-950 * Action buttons (Create/Ranked/Join): French blue → slate-700 * Modifier badges: teal → sky blue, to keep in color scheme * CTA buttons (Start Game, Join Lobby): blue-600 → sky-600 across all modals and <o-button> * Nav font: font-bold tracking-widest → font-medium tracking-wider * Username/flag inputs: font weight lightened to font-medium tracking-wider * Language flag: blue color filter applied BEFORE: <img width="1446" height="978" alt="Screenshot 2026-03-08 at 6 48 57 PM" src="https://github.com/user-attachments/assets/ff748e1c-6cb5-4a66-ac27-9538e935b325" /> AFTER: <img width="1629" height="988" alt="Screenshot 2026-03-08 at 6 46 53 PM" src="https://github.com/user-attachments/assets/364bb57a-65ff-40cf-931b-067ed36e3c5b" /> ## 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: evan
135 lines
3.7 KiB
TypeScript
135 lines
3.7 KiB
TypeScript
import { LitElement, html } from "lit";
|
|
import { customElement, property, 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 = "";
|
|
|
|
@property({ type: Boolean, attribute: "show-select-label" })
|
|
public showSelectLabel: boolean = false;
|
|
|
|
private isDefaultFlagValue(flag: string): boolean {
|
|
return !flag || flag === "xx";
|
|
}
|
|
|
|
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;
|
|
}
|
|
};
|
|
|
|
private onInputClick(e: Event) {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
this.dispatchEvent(
|
|
new CustomEvent("flag-input-click", {
|
|
bubbles: true,
|
|
composed: true,
|
|
}),
|
|
);
|
|
}
|
|
|
|
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() {
|
|
const isDefaultFlag = this.isDefaultFlagValue(this.flag);
|
|
const showSelect = this.showSelectLabel && isDefaultFlag;
|
|
const buttonTitle = showSelect
|
|
? translateText("flag_input.title")
|
|
: translateText("flag_input.button_title");
|
|
|
|
return html`
|
|
<button
|
|
id="flag-input"
|
|
class="flag-btn p-0 m-0 border-0 w-full h-full flex cursor-pointer justify-center items-center focus:outline-none focus:ring-0 transition-all duration-200 hover:scale-105 bg-[color-mix(in_oklab,var(--frenchBlue)_75%,black)] hover:brightness-[1.08] active:brightness-[0.95] rounded-lg overflow-hidden"
|
|
title=${buttonTitle}
|
|
@click=${this.onInputClick}
|
|
>
|
|
<span
|
|
id="flag-preview"
|
|
class=${showSelect ? "hidden" : "w-full h-full overflow-hidden"}
|
|
></span>
|
|
${showSelect
|
|
? html`<span
|
|
class="text-[10px] font-medium tracking-wider text-white uppercase leading-none break-words w-full text-center px-1"
|
|
>
|
|
${translateText("flag_input.title")}
|
|
</span>`
|
|
: null}
|
|
</button>
|
|
`;
|
|
}
|
|
|
|
updated() {
|
|
const preview = this.renderRoot.querySelector(
|
|
"#flag-preview",
|
|
) as HTMLElement;
|
|
if (!preview) return;
|
|
|
|
if (this.showSelectLabel && this.isDefaultFlagValue(this.flag)) {
|
|
preview.innerHTML = "";
|
|
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.className = "w-full h-full object-cover pointer-events-none";
|
|
img.draggable = false;
|
|
img.onerror = () => {
|
|
if (!img.src.endsWith("/flags/xx.svg")) {
|
|
img.src = "/flags/xx.svg";
|
|
}
|
|
};
|
|
preview.appendChild(img);
|
|
}
|
|
}
|
|
}
|