1- <script setup lang="ts">
1+ <script setup lang="ts" generic = " TOption extends CheckboxGroupOption " >
22import type { AcceptableValue } from ' reka-ui'
33import type { HTMLAttributes } from ' vue'
44import { cn } from ' ../../utils'
55import { Checkbox } from ' ../checkbox/checkbox'
66import { Label } from ' ../label/label'
77
8- interface CheckboxGroupOption {
8+ export interface CheckboxGroupOption {
99 label: string
1010 value: AcceptableValue
1111 description? : string
@@ -18,7 +18,7 @@ defineOptions({
1818})
1919
2020const props = defineProps <{
21- options: CheckboxGroupOption []
21+ options: TOption []
2222 disabled? : boolean
2323 min? : number
2424 max? : number
@@ -35,7 +35,7 @@ const emit = defineEmits<{
3535
3636const slots = defineSlots <{
3737 option? : (props : {
38- option: CheckboxGroupOption
38+ option: TOption
3939 checked: boolean
4040 disabled: boolean
4141 id: string
@@ -53,11 +53,11 @@ watch(value, (newValue) => {
5353 emit (' change' , newValue )
5454})
5555
56- function getOptionId(option : CheckboxGroupOption , index : number ) {
56+ function getOptionId(option : TOption , index : number ) {
5757 return option .id || ` ${baseId }-${index } `
5858}
5959
60- function getOptionKey(option : CheckboxGroupOption , index : number ) {
60+ function getOptionKey(option : TOption , index : number ) {
6161 if (option .id ) {
6262 return option .id
6363 }
@@ -67,7 +67,7 @@ function getOptionKey(option: CheckboxGroupOption, index: number) {
6767 : index
6868}
6969
70- function isOptionDisabled(option : CheckboxGroupOption ) {
70+ function isOptionDisabled(option : TOption ) {
7171 if (props .disabled || option .disabled ) {
7272 return true
7373 }
@@ -85,15 +85,15 @@ function isOptionDisabled(option: CheckboxGroupOption) {
8585 return false
8686}
8787
88- function findOptionIndex(option : CheckboxGroupOption ) {
88+ function findOptionIndex(option : TOption ) {
8989 return value .value .findIndex (item => Object .is (item , option .value ))
9090}
9191
92- function isOptionChecked(option : CheckboxGroupOption ) {
92+ function isOptionChecked(option : TOption ) {
9393 return findOptionIndex (option ) > - 1
9494}
9595
96- function updateOptionChecked(option : CheckboxGroupOption , checked : boolean ) {
96+ function updateOptionChecked(option : TOption , checked : boolean ) {
9797 const nextValue = [... value .value ]
9898 const optionIndex = nextValue .findIndex (item => Object .is (item , option .value ))
9999
@@ -109,23 +109,23 @@ function updateOptionChecked(option: CheckboxGroupOption, checked: boolean) {
109109 value .value = nextValue
110110}
111111
112- function handleOptionModelValueChange(option : CheckboxGroupOption , checked : boolean | ' indeterminate' ) {
112+ function handleOptionModelValueChange(option : TOption , checked : boolean | ' indeterminate' ) {
113113 if (isOptionDisabled (option )) {
114114 return
115115 }
116116
117117 updateOptionChecked (option , checked === true )
118118}
119119
120- function handleCustomOptionClick(option : CheckboxGroupOption ) {
120+ function handleCustomOptionClick(option : TOption ) {
121121 if (! slots .option || isOptionDisabled (option )) {
122122 return
123123 }
124124
125125 updateOptionChecked (option , ! isOptionChecked (option ))
126126}
127127
128- function handleCustomOptionKeydown(option : CheckboxGroupOption ) {
128+ function handleCustomOptionKeydown(option : TOption ) {
129129 if (! slots .option || isOptionDisabled (option )) {
130130 return
131131 }
0 commit comments