element-plus/docs/.vitepress/vitepress/composables/toggle.ts
三咲智子 d28d0701d7
docs: improve code (#5040)
* docs: remove unused code

* refactor(docs): improve code
2021-12-30 19:00:11 +08:00

17 lines
415 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
}