Skip to content

Commit

Permalink
feat: toasts
Browse files Browse the repository at this point in the history
Merge in SUN/veera-components from feature-PH-125-toasts to master

Squashed commit of the following:

commit a12ccb70416a25ef3d0cae91d99a2b4ba73c777f
Author: Aleksandr Beliaev <[email protected]>
Date:   Mon Nov 7 11:49:45 2022 +0200

    refactor: replaced raw svg icons in toast with veera-ng-icon component

commit 7739510b0c906a0e9a6ce8e42816a1bb5e88fad3
Author: Aleksandr Beliaev <[email protected]>
Date:   Mon Nov 7 11:37:55 2022 +0200

    refactor: added success icon to registry for toasts

commit ef1508f808733f3ae27ad04a1bbb75277dfd28a5
Author: Aleksandr Beliaev <[email protected]>
Date:   Mon Nov 7 11:36:36 2022 +0200

    fix: sometimes icons have their viewBox removed

commit adb6f7943710d3d06a4d20c699064cbde60b7007
Author: Markus Saarniit <[email protected]>
Date:   Wed Nov 2 12:26:11 2022 +0200

    chore: revert check icon

commit b208d7dce4baa90a0c7acabde72be45e41427537
Author: Markus Saarniit <[email protected]>
Date:   Wed Nov 2 12:02:37 2022 +0200

    fix: export track component

commit 7b19583f07bbcd626bed2e18d7a5a402d09e04e6
Author: Markus Saarniit <[email protected]>
Date:   Wed Nov 2 11:50:41 2022 +0200

    fix: package json fix

commit 3c1fe9b9ac5e1dfe095f40f4d5dd6403fe3bf650
Author: Markus Saarniit <[email protected]>
Date:   Wed Nov 2 11:40:26 2022 +0200

    chore: fix formatting

commit ae2622b7596176018fc718017617a7795069f756
Author: Markus Saarniit <[email protected]>
Date:   Wed Nov 2 11:39:54 2022 +0200

    feat: refactor

commit 65a54a2e132e885137ea2156ff5ff2683bde752b
Author: Aleksandr Beliaev <[email protected]>
Date:   Tue Nov 1 21:26:39 2022 +0200

    fix(styling): made toast shadow less strong and consistent with existing designs

commit adb2ae097db71b7ede14f986a665cd3644be2566
Author: Aleksandr Beliaev <[email protected]>
Date:   Tue Nov 1 21:22:21 2022 +0200

    feat(styling): added css variables for all colors in rgb format for sass-less usage with opacity specified

commit 710966fd1f9e4c0d2cef33364f956a2baea1148f
Author: Aleksandr Beliaev <[email protected]>
Date:   Tue Nov 1 20:54:45 2022 +0200

    feat: added track utilitycomponent for quick creation of flex-like layout

commit 96b9f0876f5444632314592e5d3d268de16ed222
Author: Aleksandr Beliaev <[email protected]>
Date:   Tue Nov 1 20:52:11 2022 +0200

    format: tiny css formatting fixes

commit 7aeb1c5b269e550ad17f253d2600f6d7a67ed035
Author: Aleksandr Beliaev <[email protected]>
Date:   Tue Nov 1 17:24:48 2022 +0200

    fix(ui): ensure close button of a toast is situated on same distance from the edge on both axis

commit 3676fe272c0040fa22e0f7ca074c1b33e42d0baa
Author: Markus Saarniit <[email protected]>
Date:   Mon Oct 31 16:19:24 2022 +0200

    chore: formatting

commit 87e78ea4973d2656a19c4f6ee0c36109bd62b070
Author: Markus Saarniit <[email protected]>
Date:   Mon Oct 31 16:18:37 2022 +0200

    feat: change detection strategy OnPush

commit 72e9e9d6ab34c03e76c9843e8595e3c34262ed23
Author: Markus Saarniit <[email protected]>
Date:   Mon Oct 31 15:36:08 2022 +0200

    chore: refactor

commit 1cc5ccfa452a251196b1de3bd4daa11db7931891
Author: Markus Saarniit <[email protected]>
Date:   Mon Oct 31 15:32:52 2022 +0200

    chore: fix formatting

