Skip to content

Commit

Permalink
ToastContainer > Add toast.show trigger (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
mosarabi committed Jan 24, 2024
1 parent bae9064 commit 5fe1881
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 20 deletions.
48 changes: 34 additions & 14 deletions packages/vue3/src/_dev/App.vue
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
<script setup lang="ts">
import 'uno.css';
import '../assets/main.css';
import { ref } from 'vue';
import { Input, TextArea } from '~/components';
import { PrimaryButton, ToastContainer, toast } from '~/components';
import type { ToastOptions } from '~/components/ToastContainer/types';
const comment = ref('');
const toasts: ToastOptions[] = [
{
title: 'Info',
description: 'Click here to learn more about the exciting enhancements we\'ve made.',
type: 'info',
},
{
title: 'Success',
description: 'Your profile information has been successfully updated.',
type: 'success',
},
{
title: 'Warning',
description: 'Please check your internet connection.',
type: 'warning',
},
{
title: 'Error',
description: 'Unable to save data, check again later.',
type: 'error',
},
];
const handleClick = () => {
const toastOptions: ToastOptions = toasts[Math.floor(Math.random() * toasts.length)];
toast.show(toastOptions);
};
</script>

<template>
<div class="container">
<TextArea
v-model="comment"
placeholder="Leave your comment"
/>
<Input
v-model="comment"
placeholder="Leave your comment"
type="password"
can-show
/>
<ToastContainer :limit="3" />
<div className="container">
<PrimaryButton @click="handleClick">
Show Toast
</PrimaryButton>
</div>
</template>

Expand Down
6 changes: 0 additions & 6 deletions packages/vue3/src/components/ToastContainer/index.ts

This file was deleted.

8 changes: 8 additions & 0 deletions packages/vue3/src/components/ToastContainer/toast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { ToastOptions } from './types';

export const toast = {
show: (toastOptions: ToastOptions) => {
const data = { id: 'show-toast', options: toastOptions };
window.postMessage(data);
},
};
1 change: 1 addition & 0 deletions packages/vue3/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export { default as SearchInput } from './Search/SearchInput.vue';
export { default as Alert } from './Alert/Alert.vue';
export { default as Toast } from './Toast/Toast.vue';
export { default as ToastContainer } from './ToastContainer/ToastContainer.vue';
export { toast } from './ToastContainer/toast';
export { default as DraggableItem } from './Draggable/DraggableItem.vue';
export { default as Draggable } from './Draggable/Draggable.vue';
export { default as Radio } from './Radio/Radio.vue';
Expand Down

0 comments on commit 5fe1881

Please sign in to comment.