-
Notifications
You must be signed in to change notification settings - Fork 52
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
Yan Heng
committed
Aug 12, 2023
1 parent
89aa968
commit 1ad6db2
Showing
4 changed files
with
52 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<script setup lang="ts"> | ||
import { computed, ref, toRefs, watch } from 'vue'; | ||
import { FormValue, SliderConfig } from '../types'; | ||
const props = withDefaults( | ||
defineProps<{ | ||
config: SliderConfig; | ||
prop: string; | ||
model?: FormValue; | ||
}>(), | ||
{ | ||
model: () => ({}), | ||
} | ||
); | ||
const emits = defineEmits<{ | ||
(event: 'change', prop: string, value: number): void; | ||
}>(); | ||
const { model, prop, config } = toRefs(props); | ||
const value = ref<number>(prop?.value && model?.value?.[prop?.value]); | ||
const min = computed<number>(() => config.value.min || 0); | ||
const max = computed<number>(() => config.value.max || 1); | ||
const step = computed<number>(() => config.value.step || 0.01); | ||
watch( | ||
() => value.value, | ||
(v) => emits('change', prop.value, v) | ||
); | ||
</script> | ||
|
||
<template> | ||
<div class="w-full h-full"> | ||
<input v-model="value" type="range" class="block w-full h-full cursor-pointer" :min="min" :max="max" :step="step" /> | ||
</div> | ||
</template> |
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