Skip to content

Commit ab5a550

Browse files
committed
feat(toast): supports top-center and bottom-center positions
1 parent 2be1769 commit ab5a550

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

docs/content/components/toast.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ By default, toasts appear in the bottom-right corner.
5656

5757
<div class="flex flex-wrap items-center gap-4">
5858
<Button @click="changePosition('top-left')" variant="surface">Top left</Button>
59+
<Button @click="changePosition('top-center')" variant="surface">Top center</Button>
5960
<Button @click="changePosition('top-right')" variant="surface">Top right</Button>
6061
<Button @click="changePosition('bottom-left')" variant="surface">Bottom left</Button>
62+
<Button @click="changePosition('bottom-center')" variant="surface">Bottom center</Button>
6163
<Button @click="changePosition('bottom-right')" variant="surface">Bottom right</Button>
6264
</div>
6365

src/components/toast/ToastItem.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import type { ToastMessage, MessageCategory } from './manager'
1010
import { useToastManager } from './manager'
1111
1212
export interface ToastItemProps {
13-
yPosition: 'top' | 'bottom'
14-
xPosition: 'left' | 'right'
13+
yPosition: 'top' | 'bottom' | 'center'
14+
xPosition: 'left' | 'right' | 'center'
1515
message: ToastMessage
1616
index: number
1717
}
@@ -222,11 +222,11 @@ onMounted(() => {
222222
--toast-item-swipe-to-x: calc(100% + var(--toast-x-position))
223223
}
224224
225-
.ui-ToastItem:where([data-swipe-direction="top"]) {
225+
.ui-ToastItem:where([data-swipe-direction="up"]) {
226226
--toast-item-swipe-to-y: calc(0 - 100% - var(--toast-y-position))
227227
}
228228
229-
.ui-ToastItem:where([data-swipe-direction="bottom"]) {
229+
.ui-ToastItem:where([data-swipe-direction="down"]) {
230230
--toast-item-swipe-to-y: calc(100% + var(--toast-y-position))
231231
}
232232

src/components/toast/ToastProvider.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ToastProviderProps as RekaToastProviderProps } from 'reka-ui'
33
44
export interface ToastProviderProps extends RekaToastProviderProps {
55
size?: '1' | '2' | '3'
6-
position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'
6+
position?: 'top-left' | 'top-right' | 'top-center' | 'bottom-left' | 'bottom-right' | 'bottom-center'
77
}
88
</script>
99

@@ -32,18 +32,21 @@ const forwarded = useForwardPropsWithout(props, ['position', 'size'])
3232
const { messages } = useToastManager()
3333
3434
const yPosition = computed(() => {
35-
return props.position.split('-')[0] as 'top' | 'bottom'
35+
return props.position.split('-')[0] as 'top' | 'bottom' | 'center'
3636
})
3737
3838
const xPosition = computed(() => {
39-
return props.position.split('-')[1] as 'left' | 'right'
39+
return props.position.split('-')[1] as 'left' | 'right' | 'center'
4040
})
4141
4242
const swipeDirection = computed(() => {
4343
if (props.swipeDirection) {
4444
return props.swipeDirection
4545
}
46-
return xPosition.value
46+
if (xPosition.value !== 'center') {
47+
return xPosition.value
48+
}
49+
return yPosition.value === 'top' ? 'up' : 'down'
4750
})
4851
</script>
4952

@@ -122,6 +125,9 @@ const swipeDirection = computed(() => {
122125
.ui-ToastViewport:where([data-x-position="right"]) {
123126
right: var(--toast-x-position);
124127
}
128+
.ui-ToastViewport:where([data-x-position="center"]) {
129+
left: calc(50% - var(--toast-width) / 2);
130+
}
125131
.ui-ToastViewport:where([data-y-position="top"]) {
126132
top: var(--toast-y-position);
127133
}

0 commit comments

Comments
 (0)