Skip to content

Commit

Permalink
feat: useLoading
Browse files Browse the repository at this point in the history
  • Loading branch information
nemo-shen committed Jan 14, 2024
1 parent 42899b2 commit 73e5343
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './useToast'
export * from './useEllipsis'
export * from './useLoading'
1 change: 1 addition & 0 deletions packages/core/useLoading/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# useLoading
4 changes: 4 additions & 0 deletions packages/core/useLoading/README.zh-CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# useLoading

loading本身不会和任何弹层挂钩
loading实现一个进度管理
17 changes: 15 additions & 2 deletions packages/core/useLoading/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import { test, describe, expect } from 'vitest'
import { useLoading } from '.'

describe('useLoading', () => {
test('should be right', () => {
expect(true).toBeTruthy()
test('should be defined', () => {
expect(useLoading).toBeDefined()
})

test('should be loading correctly', () => {
const { isLoading, start, stop } = useLoading()

expect(isLoading.value).toBeFalsy()

start()
expect(isLoading.value).toBeTruthy()

stop()
expect(isLoading.value).toBeFalsy()
})
})
25 changes: 25 additions & 0 deletions packages/core/useLoading/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ref, type Ref } from 'vue'

interface UseLoadingReturn {
isLoading: Ref<boolean>
start: () => void
stop: () => void
}

export const useLoading = (): UseLoadingReturn => {
const isLoading = ref(false)

const start = () => {
isLoading.value = true
}

const stop = () => {
isLoading.value = false
}

return {
isLoading,
start,
stop,
}
}
6 changes: 4 additions & 2 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<script setup lang="ts">
import UseEllipsis from './demo/UseEllipsis.vue'
// import UseEllipsis from './demo/UseEllipsis.vue'
import UseLoading from './demo/UseLoading.vue'
</script>

<template>
<UseEllipsis />
<!-- <UseEllipsis /> -->
<UseLoading />
</template>
30 changes: 30 additions & 0 deletions src/demo/UseLoading.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script setup lang="ts">
import { ref } from 'vue'
import { useLoading } from '@noi/core'
const { isLoading, start, stop } = useLoading()
// const upload = () => {
// start();
// setTimeout(() => {
// stop()
// }, 1000)
// }
// const loading = ref(false)
// const upload = () => {
// loading.value = true
// setTimeout(() => {
// loading.value = false
// }, 1000)
// }
</script>

<template>
<div v-show="isLoading">loading...</div>
<button @click="start">start loading</button>
<button @click="stop">stop loading</button>
</template>

0 comments on commit 73e5343

Please sign in to comment.