Skip to content

Commit

Permalink
feat(design): convert notification component to standalone (#3054)
Browse files Browse the repository at this point in the history
  • Loading branch information
xelaint authored and damienwebdev committed Sep 27, 2024
1 parent dcf8f5c commit 7ca68fd
Show file tree
Hide file tree
Showing 19 changed files with 109 additions and 23 deletions.
41 changes: 41 additions & 0 deletions libs/design/notification/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,47 @@ Notifications are used to display short messages that provide context in close p
### Default Notification
<design-land-example-viewer-container example="default-notification"></design-land-example-viewer-container>

## Usage

### Within a standalone component
To use notification in a standalone component, import `DAFF_NOTIFICATION_COMPONENTS` directly into your custom component:

```ts
@Component({
selector: 'custom-component',
templateUrl: './custom-component.component.html',
standalone: true,
imports: [
DAFF_NOTIFICATION_COMPONENTS,
],
})
export class CustomComponent {}
```

### Within a module (deprecated)
To use notification in a module, import `DaffNotificationModule` into your custom module:

```ts
import { NgModule } from '@angular/core';

import { DaffNotificationModule } from '@daffodil/design/notification';

@NgModule({
declarations: [
CustomComponent,
],
exports: [
CustomComponent,
],
imports: [
DaffNotificationModule,
],
})
export class CustomComponentModule { }
```

> This method is deprecated. It's recommended to update all custom components to standalone.
## Supported Content Types

### Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { faInfoCircle } from '@fortawesome/free-solid-svg-icons';

import { DaffPrefixSuffixModule } from '@daffodil/design';
import { DAFF_BUTTON_COMPONENTS } from '@daffodil/design/button';
import { DaffNotificationModule } from '@daffodil/design/notification';
import { DAFF_NOTIFICATION_COMPONENTS } from '@daffodil/design/notification';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
Expand All @@ -18,7 +18,7 @@ import { DaffNotificationModule } from '@daffodil/design/notification';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
DaffNotificationModule,
DAFF_NOTIFICATION_COMPONENTS,
FaIconComponent,
DaffPrefixSuffixModule,
DAFF_BUTTON_COMPONENTS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FaIconComponent } from '@fortawesome/angular-fontawesome';
import { faInfoCircle } from '@fortawesome/free-solid-svg-icons';

import { DaffPrefixSuffixModule } from '@daffodil/design';
import { DaffNotificationModule } from '@daffodil/design/notification';
import { DAFF_NOTIFICATION_COMPONENTS } from '@daffodil/design/notification';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
Expand All @@ -22,7 +22,7 @@ import { DaffNotificationModule } from '@daffodil/design/notification';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
DaffNotificationModule,
DAFF_NOTIFICATION_COMPONENTS,
FaIconComponent,
DaffPrefixSuffixModule,
NgIf,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {

import { DaffPrefixSuffixModule } from '@daffodil/design';
import { DAFF_BUTTON_COMPONENTS } from '@daffodil/design/button';
import { DaffNotificationModule } from '@daffodil/design/notification';
import { DAFF_NOTIFICATION_COMPONENTS } from '@daffodil/design/notification';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
Expand All @@ -25,7 +25,7 @@ import { DaffNotificationModule } from '@daffodil/design/notification';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
DaffNotificationModule,
DAFF_NOTIFICATION_COMPONENTS,
FaIconComponent,
DaffPrefixSuffixModule,
DAFF_BUTTON_COMPONENTS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {

import { DaffPrefixSuffixModule } from '@daffodil/design';
import { DAFF_BUTTON_COMPONENTS } from '@daffodil/design/button';
import { DaffNotificationModule } from '@daffodil/design/notification';
import { DAFF_NOTIFICATION_COMPONENTS } from '@daffodil/design/notification';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
Expand All @@ -26,7 +26,7 @@ import { DaffNotificationModule } from '@daffodil/design/notification';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
DaffNotificationModule,
DAFF_NOTIFICATION_COMPONENTS,
NgIf,
FaIconComponent,
DaffPrefixSuffixModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { faExclamationCircle } from '@fortawesome/free-solid-svg-icons';

import { DAFF_BUTTON_COMPONENTS } from '@daffodil/design/button';
import { DaffNotificationModule } from '@daffodil/design/notification';
import { DAFF_NOTIFICATION_COMPONENTS } from '@daffodil/design/notification';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
Expand All @@ -23,7 +23,7 @@ import { DaffNotificationModule } from '@daffodil/design/notification';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
DaffNotificationModule,
DAFF_NOTIFICATION_COMPONENTS,
FontAwesomeModule,
DAFF_BUTTON_COMPONENTS,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import { DaffNotificationActionsDirective } from './notification-actions.directi
template: `
<h3 daffNotificationActions>Lorem Ipsum</h3>
`,
standalone: true,
imports: [
DaffNotificationActionsDirective,
],
})
class WrapperComponent {}

