Skip to content

Commit 60bb408

Browse files
committed
FaCheckbox 支持半选状态
1 parent 705f14e commit 60bb408

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/ui/components/FaCheckbox/checkbox/Checkbox.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import type { CheckboxRootEmits, CheckboxRootProps } from 'reka-ui'
33
import type { HTMLAttributes } from 'vue'
44
import { reactiveOmit } from '@vueuse/core'
5-
import { Check } from 'lucide-vue-next'
5+
import { Check, Minus } from 'lucide-vue-next'
66
import { CheckboxIndicator, CheckboxRoot, useForwardPropsEmits } from 'reka-ui'
77
import { cn } from '@/utils'
88
@@ -17,11 +17,12 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits)
1717
<template>
1818
<CheckboxRoot
1919
v-bind="forwarded"
20-
:class="cn('peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground', props.class)"
20+
:class="cn('peer h-4 w-4 shrink-0 rounded-sm border border-primary bg-transparent ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground', props.class)"
2121
>
2222
<CheckboxIndicator class="h-full w-full flex items-center justify-center text-current">
2323
<slot>
24-
<Check class="h-4 w-4" />
24+
<Minus v-if="props.modelValue === 'indeterminate'" class="h-4 w-4" />
25+
<Check v-if="props.modelValue === true" class="h-4 w-4" />
2526
</slot>
2627
</CheckboxIndicator>
2728
</CheckboxRoot>

src/ui/components/FaCheckbox/index.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
<script setup lang="ts">
2+
import type { CheckboxRootProps } from 'reka-ui'
3+
import type { HTMLAttributes } from 'vue'
4+
import { cn } from '@/utils'
25
import { Checkbox } from './checkbox'
36
47
defineOptions({
58
name: 'FaCheckbox',
69
})
710
8-
defineProps<{
11+
const props = defineProps<{
912
disabled?: boolean
13+
class?: HTMLAttributes['class']
1014
}>()
1115
12-
const value = defineModel<boolean>()
16+
const value = defineModel<CheckboxRootProps['modelValue']>()
1317
1418
const id = useId()
1519
</script>
1620

1721
<template>
18-
<div class="flex-center-start gap-2">
22+
<div :class="cn('flex-center-start gap-2', props.class)">
1923
<Checkbox :id v-model="value" :disabled />
20-
<label :for="id" class="cursor-pointer text-sm">
24+
<label :for="id" class="cursor-pointer text-sm empty:hidden">
2125
<slot />
2226
</label>
2327
</div>

src/views/component_built_in_example/checkbox.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ meta:
55

66
<script setup lang="ts">
77
const checked = ref(false)
8+
const checked2 = ref<'indeterminate' | boolean>('indeterminate')
89
</script>
910

1011
<template>
@@ -18,5 +19,10 @@ const checked = ref(false)
1819
{{ checked }}
1920
</div>
2021
</FaPageMain>
22+
<FaPageMain title="半选状态">
23+
<FaCheckbox v-model="checked2">
24+
复选框
25+
</FaCheckbox>
26+
</FaPageMain>
2127
</div>
2228
</template>

0 commit comments

Comments
 (0)