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 30 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 @@ -197,16 +197,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
117 changes: 117 additions & 0 deletions codex-ui/dev/pages/components/Alert.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<template>
<PageHeader>
Alert
<template #description>
Light and beautiful codex alert
<code>click the button to see for yourself </code>
</template>
</PageHeader>

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

<div class="flex-content">
<div>
Message - message of the alert to be displayed (string)
</div>

<div>
Position - position of alert (bottom-center)
</div>

<div>
Type - alert type (success, error, warning, info and default)
</div>

<div>
Timeout - visibility duration in milliseconds, set timeout to keep toast visible
</div>
</div>

<div class="flex-type">
<div class="flex">
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
<span>Success</span>
<Button
@click="showToast('success')"
iamgabrielsoft marked this conversation as resolved.
Show resolved Hide resolved
>
click success
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
</Button>
</div>

<div class="flex">
<span>Error</span>
<Button
@click="showToast('error')"
>
click error
</Button>
</div>

<div class="flex">
<span>Warning</span>
<Button
@click="showToast('warning')"
>
click warning
</Button>
</div>

<div class="flex">
<span>Info</span>
<Button
@click="showToast('info')"
>
click info
</Button>
</div>

<div class="flex">
<span>Default</span>
<Button
@click="showToast('default')"
>
click default
</Button>
</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

</template>

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

const toast = useAlert;

const showToast = (status: AlertType) => {
toast(status, {
message: 'codex',
icon: 'Trash',
timeout: 5000,
});
};

</script>

<style lang="postcss">
.flex-content {
display: grid;
grid-template-columns: 1fr;
gap: var(--spacing-l);
align-items: center;
}

.flex-type {
display: flex;
flex-direction: column;
gap: 3rem;
margin-top: 2rem;

.flex {
display: grid;
grid-template-columns: repeat(2, max-content);
gap: var(--spacing-l);
align-items: center;
}
}
</style>
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;
56 changes: 56 additions & 0 deletions codex-ui/src/vue/components/alert/AlertContainer.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<template>
<div ref="alertRef">
iamgabrielsoft marked this conversation as resolved.
Show resolved Hide resolved
<div
:class="[
$style.alert__container,
$style['alert__container--' + props.position]
]"
>
<AlertTransition>
<BaseAlert
v-for="alert in alertStore"
:key="alert.id"
v-bind="alert"
/>
</AlertTransition>
</div>
</div>
</template>

<script setup lang="ts">
import BaseAlert from './BaseAlert.vue';
import AlertTransition from './AlertTransition.vue';
import { useAlert } from './core/useAlert';
import type { AlertOptions } from './core/types';
import { ALERT_CONTAINER_STYLES } from './core/constant';

const props = withDefaults(defineProps<AlertOptions>(), {
id: ALERT_CONTAINER_STYLES.id,
position: ALERT_CONTAINER_STYLES.position,
content: ALERT_CONTAINER_STYLES.message,
icon: ALERT_CONTAINER_STYLES.icon,
type: ALERT_CONTAINER_STYLES.type,
timeout: ALERT_CONTAINER_STYLES.timeout,
});

const { alertRef, alertStore } = useAlert(props.type, props);
</script>

<style module lang="postcss">
.alert__container {
--zIndex: 9999;
neSpecc marked this conversation as resolved.
Show resolved Hide resolved

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

&--bottom-center {
left: 50%;
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
bottom: 2rem
Copy link
Member

Choose a reason for hiding this comment

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

use size from Figma

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bottom: 2rem
bottom: var(--spacing-l)

}
}

</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>
134 changes: 134 additions & 0 deletions codex-ui/src/vue/components/alert/BaseAlert.vue
iamgabrielsoft marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<template>
<div
ref="el"
:class="[
$style.alert,
$style['alert--' + computedStyle]
iamgabrielsoft marked this conversation as resolved.
Show resolved Hide resolved
]"
:theme-base="computedTheme"
>
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
<Icon
v-show="icon"
:name="icon"
/>
<div>{{ props.message }}</div>
</div>
</template>

<script setup lang="ts">
import { defineProps, computed, withDefaults, ref } from 'vue';
import Icon from '../icon/Icon.vue';
import type { AlertOptions, AlertType } from './core/types';
import { ALERT_CONTAINER_STYLES } from './core/constant';

const el = ref<HTMLElement>();

const props = withDefaults(defineProps<AlertOptions>(), {
id: ALERT_CONTAINER_STYLES.id,
position: ALERT_CONTAINER_STYLES.position,
message: ALERT_CONTAINER_STYLES.message,
icon: ALERT_CONTAINER_STYLES.icon,
type: ALERT_CONTAINER_STYLES.type,
timeout: ALERT_CONTAINER_STYLES.timeout,
});

/**
* computed style
*/
const computedStyle = computed<AlertType | null>(() => {
if (props.type === 'success') {
return 'success';
}

if (props.type === 'error') {
return 'error';
}

if (props.type === 'warning') {
return 'warning';
}

if (props.type === 'info') {
return 'info';
}

if (props.type === 'default') {
return 'default';
}

return null;
});

/**
*
* computed theme
*/
const computedTheme = computed(() => {
if (props.type === 'success') {
return 'grass';
}

if (props.type === 'error') {
return 'red';
}

if (props.type === 'warning') {
return 'amber';
}

if (props.type === 'info') {
return 'graphite';
}

return '';
iamgabrielsoft marked this conversation as resolved.
Show resolved Hide resolved
});
</script>

<style module lang="postcss">
.alert {
--padding-left: var(--h-padding);
--padding-right: var(--h-padding);
--color: var(--accent--text-solid-foreground);
--bg: var(--base-text);
iamgabrielsoft marked this conversation as resolved.
Show resolved Hide resolved

position: relative;
box-sizing: border-box;
display: flex;
align-items: center;
gap: var(--v-padding);
border: 0;
margin-block-start: 0.4rem;
outline: 0;
font-family: inherit;
pointer-events: auto;
background-color: var(--bg);
overflow: hidden;
word-break: keep-all;
transform: translateZ(0);
direction: ltr;
padding: var(--v-padding) var(--padding-right) var(--v-padding) var(--padding-left);
border-radius: var(--radius-field);
box-shadow: inset 0 0 0 1px var(--border-color);
Copy link
Member

Choose a reason for hiding this comment

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

where this border came from?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the existing border-radius and the one on Figma are the same 8px

color: var(--color);

&--success {
--bg: var(--base--solid);
}

&--error {
--bg: var(--base--solid);
}

&--warning {
--bg: var(--base--solid);
}

&--info {
--bg: var(--base--solid);
}
iamgabrielsoft marked this conversation as resolved.
Show resolved Hide resolved

&--default {
--bg: var(--base--solid-secondary);
}
}
</style>
Loading
Loading