-
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 40 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 |
---|---|---|
|
@@ -197,16 +197,25 @@ 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; | ||
background-color: var(--base--bg-primary); | ||
color: var(--base--text); | ||
min-height: 100%; | ||
min-height: 100vh; | ||
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. min hight 100% worked fine 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. actual 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 |
||
width: 100%; | ||
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. seems like nothing changes here |
||
} | ||
.header { | ||
display: grid; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<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" | ||
> | ||
Show success alert | ||
</Button> | ||
</div> | ||
|
||
<div class="flex"> | ||
<span>Error</span> | ||
<Button | ||
@click="showErrorAlert" | ||
> | ||
Show error alert | ||
</Button> | ||
</div> | ||
|
||
<div class="flex"> | ||
<span>Warning</span> | ||
<Button | ||
@click="showWarningAlert" | ||
> | ||
Show warning alert | ||
</Button> | ||
</div> | ||
|
||
<div class="flex"> | ||
<span>Info</span> | ||
<Button | ||
@click="showInfoAlert" | ||
> | ||
Show info alert | ||
</Button> | ||
</div> | ||
|
||
<div class="flex"> | ||
<span>Default</span> | ||
<Button | ||
@click="showDefaultAlert" | ||
> | ||
Show default alert | ||
</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, alert } = useAlert(); | ||
|
||
const showSuccessAlert = () => { | ||
success({ | ||
message: 'codex', | ||
timeout: 5000, | ||
}); | ||
}; | ||
|
||
const showErrorAlert = () => { | ||
error({ | ||
message: 'codex', | ||
timeout: 5000, | ||
}); | ||
}; | ||
|
||
const showWarningAlert = () => { | ||
warning({ | ||
message: 'codex', | ||
timeout: 5000, | ||
}); | ||
}; | ||
|
||
const showInfoAlert = () => { | ||
info({ | ||
message: 'codex', | ||
timeout: 5000, | ||
}); | ||
}; | ||
|
||
const showDefaultAlert = () => { | ||
alert({ | ||
message: 'codex', | ||
timeout: 5000, | ||
}); | ||
}; | ||
|
||
</script> | ||
|
||
<style lang="postcss"> | ||
.flex-content { | ||
display: grid; | ||
grid-template-columns: 1fr; | ||
gap: var(--spacing-l); | ||
align-items: center; | ||
} | ||
|
||
.flex-type { | ||
display: grid; | ||
grid-template-columns: repeat(1, 2fr); | ||
gap: var(--spacing-l); | ||
align-items: center; | ||
margin-top: 2rem; | ||
|
||
.flex { | ||
display: grid; | ||
grid-template-columns: repeat(5, 1fr); | ||
align-items: center; | ||
gap: var(--spacing-l); | ||
|
||
button { | ||
display: grid; | ||
grid-column: span 1; | ||
} | ||
} | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
:root { | ||
--z-popover: 3; | ||
--z-alert: calc(var(--z-popover) + 1) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Various alert type | ||
*/ | ||
export type AlerType = 'success' | 'error' | 'warning' | 'info' | 'default'; | ||
|
||
/** | ||
* Various alert theme type | ||
*/ | ||
export type AlertTheme = 'grass' | 'red' | 'amber' | 'graphite' | ''; | ||
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. theme is accepting globally, you don't need to define it on a component level |
||
|
||
/** | ||
* alert configuration | ||
*/ | ||
export interface AlertOptions { | ||
/** unique alert id */ | ||
id?: string; | ||
|
||
/** | ||
* Custom icon class to be used. | ||
* | ||
*/ | ||
icon?: string; | ||
|
||
/** | ||
* content to be rendered | ||
*/ | ||
message: string; | ||
|
||
/** | ||
* Type of the alert. | ||
* | ||
* Can be any of `(success, error, default, info, warning)` | ||
*/ | ||
type?: AlerType; | ||
|
||
/** | ||
* Position of the alert on the screen. | ||
* | ||
* (bottom-center). | ||
*/ | ||
position?: 'bottom-center'; | ||
|
||
/** | ||
* How many milliseconds for the alert to be auto dismissed | ||
*/ | ||
timeout?: number; | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,99 @@ | ||||||
<template> | ||||||
<div | ||||||
ref="el" | ||||||
:class="[ | ||||||
$style.alert, | ||||||
$style['alert--' + props.type] | ||||||
]" | ||||||
:theme-base="computedTheme" | ||||||
> | ||||||
<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, AlertTheme } from './Alert.types'; | ||||||
|
||||||
const el = ref<HTMLElement>(); | ||||||
|
||||||
const props = withDefaults(defineProps<AlertOptions>(), { | ||||||
id: `alert-' ${Math.random()}`, | ||||||
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
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. addressed |
||||||
position: 'bottom-center', | ||||||
message: '', | ||||||
icon: '', | ||||||
type: 'default', | ||||||
timeout: 5000, | ||||||
}); | ||||||
|
||||||
/** | ||||||
* | ||||||
* computed theme | ||||||
*/ | ||||||
const computedTheme = computed((): AlertTheme => { | ||||||
switch (props.type) { | ||||||
case 'success': | ||||||
return 'grass'; | ||||||
|
||||||
case 'error': | ||||||
return 'red'; | ||||||
|
||||||
case 'warning': | ||||||
return 'amber'; | ||||||
|
||||||
case 'info': | ||||||
return 'graphite'; | ||||||
|
||||||
default: | ||||||
return ''; | ||||||
} | ||||||
}); | ||||||
</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); | ||||||
color: var(--accent--text-solid-foreground); | ||||||
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. probably |
||||||
|
||||||
&--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--bg-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. you need to override color with |
||||||
} | ||||||
} | ||||||
</style> |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,42 @@ | ||||||
<template> | ||||||
<div | ||||||
:class="[ | ||||||
$style.alert__container, | ||||||
$style['alert__container--' + defaultAlertOpt.position] | ||||||
iamgabrielsoft marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
]" | ||||||
> | ||||||
<AlertTransition> | ||||||
<Alert | ||||||
v-for="(alert, index) in alerts" | ||||||
:key="index" | ||||||
v-bind="alert" | ||||||
/> | ||||||
</AlertTransition> | ||||||
</div> | ||||||
</template> | ||||||
|
||||||
<script setup lang="ts"> | ||||||
import Alert from './Alert.vue'; | ||||||
import AlertTransition from './AlertTransition.vue'; | ||||||
import { useAlert } from './useAlert'; | ||||||
|
||||||
const { alerts, defaultAlertOpt } = useAlert(); | ||||||
|
||||||
</script> | ||||||
|
||||||
<style module lang="postcss"> | ||||||
.alert__container { | ||||||
position: fixed; | ||||||
min-height: 100%; | ||||||
display: flex; | ||||||
flex-direction: column-reverse; | ||||||
box-sizing: border-box; | ||||||
z-index: var(--z-alert); | ||||||
|
||||||
&--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> |
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