Skip to content

Commit 92632e9

Browse files
feat(Toast): add progress prop to hide progress bar (#4125)
Co-authored-by: Benjamin Canac <[email protected]>
1 parent f6d7994 commit 92632e9

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/runtime/components/Toast.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ export interface ToastProps extends Pick<ToastRootProps, 'defaultOpen' | 'open'
2929
* @defaultValue 'vertical'
3030
*/
3131
orientation?: Toast['variants']['orientation']
32+
/**
33+
* Whether to show the progress bar.
34+
* @defaultValue true
35+
*/
36+
progress?: boolean
3237
/**
3338
* Display a list of actions:
3439
* - under the title and description when orientation is `vertical`
@@ -76,7 +81,8 @@ import UButton from './Button.vue'
7681
7782
const props = withDefaults(defineProps<ToastProps>(), {
7883
close: true,
79-
orientation: 'vertical'
84+
orientation: 'vertical',
85+
progress: true
8086
})
8187
const emits = defineEmits<ToastEmits>()
8288
const slots = defineSlots<ToastSlots>()
@@ -179,6 +185,6 @@ defineExpose({
179185
</ToastClose>
180186
</div>
181187

182-
<div v-if="remaining > 0 && duration" :class="ui.progress({ class: props.ui?.progress })" :style="{ width: `${remaining / duration * 100}%` }" />
188+
<div v-if="progress && remaining > 0 && duration" :class="ui.progress({ class: props.ui?.progress })" :style="{ width: `${remaining / duration * 100}%` }" />
183189
</ToastRoot>
184190
</template>

src/runtime/components/Toaster.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ export interface ToasterProps extends Omit<ToastProviderProps, 'swipeDirection'>
1717
* @defaultValue true
1818
*/
1919
expand?: boolean
20+
/**
21+
* Whether to show the progress bar on all toasts.
22+
* @defaultValue true
23+
*/
24+
progress?: boolean
2025
/**
2126
* Render the toaster in a portal.
2227
* @defaultValue true
@@ -49,7 +54,8 @@ import UToast from './Toast.vue'
4954
const props = withDefaults(defineProps<ToasterProps>(), {
5055
expand: true,
5156
portal: true,
52-
duration: 5000
57+
duration: 5000,
58+
progress: true
5359
})
5460
defineSlots<ToasterSlots>()
5561
@@ -109,6 +115,7 @@ function getOffset(index: number) {
109115
v-for="(toast, index) of toasts"
110116
:key="toast.id"
111117
ref="refs"
118+
:progress="progress"
112119
v-bind="omit(toast, ['id', 'close'])"
113120
:close="(toast.close as boolean)"
114121
:data-expanded="expanded"

0 commit comments

Comments
 (0)