Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alert toast component #248

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
94572f6
alert toast
iamgabrielsoft Jul 4, 2024
c6df9dd
remove alert position for now
iamgabrielsoft Jul 4, 2024
d439310
lint file working on useToast hook
iamgabrielsoft Jul 4, 2024
f73a83b
lint files
iamgabrielsoft Jul 4, 2024
62addcd
theme not added yet
iamgabrielsoft Jul 17, 2024
79117fa
fix build
iamgabrielsoft Jul 17, 2024
9f149c1
check build error
iamgabrielsoft Jul 17, 2024
b131ed2
alert review fix
iamgabrielsoft Jul 19, 2024
ce95381
alert toast
iamgabrielsoft Jul 4, 2024
e5440ea
remove alert position for now
iamgabrielsoft Jul 4, 2024
0f6eb6c
lint file working on useToast hook
iamgabrielsoft Jul 4, 2024
7e44b33
lint files
iamgabrielsoft Jul 4, 2024
3d68e60
theme not added yet
iamgabrielsoft Jul 17, 2024
64ce771
fix build
iamgabrielsoft Jul 17, 2024
0524edf
check build error
iamgabrielsoft Jul 17, 2024
7953e4c
review and resolved conflict
iamgabrielsoft Jul 19, 2024
3ec5221
merge
iamgabrielsoft Jul 19, 2024
2caef63
edited default alert
iamgabrielsoft Jul 19, 2024
374c80a
added more description to alert
iamgabrielsoft Jul 19, 2024
b28f407
added description
iamgabrielsoft Jul 25, 2024
14ec3d6
remove alert plugin type
iamgabrielsoft Jul 25, 2024
7799dc7
fix build error
iamgabrielsoft Jul 25, 2024
fbd7ca2
Merge remote-tracking branch 'origin' into feat/alert
iamgabrielsoft Aug 1, 2024
7b76630
resolving merge
iamgabrielsoft Aug 1, 2024
8ebbcd5
lint file
iamgabrielsoft Aug 1, 2024
8a9b369
lint files
iamgabrielsoft Jul 4, 2024
5a41e1c
theme not added yet
iamgabrielsoft Jul 17, 2024
43e9d83
check build error
iamgabrielsoft Jul 17, 2024
6ed401f
added theme attr to alert
iamgabrielsoft Aug 8, 2024
1e1d2f0
remove unecessary styles
iamgabrielsoft Aug 8, 2024
f724101
Update codex-ui/src/vue/components/alert/BaseAlert.vue
iamgabrielsoft Aug 14, 2024
8b26112
removed computed styles property
iamgabrielsoft Aug 15, 2024
468be67
added alert type methods
iamgabrielsoft Aug 15, 2024
18f3575
removed unecessaru styles
iamgabrielsoft Aug 15, 2024
b64c389
moved z-index to z-axis file
iamgabrielsoft Aug 18, 2024
de4a5e7
remove core folder
iamgabrielsoft Aug 22, 2024
e6a1d47
remove usestore from alert hook
iamgabrielsoft Sep 17, 2024
8859247
review fix
iamgabrielsoft Sep 24, 2024
4509f67
removed alert constant
iamgabrielsoft Sep 26, 2024
e200e7b
triggerAlert props are constant
iamgabrielsoft Sep 28, 2024
cbe1b01
fix transition
iamgabrielsoft Oct 11, 2024
6ad6208
rm reduntant props
iamgabrielsoft Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions codex-ui/dev/Playground.vue
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,27 @@ const pages = computed(() => [
onActivate: () => router.push('/components/editor'),
isActive: route.path === '/components/editor',
},

{
title: 'Alert',
onActivate: () => router.push('/components/alert'),
isActive: route.path === '/components/alert',
},
],
},
]);
</script>