Expand All @@ -25,8 +29,7 @@ describe('@daffodil/design/notification | DaffNotificationActionsDirective', ()

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
DaffNotificationActionsDirective,
imports: [
WrapperComponent,
],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {

@Directive({
selector: '[daffNotificationActions]',
standalone: true,
})

export class DaffNotificationActionsDirective {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import { DaffNotificationMessageDirective } from './notification-message.directi
template: `
<h3 daffNotificationMessage>Lorem Ipsum</h3>
`,
standalone: true,
imports: [
DaffNotificationMessageDirective,
],
})
class WrapperComponent {}

Expand All @@ -25,8 +29,7 @@ describe('@daffodil/design/notification | DaffNotificationMessageDirective', ()

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
DaffNotificationMessageDirective,
imports: [
WrapperComponent,
],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {

@Directive({
selector: '[daffNotificationMessage]',
standalone: true,
})

export class DaffNotificationMessageDirective {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import { DaffNotificationSubtitleDirective } from './notification-subtitle.direc
template: `
<h3 daffNotificationSubtitle>Subtitle</h3>
`,
standalone: true,
imports: [
DaffNotificationSubtitleDirective,
],
})
class WrapperComponent {}

Expand All @@ -25,8 +29,7 @@ describe('@daffodil/design/notification | DaffNotificationSubtitleDirective', ()

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
DaffNotificationSubtitleDirective,
imports: [
WrapperComponent,
],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {

@Directive({
selector: '[daffNotificationSubtitle]',
standalone: true,
})

export class DaffNotificationSubtitleDirective {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import { DaffNotificationTitleDirective } from './notification-title.directive';
template: `
<h3 daffNotificationTitle>Title</h3>
`,
standalone: true,
imports: [
DaffNotificationTitleDirective,
],
})
class WrapperComponent {}

Expand All @@ -25,8 +29,7 @@ describe('@daffodil/design/notification | DaffNotificationTitleDirective', () =>

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
DaffNotificationTitleDirective,
imports: [
WrapperComponent,
],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {

@Directive({
selector: '[daffNotificationTitle]',
standalone: true,
})

export class DaffNotificationTitleDirective {
Expand Down
6 changes: 3 additions & 3 deletions libs/design/notification/src/notification.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { DaffNotificationMessageDirective } from './notification-message/notific
import { DaffNotificationSubtitleDirective } from './notification-subtitle/notification-subtitle.directive';
import { DaffNotificationTitleDirective } from './notification-title/notification-title.directive';


/**
* @deprecated in favor of {@link DAFF_NOTIFICATION_COMPONENTS}
*/
@NgModule({
imports: [
CommonModule,
DaffPrefixSuffixModule,
FontAwesomeModule,
],
declarations: [
DaffNotificationComponent,
DaffNotificationActionsDirective,
DaffNotificationMessageDirective,
Expand Down
16 changes: 16 additions & 0 deletions libs/design/notification/src/notification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { DaffPrefixSuffixModule } from '@daffodil/design';

import { DaffNotificationComponent } from './notification/notification.component';
import { DaffNotificationActionsDirective } from './notification-actions/notification-actions.directive';
import { DaffNotificationMessageDirective } from './notification-message/notification-message.directive';
import { DaffNotificationSubtitleDirective } from './notification-subtitle/notification-subtitle.directive';
import { DaffNotificationTitleDirective } from './notification-title/notification-title.directive';

export const DAFF_NOTIFICATION_COMPONENTS = <const> [
DaffNotificationComponent,
DaffNotificationActionsDirective,
DaffNotificationMessageDirective,
DaffNotificationTitleDirective,
DaffNotificationSubtitleDirective,
DaffPrefixSuffixModule,
];
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import {
(closeNotification)="closeNotificationFunction()">
</daff-notification>
`,
standalone: true,
imports: [
DaffNotificationComponent,
],
})

class WrapperComponent {
Expand All @@ -42,8 +46,7 @@ describe('@daffodil/design/notification | DaffNotificationComponent', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
DaffNotificationComponent,
imports: [
WrapperComponent,
],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NgIf } from '@angular/common';
import {
Component,
Input,
Expand All @@ -10,12 +11,14 @@ import {
Output,
EventEmitter,
} from '@angular/core';
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
import { faTimes } from '@fortawesome/free-solid-svg-icons';

import {
DaffArticleEncapsulatedDirective,
DaffPrefixable,
DaffPrefixDirective,
DaffPrefixSuffixModule,
DaffStatusableDirective,
DaffStatusEnum,
} from '@daffodil/design';
Expand Down Expand Up @@ -46,6 +49,12 @@ enum DaffNotificationOrientationEnum {
],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
NgIf,
FaIconComponent,
DaffPrefixSuffixModule,
],
})
export class DaffNotificationComponent implements DaffPrefixable {
faTimes = faTimes;
Expand Down
1 change: 1 addition & 0 deletions libs/design/notification/src/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './notification-actions/notification-actions.directive';
export * from './notification-title/notification-title.directive';
export * from './notification-subtitle/notification-subtitle.directive';
export * from './notification-message/notification-message.directive';
export { DAFF_NOTIFICATION_COMPONENTS } from './notification';

0 comments on commit 7ca68fd

Please sign in to comment.