-
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.
- Loading branch information
Showing
4 changed files
with
99 additions
and
107 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -1,68 +1,52 @@ | ||
<script setup lang="ts"> | ||
import { onMounted } from 'vue'; | ||
import { nextTick, ref, watch } from 'vue'; | ||
import { useI18n } from 'vue-i18n'; | ||
import type { PropType } from 'vue'; | ||
const { locale } = useI18n(); | ||
const labelRef = ref<HTMLElement | null>(null); | ||
const cssVariables = ref<Record<string, string>>({ '--width': '0px' }); | ||
onMounted(() => updateWidth()); | ||
watch(locale, async() => updateWidth()); | ||
defineProps({ | ||
colorScheme: { | ||
type: String as PropType<'primary' | 'secondary'>, | ||
default: 'primary' | ||
} | ||
}); | ||
const updateWidth = async () => { | ||
await nextTick(); | ||
cssVariables.value['--width'] = `${labelRef.value ? labelRef.value.offsetWidth + 18 : 0}px`; | ||
// First string = text or border, second string = color scheme | ||
const colorOptions: Record<string, Record<string, string>> = { | ||
text: { | ||
primary: 'primary-hover-text', | ||
secondary: 'secondary-hover-text' | ||
}, | ||
border: { | ||
primary: 'primary-hover-border', | ||
secondary: 'secondary-hover-border' | ||
} | ||
} | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<!-- Wrapper to avoid the padding from the outside of this element to affect the insets --> | ||
<div class="relative group"> | ||
<label | ||
ref="labelRef" | ||
for="locale" | ||
:style="cssVariables" | ||
class="absolute text-sm -mt-2.5 left-3 floating-label-position primary-hover-text group-text-color" | ||
<fieldset | ||
:class="colorOptions.border[colorScheme]" | ||
class="group border rounded-md px-2 pb-3 -mt-2 has-[:focus-within]:focus-outline" | ||
> | ||
<legend | ||
class="px-1 text-sm" | ||
:class="colorOptions.text[colorScheme]" | ||
> | ||
{{ $t('locale.select') }} | ||
</legend> | ||
<select | ||
id="locale" | ||
v-model="$i18n.locale" | ||
class="w-full bg-transparent focus-visible:outline-none text-primary-darkest dark:text-primary-lighter" | ||
@click="$event.stopPropagation()" | ||
> | ||
<option | ||
v-for="(loc, index) in $i18n.availableLocales" | ||
:key="`locale-${loc}`" | ||
:data-index="index" | ||
:value="loc" | ||
class="bg-primary-lightest dark:bg-accent-darker" | ||
> | ||
{{ $t('locale.select') }} | ||
</label> | ||
<div class="hide-border-top relative overflow-clip rounded-md text-primary-darkest dark:text-primary-lighter"> | ||
<div | ||
class="absolute top-0 left-0 w-2 border-t border-x-0 primary-hover-border group-border-color rounded-tl-md" | ||
/> | ||
<div | ||
:style="cssVariables" | ||
class="absolute top-0 right-0 border-t border-x-0 primary-hover-border group-border-color top-border-right" | ||
/> | ||
<select | ||
id="locale" | ||
v-model="$i18n.locale" | ||
class="block h-12 py-0 px-6 w-full bg-transparent rounded-md border primary-hover-border group-border-color hide-border-top focus-visible:border-2 focus-visible:outline-0 focus-visible:outline-transparent appearance-none" | ||
@click="$event.stopPropagation()" | ||
> | ||
<option | ||
v-for="(loc, index) in $i18n.availableLocales" | ||
:key="`locale-${loc}`" | ||
:data-index="index" | ||
:value="loc" | ||
class="bg-primary-lightest dark:bg-accent-darker" | ||
> | ||
{{ $t('locale.' + loc) }} | ||
</option> | ||
</select> | ||
</div> | ||
</div> | ||
</div> | ||
{{ $t('locale.' + loc) }} | ||
</option> | ||
</select> | ||
</fieldset> | ||
</template> | ||
|
||
<style scoped> | ||
.hide-border-top { | ||
border-top: none; | ||
} | ||
.top-border-right { | ||
width: calc(100% - var(--width)); | ||
} | ||
</style> |
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