Skip to content

A self-hosted media server and file management system

2.3 KB
Raw Blame
<script setup lang="ts">
import type { PopoverSlider } from '@/types/types';

import { ButtonBase } from '@/components/cedar-ui/button';
import { useId } from 'vue';
import { cn } from '@aminnausin/cedar-ui';

defineOptions({ inheritAttrs: false });

const id = useId();

const props = withDefaults(defineProps<PopoverSlider>(), { min: 10, max: 200, step: 5 });
const model = defineModel();
const resetModel = () => {
    if (props.defaultValue === undefined) return;
    model.value = props.defaultValue;
    props.action?.();
};
</script>
<template>
    <div class="px-1 text-[10px] sm:text-xs">
        <label
            v-show="!hidden"
            v-bind="$attrs"
            :for="id"
            :title="title ?? 'Popover Slider'"
            :class="
                cn(
                    'transition-input flex w-full flex-wrap items-center gap-y-2 rounded-md px-2 py-1.5',
                    'ring-white outline-hidden ring-inset focus-within:bg-neutral-950 hover:bg-neutral-900 focus:outline-none has-focus-visible:ring',
                    { 'button-disabled': disabled },
                    style,
                    $attrs.class,
                )
            "
            @dblclick="resetModel"
            @wheel="wheelAction"
        >
            <component v-if="icon" :is="icon" class="mr-2 size-4 shrink-0" />

            <span class="text-nowrap">{{ text }}</span>
            <ButtonBase
                v-if="defaultValue !== undefined"
                type="button"
                class="text-foreground-1 dark ml-auto h-fit cursor-pointer p-0 tracking-wide focus-visible:outline-offset-2"
                :title="defaultValue !== undefined ? `Reset ${text}` : undefined"
                @click="resetModel"
            >
                {{ shortcut }}
            </ButtonBase>
            <span v-else class="text-foreground-1 dark ml-auto cursor-pointer tracking-wide">
                {{ shortcut }}
            </span>
            <input
                v-model="model"
                type="range"
                :id="id"
                :class="`slider volume h-2 w-full ring-white outline-hidden focus-visible:ring`"
                :min="min"
                :max="max"
                :step="step"
                :disabled="disabled"
                @input="action"
            />
        </label>
    </div>
</template>