-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
69 additions
and
18 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { computed, type ComputedRef, type UnwrapRef, ref } from 'vue' | ||
|
||
export function useControllable<T>( | ||
controlledValue: ComputedRef<T | undefined>, | ||
onChange?: (value: T) => void, | ||
defaultValue?: ComputedRef<T> | ||
) { | ||
const internalValue = ref(defaultValue?.value) | ||
const isControlled = computed(() => controlledValue.value !== undefined) | ||
|
||
return [ | ||
computed(() => (isControlled.value ? controlledValue.value : internalValue.value)), | ||
function (value: unknown) { | ||
if (isControlled.value) { | ||
return onChange?.(value as T) | ||
} else { | ||
internalValue.value = value as UnwrapRef<T> | ||
return onChange?.(value as T) | ||
} | ||
}, | ||
] as const | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
e7d3456
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
elenext – ./
elenext.vercel.app
elenext-jaskang.vercel.app
elenext.jaskang.vip
elenext-git-main-jaskang.vercel.app