Skip to content

alert toast component #248

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

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open

alert toast component #248

wants to merge 47 commits into from

Conversation

iamgabrielsoft
Copy link
Contributor

The attached issue #247

@iamgabrielsoft iamgabrielsoft self-assigned this Jul 4, 2024
Copy link
Contributor

@TatianaFomina TatianaFomina left a 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

@TatianaFomina

This comment was marked as resolved.

@iamgabrielsoft

This comment was marked as resolved.


&--bottom-center {
left: 50%;
bottom: 2rem
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in default it should be --base--bg-secondary
image

Comment on lines 8 to 15
/**
* position of alert, default position -> bottom-center
*/
export enum POSITION {

// eslint-disable-next-line @typescript-eslint/naming-convention
BOTTOM_CENTER = 'bottom-center'
}
Copy link
Member

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

Copy link
Contributor Author

@iamgabrielsoft iamgabrielsoft Sep 23, 2024

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 {
Copy link
Member

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

Copy link
Contributor Author

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);
Copy link
Member

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

Suggested change
transform: translateY(30px);

Copy link
Contributor Author

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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),
Copy link
Member

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

Copy link
Contributor Author

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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export type Alertype = 'success' | 'error' | 'warning' | 'info' | 'default';
export type AlertType = 'success' | 'error' | 'warning' | 'info' | 'default';

position: 'bottom-center',
message: '',
icon: '',
type: undefined,
Copy link
Member

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

Copy link
Contributor Author

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?

Comment on lines 26 to 31
id: genId(),
position: 'bottom-center',
content: '',
icon: '',
type: undefined,
timeout: 5000,
Copy link
Member

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

Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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

yes I added a defaultAlertOpt on useAlert()


return {
alerts,
success: (opt?: Omit<AlertOptions, 'id'>) => triggerAlert('success', opt),
Copy link
Collaborator

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still actual, but now opt?: Omit<AlertOptions, 'id'> not equals to opt: AlertOptions

Copy link
Member

@neSpecc neSpecc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • no animation
  • default alert styles looks incorrect
image - when leaving, alert styles becomes wrong (both red, for example)

/**
* Various alert theme type
*/
export type AlertTheme = 'grass' | 'red' | 'amber' | 'graphite' | '';
Copy link
Member

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);
Copy link
Member

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

Comment on lines 80 to 96
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);
Copy link
Member

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

Comment on lines 217 to 218
min-height: 100vh;
width: 100%;
Copy link
Member

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;
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actual

Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bottom: 2rem
bottom: var(--spacing-l)

import type { AlertOptions, AlerType } from './Alert.types';

/**
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
*

export const useAlert = createSharedComposable((): UseAlertComposableState => {
const alerts = ref<AlertOptions[]>([]);

const defaultAlertOpt = ref<AlertOptions>({
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix

Copy link
Member

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 />
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not fixed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still actual

Copy link
Member

@neSpecc neSpecc left a 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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not used

Copy link
Contributor Author

@iamgabrielsoft iamgabrielsoft Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been removed

Copy link
Member

@neSpecc neSpecc left a 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);
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

opt.id = counter.value++, opt.type = type, opt.timeout = currentTimeout;

alerts.value = [...alerts.value, opt];
setInterval(removeExpiredAlerts, currentTimeout);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets try to use requestAnimationFrame instead

@iamgabrielsoft iamgabrielsoft requested a review from e11sy July 4, 2025 17:07

return {
alerts,
success: (opt: Omit<AlertOptions, 'id'>) => triggerAlert('success', opt),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omit<AlertOptions, 'id'> contains alertType inside, so why we need to pass it as a constant too?

i think that one of those two presentations of alertType is redundant

@e11sy
Copy link
Collaborator

e11sy commented Jul 5, 2025

you have several small visual bugs

  1. Alert collapses at the start when hiding
  2. Alert is shaking (create 15 alerts in a row fast -> wait for 1 second -> create 2 more -> wait one second -> create two more) second alert will start to shake

@iamgabrielsoft iamgabrielsoft requested a review from neSpecc July 9, 2025 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants