Skip to content

Commit dcf8f5c

Browse files
xelaintdamienwebdev
authored andcommitted
feat(design): convert navbar component to standalone (#3054)
1 parent fd933cc commit dcf8f5c

File tree

11 files changed

+74
-21
lines changed

11 files changed

+74
-21
lines changed

libs/design/navbar/README.md

+41
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,47 @@ The navbar contains minimal layout styles, allowing the content within it to be
77
## Basic Navbar
88
<design-land-example-viewer-container example="basic-navbar"></design-land-example-viewer-container>
99

10+
## Usage
11+
12+
### Within a standalone component
13+
To use navbar in a standalone component, import `DAFF_NAVBAR_COMPONENTS` directly into your custom component:
14+
15+
```ts
16+
@Component({
17+
selector: 'custom-component',
18+
templateUrl: './custom-component.component.html',
19+
standalone: true,
20+
imports: [
21+
DAFF_NAVBAR_COMPONENTS,
22+
],
23+
})
24+
export class CustomComponent {}
25+
```
26+
27+
### Within a module (deprecated)
28+
To use navbar in a module, import `DaffNavbarModule` into your custom module:
29+
30+
```ts
31+
import { NgModule } from '@angular/core';
32+
33+
import { DaffNavbarModule } from '@daffodil/design/navbar';
34+
35+
@NgModule({
36+
declarations: [
37+
CustomComponent,
38+
],
39+
exports: [
40+
CustomComponent,
41+
],
42+
imports: [
43+
DaffNavbarModule,
44+
],
45+
})
46+
export class CustomComponentModule { }
47+
```
48+
49+
> This method is deprecated. It's recommended to update all custom components to standalone.
50+
1051
## Theming
1152
The default background color of a navbar is light gray, but it can be updated to one of the supported colors by using the `color` property.
1253

libs/design/navbar/examples/src/basic-navbar/basic-navbar.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
} from '@angular/core';
55

66
import { DAFF_BUTTON_COMPONENTS } from '@daffodil/design/button';
7-
import { DaffNavbarModule } from '@daffodil/design/navbar';
7+
import { DAFF_NAVBAR_COMPONENTS } from '@daffodil/design/navbar';
88

99
@Component({
1010
// eslint-disable-next-line @angular-eslint/component-selector
@@ -14,7 +14,7 @@ import { DaffNavbarModule } from '@daffodil/design/navbar';
1414
changeDetection: ChangeDetectionStrategy.OnPush,
1515
standalone: true,
1616
imports: [
17-
DaffNavbarModule,
17+
DAFF_NAVBAR_COMPONENTS,
1818
DAFF_BUTTON_COMPONENTS,
1919
],
2020
})

libs/design/navbar/examples/src/contained-navbar/contained-navbar.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55

66
import { DAFF_BUTTON_COMPONENTS } from '@daffodil/design/button';
77
import { DAFF_CONTAINER_COMPONENTS } from '@daffodil/design/container';
8-
import { DaffNavbarModule } from '@daffodil/design/navbar';
8+
import { DAFF_NAVBAR_COMPONENTS } from '@daffodil/design/navbar';
99