commit 567158033e53d2da2738c5033ce13680e5e1a375
Author: Markus Saarniit <[email protected]>
Date:   Mon Oct 31 15:32:15 2022 +0200

    feat: add toasts
  • Loading branch information
Markus Saarniit committed Nov 7, 2022
1 parent f26bf19 commit d91044b
Show file tree
Hide file tree
Showing 33 changed files with 40,882 additions and 487 deletions.
4 changes: 4 additions & 0 deletions libs/icons/src/lib/svg/success.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion libs/storybook/.storybook/sorting-order.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
["Installation", "Usage"],
"HTML",
[
"Track",
"Button",
"Form item",
"Input",
Expand All @@ -28,6 +29,7 @@
"Angular",
[
"Installation",
"Track",
"Button",
"Form item",
"Input",
Expand All @@ -43,7 +45,8 @@
"Select",
"Tab group",
"Html Section",
"Tooltip"
"Tooltip",
"Toast"
]
]
}
2 changes: 1 addition & 1 deletion libs/storybook/src/lib/stories/css.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ To create a new Sass component, follow these steps:
6. Breakpoints (`@media` queries).

2. Use `get-spacing(<spacing-name>)` Sass function or `--veera-spacing-<name>` CSS variable to set margin and padding values.
3. Use `get-color(<color-name>)` Sass function or `--veera-color-<name>` CSS variable to set color values.
3. Use `get-color(<color-name>)` Sass function or `--veera-color-<name>` CSS variable to set color values. Use `--veera-color-rgb-<name>` to achieve translucent color, in this format: `rgba(var(--veera-color-rgb-<name>) / <opacity>)`, for example `rgba(var(--veera-color-rgb-dark-tangerine-2) / .15)`.
4. Use `veera-breakpoint-down()` and `veera-breakpoint-up()` mixins to set media queries.
5. Avoid decimal values (eg `13.2px`).
6. Round pixel values to the nearest even integer, preferably one that is divisible by 4 (eg `12px` is better than `13px`, but `14px` but is still OK). This applies even if the Figma design tells otherwise.
Expand Down
6 changes: 4 additions & 2 deletions libs/storybook/src/lib/stories/todos.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ e.g projects using this system, where to find docs, what is included
## Planned Angular components
[ ] - modal component (Pääsuke)

[ ] - select component (Pääsuke)
[X] - select component (Pääsuke)

[ ] - tooltip component (Pääsuke)
[X] - tooltip component (Pääsuke)

[X] - toasts (pääsuke)

## Requested features and components
[ ] - ...
4 changes: 2 additions & 2 deletions libs/storybook/src/lib/stories/usage.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ constructor(private registry: IconsRegistry) {
```
import {veeraCall, VeeraIcon} from '@ria/veera-icons';
const conatiner = document.getElementById('.container');
const container = document.getElementById('.container');
function buildSVGElement(icon: VeeraIcon): SVGElement {
const div = document.createElement('DIV');
Expand All @@ -43,7 +43,7 @@ container.appendChild(buildSVGElement(icon));
```
import {veeraCall} from '@ria/veera-icons';
const conatiner = document.getElementById('.container');
const container = document.getElementById('.container');
function buildSVGElement(icon) {
const div = document.createElement('DIV');
Expand Down
14 changes: 13 additions & 1 deletion libs/styles/src/lib/scss/_apply.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,17 @@
}

.veera-tab-group {
@include veera-tab-group
@include veera-tab-group;
}

.veera-toast {
@include veera-toast;
}

.veera-toast-container {
@include veera-toast-container;
}

.veera-track {
@include veera-track;
}
5 changes: 5 additions & 0 deletions libs/styles/src/lib/scss/components/_toast-container.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@mixin veera-toast-container($base: &) {
position: fixed;
top: get-spacing('elva');
right: get-spacing('elva');
}
106 changes: 106 additions & 0 deletions libs/styles/src/lib/scss/components/_toast.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
@mixin veera-toast($base: &) {
--comment: 'A toast aka floating notification';

position: relative;
width: 300px;
overflow: hidden;
padding: var(--veera-spacing-haapsalu);
margin-bottom: var(--veera-spacing-paldiski);
border-radius: 5px;
color: var(--veera-color-black-coral-18);
cursor: pointer;
display: block;

&:hover {
box-shadow: $veera-shadow-alpha;
}

@at-root {
#{$base}__icon-wrapper {
fill: get-color(black-coral-18);
display: block;
}

#{$base}__icon {
display: block;
width: 16px;
height: 16px;
}

#{$base}--appearance-success {
background-color: var(--veera-color-sea-green-0);
border: 1px solid var(--veera-color-sea-green-10);

& #{$base}__progress-bar {
background-color: var(--veera-color-sea-green-10);
}
}

#{$base}--appearance-info {
background-color: var(--veera-color-sapphire-blue-1);
border: 1px solid var(--veera-color-sapphire-blue-10);

& #{$base}__progress-bar {
background-color: var(--veera-color-sapphire-blue-10);
}
}

#{$base}--appearance-warning {
background-color: var(--veera-color-dark-tangerine-1);
border: 1px solid var(--veera-color-dark-tangerine-11);

& #{$base}__progress-bar {
background-color: var(--veera-color-dark-tangerine-11);
}
}

#{$base}--appearance-error {
background-color: var(--veera-color-jasper-0);
border: 1px solid var(--veera-color-jasper-10);

& #{$base}__progress-bar {
background-color: var(--veera-color-jasper-10);
}
}

#{$base}__title {
display: flex;
align-items: center;
}

#{$base}__title-text {
font-size: 18px;
margin-left: 10px;
}

#{$base}__close-button {
position: absolute;
top: 20px;
right: 20px;
cursor: pointer;
}

#{$base}__close-button-icon {
fill: get-color(black-coral-18);
display: block;
width: 16px;
height: 16px;
}

#{$base}__close-button-inner {
display: block;
}

#{$base}__message {
margin-top: var(--veera-spacing-elva);
}

#{$base}__progress-bar {
position: absolute;
left: 0;
bottom: 0;
height: 4px;
opacity: 0.4;
}
}
}
12 changes: 12 additions & 0 deletions libs/styles/src/lib/scss/components/_track.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@mixin veera-track($base: &) {
--comment: 'An utility for quick grid setting';

display: flex;
gap: calc(var(--veera-spacing-unit) * var(--gap));
justify-content: var(--horizontal-alignment);
flex-direction: var(--direction);
flex-wrap: var(--wrap);

@at-root {
}
}
3 changes: 3 additions & 0 deletions libs/styles/src/lib/scss/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@import 'generic/base';

// Components
@import 'components/track';
@import 'components/button';
@import 'components/textfield';
@import 'components/form-item';
Expand All @@ -39,6 +40,8 @@
@import 'components/select';
@import 'components/tooltip';
@import 'components/tab-group';
@import 'components/toast';
@import 'components/toast-container';

@import 'apply';

Expand Down
3 changes: 3 additions & 0 deletions libs/styles/src/lib/scss/settings/variables/_colors.scss
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,7 @@ $veera-colors: (
@each $name, $color in $veera-colors {
--veera-color-#{'' + $name}: #{$color};
}
@each $name, $color in $veera-colors {
--veera-color-rgb-#{'' + $name}: #{red($color) green($color) blue($color)};
}
}
3 changes: 3 additions & 0 deletions libs/styles/src/lib/scss/settings/variables/_other.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ $veera-radius-xs: 2px;

// Border widths
$veera-border-width: 2px;

// Shadows
$veera-shadow-alpha: 0 1px 5px 0 rgba(var(--veera-color-rgb-black) / .15);
1 change: 1 addition & 0 deletions libs/styles/src/lib/scss/settings/variables/_spacing.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ $veera-spacing-patterns: (
);

:root {
--veera-spacing-unit: #{$veera-spacing-unit};
@each $name, $size in $veera-spacing-patterns {
--veera-spacing-#{'' + $name}: #{$size};
}
Expand Down
6 changes: 6 additions & 0 deletions libs/ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ export * from './lib/select/select-templates.directive';
export * from './lib/select/select.component';
export * from './lib/tooltip/tooltip.component';
export * from './lib/tooltip/tooltip.directive';
export * from './lib/toast/toast.service';
export * from './lib/toast/toast-config';
export * from './lib/toast/toast.component';
export * from './lib/toast/toast-container.component';
export * from './lib/toast/overlay';
export * from './lib/track/track.component';
48 changes: 48 additions & 0 deletions libs/ui/src/lib/toast/overlay.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {
ApplicationRef,
ComponentRef,
createComponent,
Inject,
Injectable,
OnDestroy,
Injector,
EmbeddedViewRef,
} from '@angular/core';
import { DOCUMENT } from '@angular/common';
import { ToastContainerComponent } from './toast-container.component';

@Injectable({ providedIn: 'root' })
export class Overlay implements OnDestroy {
private containerRef!: ComponentRef<ToastContainerComponent>;

constructor(
private readonly appRef: ApplicationRef,
private readonly injector: Injector,
@Inject(DOCUMENT) private readonly document: Document
) {}

ngOnDestroy() {
if (this.containerRef) {
this.containerRef.destroy();
}
}

getContainerElement(): ComponentRef<ToastContainerComponent> {
if (!this.containerRef) {
this.createContainer();
}

return this.containerRef;
}

private createContainer(): void {
this.containerRef = createComponent(ToastContainerComponent, {
environmentInjector: this.appRef.injector,
elementInjector: this.injector,
});
this.appRef.attachView(this.containerRef.hostView);
const domElement = (this.containerRef.hostView as EmbeddedViewRef<any>)
.rootNodes[0] as HTMLElement;
this.document.body.appendChild(domElement);
}
}
46 changes: 46 additions & 0 deletions libs/ui/src/lib/toast/toast-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { InjectionToken } from '@angular/core';

export interface ToastConfig {
timeOut: number;
toastTypes: ToastTypes;
progressBar: boolean;
easeTime: number;
extendedTimeOut: number;
}

export interface ToastTypes {
error: string;
info: string;
success: string;
warning: string;
}

export interface ToastToken {
default: ToastConfig;
config: Partial<ToastConfig>;
}

export const DefaultToastConfig: ToastConfig = {
timeOut: 5000,
toastTypes: {
error: 'veera-toast--appearance-error',
info: 'veera-toast--appearance-info',
success: 'veera-toast--appearance-success',
warning: 'veera-toast--appearance-warning',
},
progressBar: true,
easeTime: 300,
extendedTimeOut: 1000,
};

export const TOAST_CONFIG = new InjectionToken<ToastToken>('ToastConfig');

export class ToastPackage {
constructor(
public id: number,
public config: ToastConfig,
public toastType: string,
public title: string | undefined,
public message: string | undefined
) {}
}
13 changes: 13 additions & 0 deletions libs/ui/src/lib/toast/toast-container.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ChangeDetectionStrategy, Component, HostBinding } from '@angular/core';

@Component({
selector: 'veera-ng-toast-container',
template: `<ng-content></ng-content>`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ToastContainerComponent {
@HostBinding('class')
get hostClasses() {
return 'veera-toast-container';
}
}
14 changes: 14 additions & 0 deletions libs/ui/src/lib/toast/toast.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<h1 class="veera-toast__title">
<veera-ng-icon *ngIf="isSuccessToast" name="success" class="veera-toast__icon-wrapper" svgClass="veera-toast__icon"></veera-ng-icon>
<veera-ng-icon *ngIf="isInfoToast" name="info" class="veera-toast__icon-wrapper" svgClass="veera-toast__icon"></veera-ng-icon>
<veera-ng-icon *ngIf="isWarningToast" name="warning_amber" class="veera-toast__icon-wrapper" svgClass="veera-toast__icon"></veera-ng-icon>
<veera-ng-icon *ngIf="isErrorToast" name="error_outline" class="veera-toast__icon-wrapper" svgClass="veera-toast__icon"></veera-ng-icon>
<div class="veera-toast__title-text">{{ title }}</div>
<button class="veera-toast__close-button" (click)="remove()">
<veera-ng-icon name="close" class="veera-toast__close-button-inner" svgClass="veera-toast__close-button-icon"></veera-ng-icon>
</button>
</h1>
<div *ngIf="message" class="veera-toast__message">
{{ message }}
</div>
<div *ngIf="progressBar" class="veera-toast__progress-bar" [style.width]="progressBarWidth + '%'"></div>
Loading

0 comments on commit d91044b

Please sign in to comment.