-
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
base: main
Are you sure you want to change the base?
Changes from 34 commits
94572f6
c6df9dd
d439310
f73a83b
62addcd
79117fa
9f149c1
b131ed2
ce95381
e5440ea
0f6eb6c
7e44b33
3d68e60
64ce771
0524edf
7953e4c
3ec5221
2caef63
374c80a
b28f407
14ec3d6
7799dc7
fbd7ca2
7b76630
8ebbcd5
8a9b369
5a41e1c
43e9d83
6ed401f
1e1d2f0
f724101
8b26112
468be67
18f3575
b64c389
de4a5e7
e6a1d47
8859247
4509f67
e200e7b
cbe1b01
6ad6208
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
<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 alert 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="showSuccessAlert" | ||
> | ||
click success | ||
neSpecc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</Button> | ||
</div> | ||
|
||
<div class="flex"> | ||
<span>Error</span> | ||
<Button | ||
@click="showErrorAlert" | ||
> | ||
click error | ||
</Button> | ||
</div> | ||
|
||
<div class="flex"> | ||
<span>Warning</span> | ||
<Button | ||
@click="showWarningAlert" | ||
> | ||
click warning | ||
</Button> | ||
</div> | ||
|
||
<div class="flex"> | ||
<span>Info</span> | ||
<Button | ||
@click="showInfoAlert" | ||
> | ||
click info | ||
</Button> | ||
</div> | ||
|
||
<div class="flex"> | ||
<span>Default</span> | ||
<Button | ||
@click="showDefaultAlert" | ||
> | ||
click default | ||
</Button> | ||
</div> | ||
</div> | ||
|
||
<AlertContainer /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, useAlert, AlertContainer } from '../../../src/vue'; | ||
|
||
const { success, error, warning, info, defaultAlert } = useAlert(); | ||
|
||
const showSuccessAlert = () => { | ||
success({ | ||
message: 'success', | ||
icon: 'Trash', | ||
timeout: 5000, | ||
}); | ||
}; | ||
|
||
const showErrorAlert = () => { | ||
error({ | ||
message: 'error', | ||
icon: 'Trash', | ||
timeout: 5000, | ||
}); | ||
}; | ||
|
||
const showWarningAlert = () => { | ||
warning({ | ||
message: 'warning', | ||
icon: 'Trash', | ||
timeout: 5000, | ||
}); | ||
}; | ||
|
||
const showInfoAlert = () => { | ||
info({ | ||
message: 'info', | ||
icon: 'Trash', | ||
timeout: 5000, | ||
}); | ||
}; | ||
|
||
const showDefaultAlert = () => { | ||
defaultAlert({ | ||
message: 'default', | ||
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> |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,59 @@ | ||||||
<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, | ||||||
neSpecc marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} = 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 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use size from Figma There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
} | ||||||
|
||||||
</style> |
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> |
iamgabrielsoft marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<template> | ||
<div | ||
ref="el" | ||
:class="[ | ||
$style.alert, | ||
$style['alert--' + props.type] | ||
]" | ||
: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 } 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 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 undefined; | ||
}); | ||
</script> | ||
|
||
<style module lang="postcss"> | ||
.alert { | ||
|
||
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(--base-text); | ||
overflow: hidden; | ||
word-break: keep-all; | ||
transform: translateZ(0); | ||
direction: ltr; | ||
padding: var(--v-padding) var(--h-padding) var(--v-padding) var(--h-padding); | ||
border-radius: var(--radius-field); | ||
box-shadow: inset 0 0 0 1px var(--border-color); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where this border came from? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(--accent--text-solid-foreground); | ||
|
||
&--success { | ||
background-color: var(--base--solid); | ||
} | ||
|
||
&--error { | ||
background-color: var(--base--solid); | ||
} | ||
|
||
&--warning { | ||
background-color: var(--base--solid); | ||
} | ||
|
||
&--info { | ||
background-color: var(--base--solid); | ||
} | ||
|
||
&--default { | ||
background-color: var(--base--solid-secondary); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
} | ||
</style> |
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