Skip to content

Commit

Permalink
feat(Toast): expose toast duration in slot
Browse files Browse the repository at this point in the history
  • Loading branch information
cyyynthia committed Jul 10, 2024
1 parent 1c850cc commit d39d1c6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions docs/content/meta/ToastRoot.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,10 @@
'name': 'remaining',
'description': '<p>Remaining time (in ms)</p>\n',
'type': 'number'
},
{
'name': 'duration',
'description': '<p>Total time the toast will remain visible for (in ms)</p>\n',
'type': 'number'
}
]" />
2 changes: 1 addition & 1 deletion packages/radix-vue/src/Toast/Toast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Toast from './story/_Toast.vue'

const CLOSE_TEXT = 'Close'

describe('given a default Dialog', () => {
describe('given a default Toast', () => {
let wrapper: VueWrapper<InstanceType<typeof Toast>>
let trigger: DOMWrapper<HTMLElement>
let closeButton: HTMLElement
Expand Down
5 changes: 4 additions & 1 deletion packages/radix-vue/src/Toast/ToastRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ defineSlots<{
open: typeof open.value
/** Remaining time (in ms) */
remaining: number
/** Total time the toast will remain visible for (in ms) */
duration: number
}) => any
}>()
Expand All @@ -53,7 +55,7 @@ const open = useVModel(props, 'open', emits, {
<Presence :present="forceMount || open">
<ToastRootImpl
:ref="forwardRef"
v-slot="{ remaining }"
v-slot="{ remaining, duration: _duration }"
:open="open"
:type="type"
:as="as"
Expand Down Expand Up @@ -96,6 +98,7 @@ const open = useVModel(props, 'open', emits, {
>
<slot
:remaining="remaining"
:duration="_duration"
:open="open"
/>
</ToastRootImpl>
Expand Down
5 changes: 4 additions & 1 deletion packages/radix-vue/src/Toast/ToastRootImpl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ provideToastRootContext({ onClose: handleClose })
}
}"
>
<slot :remaining="remainingTime" />
<slot
:remaining="remainingTime"
:duration="duration"
/>
</Primitive>
</Teleport>
</template>

0 comments on commit d39d1c6

Please sign in to comment.