19 lines
433 B
TypeScript
19 lines
433 B
TypeScript
import { isRef, ref } from 'vue'
|
|
import { isBoolean } from '@vueuse/core'
|
|
import type { MaybeRef } from '@vueuse/core'
|
|
|
|
export const useToggle = (getToggled?: MaybeRef<boolean>) => {
|
|
const val = isRef(getToggled)
|
|
? getToggled
|
|
: ref(isBoolean(getToggled) ? getToggled : false)
|
|
|
|
return [
|
|
val,
|
|
(toggle?: boolean) => {
|
|
val.value = isBoolean(toggle) ? toggle : !val.value
|
|
}
|
|
] as const
|
|
}
|
|
|
|
export default {}
|