mirror of
https://github.com/versia-pub/frontend.git
synced 2025-12-06 16:38:20 +01:00
feat: ✨ Add string preferences and custom background images
This commit is contained in:
parent
57fafbd1a8
commit
aa61f28004
31
components/preferences/string.vue
Normal file
31
components/preferences/string.vue
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
<template>
|
||||||
|
<Card class="grid grid-rows-[1fr,auto] xl:grid-rows-none xl:grid-cols-[1fr,auto] items-center p-6 gap-4">
|
||||||
|
<CardHeader class="space-y-0.5 p-0">
|
||||||
|
<CardTitle class="text-base">
|
||||||
|
{{ setting.title() }}
|
||||||
|
</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
{{ setting.description() }}
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardFooter class="p-0">
|
||||||
|
<Input :model-value="setting.value" @update:model-value="v => { setting.value = String(v) }" />
|
||||||
|
</CardFooter>
|
||||||
|
</Card>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardDescription,
|
||||||
|
CardFooter,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
} from "~/components/ui/card";
|
||||||
|
import { Input } from "~/components/ui/input";
|
||||||
|
import type { StringSetting } from "~/settings.ts";
|
||||||
|
|
||||||
|
defineModel<StringSetting>("setting", {
|
||||||
|
required: true,
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
@ -27,7 +27,7 @@ const route = useRoute();
|
||||||
<LeftSidebar />
|
<LeftSidebar />
|
||||||
<SidebarInset>
|
<SidebarInset>
|
||||||
<header
|
<header
|
||||||
class="flex h-16 shrink-0 items-center gap-2 transition-[width,height] ease-linear group-has-[[data-collapsible=icon]]/sidebar-wrapper:h-12 overflow-hidden">
|
class="flex h-16 shrink-0 items-center gap-2 transition-[width,height] ease-linear group-has-[[data-collapsible=icon]]/sidebar-wrapper:h-12 overflow-hidden bg-background">
|
||||||
<div class="flex items-center gap-2 px-4">
|
<div class="flex items-center gap-2 px-4">
|
||||||
<SidebarTrigger class="-ml-1" />
|
<SidebarTrigger class="-ml-1" />
|
||||||
<Separator orientation="vertical" class="mr-2 h-4" />
|
<Separator orientation="vertical" class="mr-2 h-4" />
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,30 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import type { HTMLAttributes } from "vue";
|
import type { HTMLAttributes } from "vue";
|
||||||
|
import { SettingIds } from "~/settings";
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
class?: HTMLAttributes["class"];
|
class?: HTMLAttributes["class"];
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
const backgroundImage = useSetting(SettingIds.BackgroundURL);
|
||||||
|
|
||||||
|
const canParseUrl = URL.canParse;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<main
|
<main :class="cn(
|
||||||
:class="cn(
|
|
||||||
'relative flex min-h-svh max-w-full flex-1 flex-col bg-background',
|
'relative flex min-h-svh max-w-full flex-1 flex-col bg-background',
|
||||||
'peer-data-[variant=inset]:min-h-[calc(100svh-theme(spacing.4))] md:peer-data-[variant=inset]:m-2 md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow',
|
'peer-data-[variant=inset]:min-h-[calc(100svh-theme(spacing.4))] md:peer-data-[variant=inset]:m-2 md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:overflow-hidden md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow',
|
||||||
props.class,
|
props.class,
|
||||||
)"
|
)" :style="{
|
||||||
>
|
backgroundImage: canParseUrl(backgroundImage.value as string) ? `url(${backgroundImage.value})` : undefined,
|
||||||
|
backgroundSize: canParseUrl(backgroundImage.value as string) ? 'cover' : undefined,
|
||||||
|
backgroundPosition: canParseUrl(backgroundImage.value as string) ? 'center' : undefined,
|
||||||
|
backgroundRepeat: canParseUrl(backgroundImage.value as string) ? 'no-repeat' : undefined,
|
||||||
|
}">
|
||||||
|
<!-- Overlay for the background image -->
|
||||||
|
<div v-if="canParseUrl(backgroundImage.value as string)" class="absolute -z-10 inset-0 bg-black/20" />
|
||||||
<slot />
|
<slot />
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<Sidebar>
|
<Sidebar>
|
||||||
<SquarePattern />
|
<SquarePattern v-if="!canParseUrl(backgroundImage.value as string)" />
|
||||||
<slot v-if="!route.meta.requiresAuth || identity" />
|
<slot v-if="!route.meta.requiresAuth || identity" />
|
||||||
<Card v-else class="shadow-none bg-transparent border-none p-4 max-w-md mx-auto">
|
<Card v-else class="shadow-none bg-transparent border-none p-4 max-w-md mx-auto">
|
||||||
<CardHeader class="text-center gap-y-4">
|
<CardHeader class="text-center gap-y-4">
|
||||||
|
|
@ -34,6 +34,7 @@ import {
|
||||||
CardTitle,
|
CardTitle,
|
||||||
} from "~/components/ui/card";
|
} from "~/components/ui/card";
|
||||||
import * as m from "~/paraglide/messages.js";
|
import * as m from "~/paraglide/messages.js";
|
||||||
|
import { SettingIds } from "~/settings";
|
||||||
|
|
||||||
const appData = useAppData();
|
const appData = useAppData();
|
||||||
const signInAction = () => signIn(appData);
|
const signInAction = () => signIn(appData);
|
||||||
|
|
@ -45,6 +46,9 @@ const notUsingInput = computed(
|
||||||
activeElement.value?.tagName !== "TEXTAREA",
|
activeElement.value?.tagName !== "TEXTAREA",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const backgroundImage = useSetting(SettingIds.BackgroundURL);
|
||||||
|
const canParseUrl = URL.canParse;
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
|
||||||
watchEffect(async () => {
|
watchEffect(async () => {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
<SwitchPreference v-if="setting.type === SettingType.Boolean" :setting="(setting as BooleanSetting)" @update:setting="updateSetting(id, setting)" />
|
<SwitchPreference v-if="setting.type === SettingType.Boolean" :setting="(setting as BooleanSetting)" @update:setting="updateSetting(id, setting)" />
|
||||||
<SelectPreference v-else-if="setting.type === SettingType.Enum" :setting="(setting as EnumSetting)" @update:setting="updateSetting(id, setting)" />
|
<SelectPreference v-else-if="setting.type === SettingType.Enum" :setting="(setting as EnumSetting)" @update:setting="updateSetting(id, setting)" />
|
||||||
<CodePreference v-else-if="setting.type === SettingType.Code" :setting="(setting as CodeSetting)" @update:setting="updateSetting(id, setting)" />
|
<CodePreference v-else-if="setting.type === SettingType.Code" :setting="(setting as CodeSetting)" @update:setting="updateSetting(id, setting)" />
|
||||||
|
<StringPreference v-else-if="setting.type === SettingType.String" :setting="(setting as StringSetting)" @update:setting="updateSetting(id, setting)" />
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -16,6 +17,7 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import CodePreference from "~/components/preferences/code.vue";
|
import CodePreference from "~/components/preferences/code.vue";
|
||||||
import SelectPreference from "~/components/preferences/select.vue";
|
import SelectPreference from "~/components/preferences/select.vue";
|
||||||
|
import StringPreference from "~/components/preferences/string.vue";
|
||||||
import SwitchPreference from "~/components/preferences/switch.vue";
|
import SwitchPreference from "~/components/preferences/switch.vue";
|
||||||
import * as m from "~/paraglide/messages.js";
|
import * as m from "~/paraglide/messages.js";
|
||||||
import {
|
import {
|
||||||
|
|
@ -26,6 +28,7 @@ import {
|
||||||
type SettingIds,
|
type SettingIds,
|
||||||
type SettingPages,
|
type SettingPages,
|
||||||
SettingType,
|
SettingType,
|
||||||
|
type StringSetting,
|
||||||
} from "~/settings.ts";
|
} from "~/settings.ts";
|
||||||
|
|
||||||
useHead({
|
useHead({
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue