Skip to content
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
wants to merge 42 commits into
base: main
Choose a base branch
from
Open

alert toast component #248

wants to merge 42 commits into from

Conversation

iamgabrielsoft
Copy link
Contributor

The attached issue #247

@iamgabrielsoft iamgabrielsoft self-assigned this Jul 4, 2024
codex-ui/dev/pages/components/Alert.vue Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/Alert.vue Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/Alert.vue Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/Alert.vue Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/Alert.vue Outdated Show resolved Hide resolved
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

codex-ui/dev/Playground.vue Outdated Show resolved Hide resolved
codex-ui/dev/pages/components/Alert.vue Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/BaseAlert.vue Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/BaseAlert.vue Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/BaseAlert.vue Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/core/useAlert.ts Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/core/constant.ts Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/core/constant.ts Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/core/types.ts Outdated Show resolved Hide resolved
@TatianaFomina

This comment was marked as resolved.

@iamgabrielsoft

This comment was marked as resolved.

codex-ui/dev/pages/components/Alert.vue Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/BaseAlert.vue Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/BaseAlert.vue Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/BaseAlert.vue Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/BaseAlert.vue Outdated Show resolved Hide resolved
import type { AlertInterface, AlertOptions, AlertType } from './types';
import { getId } from './constant';

const useStore = createSharedComposable(() => {
Copy link
Member

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[]>([]);

Copy link
Contributor Author

@iamgabrielsoft iamgabrielsoft Aug 16, 2024

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

codex-ui/src/vue/components/alert/core/useAlert.ts Outdated Show resolved Hide resolved
@iamgabrielsoft iamgabrielsoft requested review from e11sy and removed request for TatianaFomina and elizachi August 15, 2024 16:21
codex-ui/src/vue/components/alert/AlertContainer.vue Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/AlertContainer.vue Outdated Show resolved Hide 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

codex-ui/src/vue/components/alert/AlertTransition.vue Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/core/types.ts Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/core/types.ts Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/AlertContainer.vue Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/core/useAlert.ts Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/core/useAlert.ts Outdated Show resolved Hide resolved
codex-ui/dev/pages/components/Alert.vue Outdated Show resolved Hide resolved
codex-ui/dev/pages/components/Alert.vue Show resolved Hide resolved
codex-ui/src/vue/components/alert/core/types.ts Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/core/useAlert.ts Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/core/useAlert.ts Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/core/constant.ts Outdated Show resolved Hide resolved
}

&--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

codex-ui/dev/Playground.vue Outdated Show resolved Hide resolved
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

codex-ui/src/vue/components/alert/useAlert.ts Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/BaseAlert.vue Outdated Show resolved Hide resolved
codex-ui/src/vue/components/alert/AlertTransition.vue Outdated Show resolved Hide resolved
.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()

codex-ui/src/vue/components/alert/constant.ts Outdated Show resolved Hide resolved
Comment on lines 40 to 54
if (props.type === 'success') {
return 'grass';
}

if (props.type === 'error') {
return 'red';
}

if (props.type === 'warning') {
return 'amber';
}

if (props.type === 'info') {
return 'graphite';
}
Copy link
Contributor

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

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

Comment on lines 21 to 26
/**
* Type of the alert.
*
* Can be any of `(success, error, default, info, warning)`
*/
type?: Alertype;
Copy link
Contributor

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

Copy link
Contributor Author

@iamgabrielsoft iamgabrielsoft Sep 28, 2024

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),
Copy link
Contributor

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

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

Copy link
Contributor Author

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)

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

codex-ui/src/vue/components/alert/AlertContainer.vue Outdated Show resolved Hide resolved
</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

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