diff --git a/packages/core/src/composables/utils.ts b/packages/core/src/composables/utils.ts index e2be452..dcbd9e5 100644 --- a/packages/core/src/composables/utils.ts +++ b/packages/core/src/composables/utils.ts @@ -2,12 +2,19 @@ import { onMounted, onUnmounted, ref } from '@vue/runtime-core' export function useInterval(fn: () => void, interval?: number) { let handle: ReturnType - onMounted(() => { + + function restart() { + stop() handle = setInterval(fn, interval) - }) - onUnmounted(() => { + } + function stop() { clearInterval(handle) - }) + } + + onMounted(restart) + onUnmounted(stop) + + return { restart, stop } } export function useTimeout(fn: () => void, delay?: number) { diff --git a/packages/playground/components.d.ts b/packages/playground/components.d.ts index 8c0f2b4..5f5f116 100644 --- a/packages/playground/components.d.ts +++ b/packages/playground/components.d.ts @@ -10,7 +10,7 @@ declare module '@vue/runtime-core' { Box: typeof import('vue-termui')['TuiBox'] Br: typeof import('vue-termui')['TuiNewline'] Div: typeof import('vue-termui')['TuiBox'] - Input: typeof import('vue-termui')['TuiInput'] + Input: typeof import('./src/components/Input.vue')['default'] Link: typeof import('vue-termui')['TuiLink'] Newline: typeof import('vue-termui')['TuiNewline'] Progressbar: typeof import('vue-termui')['TuiProgressBar'] diff --git a/packages/playground/src/InputDemo.vue b/packages/playground/src/InputDemo.vue index b6b1fc7..1c8440e 100644 --- a/packages/playground/src/InputDemo.vue +++ b/packages/playground/src/InputDemo.vue @@ -1,18 +1,17 @@ diff --git a/packages/playground/src/components/Input.vue b/packages/playground/src/components/Input.vue new file mode 100644 index 0000000..2c3e1c3 --- /dev/null +++ b/packages/playground/src/components/Input.vue @@ -0,0 +1,182 @@ + + +