Skip to content

Commit

Permalink
YSHOP2-1270 : ToastContainer > new component (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
mosarabi committed Jan 15, 2024
1 parent 0fdcfd8 commit 28ef744
Show file tree
Hide file tree
Showing 10 changed files with 442 additions and 160 deletions.
6 changes: 3 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"prettier.enable": false,
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.fixAll.stylelint": true,
"source.organizeImports": false
"source.fixAll.eslint": "explicit",
"source.fixAll.stylelint": "explicit",
"source.organizeImports": "never"
},
"stylelint.validate": ["vue"],
"cSpell.words": [
Expand Down
171 changes: 36 additions & 135 deletions packages/vue3/src/_dev/App.vue
Original file line number Diff line number Diff line change
@@ -1,153 +1,54 @@
<script setup lang="ts">
import 'uno.css';
import '../assets/main.css';
import { ref } from 'vue';
import { Table } from '~/components';
import type { StaticStatusDefinition } from '~/components/Status/types';
import type { TableActions, TableColumn, TableData } from '~/components/Table/types';
import { PrimaryButton, ToastContainer } from '~/components';
import { showToast } from '~/components/ToastContainer';
import type { ToastOptions } from '~/components/ToastContainer/types';
const columns: TableColumn[] = [
{ label: 'Domain', accessor: 'domain', sortable: 'desc' },
{ label: 'Status', accessor: 'status', sortable: 'desc' },
{ label: 'Git Branch', accessor: 'branch', sortable: 'desc' },
];
const actions: TableActions[] = [
const toasts: ToastOptions[] = [
{
label: 'Redeploy',
iconName: 'i-youcan-arrows-clockwise',
tooltip: 'Redeploy',
title: 'Info',
description: 'Click here to learn more about the exciting enhancements we\'ve made.',
type: 'info',
},
{
label: 'Copy URL',
iconName: 'i-youcan-copy',
tooltip: 'Copy URL',
title: 'Success',
description: 'Your profile information has been successfully updated.',
type: 'success',
},
{
label: 'Source Code',
iconName: 'i-youcan-code',
tooltip: 'Source Code',
},
];
const domainStatuses: { [k: string]: StaticStatusDefinition } = {
ready: {
color: '#52E2C0',
label: 'Ready',
labelColor: '#2d4236',
},
error: {
color: '#EE0200',
label: 'Error',
labelColor: '#f8dcdc',
},
building: {
color: '#ffc35c',
label: 'Building',
labelColor: '#574811',
title: 'Warning',
description: 'Please check your internet connection.',
type: 'warning',
},
queued: {
color: '#999999',
label: 'Queued',
labelColor: '#fff2f2',
},
};
const data = ref<TableData[]>([
{
row: {
id: 'eihabkhan.com',
domain: 'eihabkhan.com',
status: {
variant: 'static-status',
data: {
status: domainStatuses.building,
},
},
branch: 'main',
},
title: 'Error',
description: 'Unable to save data, check again later.',
type: 'error',
},
{
row: {
id: 'supershop.youcan.shop',
domain: 'supershop.youcan.shop',
status: {
variant: 'static-status',
data: {
status: domainStatuses.queued,
},
},
branch: 'main',
},
},
{
row: {
id: 'vercel.com',
domain: 'vercel.com',
status: {
variant: 'static-status',
data: {
status: domainStatuses.ready,
},
},
branch: 'main',
},
},
{
row: {
domain: 'nextjs.org',
status: {
variant: 'static-status',
data: {
status: domainStatuses.error,
},
},
branch: 'feat/next-conf',
},
},
]);
const selectedRows = ref<TableData[]>([]);
const handleSort = (column: TableColumn) => {
data.value = data.value.sort((a: any, b: any) => {
let textA = '';
let textB = '';
if (typeof a.row[column.accessor] === 'string') {
textA = (a.row[column.accessor] as string)?.toUpperCase();
textB = (b.row[column.accessor] as string)?.toUpperCase();
}
else if (a.row?.status?.data.status.label && b.row?.status?.data.status.label) {
textA = a.row?.status?.data.status.label;
textB = b.row?.status?.data.status.label;
}
if (textA < textB) {
return -1;
}
if (textA > textB) {
return 1;
}
return 0;
});
};
];
const updateSelectedRows = (data: TableData[]) => {
selectedRows.value = data;
const handleClick = () => {
const toast: ToastOptions = toasts[Math.floor(Math.random() * toasts.length)];
showToast(toast);
};
</script>

<template>
<Table
:columns="columns"
:data="data"
:actions="actions"
:selectable="true"
:selected-rows="selectedRows"
@sort="handleSort"
@update:selected-rows="updateSelectedRows"
/>
<ToastContainer :limit="3" position="bottom-right" :duration="100000" />
<div class="container">
<PrimaryButton @click="handleClick">
Show Toast
</PrimaryButton>
</div>
</template>

<style scoped>
.container {
display: flex;
align-items: center;
justify-content: center;
width: 100vw;
height: 100vh;
}
</style>
2 changes: 1 addition & 1 deletion packages/vue3/src/components/Alert/Alert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ onUnmounted(() => {
display: flex;
position: relative;
box-sizing: border-box;
width: max-content;
width: 400px;
max-width: 100%;
margin-bottom: 12px;
padding: 12px;
Expand Down
45 changes: 24 additions & 21 deletions packages/vue3/src/components/Toast/Toast.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ withDefaults(
{
position: 'top-right',
canClose: true,
type: 'info',
},
);
const emit = defineEmits(['close']);
Expand All @@ -17,7 +18,7 @@ const { title, description } = useSlots();

<template>
<Transition :name="position">
<div v-if="show" class="toast-block" :class="position">
<div v-if="show" class="toast-block" :class="[position, { relative }]">
<Alert :type="type" :can-close="canClose" :close-after-duration="closeAfterDuration" @close="emit('close')">
<template v-if="title" #title>
<slot name="title" />
Expand All @@ -35,31 +36,33 @@ $edges-margin: 20px;
$animation-duration: 0.3s;
.toast-block {
position: fixed;
z-index: 9999999999;
&.top {
&-right,
&-left {
top: $edges-margin;
&:not(.relative) {
position: fixed;
z-index: 9999999999;
&.top {
&-right,
&-left {
top: $edges-margin;
}
}
}
&.bottom {
&-right,
&-left {
bottom: $edges-margin;
&.bottom {
&-right,
&-left {
bottom: $edges-margin;
}
}
}
&.bottom,
&.top {
&-right {
right: $edges-margin;
}
&.bottom,
&.top {
&-right {
right: $edges-margin;
}
&-left {
left: $edges-margin;
&-left {
left: $edges-margin;
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/vue3/src/components/Toast/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export interface ToastProps {
type?: AlertType
closeAfterDuration?: number
canClose?: boolean
relative?: boolean
}
Loading

0 comments on commit 28ef744

Please sign in to comment.