-
Notifications
You must be signed in to change notification settings - Fork 6
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
iamgabrielsoft
wants to merge
42
commits into
main
Choose a base branch
from
feat/alert
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+462
−3
Open
Changes from 4 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
94572f6
alert toast
iamgabrielsoft c6df9dd
remove alert position for now
iamgabrielsoft d439310
lint file working on useToast hook
iamgabrielsoft f73a83b
lint files
iamgabrielsoft 62addcd
theme not added yet
iamgabrielsoft 79117fa
fix build
iamgabrielsoft 9f149c1
check build error
iamgabrielsoft b131ed2
alert review fix
iamgabrielsoft ce95381
alert toast
iamgabrielsoft e5440ea
remove alert position for now
iamgabrielsoft 0f6eb6c
lint file working on useToast hook
iamgabrielsoft 7e44b33
lint files
iamgabrielsoft 3d68e60
theme not added yet
iamgabrielsoft 64ce771
fix build
iamgabrielsoft 0524edf
check build error
iamgabrielsoft 7953e4c
review and resolved conflict
iamgabrielsoft 3ec5221
merge
iamgabrielsoft 2caef63
edited default alert
iamgabrielsoft 374c80a
added more description to alert
iamgabrielsoft b28f407
added description
iamgabrielsoft 14ec3d6
remove alert plugin type
iamgabrielsoft 7799dc7
fix build error
iamgabrielsoft fbd7ca2
Merge remote-tracking branch 'origin' into feat/alert
iamgabrielsoft 7b76630
resolving merge
iamgabrielsoft 8ebbcd5
lint file
iamgabrielsoft 8a9b369
lint files
iamgabrielsoft 5a41e1c
theme not added yet
iamgabrielsoft 43e9d83
check build error
iamgabrielsoft 6ed401f
added theme attr to alert
iamgabrielsoft 1e1d2f0
remove unecessary styles
iamgabrielsoft f724101
Update codex-ui/src/vue/components/alert/BaseAlert.vue
iamgabrielsoft 8b26112
removed computed styles property
iamgabrielsoft 468be67
added alert type methods
iamgabrielsoft 18f3575
removed unecessaru styles
iamgabrielsoft b64c389
moved z-index to z-axis file
iamgabrielsoft de4a5e7
remove core folder
iamgabrielsoft e6a1d47
remove usestore from alert hook
iamgabrielsoft 8859247
review fix
iamgabrielsoft 4509f67
removed alert constant
iamgabrielsoft e200e7b
triggerAlert props are constant
iamgabrielsoft cbe1b01
fix transition
iamgabrielsoft 6ad6208
rm reduntant props
iamgabrielsoft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
iamgabrielsoft marked this conversation as resolved.
Show resolved
Hide resolved
iamgabrielsoft marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Alert from './Alert.vue'; | ||
|
||
export { Alert }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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