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 4 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
12 changes: 12 additions & 0 deletions codex-ui/dev/Playground.vue
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,28 @@ 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
/* height: 100vh; */
iamgabrielsoft marked this conversation as resolved.
Show resolved Hide resolved
}
.header {
display: grid;
Expand Down
10 changes: 10 additions & 0 deletions codex-ui/dev/pages/components/Alert.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<Alert
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
:message="'Hello alert'"
type="info"
/>
</template>

<script setup lang="ts">
import { Alert } from '../../../src/vue';
</script>
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;
136 changes: 136 additions & 0 deletions codex-ui/src/vue/components/alert/Alert.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<template>
<transition name="fadeInBottom">
<div
v-show="message"
class="alert"
:class="`alert--${alertType}`"
>
<Icon name="Check" />
iamgabrielsoft marked this conversation as resolved.
Show resolved Hide resolved
<span v-if="props.message">{{ message }}</span>
<slot />
</div>
</transition>
</template>

<script setup lang="ts">
import { defineProps, computed, withDefaults } from 'vue';
import Icon from '../icon/Icon.vue';

const props = withDefaults(
defineProps<{
/**
* message to display
*/
message?: string;

/**
* alert status
*/
type: 'success' | 'error' | 'warning' | 'default' | 'info';

}>(), {
message: '',
type: 'default',
}
);

/** determine alert status */
const alertType = computed(() => {
if (props.type === 'success') {
return 'success';
}

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

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

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

return 'default';
});

</script>

<style lang="postcss">

@keyframes fadeInBottom {
0% {
transform: translateY(50px);
opacity: 0;
}

100% {
transform: translateY(0);
opacity: 1;
}
}

.alert {
--padding-left: var(--h-padding);
--padding-right: var(--h-padding);
iamgabrielsoft marked this conversation as resolved.
Show resolved Hide resolved
--success: #00A64D;
--error: #BB393D;
--warning: #DE6205;
--info: #54617B;
--default: #54617B;
neSpecc marked this conversation as resolved.
Show resolved Hide resolved

position: fixed;
bottom: 0;
left: 50%;
margin-bottom: 1rem;
display: flex;
align-items: center;
font-size: inherit;
gap: var(--v-padding);
border: 0;
outline: 0;
font-family: inherit;
cursor: text;
word-break: keep-all;
z-index: 1;
border-radius: var(--radius-field);
padding: 1rem;

&--success {
background-color: var(--success);
}

&--error {
background-color: var(--error);
}

&--warning {
background-color: var(--warning);
}

&--default {
background-color: var(--default);
}

&--info {
background-color: var(--info);
}
}

.fadeInBottom__fade-enter-active {
animation-name: fadeInBottom;
}

.fadeInBottom__fade-leave-active,
.fadeInBottom__fade-enter-active {
animation-duration: 750ms;
neSpecc marked this conversation as resolved.
Show resolved Hide resolved
animation-fill-mode: both;
}

.fadeInBottom__fade-move {
transition-timing-function: ease-in-out;
transition-property: all;
transition-duration: 400ms;
}
</style>
17 changes: 17 additions & 0 deletions codex-ui/src/vue/components/alert/constant.ts
iamgabrielsoft marked this conversation as resolved.
Show resolved Hide resolved
iamgabrielsoft marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export enum ToastType {
SUCCESS = 'success',
ERROR = 'error',
WARNING = 'warning',
INFO = 'info',
DEFAULT = 'default'
};

export enum EVENTS {
ADD = 'add'
}

export interface ToastInterface {};

export interface ToastOptions {

}
3 changes: 3 additions & 0 deletions codex-ui/src/vue/components/alert/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Alert from './Alert.vue';

export { Alert };
84 changes: 84 additions & 0 deletions codex-ui/src/vue/components/alert/useToast.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { inject } from 'vue';
import type { ToastInterface, ToastOptions } from './constant';
import { EVENTS, ToastType } from './constant';

const toastSymbolKey = Symbol('Alert');

type Events = {
[EVENTS.ADD]: {
id: string;
};
};

type Handler<E extends EVENTS> = (event: Events[E]) => void;

type HandlerList<E extends EVENTS> = Handler<E>[];
type HandlerMap = {
[E in EVENTS]?: HandlerList<E>
};

/**
*
*/
class EventBus {
protected allHandlers: HandlerMap = {};

protected getHandlers<E extends EVENTS>(eventType: E) {
return (this.allHandlers[eventType]) || [];
}

public on<E extends EVENTS>(eventType: E, handler: Handler<E>) {
const handlers = this.getHandlers(eventType).push(handler);

this.allHandlers[eventType] = handlers as unknown as EventBus['allHandlers'][E ];
}

public off<E extends EVENTS>(eventType: E, handler: Handler<E>) {
const handlers = this.getHandlers(eventType);

handlers.splice(handlers.indexOf(handler) >>> 0, 1);
}

public emit<E extends EVENTS>(eventType: E, event: Events[E]) {
return this.getHandlers(eventType).forEach(handler => handler(event));
}
};

const eventBus = new EventBus();

interface ToastInstance {
(option?: ToastOptions): ToastInterface;
}

const toastId = (i: number = 0) => i++;

/**
*
* @param eventBus
*/
const useToast = (eventBus?: EventBus) => {
if (!eventBus) {
return;
}

const toastMethod = <T extends ToastType = ToastType> (type: T) => {
eventBus.emit(EVENTS.ADD, eventBus);

return {
id: toastId(),
type,
};
};

return {
success: toastMethod(ToastType.SUCCESS),
error: toastMethod(ToastType.ERROR),
info: toastMethod(ToastType.INFO),
warning: toastMethod(ToastType.WARNING),
default: toastMethod(ToastType.DEFAULT),
};
};

export {
useToast
};
10 changes: 8 additions & 2 deletions codex-ui/src/vue/components/row/Row.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@
<div :class="$style['row__body']">
<div :class="$style['row__body-inner']">
<div :class="$style['row__center']">
<div v-if="label" :class="[$style['row__label'], 'text-ui-footnote']">
<div
v-if="label"
:class="[$style['row__label'], 'text-ui-footnote']"
>
{{ label }}
</div>

<div :class="[$style['row__title'], 'text-ui-base-medium']">
{{ title }}
</div>

<div v-if="subtitle" class="text-ui-subtle">
<div
v-if="subtitle"
class="text-ui-subtle"
>
{{ subtitle }}
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions codex-ui/src/vue/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './components/alert';
export * from './components/button';
export * from './components/form';
export * from './components/heading';
Expand Down
Loading