diff --git a/src/framework/theme/components/toastr/_toast.component.theme.scss b/src/framework/theme/components/toastr/_toast.component.theme.scss index 60c2586da8..f52c6631ac 100644 --- a/src/framework/theme/components/toastr/_toast.component.theme.scss +++ b/src/framework/theme/components/toastr/_toast.component.theme.scss @@ -6,16 +6,39 @@ @mixin nb-toast-theme() { nb-toast { - background-color: nb-theme(toastr-bg); - padding: nb-theme(toastr-padding); - color: nb-theme(toastr-fg); - border: nb-theme(toastr-border); + background-color: nb-theme(toastr-background); + border-color: nb-theme(toastr-border-color); + border-style: nb-theme(toastr-border-style); + border-width: nb-theme(toastr-border-width); border-radius: nb-theme(toastr-border-radius); + padding: nb-theme(toastr-padding); + box-shadow: nb-theme(toastr-shadow); + + color: nb-theme(toastr-text-color); + + &.destroy-by-click:hover { + background: nb-theme(toastr-destroyable-hover-background); + border-color: nb-theme(toastr-destroyable-hover-border-color); + } + + .title { + font-family: nb-theme(toastr-title-text-font-family); + font-size: nb-theme(toastr-title-text-font-size); + font-weight: nb-theme(toastr-title-text-font-weight); + line-height: nb-theme(toastr-title-text-line-height); + } + + .message { + font-family: nb-theme(toastr-text-font-family); + font-size: nb-theme(toastr-text-font-size); + font-weight: nb-theme(toastr-text-font-weight); + line-height: nb-theme(toastr-text-line-height); + } .icon-container { @include nb-ltr(margin-right, 1.25rem); @include nb-rtl(margin-left, 1.25rem); - border-radius: nb-theme(toastr-icon-radius); + border-radius: nb-theme(toastr-border-radius); width: 2.5rem; height: 2.5rem; display: flex; @@ -26,118 +49,22 @@ font-size: 1.5rem; } } + } - @include nb-except-theme(cosmic) { - box-shadow: nb-theme(toastr-shadow); - } - - &.default { - border-color: nb-theme(toastr-border-color); - padding: calc(#{nb-theme(toastr-padding)} / 2) nb-theme(toastr-padding); - - @include nb-for-theme(cosmic) { - color: nb-theme(toastr-color-fg); - background-color: nb-theme(toastr-default-background); - } - } - - &.success { - border-color: nb-theme(color-success); - color: nb-theme(color-success); - - .icon-container { - background-color: nb-theme(color-success); - color: nb-theme(color-white); - } - - @include nb-for-theme(cosmic) { - background-color: nb-theme(color-success); - color: nb-theme(toastr-color-fg); - - .icon-container { - background-color: nb-theme(color-white); - color: nb-theme(color-success); - } - } - } - - &.info { - border-color: nb-theme(color-info); - color: nb-theme(color-info); - - .icon-container { - background-color: nb-theme(color-info); - color: nb-theme(color-white); - } - - @include nb-for-theme(cosmic) { - background-color: nb-theme(color-info); - color: nb-theme(toastr-color-fg); - - .icon-container { - background-color: nb-theme(color-white); - color: nb-theme(color-info); - } - } - } - - &.warning { - border-color: nb-theme(color-warning); - color: nb-theme(color-warning); - - .icon-container { - background-color: nb-theme(color-warning); - color: nb-theme(color-white); - } - - @include nb-for-theme(cosmic) { - background-color: nb-theme(color-warning); - color: nb-theme(toastr-color-fg); - - .icon-container { - background-color: nb-theme(color-white); - color: nb-theme(color-warning); - } - } - } - - &.primary { - border-color: nb-theme(color-primary); - color: nb-theme(color-primary); - - .icon-container { - background-color: nb-theme(color-primary); - color: nb-theme(color-white); - } - - @include nb-for-theme(cosmic) { - background-color: nb-theme(color-primary); - color: nb-theme(toastr-color-fg); + @each $status in nb-get-statuses() { + nb-toast.status-#{$status} { + background: nb-theme(toastr-#{$status}-background); + border-color: nb-theme(toastr-#{$status}-border-color); + color: nb-theme(toastr-#{$status}-text-color); - .icon-container { - background-color: nb-theme(color-white); - color: nb-theme(color-primary); - } + &.destroy-by-click:hover { + background: nb-theme(toastr-destroyable-hover-#{$status}-background); + border-color: nb-theme(toastr-destroyable-hover-#{$status}-border-color); } - } - - &.danger { - border-color: nb-theme(color-danger); - color: nb-theme(color-danger); .icon-container { - background-color: nb-theme(color-danger); - color: nb-theme(color-white); - } - - @include nb-for-theme(cosmic) { - background-color: nb-theme(color-danger); - color: nb-theme(toastr-color-fg); - - .icon-container { - background-color: nb-theme(color-white); - color: nb-theme(color-danger); - } + background: nb-theme(toastr-icon-#{$status}-background); + color: nb-theme(toastr-icon-#{$status}-color); } } } diff --git a/src/framework/theme/components/toastr/model.ts b/src/framework/theme/components/toastr/model.ts index 4111910838..2366958082 100644 --- a/src/framework/theme/components/toastr/model.ts +++ b/src/framework/theme/components/toastr/model.ts @@ -6,16 +6,6 @@ import { NbToastrConfig } from './toastr-config'; - -export enum NbToastStatus { - SUCCESS = 'success', - INFO = 'info', - WARNING = 'warning', - PRIMARY = 'primary', - DANGER = 'danger', - DEFAULT = 'default', -} - export class NbToast { title: string; message: string; diff --git a/src/framework/theme/components/toastr/toast.component.scss b/src/framework/theme/components/toastr/toast.component.scss index d6cd2721ed..da757b579e 100644 --- a/src/framework/theme/components/toastr/toast.component.scss +++ b/src/framework/theme/components/toastr/toast.component.scss @@ -9,7 +9,6 @@ align-items: center; width: 25rem; margin: 0.5rem; - opacity: 0.9; .title { font-weight: 800; @@ -33,10 +32,6 @@ &.destroy-by-click { cursor: pointer; - - &:hover { - opacity: 1; - } } nb-icon { diff --git a/src/framework/theme/components/toastr/toast.component.ts b/src/framework/theme/components/toastr/toast.component.ts index 1677ecb0e9..175f4d80f8 100644 --- a/src/framework/theme/components/toastr/toast.component.ts +++ b/src/framework/theme/components/toastr/toast.component.ts @@ -6,8 +6,7 @@ import { Component, EventEmitter, HostBinding, HostListener, Input, Output } from '@angular/core'; -import { NbToast, NbToastStatus } from './model'; - +import { NbToast } from './model'; /** * The `NbToastComponent` is responsible for rendering each toast with appropriate styles. @@ -21,10 +20,6 @@ import { NbToast, NbToastStatus } from './model'; * toastr-border-radius * toastr-border-color * */ -/** - * TODO - * Remove svg icons, include them in font. - * */ @Component({ selector: 'nb-toast', styleUrls: ['./toast.component.scss'], @@ -36,34 +31,29 @@ export class NbToastComponent { @Output() destroy: EventEmitter = new EventEmitter(); - @HostBinding('class.success') + @HostBinding('class.status-success') get success(): boolean { - return this.toast.config.status === NbToastStatus.SUCCESS; + return this.toast.config.status === 'success'; } - @HostBinding('class.info') + @HostBinding('class.status-info') get info(): boolean { - return this.toast.config.status === NbToastStatus.INFO; + return this.toast.config.status === 'info'; } - @HostBinding('class.warning') + @HostBinding('class.status-warning') get warning(): boolean { - return this.toast.config.status === NbToastStatus.WARNING; + return this.toast.config.status === 'warning'; } - @HostBinding('class.primary') + @HostBinding('class.status-primary') get primary(): boolean { - return this.toast.config.status === NbToastStatus.PRIMARY; + return this.toast.config.status === 'primary'; } - @HostBinding('class.danger') + @HostBinding('class.status-danger') get danger(): boolean { - return this.toast.config.status === NbToastStatus.DANGER; - } - - @HostBinding('class.default') - get default(): boolean { - return this.toast.config.status === NbToastStatus.DEFAULT; + return this.toast.config.status === 'danger'; } @HostBinding('class.destroy-by-click') @@ -73,7 +63,7 @@ export class NbToastComponent { @HostBinding('class.has-icon') get hasIcon(): boolean { - return this.toast.config.hasIcon && this.toast.config.status !== NbToastStatus.DEFAULT; + return this.toast.config.hasIcon && !!this.toast.config.status; } @HostBinding('class.custom-icon') diff --git a/src/framework/theme/components/toastr/toastr-config.ts b/src/framework/theme/components/toastr/toastr-config.ts index e8e0ac31e0..0765e75f7b 100644 --- a/src/framework/theme/components/toastr/toastr-config.ts +++ b/src/framework/theme/components/toastr/toastr-config.ts @@ -6,9 +6,12 @@ import { InjectionToken } from '@angular/core'; -import { NbToastStatus } from './model'; import { NbGlobalLogicalPosition, NbGlobalPosition } from '../cdk'; +import { NbComponentStatus } from '../component-status'; +type IconToClassMap = { + [status in NbComponentStatus]: string; +} export const NB_TOASTR_CONFIG = new InjectionToken('Default toastr options'); @@ -23,7 +26,7 @@ export class NbToastrConfig { /** * Status chooses color scheme for the toast. * */ - status: NbToastStatus = NbToastStatus.PRIMARY; + status: '' | NbComponentStatus = 'primary'; /** * Duration is timeout between toast appears and disappears. * */ @@ -51,12 +54,12 @@ export class NbToastrConfig { /** * Toast status icon-class mapping. * */ - protected icons = { - [NbToastStatus.DANGER]: 'flash-outline', - [NbToastStatus.SUCCESS]: 'checkmark-outline', - [NbToastStatus.INFO]: 'question-mark-outline', - [NbToastStatus.WARNING]: 'alert-triangle-outline', - [NbToastStatus.PRIMARY]: 'email-outline', + protected icons: IconToClassMap = { + danger: 'flash-outline', + success: 'checkmark-outline', + info: 'question-mark-outline', + warning: 'alert-triangle-outline', + primary: 'email-outline', }; constructor(config: Partial) { @@ -66,7 +69,7 @@ export class NbToastrConfig { protected patchIcon(config: Partial) { if (!('icon' in config)) { - config.icon = this.icons[config.status || NbToastStatus.PRIMARY]; + config.icon = this.icons[config.status || 'primary']; config.iconPack = 'nebular-essentials'; } } diff --git a/src/framework/theme/components/toastr/toastr.service.spec.ts b/src/framework/theme/components/toastr/toastr.service.spec.ts index e0ee59139f..0502e23615 100644 --- a/src/framework/theme/components/toastr/toastr.service.spec.ts +++ b/src/framework/theme/components/toastr/toastr.service.spec.ts @@ -1,6 +1,5 @@ import { NbToastrContainerRegistry, NbToastrService } from './toastr.service'; import { NbGlobalLogicalPosition, NbGlobalPhysicalPosition } from '../cdk'; -import { NbToastStatus } from './model'; import { TestBed } from '@angular/core/testing'; import { ComponentFactoryResolver } from '@angular/core'; import { NbToastrModule } from '@nebular/theme'; @@ -53,7 +52,7 @@ describe('toastr-service', () => { expect(attachSpy).toHaveBeenCalled(); const [[{ config }]] = attachSpy.calls.allArgs(); expect(config.position).toBe(NbGlobalLogicalPosition.BOTTOM_START, 'incorrect position'); - expect(config.status).toBe(NbToastStatus.PRIMARY, 'incorrect status'); + expect(config.status).toBe('primary', 'incorrect status'); expect(config.duration).toBe(1234, 'incorrect duration'); expect(config.destroyByClick).toBe(true, 'incorrect destroyByClick'); expect(config.preventDuplicates).toBe(true, 'incorrect preventDuplicates'); @@ -67,7 +66,7 @@ describe('toastr-service', () => { expect(toastrSpy).toHaveBeenCalled(); const [, , { status }] = toastrSpy.calls.allArgs()[0]; - expect(status).toBe(NbToastStatus.SUCCESS); + expect(status).toBe('success'); }); it('should call show with info status when info called', () => { @@ -77,7 +76,7 @@ describe('toastr-service', () => { expect(toastrSpy).toHaveBeenCalled(); const [, , { status }] = toastrSpy.calls.allArgs()[0]; - expect(status).toBe(NbToastStatus.INFO); + expect(status).toBe('info'); }); it('should call show with warning status when warning called', () => { @@ -87,7 +86,7 @@ describe('toastr-service', () => { expect(toastrSpy).toHaveBeenCalled(); const [, , { status }] = toastrSpy.calls.allArgs()[0]; - expect(status).toBe(NbToastStatus.WARNING); + expect(status).toBe('warning'); }); it('should call show with primary status when primary called', () => { @@ -97,7 +96,7 @@ describe('toastr-service', () => { expect(toastrSpy).toHaveBeenCalled(); const [, , { status }] = toastrSpy.calls.allArgs()[0]; - expect(status).toBe(NbToastStatus.PRIMARY); + expect(status).toBe('primary'); }); it('should call show with danger status when danger called', () => { @@ -107,7 +106,7 @@ describe('toastr-service', () => { expect(toastrSpy).toHaveBeenCalled(); const [, , { status }] = toastrSpy.calls.allArgs()[0]; - expect(status).toBe(NbToastStatus.DANGER); + expect(status).toBe('danger'); }); it('should call show with default status when default called', () => { @@ -117,7 +116,7 @@ describe('toastr-service', () => { expect(toastrSpy).toHaveBeenCalled(); const [, , { status }] = toastrSpy.calls.allArgs()[0]; - expect(status).toBe(NbToastStatus.DEFAULT); + expect(status).toBe(''); }); }); diff --git a/src/framework/theme/components/toastr/toastr.service.ts b/src/framework/theme/components/toastr/toastr.service.ts index 272dafc09c..a319de8983 100644 --- a/src/framework/theme/components/toastr/toastr.service.ts +++ b/src/framework/theme/components/toastr/toastr.service.ts @@ -17,7 +17,7 @@ import { } from '../cdk'; import { NbToastrContainerComponent } from './toastr-container.component'; import { NB_TOASTR_CONFIG, NbToastrConfig } from './toastr-config'; -import { NbToast, NbToastStatus } from './model'; +import { NbToast } from './model'; import { NbToastComponent } from './toast.component'; import { NB_DOCUMENT } from '../../theme.options'; @@ -161,7 +161,7 @@ export class NbToastrContainerRegistry { * ```ts * @NgModule({ * imports: [ - * // ... + * // ... * NbToastrModule.forRoot(config), * ], * }) @@ -231,41 +231,41 @@ export class NbToastrService { * Shows success toast with message, title and user config. * */ success(message, title?, config?: Partial): NbToastRef { - return this.show(message, title, { ...config, status: NbToastStatus.SUCCESS }); + return this.show(message, title, { ...config, status: 'success' }); } /** * Shows info toast with message, title and user config. * */ info(message, title?, config?: Partial): NbToastRef { - return this.show(message, title, { ...config, status: NbToastStatus.INFO }); + return this.show(message, title, { ...config, status: 'info' }); } /** * Shows warning toast with message, title and user config. * */ warning(message, title?, config?: Partial): NbToastRef { - return this.show(message, title, { ...config, status: NbToastStatus.WARNING }); + return this.show(message, title, { ...config, status: 'warning' }); } /** * Shows primary toast with message, title and user config. * */ primary(message, title?, config?: Partial): NbToastRef { - return this.show(message, title, { ...config, status: NbToastStatus.PRIMARY }); + return this.show(message, title, { ...config, status: 'primary' }); } /** * Shows danger toast with message, title and user config. * */ danger(message, title?, config?: Partial): NbToastRef { - return this.show(message, title, { ...config, status: NbToastStatus.DANGER }); + return this.show(message, title, { ...config, status: 'danger' }); } /** * Shows default toast with message, title and user config. * */ default(message, title?, config?: Partial): NbToastRef { - return this.show(message, title, { ...config, status: NbToastStatus.DEFAULT }); + return this.show(message, title, { ...config, status: '' }); } } diff --git a/src/framework/theme/styles/themes/_default.scss b/src/framework/theme/styles/themes/_default.scss index 30ad235e1d..72aad263b2 100644 --- a/src/framework/theme/styles/themes/_default.scss +++ b/src/framework/theme/styles/themes/_default.scss @@ -637,14 +637,66 @@ $theme: ( smart-table-paging-bg-active: color-success, smart-table-paging-hover: rgba(0, 0, 0, 0.05), - toastr-bg: color-bg, - toastr-padding: 1.125rem, - toastr-fg: color-fg-text, - toastr-border: 0.125rem solid, - toastr-border-radius: radius, - toastr-border-color: #bcc3cc, - toastr-icon-radius: 0.25rem, - toastr-shadow: shadow, + toastr-background: color-white, + toastr-border-color: color-basic, + toastr-border-style: solid, + toastr-border-width: 0.125rem, + toastr-border-radius: 0.75rem, + toastr-padding: 1rem, + toastr-shadow: none, + + toastr-text-color: text-dark-color, + toastr-text-font-family: text-paragraph-font-family, + toastr-text-font-size: text-paragraph-font-size, + toastr-text-font-weight: text-paragraph-font-weight, + toastr-text-line-height: text-paragraph-line-height, + toastr-title-text-font-family: text-subtitle-font-family, + toastr-title-text-font-size: text-subtitle-font-size, + toastr-title-text-font-weight: text-subtitle-font-weight, + toastr-title-text-line-height: text-subtitle-line-height, + + toastr-destroyable-hover-background: color-white, + toastr-destroyable-hover-border-color: color-basic-hover, + + toastr-primary-background: color-primary, + toastr-primary-border-color: color-primary, + toastr-primary-text-color: color-white, + toastr-icon-primary-background: color-white, + toastr-icon-primary-color: color-primary, + toastr-destroyable-hover-primary-background: color-primary-hover, + toastr-destroyable-hover-primary-border-color: color-primary-hover, + + toastr-success-background: color-success, + toastr-success-border-color: color-success, + toastr-success-text-color: color-white, + toastr-icon-success-background: color-white, + toastr-icon-success-color: color-success, + toastr-destroyable-hover-success-background: color-success-hover, + toastr-destroyable-hover-success-border-color: color-success-hover, + + toastr-info-background: color-info, + toastr-info-border-color: color-info, + toastr-info-text-color: color-white, + toastr-icon-info-background: color-white, + toastr-icon-info-color: color-info, + toastr-destroyable-hover-info-background: color-info-hover, + toastr-destroyable-hover-info-border-color: color-info-hover, + + toastr-warning-background: color-warning, + toastr-warning-border-color: color-warning, + toastr-warning-text-color: color-white, + toastr-icon-warning-background: color-white, + toastr-icon-warning-color: color-warning, + toastr-destroyable-hover-warning-background: color-warning-hover, + toastr-destroyable-hover-warning-border-color: color-warning-hover, + + toastr-danger-background: color-danger, + toastr-danger-border-color: color-danger, + toastr-danger-text-color: color-white, + toastr-icon-danger-background: color-white, + toastr-icon-danger-color: color-danger, + toastr-destroyable-hover-danger-background: color-danger-hover, + toastr-destroyable-hover-danger-border-color: color-danger-hover, button-cursor: pointer, button-outline-width: outline-width, diff --git a/src/playground/with-layout/toastr/toastr.module.ts b/src/playground/with-layout/toastr/toastr.module.ts index ebb201d0cb..a374a7038c 100644 --- a/src/playground/with-layout/toastr/toastr.module.ts +++ b/src/playground/with-layout/toastr/toastr.module.ts @@ -5,7 +5,7 @@ */ import { NgModule } from '@angular/core'; -import { NbToastrModule } from '@nebular/theme'; +import { NbButtonModule, NbToastrModule } from '@nebular/theme'; import { ToastrRoutingModule } from './toastr-routing.module'; import { ToastrDestroyByClickComponent } from './toastr-destroy-by-click.component'; import { ToastrDurationComponent } from './toastr-duration.component'; @@ -27,6 +27,7 @@ import { ToastrStatusesComponent } from './toastr-statuses.component'; ], imports: [ NbToastrModule.forRoot(), + NbButtonModule, ToastrRoutingModule, ], })