mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-02 19:42:51 +08:00
259 lines
8.1 KiB
Vue
259 lines
8.1 KiB
Vue
<template>
|
|
<div ref="root" class="skin-switcher" :class="{ open }" @keydown.esc="close">
|
|
<button
|
|
type="button"
|
|
class="skin-trigger"
|
|
data-ws-part="skin.trigger"
|
|
:disabled="options.length === 0"
|
|
:aria-label="menuLabel"
|
|
:title="`${menuLabel}: ${selectedOption.label}`"
|
|
aria-haspopup="listbox"
|
|
:aria-expanded="open"
|
|
:data-ws-state="open ? 'open' : 'closed'"
|
|
:aria-controls="menuId"
|
|
@click.stop="toggle"
|
|
>
|
|
<Icon :name="selectedOption.icon || 'compass'" :size="15" data-ws-icon-slot="skin.trigger" />
|
|
<span>{{ menuLabel }}</span>
|
|
<Icon name="chevron-down" :size="12" />
|
|
</button>
|
|
|
|
<div v-if="open" :id="menuId" class="skin-dropdown" data-ws-part="skin.menu" role="listbox" :aria-label="menuLabel" @click.stop>
|
|
<button
|
|
v-for="option in options"
|
|
:key="option.value"
|
|
type="button"
|
|
class="skin-option"
|
|
data-ws-part="skin.option"
|
|
:data-ws-skin-id="option.value"
|
|
:class="{ selected: modelValue === option.value }"
|
|
role="option"
|
|
:aria-selected="modelValue === option.value"
|
|
@click="select(option.value)"
|
|
>
|
|
<Icon :name="option.icon || 'compass'" :size="16" />
|
|
<span>{{ option.label }}</span>
|
|
<Icon v-if="modelValue === option.value" name="check" :size="14" />
|
|
</button>
|
|
<button type="button" class="skin-option skin-authorization" role="option" :aria-selected="false" @click="authorization">
|
|
<Icon name="shield" :size="16" /><span>{{ authorizationCopy.menu }}</span><small>{{ thirdPartyAllowed ? authorizationCopy.enabled : authorizationCopy.disabled }}</small>
|
|
</button>
|
|
<button v-if="thirdPartyAllowed && pluginLibraryAvailable" type="button" class="skin-option skin-library" data-ws-part="skin.library" role="option" :aria-selected="false" @click="openLibrary">
|
|
<Icon name="grid" :size="16" /><span>{{ libraryLabel }}</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { computed, onMounted, onUnmounted, ref } from "vue";
|
|
import Icon from "./Icon.vue";
|
|
import { authorizationLanguage, canUseSkin, openInstanceAuthorization, thirdPartyAllowed } from '../services/instance-authorization.js';
|
|
import { instanceAuthorizationCopy } from '../i18n/instance-authorization.js';
|
|
import { hostChromeCopy } from '../i18n/host-chrome.js';
|
|
import { openPluginLibrary } from '../services/host-chrome.js';
|
|
|
|
export interface SkinOption {
|
|
value: string;
|
|
label: string;
|
|
icon?: string;
|
|
}
|
|
|
|
const props = defineProps<{
|
|
modelValue: string;
|
|
menuLabel: string;
|
|
options: SkinOption[];
|
|
pluginLibraryAvailable?: boolean;
|
|
}>();
|
|
|
|
const emit = defineEmits<{
|
|
"update:modelValue": [value: string];
|
|
change: [value: string];
|
|
}>();
|
|
|
|
const options = computed(() => props.options.filter(option => canUseSkin(option.value)));
|
|
const authorizationCopy = computed(() => instanceAuthorizationCopy[authorizationLanguage.value]);
|
|
const libraryLabel = computed(() => hostChromeCopy[authorizationLanguage.value]?.library ?? hostChromeCopy.en.library);
|
|
function authorization() { close(); openInstanceAuthorization(); }
|
|
function openLibrary() { close(); openPluginLibrary(); }
|
|
const selectedOption = computed(() => options.value.find((option) => option.value === props.modelValue) ?? options.value[0] ?? {
|
|
value: props.modelValue,
|
|
label: props.menuLabel,
|
|
icon: "compass",
|
|
});
|
|
const root = ref<HTMLElement | null>(null);
|
|
const open = ref(false);
|
|
const menuId = `skin-menu-${Math.random().toString(36).slice(2, 9)}`;
|
|
|
|
function toggle() { open.value = !open.value; }
|
|
function close() { open.value = false; }
|
|
function select(value: string) {
|
|
emit("update:modelValue", value);
|
|
emit("change", value);
|
|
close();
|
|
}
|
|
function onDocumentPointerDown(event: PointerEvent) {
|
|
if (root.value && !root.value.contains(event.target as Node)) close();
|
|
}
|
|
|
|
onMounted(() => document.addEventListener("pointerdown", onDocumentPointerDown));
|
|
onUnmounted(() => document.removeEventListener("pointerdown", onDocumentPointerDown));
|
|
</script>
|
|
|
|
<style scoped>
|
|
.skin-switcher {
|
|
position: relative;
|
|
z-index: 20;
|
|
flex: 0 0 auto;
|
|
color: var(--text-muted);
|
|
}
|
|
.skin-authorization{margin-top:6px;border-top:1px solid #8bdad8!important}
|
|
.skin-authorization small{margin-left:auto;font-size:10px;opacity:.75}
|
|
.skin-library{opacity:.9}
|
|
|
|
.skin-trigger {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 5px;
|
|
min-width: 34px;
|
|
min-height: 32px;
|
|
padding: 0 8px;
|
|
color: #08766f;
|
|
background: rgba(250, 254, 255, .94);
|
|
border: 1px solid #c8e6e1;
|
|
border-radius: 8px;
|
|
font: inherit;
|
|
font-size: 10px;
|
|
font-weight: 700;
|
|
white-space: nowrap;
|
|
cursor: pointer;
|
|
box-shadow: 0 4px 12px rgba(8, 126, 134, .08);
|
|
transition: color .16s, background .16s, border-color .16s, box-shadow .16s;
|
|
}
|
|
|
|
.skin-trigger:hover,
|
|
.skin-switcher.open .skin-trigger {
|
|
color: #056e76;
|
|
background: #edfafa;
|
|
border-color: #8fd7d9;
|
|
box-shadow: 0 6px 16px rgba(30, 170, 184, .14);
|
|
}
|
|
|
|
.skin-trigger > .ui-icon:last-child { margin-left: 1px; }
|
|
|
|
.skin-dropdown {
|
|
position: absolute;
|
|
top: calc(100% + 7px);
|
|
right: 0;
|
|
display: grid;
|
|
gap: 3px;
|
|
min-width: 176px;
|
|
padding: 6px;
|
|
color: #123849;
|
|
background: linear-gradient(145deg, rgba(250, 255, 255, .99), rgba(232, 249, 250, .98));
|
|
border: 1px solid rgba(104, 196, 211, .58);
|
|
border-radius: 11px;
|
|
box-shadow: 0 18px 42px rgba(29, 115, 139, .2), inset 0 1px 0 rgba(255, 255, 255, .96);
|
|
backdrop-filter: blur(18px) saturate(1.12);
|
|
}
|
|
|
|
.skin-option {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 9px;
|
|
min-height: 36px;
|
|
padding: 0 9px;
|
|
color: #123849;
|
|
background: linear-gradient(112deg, rgba(255, 255, 255, .96), rgba(225, 250, 249, .96), rgba(188, 241, 237, .94), rgba(255, 255, 255, .96));
|
|
background-size: 240% 100%;
|
|
border: 1px solid rgba(139, 218, 216, .46);
|
|
border-radius: 7px;
|
|
font: inherit;
|
|
font-size: 11px;
|
|
text-align: left;
|
|
cursor: pointer;
|
|
animation: skin-option-gradient 8s ease-in-out infinite alternate;
|
|
transition: color .18s, border-color .18s, box-shadow .18s, background-position .4s ease;
|
|
}
|
|
|
|
.skin-option > .ui-icon:first-child { color: #64858a; }
|
|
.skin-option > .ui-icon:last-child { margin-left: auto; color: #087e86; }
|
|
.skin-option:hover,
|
|
.skin-option:focus-visible {
|
|
color: #087e86;
|
|
border-color: rgba(57, 195, 193, .74);
|
|
background-position: 100% 50%;
|
|
box-shadow: 0 4px 13px rgba(43, 179, 181, .16), inset 0 0 0 1px rgba(255, 255, 255, .84);
|
|
}
|
|
|
|
.skin-option.selected {
|
|
color: #056f73;
|
|
border-color: rgba(44, 183, 181, .78);
|
|
background-image: linear-gradient(112deg, #faffff 0%, #c8f5f1 36%, #82e2dc 70%, #d9fbf8 100%);
|
|
background-position: 100% 50%;
|
|
box-shadow: 0 5px 16px rgba(37, 170, 171, .22), inset 0 0 0 1px rgba(255, 255, 255, .94), inset 0 -1px 0 rgba(31, 164, 163, .12);
|
|
}
|
|
|
|
.skin-option.selected > .ui-icon:first-child,
|
|
.skin-option.selected > .ui-icon:last-child { color: #087e86; }
|
|
|
|
@keyframes skin-option-gradient {
|
|
from { background-position: 0% 50%; }
|
|
to { background-position: 100% 50%; }
|
|
}
|
|
|
|
@media (prefers-reduced-motion: reduce) {
|
|
.skin-option { animation: none; }
|
|
}
|
|
|
|
@media (max-width: 520px) {
|
|
.skin-trigger { min-height: 36px; }
|
|
.skin-dropdown { min-width: 190px; }
|
|
}
|
|
|
|
.skin-switcher.mobile-skin-switcher .skin-trigger {
|
|
width: 100%;
|
|
min-height: 44px;
|
|
justify-content: flex-start;
|
|
padding-inline: 12px;
|
|
font-size: 12px;
|
|
}
|
|
|
|
@media (max-width: 420px) {
|
|
.skin-switcher.join-skin-switcher .skin-trigger {
|
|
width: 28px;
|
|
min-width: 28px;
|
|
min-height: 28px;
|
|
padding: 0;
|
|
}
|
|
|
|
.skin-switcher.join-skin-switcher .skin-trigger > span,
|
|
.skin-switcher.join-skin-switcher .skin-trigger > .ui-icon:last-child { display: none; }
|
|
}
|
|
|
|
@media (max-width: 740px) {
|
|
.skin-switcher.mobile-skin-switcher .skin-dropdown {
|
|
position: static;
|
|
width: 100%;
|
|
min-width: 0;
|
|
max-height: min(45vh, 280px);
|
|
margin-top: 8px;
|
|
overflow-y: auto;
|
|
box-sizing: border-box;
|
|
}
|
|
}
|
|
|
|
@media (max-width: 740px) {
|
|
.skin-switcher.mobile-skin-switcher .skin-dropdown {
|
|
position: static;
|
|
width: 100%;
|
|
min-width: 0;
|
|
max-height: min(45vh, 280px);
|
|
margin-top: 8px;
|
|
overflow-y: auto;
|
|
box-sizing: border-box;
|
|
}
|
|
}
|
|
</style>
|