Skip to content

Commit f02298b

Browse files
committed
feat: 新增 FaSlider 组件
1 parent 5fcd3fe commit f02298b

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

src/types/components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ declare module 'vue' {
3434
FaScrollArea: typeof import('./../ui/components/FaScrollArea/index.vue')['default']
3535
FaSearchBar: typeof import('./../ui/components/FaSearchBar/index.vue')['default']
3636
FaSelect: typeof import('./../ui/components/FaSelect/index.vue')['default']
37+
FaSlider: typeof import('./../ui/components/FaSlider/index.vue')['default']
3738
FaSmartFixedBlock: typeof import('./../ui/components/FaSmartFixedBlock/index.vue')['default']
3839
FaSwitch: typeof import('./../ui/components/FaSwitch/index.vue')['default']
3940
FaSystemInfo: typeof import('./../ui/components/FaSystemInfo/index.vue')['default']
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<script setup lang="ts">
2+
import type { SliderRootProps } from 'reka-ui'
3+
import type { HTMLAttributes } from 'vue'
4+
import { Slider } from './slider'
5+
6+
const props = withDefaults(defineProps<{
7+
defaultValue?: SliderRootProps['defaultValue']
8+
disabled?: SliderRootProps['disabled']
9+
inverted?: SliderRootProps['inverted']
10+
max?: SliderRootProps['max']
11+
min?: SliderRootProps['min']
12+
step?: SliderRootProps['step']
13+
orientation?: SliderRootProps['orientation']
14+
thumbAlignment?: SliderRootProps['thumbAlignment']
15+
class?: HTMLAttributes['class']
16+
}>(), {
17+
defaultValue: () => [0],
18+
disabled: false,
19+
inverted: false,
20+
max: 100,
21+
min: 0,
22+
step: 1,
23+
orientation: 'horizontal',
24+
thumbAlignment: 'contain',
25+
})
26+
27+
const modelValue = defineModel<number[]>()
28+
</script>
29+
30+
<template>
31+
<Slider v-bind="props" v-model="modelValue" />
32+
</template>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<script setup lang="ts">
2+
import type { SliderRootEmits, SliderRootProps } from 'reka-ui'
3+
import type { HTMLAttributes } from 'vue'
4+
import { cn } from '@/utils'
5+
import { SliderRange, SliderRoot, SliderThumb, SliderTrack, useForwardPropsEmits } from 'reka-ui'
6+
import { computed } from 'vue'
7+
8+
const props = defineProps<SliderRootProps & { class?: HTMLAttributes['class'] }>()
9+
const emits = defineEmits<SliderRootEmits>()
10+
11+
const delegatedProps = computed(() => {
12+
const { class: _, ...delegated } = props
13+
14+
return delegated
15+
})
16+
17+
const forwarded = useForwardPropsEmits(delegatedProps, emits)
18+
</script>
19+
20+
<template>
21+
<SliderRoot
22+
:class="cn(
23+
'relative flex w-full touch-none select-none items-center data-[orientation=vertical]:flex-col data-[orientation=vertical]:w-2 data-[orientation=vertical]:h-full',
24+
props.class,
25+
)"
26+
v-bind="forwarded"
27+
>
28+
<SliderTrack class="relative h-2 w-full grow overflow-hidden rounded-full bg-secondary data-[orientation=vertical]:w-2">
29+
<SliderRange class="absolute h-full bg-primary data-[orientation=vertical]:w-full" />
30+
</SliderTrack>
31+
<FaTooltip v-for="(val, key) in modelValue" :key="key" :text="val.toString()" disable-closing-trigger>
32+
<SliderThumb
33+
class="block h-5 w-5 border-2 border-primary rounded-full bg-background ring-offset-background transition-colors disabled:pointer-events-none disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-ring"
34+
/>
35+
</FaTooltip>
36+
</SliderRoot>
37+
</template>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as Slider } from './Slider.vue'

0 commit comments

Comments
 (0)