1010
@Component({
1111
// eslint-disable-next-line @angular-eslint/component-selector
@@ -15,7 +15,7 @@ import { DaffNavbarModule } from '@daffodil/design/navbar';
1515
changeDetection: ChangeDetectionStrategy.OnPush,
1616
standalone: true,
1717
imports: [
18-
DaffNavbarModule,
18+
DAFF_NAVBAR_COMPONENTS,
1919
DAFF_CONTAINER_COMPONENTS,
2020
DAFF_BUTTON_COMPONENTS,
2121
],

libs/design/navbar/examples/src/navbar-theming/navbar-theming.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from '@angular/forms';
1010

1111
import { DAFF_BUTTON_COMPONENTS } from '@daffodil/design/button';
12-
import { DaffNavbarModule } from '@daffodil/design/navbar';
12+
import { DAFF_NAVBAR_COMPONENTS } from '@daffodil/design/navbar';
1313

1414
@Component({
1515
// eslint-disable-next-line @angular-eslint/component-selector
@@ -19,7 +19,7 @@ import { DaffNavbarModule } from '@daffodil/design/navbar';
1919
changeDetection: ChangeDetectionStrategy.OnPush,
2020
standalone: true,
2121
imports: [
22-
DaffNavbarModule,
22+
DAFF_NAVBAR_COMPONENTS,
2323
DAFF_BUTTON_COMPONENTS,
2424
ReactiveFormsModule,
2525
NgFor,

libs/design/navbar/examples/src/raised-navbar/raised-navbar.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
} from '@angular/core';
55

66
import { DAFF_BUTTON_COMPONENTS } from '@daffodil/design/button';
7-
import { DaffNavbarModule } from '@daffodil/design/navbar';
7+
import { DAFF_NAVBAR_COMPONENTS } from '@daffodil/design/navbar';
88

99
@Component({
1010
// eslint-disable-next-line @angular-eslint/component-selector
@@ -14,7 +14,7 @@ import { DaffNavbarModule } from '@daffodil/design/navbar';
1414
changeDetection: ChangeDetectionStrategy.OnPush,
1515
standalone: true,
1616
imports: [
17-
DaffNavbarModule,
17+
DAFF_NAVBAR_COMPONENTS,
1818
DAFF_BUTTON_COMPONENTS,
1919
],
2020
})

libs/design/navbar/src/navbar.module.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
import { CommonModule } from '@angular/common';
12
import { NgModule } from '@angular/core';
23

34
import { DaffNavbarComponent } from './navbar/navbar.component';
45

6+
/**
7+
* @deprecated in favor of {@link DAFF_NAVBAR_COMPONENTS}
8+
*/
59
@NgModule({
6-
declarations: [
10+
imports: [
11+
CommonModule,
712
DaffNavbarComponent,
813
],
914
exports: [

libs/design/navbar/src/navbar.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { DaffNavbarComponent } from './navbar/navbar.component';
2+
3+
export const DAFF_NAVBAR_COMPONENTS = <const> [
4+
DaffNavbarComponent,
5+
];

libs/design/navbar/src/navbar/navbar.component.spec.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ import { DaffPalette } from '@daffodil/design';
1313

1414
import { DaffNavbarComponent } from './navbar.component';
1515

16-
@Component({ template: '<nav daff-navbar [color]="color" [raised]="raised"></ nav>' })
16+
@Component({
17+
template: '<nav daff-navbar [color]="color" [raised]="raised"></ nav>',
18+
standalone: true,
19+
imports: [
20+
DaffNavbarComponent,
21+
],
22+
})
1723
class WrapperComponent {
1824
color: DaffPalette;
1925
raised = false;
@@ -26,9 +32,8 @@ describe('@daffodil/design/navbar | DaffNavbarComponent', () => {
2632

2733
beforeEach(waitForAsync(() => {
2834
TestBed.configureTestingModule({
29-
declarations: [
35+
imports: [
3036
WrapperComponent,
31-
DaffNavbarComponent,
3237
],
3338
})
3439
.compileComponents();
@@ -45,10 +50,8 @@ describe('@daffodil/design/navbar | DaffNavbarComponent', () => {
4550
expect(wrapper).toBeTruthy();
4651
});
4752

48-
describe('<nav daff-navbar>', () => {
49-
it('should add a class of "daff-navbar" to the host element', () => {
50-
expect(de.nativeElement.classList.contains('daff-navbar')).toBeTruthy();
51-
});
53+
it('should add a class of "daff-navbar" to the host element', () => {
54+
expect(de.nativeElement.classList.contains('daff-navbar')).toBeTruthy();
5255
});
5356

5457
describe('using the color property of navbar', () => {

libs/design/navbar/src/navbar/navbar.component.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ import {
1010
DaffManageContainerLayoutDirective,
1111
} from '@daffodil/design';
1212

13-
/**
14-
* @inheritdoc
15-
*/
1613
@Component({
1714
// eslint-disable-next-line @angular-eslint/component-selector
1815
selector: 'nav[daff-navbar]',
@@ -26,6 +23,7 @@ import {
2623
},
2724
],
2825
changeDetection: ChangeDetectionStrategy.OnPush,
26+
standalone: true,
2927
})
3028
export class DaffNavbarComponent {
3129

libs/design/navbar/src/public_api.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { DaffNavbarModule } from './navbar.module';
22
export * from './navbar/navbar.component';
3+
export { DAFF_NAVBAR_COMPONENTS } from './navbar';

libs/design/sidebar/examples/src/side-fixed-sidebar/side-fixed-sidebar.component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
Component,
44
} from '@angular/core';
55

6-
import { DaffNavbarModule } from '@daffodil/design/navbar';
6+
import { DAFF_NAVBAR_COMPONENTS } from '@daffodil/design/navbar';
77
import { DaffSidebarModule } from '@daffodil/design/sidebar';
88

99
@Component({
@@ -13,6 +13,6 @@ import { DaffSidebarModule } from '@daffodil/design/sidebar';
1313
styleUrls: ['side-fixed-sidebar.component.scss'],
1414
changeDetection: ChangeDetectionStrategy.OnPush,
1515
standalone: true,
16-
imports: [DaffSidebarModule, DaffNavbarModule],
16+
imports: [DaffSidebarModule, DAFF_NAVBAR_COMPONENTS],
1717
})
1818
export class SideFixedSidebarComponent {}

0 commit comments

Comments
 (0)