-
-
Notifications
You must be signed in to change notification settings - Fork 547
Expand file tree
/
Copy pathToastAction.vue
More file actions
63 lines (56 loc) · 1.52 KB
/
Copy pathToastAction.vue
File metadata and controls
63 lines (56 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<script lang="ts">
import type { ToastCloseProps } from './ToastClose.vue'
export interface ToastActionProps extends ToastCloseProps {
/**
* A short description for an alternate way to carry out the action. For screen reader users
* who will not be able to navigate to the button easily/quickly.
* @example <ToastAction altText="Goto account settings to upgrade">Upgrade</ToastAction>
* @example <ToastAction altText="Undo (Alt+U)">Undo</ToastAction>
*/
altText: string
/**
* Whether the action should close the toast when clicked.
*
* @defaultValue true
*/
closeOnClick?: boolean
}
</script>
<script setup lang="ts">
import { Primitive } from '@/Primitive'
import { useForwardExpose } from '@/shared'
import ToastAnnounceExclude from './ToastAnnounceExclude.vue'
import ToastClose from './ToastClose.vue'
const props = withDefaults(defineProps<ToastActionProps>(), {
as: 'button',
closeOnClick: true,
})
if (!props.altText)
throw new Error('Missing prop `altText` expected on `ToastAction`')
const { forwardRef } = useForwardExpose()
</script>
<template>
<ToastAnnounceExclude
v-if="altText"
:alt-text="altText"
as-child
>
<ToastClose
v-if="closeOnClick"
:ref="forwardRef"
:as="as"
:as-child="asChild"
>
<slot />
</ToastClose>
<Primitive
v-else
:ref="forwardRef"
:as="as"
:as-child="asChild"
:type="as === 'button' ? 'button' : undefined"
>
<slot />
</Primitive>
</ToastAnnounceExclude>
</template>