Skip to content

Commit c777f74

Browse files
author
issayah
committed
BProgress script setup
1 parent b83953c commit c777f74

File tree

4 files changed

+46
-36
lines changed

4 files changed

+46
-36
lines changed

src/components/BProgress.vue

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,42 @@
1717
</div>
1818
</template>
1919

20-
<script lang="ts">
21-
import {ColorVariant} from '../types'
22-
import {defineComponent, InjectionKey, PropType, provide} from 'vue'
20+
<script setup lang="ts">
21+
// import type {BProgressProps} from '@/types/components'
22+
import type {ColorVariant} from '@/types'
23+
import {InjectionKey, provide} from 'vue'
2324
24-
export interface ParentData {
25-
animated: boolean
25+
interface BProgressProps {
26+
variant: ColorVariant
2627
max: number | string
27-
showProgress: boolean
28-
showValue: boolean
29-
striped: boolean
28+
height: string
29+
animated?: boolean
30+
precision?: number | string
31+
showProgress?: boolean
32+
showValue?: boolean
33+
striped?: boolean
34+
value?: number | string
3035
}
3136
32-
export const injectionKey: InjectionKey<ParentData> = Symbol()
37+
const props = withDefaults(defineProps<BProgressProps>(), {
38+
animated: false,
39+
precision: 0,
40+
showProgress: false,
41+
showValue: false,
42+
striped: false,
43+
value: 0,
44+
})
3345
34-
export default defineComponent({
35-
name: 'BProgress',
36-
props: {
37-
animated: {type: Boolean, default: false},
38-
max: {type: [Number, String]},
39-
height: {type: String},
40-
precision: {type: [Number, String], default: 0},
41-
showProgress: {type: Boolean, default: false},
42-
showValue: {type: Boolean, default: false},
43-
striped: {type: Boolean, default: false},
44-
value: {type: [Number, String], default: 0},
45-
variant: {type: String as PropType<ColorVariant>},
46-
},
47-
setup(props) {
48-
provide(injectionKey, {
49-
animated: props.animated,
50-
max: props.max,
51-
showProgress: props.showProgress,
52-
showValue: props.showValue,
53-
striped: props.striped,
54-
})
55-
},
46+
provide(injectionKey, {
47+
animated: props.animated,
48+
max: props.max,
49+
showProgress: props.showProgress,
50+
showValue: props.showValue,
51+
striped: props.striped,
5652
})
5753
</script>
54+
55+
<script lang="ts">
56+
import type {BProgressParentData} from '@/types/components'
57+
export const injectionKey: InjectionKey<BProgressParentData> = Symbol()
58+
</script>

src/components/BProgressBar.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script lang="ts">
2-
import {ColorVariant} from '../types'
2+
import type {ColorVariant} from '@/types'
3+
import type {BProgressParentData} from '@/types/components'
34
import {computed, defineComponent, h, inject, PropType} from 'vue'
4-
import {injectionKey, ParentData} from './BProgress.vue'
5+
import {injectionKey} from './BProgress.vue'
56
67
export default defineComponent({
78
name: 'BProgressBar',
@@ -18,7 +19,7 @@ export default defineComponent({
1819
variant: {type: String as PropType<ColorVariant>},
1920
},
2021
setup(props, {slots}) {
21-
const parent = inject<ParentData>(injectionKey)
22+
const parent = inject<BProgressParentData>(injectionKey)
2223
2324
const classes = computed(() => ({
2425
'progress-bar-animated': props.animated || parent?.animated,
@@ -27,7 +28,7 @@ export default defineComponent({
2728
[`bg-${props.variant}`]: props.variant,
2829
}))
2930
30-
const computedLabel = computed(() => {
31+
const computedLabel = computed<string>(() => {
3132
if (props.showValue || parent?.showValue) {
3233
return parseFloat(props.value as string).toFixed(props.precision as number)
3334
}
@@ -43,7 +44,7 @@ export default defineComponent({
4344
return props.label || ''
4445
})
4546
46-
const width = computed(() => {
47+
const width = computed<string>(() => {
4748
if (props.max || parent?.max) {
4849
return `${
4950
((props.value as number) * 100) / parseInt((props.max || parent?.max) as string)

src/types/components/BProgress.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ export interface Props {
1414
// Emits
1515

1616
// Other
17+
export interface ParentData {
18+
animated: boolean
19+
max: number | string
20+
showProgress: boolean
21+
showValue: boolean
22+
striped: boolean
23+
}

src/types/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ export type {Emits as BPopoverEmits} from './BPopover'
152152
export type {DelayObject as BPopoverDelayObject} from './BPopover'
153153

154154
export type {Props as BProgressProps} from './BProgress'
155+
export type {ParentData as BProgressParentData} from './BProgress'
155156

156157
export type {Props as BProgressBarProps} from './BProgressBar'
157158

0 commit comments

Comments
 (0)