-
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?
Conversation
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.
please fix build errors
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
import type { AlertInterface, AlertOptions, AlertType } from './types'; | ||
import { getId } from './constant'; | ||
|
||
const useStore = createSharedComposable(() => { |
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.
I'd suggest to get rid of this composable and just use a ref at the useAlerts
const alerts = ref<Alert[]>([]);
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.
I think Composable keeps the refs' state, ref has being moved
|
||
&--bottom-center { | ||
left: 50%; | ||
bottom: 2rem |
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.
use size from Figma
} | ||
|
||
&--default { | ||
background-color: var(--base--solid-secondary); |
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.
/** | ||
* position of alert, default position -> bottom-center | ||
*/ | ||
export enum POSITION { | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
BOTTOM_CENTER = 'bottom-center' | ||
} |
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.
lets get rid of this param as it is not used at the moment
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.
effected
timeout?: number; | ||
} | ||
|
||
export interface AlertInterface { |
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.
lets move it to the useAlert
file and rename to the useAlertComposableState
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.
effected
.fade-enter-from, | ||
.fade-leave-to { | ||
opacity: 0; | ||
transform: translateY(30px); |
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.
lets use simple fade-out effect for leaving
transform: translateY(30px); |
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.
please look at the updated one, if its good enough
<style lang="postcss"> | ||
.fade-enter-active, | ||
.fade-leave-active { | ||
transition: opacity 0.5s ease, transform 0.5s ease; |
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.
transition: opacity 0.5s ease, transform 0.5s ease; | |
transition: opacity 0.25s ease, transform 0.25s ease; |
error: (opt?: Pick<AlertOptions, 'icon' | 'message' | 'timeout'>) => triggerAlert('error', opt), | ||
warning: (opt?: Pick<AlertOptions, 'icon' | 'message' | 'timeout'>) => triggerAlert('warning', opt), | ||
info: (opt?: Pick<AlertOptions, 'icon' | 'message' | 'timeout'>) => triggerAlert('info', opt), | ||
defaultAlert: (opt?: Pick<AlertOptions, 'icon' | 'message' | 'timeout'>) => triggerAlert('default', opt), |
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.
lets rename defaultAlert
to alert
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.
effected
/** | ||
* Various alert type | ||
*/ | ||
export type Alertype = 'success' | 'error' | 'warning' | 'info' | 'default'; |
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.
export type Alertype = 'success' | 'error' | 'warning' | 'info' | 'default'; | |
export type AlertType = 'success' | 'error' | 'warning' | 'info' | 'default'; |
position: 'bottom-center', | ||
message: '', | ||
icon: '', | ||
type: undefined, |
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.
lets make it default
by default
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.
as in defaultProps for the variable name?
id: genId(), | ||
position: 'bottom-center', | ||
content: '', | ||
icon: '', | ||
type: undefined, | ||
timeout: 5000, |
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.
it's better to leave the only place with default values. I think this properties are note related to Alerts Container
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.
probably,alerts
returned by useAlert()
should include them
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.
it's better to leave the only place with default values. I think this properties are note related to Alerts Container
its used in Alert container position
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.
probably,
alerts
returned byuseAlert()
should include them
yes I added a defaultAlertOpt on useAlert()
if (props.type === 'success') { | ||
return 'grass'; | ||
} | ||
|
||
if (props.type === 'error') { | ||
return 'red'; | ||
} | ||
|
||
if (props.type === 'warning') { | ||
return 'amber'; | ||
} | ||
|
||
if (props.type === 'info') { | ||
return 'graphite'; | ||
} |
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.
use switch case
for that please
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.
ok
/** | ||
* Type of the alert. | ||
* | ||
* Can be any of `(success, error, default, info, warning)` | ||
*/ | ||
type?: Alertype; |
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.
as i can see, this field is unused
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.
it's used but passed as props, hence it's passed as a constant in useAlert return values
|
||
return { | ||
alerts, | ||
success: (opt?: Omit<AlertOptions, 'id'>) => triggerAlert('success', opt), |
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.
you have incompatible types of opts, Omit<AlertOptions, 'id'>
is not the same as Pick<AlertOptions, 'id' | 'icon' | 'message' | 'timeout'>
used in triggerAlert
* @param type type of alert (success, error, warning, info and default) | ||
* @param opt alert options(timeout, message and icon) | ||
*/ | ||
function triggerAlert(type?: Alertype, opt?: Pick<AlertOptions, 'id' | 'icon' | 'message' | 'timeout'>): void { |
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.
as i can see, you are using triggerAlert
only inside of this composable, so why should type and opt be optional?
i suggest making of the type
and opts
required, also message
field should not be optional in AlertOptions
to avoid empty alerts
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.
i think passing a default message should be more helpful, something like
message: 'codex'
over
message: '' (empty string)
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.
/** | ||
* Various alert theme type | ||
*/ | ||
export type AlertTheme = 'grass' | 'red' | 'amber' | 'graphite' | ''; |
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.
theme is accepting globally, you don't need to define it on a component level
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 comment
The reason will be displayed to describe this comment to others. Learn more.
probably --base--text-solid-foreground
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 comment
The reason will be displayed to describe this comment to others. Learn more.
you need to override color with --base--text
codex-ui/dev/Playground.vue
Outdated
min-height: 100vh; | ||
width: 100%; |
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 like nothing changes here
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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
still actual
|
||
&--bottom-center { | ||
left: 50%; | ||
bottom: 2rem |
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.
bottom: 2rem | |
bottom: var(--spacing-l) |
import type { AlertOptions, AlerType } from './Alert.types'; | ||
|
||
/** | ||
* |
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.
* |
export const useAlert = createSharedComposable((): UseAlertComposableState => { | ||
const alerts = ref<AlertOptions[]>([]); | ||
|
||
const defaultAlertOpt = ref<AlertOptions>({ |
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.
redundant duplication. Default props are defined in the Alert.vue
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.
fix
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.
not fixed
</div> | ||
</div> | ||
|
||
<AlertContainer /> |
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.
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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
still actual
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.
- bug with type-change on dissapearing
- when the last alert is about to dissapear, it became vertical
- remove left-axis transition
- for dissapering, use only fade-out, for appearing only fade-in
warning: (opt: Omit<AlertOptions, 'id'>) => triggerAlert('warning', opt), | ||
info: (opt: Omit<AlertOptions, 'id'>) => triggerAlert('info', opt), | ||
alert: (opt: Omit<AlertOptions, 'id'>) => triggerAlert('default', opt), | ||
defaultAlertOpt, |
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.
it is not used
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.
This has been removed
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.
the bug with color change on leaving still exist
...opt }); | ||
|
||
setTimeout(() => { | ||
alerts.value.splice(alertIndex, alerts.value.shift() as unknown as number); |
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.
index works unstable here since it is changing dynamically. Consider removing alert by id instead
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.
ok
The attached issue #247