<style module>
.playground {
display: flex;
flex-direction: column;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems redundant. Describe a bug in details please

background-color: var(--base--bg-primary);
color: var(--base--text);
min-height: 100%;
width: 100%;
height: 100%;
overflow-x: hidden;
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
}
.header {
display: grid;
Expand Down
71 changes: 71 additions & 0 deletions codex-ui/dev/pages/components/Alert.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<template>
<PageHeader>
Alert
<template #description>
Light and beautiful notex alert
<code>click the button to see for yourself </code>
</template>
</PageHeader>

<Button
@click="showToast"
>
click alert
</Button>

<p>The following outlines options for alert to display </p>

<div class="flex-content">
<div>
Content
</div>

<div>
Position
</div>

<div>
Status
</div>

<div>
Timeout
</div>
</div>

<AlertContainer />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets move it to the root component (Playground.vue) to reuse the single container for the whole app

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still actual

</template>

<script setup lang="ts">
import PageHeader from '../../components/PageHeader.vue';
import { Button } from '../../../src/vue';
import { useAlert, AlertContainer, POSITION, AlertType } from '../../../src/vue/components/alert';

const toast = useAlert();

const getRandom = <T>(list: T[]) => list[Math.floor((Math.random() * 10) % list.length)];

const randomType = () => getRandom(Object.values(AlertType));

const randomPosition = () => getRandom(Object.values(POSITION));

const randomMessage = () =>
getRandom(['Hello', 'codex']);

const showToast = () => {
toast.success({ content: randomMessage(),
position: randomPosition(),
timeout: 10000,
status: randomType() });
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
};

</script>

<style lang="postcss">
.flex-content {
display: grid;
grid-template-columns: 1fr;
gap: var(--spacing-l);
align-items: center;
}
</style>
4 changes: 2 additions & 2 deletions codex-ui/dev/pages/components/Card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
orientation="horizontal"
src="https://via.placeholder.com/150"
>
<Button icon="Plus"/>
<Button icon="Plus" />
</Card>

<Heading :level="2">
Expand All @@ -29,7 +29,7 @@
orientation="vertical"
src="https://via.placeholder.com/150"
>
<Button icon="Plus"/>
<Button icon="Plus" />
</Card>
</template>

Expand Down
6 changes: 6 additions & 0 deletions codex-ui/dev/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import VerticalMenu from './pages/components/VerticalMenu.vue';
import ContextMenu from './pages/components/ContextMenu.vue';
import Editor from './pages/components/Editor.vue';
import ThemePreview from './pages/components/ThemePreview.vue';
import Alert from './pages/components/Alert.vue';

/**
* Vue router routes list
Expand Down Expand Up @@ -145,6 +146,11 @@ const routes: RouteRecordRaw[] = [
path: '/components/theme-preview',
component: ThemePreview as Component,
},

{
path: '/components/alert',
component: Alert as Component,
},
];

export default routes;
120 changes: 120 additions & 0 deletions codex-ui/src/vue/components/alert/AlertContainer.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<template>
<div ref="alertRef">
iamgabrielsoft marked this conversation as resolved.
Show resolved Hide resolved
<div
v-for="pos in positions"
:key="pos"
>
<AlertTransition
:class="alertClasses[pos]"
:pos="pos"
>
<BaseAlert
v-for="alert in positionToasts[pos]"
:key="alert.id"
v-bind="alert"
/>
</AlertTransition>
</div>
</div>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import BaseAlert from './BaseAlert.vue';
import AlertTransition from './AlertTransition.vue';
import { useAlert } from './core/useAlert';
import { AlertOptions, POSITION } from './core/types';
import { ALERT_CONTAINER_DEFAULTS, ALERT_NAMESPACE } from './core/constant';

const props = withDefaults(defineProps<AlertOptions>(), {
id: ALERT_CONTAINER_DEFAULTS.id,
position: ALERT_CONTAINER_DEFAULTS.position,
content: ALERT_CONTAINER_DEFAULTS.content,
closeOnClick: ALERT_CONTAINER_DEFAULTS.closeOnClick,
icon: ALERT_CONTAINER_DEFAULTS.icon,
status: ALERT_CONTAINER_DEFAULTS.status,
timeout: ALERT_CONTAINER_DEFAULTS.timeout,
onClick: ALERT_CONTAINER_DEFAULTS.onClick,
onClose: ALERT_CONTAINER_DEFAULTS.onClose,
});

const positions = Object.values(POSITION);

// eslint-disable-next-line no-unused-vars
const asPositionRecord = <T>(getValues: (position: POSITION) => T) =>
positions.reduce(
(agg, position) => ({
...agg,
[position]: getValues(position),
}),
{} as Record<POSITION, T>
);

const { alertRef, alertStore } = useAlert(props);

const positionToasts = computed(() => {
const getPosition = (position: POSITION) => {
return alertStore.value.filter((alert: AlertOptions) => alert.position === position).slice(0, 20)
.reverse();
};

return asPositionRecord(getPosition);
});

const alertClasses = computed(() => {
const getClasses = (position: POSITION) => {
const classes = [`${ALERT_NAMESPACE}__container`, position];

return classes;
};

return asPositionRecord(getClasses);
});
</script>

<style lang="postcss">
.notex-alert__container {
--padding-left: var(--h-padding);
--padding-right: var(--h-padding);
--zIndex: 9999;
neSpecc marked this conversation as resolved.
Show resolved Hide resolved

position: fixed;
min-height: 100%;
display: flex;
flex-direction: column;
box-sizing: border-box;
z-index: var(zIndex);

&.top-left,
&.top-right,
&.top-center {
top: 1rem;
}

&.bottom-left,
&.bottom-right,
&.bottom-center {
bottom: 1rem;
flex-direction: column-reverse;
}

&.top-left,
&.bottom-left {
left: 1rem;
}

&.top-right,
&.bottom-right {
right: 1rem;
}

&.top-center,
&.bottom-center {
left: 50%;
.notex-alert__alert {
margin-inline: auto;
}
}
}

</style>
36 changes: 36 additions & 0 deletions codex-ui/src/vue/components/alert/AlertTransition.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<template>
<transition-group
tag="div"
name="fade"
@leave="leave"
>
<slot />
</transition-group>
</template>

<script setup lang="ts">

const leave = (el: unknown) => {
if (el instanceof HTMLElement) {
el.style.left = el.offsetLeft + 'px';
el.style.top = el.offsetTop + 'px';
el.style.width = getComputedStyle(el).width;
el.style.position = 'absolute';
}
};
iamgabrielsoft marked this conversation as resolved.
Show resolved Hide resolved

</script>

<style lang="postcss">
.fade-enter-active,
.fade-leave-active {
transition: all 0.5s ease;
neSpecc marked this conversation as resolved.
Show resolved Hide resolved

}

.fade-enter-from,
.fade-leave-to {
opacity: 0;
transform: translate(30px, 20px);
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
}
</style>
Loading
Loading