2022-12-09 15:51:42 -05:00
|
|
|
<script lang="ts">
|
2024-06-02 16:41:44 +00:00
|
|
|
import { generateId } from '$lib/utils/generate-id';
|
2025-05-16 13:59:47 -04:00
|
|
|
import { Switch } from '@immich/ui';
|
2024-11-14 08:43:25 -06:00
|
|
|
import type { Snippet } from 'svelte';
|
2025-05-16 13:59:47 -04:00
|
|
|
import { t } from 'svelte-i18n';
|
|
|
|
|
import { quintOut } from 'svelte/easing';
|
|
|
|
|
import { fly } from 'svelte/transition';
|
2023-01-22 02:09:02 +00:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
interface Props {
|
|
|
|
|
title: string;
|
|
|
|
|
subtitle?: string;
|
|
|
|
|
checked?: boolean;
|
|
|
|
|
disabled?: boolean;
|
|
|
|
|
isEdited?: boolean;
|
|
|
|
|
onToggle?: (isChecked: boolean) => void;
|
|
|
|
|
children?: Snippet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let {
|
|
|
|
|
title,
|
|
|
|
|
subtitle = '',
|
|
|
|
|
checked = $bindable(false),
|
|
|
|
|
disabled = false,
|
|
|
|
|
isEdited = false,
|
|
|
|
|
onToggle = () => {},
|
|
|
|
|
children,
|
|
|
|
|
}: Props = $props();
|
2023-09-03 02:21:51 -04:00
|
|
|
|
2024-06-02 16:41:44 +00:00
|
|
|
let id: string = generateId();
|
2024-06-01 22:58:35 +00:00
|
|
|
|
2024-11-14 08:43:25 -06:00
|
|
|
let sliderId = $derived(`${id}-slider`);
|
|
|
|
|
let subtitleId = $derived(subtitle ? `${id}-subtitle` : undefined);
|
2022-12-09 15:51:42 -05:00
|
|
|
</script>
|
|
|
|
|
|
2024-01-19 09:57:15 -05:00
|
|
|
<div class="flex place-items-center justify-between">
|
2025-04-28 09:53:53 -04:00
|
|
|
<div class="me-2">
|
2025-10-31 16:38:17 +01:00
|
|
|
<div class="flex h-6.5 place-items-center gap-1">
|
2025-09-17 12:12:51 -04:00
|
|
|
<label class="font-medium text-primary text-sm" for={sliderId}>
|
2024-01-19 09:57:15 -05:00
|
|
|
{title}
|
|
|
|
|
</label>
|
|
|
|
|
{#if isEdited}
|
|
|
|
|
<div
|
|
|
|
|
transition:fly={{ x: 10, duration: 200, easing: quintOut }}
|
|
|
|
|
class="rounded-full bg-orange-100 px-2 text-[10px] text-orange-900"
|
|
|
|
|
>
|
2024-06-24 15:50:01 +02:00
|
|
|
{$t('unsaved_change')}
|
2024-01-19 09:57:15 -05:00
|
|
|
</div>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
2023-12-17 00:17:38 +01:00
|
|
|
|
2024-04-06 14:18:49 +00:00
|
|
|
{#if subtitle}
|
|
|
|
|
<p id={subtitleId} class="text-sm dark:text-immich-dark-fg">{subtitle}</p>
|
|
|
|
|
{/if}
|
2024-11-14 08:43:25 -06:00
|
|
|
{@render children?.()}
|
2024-01-19 09:57:15 -05:00
|
|
|
</div>
|
2024-01-19 11:34:20 -06:00
|
|
|
|
2025-05-16 13:59:47 -04:00
|
|
|
<Switch id={sliderId} bind:checked {disabled} onCheckedChange={onToggle} aria-describedby={subtitleId} />
|
2024-01-19 09:57:15 -05:00
|
|
|
</div>
|