Skip to content

Commit ce058dd

Browse files
xelaintdamienwebdev
authored andcommitted
feat(design): convert sidebar component to standalone (#3054)
1 parent 0c1fc77 commit ce058dd

28 files changed

+315
-190
lines changed

libs/design/sidebar/README.md

+58-17
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,53 @@ Sidebar is a component used to display additional information to the side of a p
44
## Overview
55
Sidebars are often used for navigation, but it's built to be flexible and extensible so that it can be used for any content. Sidebar supports a header and footer component with minimal default styling.
66

7-
### Basic sidebar
7+
## Usage
8+
9+
### Within a standalone component
10+
To use sidebar in a standalone component, import `DAFF_SIDEBAR_COMPONENTS` directly into your custom component:
11+
12+
```ts
13+
@Component({
14+
selector: 'custom-component',
15+
templateUrl: './custom-component.component.html',
16+
standalone: true,
17+
imports: [
18+
DAFF_SIDEBAR_COMPONENTS,
19+
],
20+
})
21+
export class CustomComponent {}
22+
```
23+
24+
### Within a module (deprecated)
25+
To use sidebar in a module, import `DaffSidebarModule` into your custom module:
26+
27+
```ts
28+
import { NgModule } from '@angular/core';
29+
30+
import { DaffSidebarModule } from '@daffodil/design/sidebar';
31+
32+
@NgModule({
33+
declarations: [
34+
CustomComponent,
35+
],
36+
exports: [
37+
CustomComponent,
38+
],
39+
imports: [
40+
DaffSidebarModule,
41+
],
42+
})
43+
export class CustomComponentModule { }
44+
```
45+
46+
> This method is deprecated. It's recommended to update all custom components to standalone.
47+
48+
## Basic sidebar
849
The default setting for sidebar is `mode="side"` and `side="left"`.
950

1051
<design-land-example-viewer-container example="basic-sidebar"></design-land-example-viewer-container>
1152

12-
### Implementing the main and sidebar content
53+
## Implementing the main and sidebar content
1354
The main and sidebar content should be placed inside of the `<daff-sidebar-viewport>`. The sidebar content should be placed inside of the `<daff-sidebar>`.
1455

1556
A viewport navigation can either be:
@@ -50,17 +91,17 @@ A viewport navigation can either be:
5091
</daff-sidebar-viewport>
5192
```
5293

53-
#### Required Imports
94+
### Required Imports
5495
The `BrowserAnimationsModule` or `NoopAnimationsModule` must be imported in the particular Angular `@NgModule` the sidebar is used in for the sidebar to render and work properly.
5596

56-
### Header and footer
97+
## Header and footer
5798
The `<daff-sidebar-header>` includes optional title (`[daffSidebarHeaderTitle]`) and action (`[daffSidebarHeaderAction]`) selectors, and a slot to render custom content. The action selector should be used along with the `<daff-icon-button>` (view [Button Documentation](/libs/design/button/README.md)) to make sure that the action is positioned correctly and it passes WCAG guidelines.
5899

59100
The `<daff-sidebar-footer>` is a "holder" component with minimal default styling. Its main purpose is to position the footer at the bottom of the sidebar, allowing the sidebar's content to overflow and scroll while ensuring that the footer remains constantly visible.
60101

61102
Both the header and footer are optional components that will not render in the DOM if they are not used.
62103

63-
### Opening and closing a sidebar
104+
## Opening and closing a sidebar
64105
THe `open` property is used to set the open state for a sidebar.
65106

66107
By default, sidebar supports two methods of closing itself: clicking on the backdrop of the sidebar viewport or pressing `ESC` when the sidebar has focus.
@@ -69,7 +110,7 @@ By default, sidebar supports two methods of closing itself: clicking on the back
69110
| `(backdropClicked)` | Set on the `<daff-sidebar-viewport>` |
70111
| `(escapePressed)` | Set on the `<daff-sidebar>` |
71112

72-
### Modes
113+
## Modes
73114
`<daff-sidebar>` can be rendered four different ways by using the `mode` property. If `mode` is not specified, `side` is used by default.
74115

75116
| Mode | Description |
@@ -79,27 +120,27 @@ By default, sidebar supports two methods of closing itself: clicking on the back
79120
| over | Sidebar slides over the rest of the content in the viewport and covering it with a backdrop |
80121
| under | Sidebar freezes in place and and the content slides above it, while also being covered by a backdrop |
81122

82-
#### Over sidebar
123+
### Over sidebar
83124
<design-land-example-viewer-container example="over-sidebar"></design-land-example-viewer-container>
84125

85-
#### Under sidebar
126+
### Under sidebar
86127
<design-land-example-viewer-container example="under-sidebar"></design-land-example-viewer-container>
87128

88-
#### Two fixed sidebars on either side
129+
### Two fixed sidebars on either side
89130
<design-land-example-viewer-container example="two-fixed-sidebars-either-side"></design-land-example-viewer-container>
90131

91-
#### Fixed and over sidebar
132+
### Fixed and over sidebar
92133
<design-land-example-viewer-container example="fixed-and-over-sidebar"></design-land-example-viewer-container>
93134

94-
### Sides
135+
## Sides
95136
`<daff-sidebar>` can be positioned on either side of a screen by using the `side` property. If `side` is not specificed, `left` is used by default.
96137

97138
| Side | Description |
98139
| ----- | ---------------------------------------------- |
99140
| left | Places sidebar on the left side of the screen |
100141
| right | Places sidebar on the right side of the screen |
101142

102-
### Custom styles
143+
## Custom styles
103144

104145
#### Setting a sidebar's width
105146
The default size of a sidebar is `240px`. The `--daff-sidebar-left-width` and `--daff-sidebar-right-width` variables can be used to change the width of a left or right sidebar. These variables need to be defined on `<daff-sidebar-viewport>` or on the shadow DOM.
@@ -127,7 +168,7 @@ daff-sidebar-viewport {
127168
}
128169
```
129170

130-
### Changing a side-fixed sidebar's top offset position
171+
## Changing a side-fixed sidebar's top offset position
131172
The default offset position of a sidebar is `0px`. The `--daff-sidebar-side-fixed-top-shift` variable can be used to adjust the top offset position for a primary sidebar and its viewport content.
132173

133174
```scss
@@ -136,17 +177,17 @@ body {
136177
}
137178
```
138179

139-
### Examples
180+
## Examples
140181
#### Over and under sidebars
141182
<design-land-example-viewer-container example="over-and-under-sidebars"></design-land-example-viewer-container>
142183

143-
#### Side fixed sidebar
184+
### Side fixed sidebar
144185
<design-land-example-viewer-container example="side-fixed-sidebar"></design-land-example-viewer-container>
145186

146-
### Accessibility
187+
## Accessibility
147188
A meaningful `role` should be set on all sidebars depending on how they are used.
148189

149190
When the `<daff-sidebar-header>` is not used or there is no title for the sidebar, a meaningful `aria-label` should be set to describe the sidebar.
150191

151-
#### Focus
192+
### Focus
152193
Focus trapping is enabled for `over` and `under` modes, and disabled for `side` and `side-fixed` modes. When a sidebar is opened, the first tabbable element within the will receive focus. When a sidebar is opened, the first tabbable element within the will receive focus. When a sidebar is closed, the element that was focused before the sidebar was opened will be re-focused.

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

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

6-
import { DaffSidebarModule } from '@daffodil/design/sidebar';
6+
import { DAFF_SIDEBAR_COMPONENTS } from '@daffodil/design/sidebar';
77

88
@Component({
99
// eslint-disable-next-line @angular-eslint/component-selector
@@ -12,8 +12,8 @@ import { DaffSidebarModule } from '@daffodil/design/sidebar';
1212
styleUrls: ['./basic-sidebar.component.scss'],
1313
changeDetection: ChangeDetectionStrategy.OnPush,
1414
standalone: true,
15-
imports: [DaffSidebarModule],
15+
imports: [
16+
DAFF_SIDEBAR_COMPONENTS,
17+
],
1618
})
17-
export class BasicSidebarComponent {
18-
19-
}
19+
export class BasicSidebarComponent {}

libs/design/sidebar/examples/src/over-and-under-sidebars/over-and-under-sidebars.component.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { FaIconComponent } from '@fortawesome/angular-fontawesome';
1010
import { faTimes } from '@fortawesome/free-solid-svg-icons';
1111

1212
import { DAFF_BUTTON_COMPONENTS } from '@daffodil/design/button';
13-
import { DaffSidebarModule } from '@daffodil/design/sidebar';
13+
import { DAFF_SIDEBAR_COMPONENTS } from '@daffodil/design/sidebar';
1414

1515
@Component({
1616
// eslint-disable-next-line @angular-eslint/component-selector
@@ -20,8 +20,7 @@ import { DaffSidebarModule } from '@daffodil/design/sidebar';
2020
changeDetection: ChangeDetectionStrategy.OnPush,
2121
standalone: true,
2222
imports: [
23-
DaffSidebarModule,
24-
DaffButtonModule,
23+
DAFF_SIDEBAR_COMPONENTS,
2524
FaIconComponent,
2625
ReactiveFormsModule,
2726
DAFF_BUTTON_COMPONENTS,

libs/design/sidebar/examples/src/side-fixed-sidebar/side-fixed-sidebar.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_NAVBAR_COMPONENTS } from '@daffodil/design/navbar';
7-
import { DaffSidebarModule } from '@daffodil/design/sidebar';
7+
import { DAFF_SIDEBAR_COMPONENTS } from '@daffodil/design/sidebar';
88

99
@Component({
1010
// eslint-disable-next-line @angular-eslint/component-selector
@@ -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, DAFF_NAVBAR_COMPONENTS],
16+
imports: [DAFF_SIDEBAR_COMPONENTS, DAFF_NAVBAR_COMPONENTS],
1717
})
1818
export class SideFixedSidebarComponent {}

libs/design/sidebar/examples/src/sidebar-with-sticky-content/sidebar-with-sticky-content.component.ts

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

6-
import { DaffSidebarModule } from '@daffodil/design/sidebar';
6+
import { DAFF_SIDEBAR_COMPONENTS } from '@daffodil/design/sidebar';
77

88
@Component({
99
// eslint-disable-next-line @angular-eslint/component-selector
@@ -12,6 +12,8 @@ import { DaffSidebarModule } from '@daffodil/design/sidebar';
1212
styleUrls: ['sidebar-with-sticky-content.component.scss'],
1313
changeDetection: ChangeDetectionStrategy.OnPush,
1414
standalone: true,
15-
imports: [DaffSidebarModule],
15+
imports: [
16+
DAFF_SIDEBAR_COMPONENTS,
17+
],
1618
})
1719
export class SidebarWithStickyContentComponent {}

libs/design/sidebar/src/public_api.ts

+1
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ export {
1818
} from './helper/sidebar-side';
1919
export * from './helper/is-docked-mode';
2020
export * from './helper/is-floating-mode';
21+
export { DAFF_SIDEBAR_COMPONENTS } from './sidebar';

libs/design/sidebar/src/sidebar-footer/sidebar-footer.component.spec.ts

+16-9
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,24 @@ import { By } from '@angular/platform-browser';
1111

1212
import { DaffSidebarFooterComponent } from './sidebar-footer.component';
1313

14-
@Component({ template: `
15-
<daff-sidebar-footer>Footer</daff-sidebar-footer>
16-
` })
14+
@Component({
15+
template: `<daff-sidebar-footer>Footer</daff-sidebar-footer>`,
16+
standalone: true,
17+
imports: [
18+
DaffSidebarFooterComponent,
19+
],
20+
})
1721
class WrapperComponent {}
1822

1923
describe('@daffodil/design/sidebar | DaffSidebarFooterComponent', () => {
2024
let wrapper: WrapperComponent;
2125
let fixture: ComponentFixture<WrapperComponent>;
22-
let sidebarFooter: DaffSidebarFooterComponent;
23-
let sidebarFooterDe: DebugElement;
26+
let de: DebugElement;
2427

2528
beforeEach(waitForAsync(() => {
2629
TestBed.configureTestingModule({
27-
declarations: [
30+
imports: [
2831
WrapperComponent,
29-
DaffSidebarFooterComponent,
3032
],
3133
})
3234
.compileComponents();
@@ -36,12 +38,17 @@ describe('@daffodil/design/sidebar | DaffSidebarFooterComponent', () => {
3638
fixture = TestBed.createComponent(WrapperComponent);
3739
wrapper = fixture.componentInstance;
3840

39-
sidebarFooterDe = fixture.debugElement.query(By.css('daff-sidebar-footer'));
40-
sidebarFooter = sidebarFooterDe.componentInstance;
41+
de = fixture.debugElement.query(By.css('daff-sidebar-footer'));
4142
fixture.detectChanges();
4243
});
4344

4445
it('should create', () => {
4546
expect(wrapper).toBeTruthy();
4647
});
48+
49+
it('should add a class of `daff-sidebar-footer` to its host element', () => {
50+
expect(de.classes).toEqual(jasmine.objectContaining({
51+
'daff-sidebar-footer': true,
52+
}));
53+
});
4754
});

libs/design/sidebar/src/sidebar-footer/sidebar-footer.component.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
template: '<ng-content></ng-content>',
1010
styleUrls: ['./sidebar-footer.component.scss'],
1111
changeDetection: ChangeDetectionStrategy.OnPush,
12+
standalone: true,
1213
})
1314
export class DaffSidebarFooterComponent {
1415
@HostBinding('class.daff-sidebar-footer') class = true;

libs/design/sidebar/src/sidebar-header/sidebar-header-action/sidebar-header-action.directive.spec.ts

+10-11
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import { By } from '@angular/platform-browser';
1212
import { DaffSidebarHeaderActionDirective } from './sidebar-header-action.directive';
1313

1414
@Component({
15-
template: `
16-
<div daffSidebarHeaderAction>Action</div>
17-
`,
15+
template: `<div daffSidebarHeaderAction>Action</div>`,
16+
standalone: true,
17+
imports: [
18+
DaffSidebarHeaderActionDirective,
19+
],
1820
})
1921
class WrapperComponent {}
2022

@@ -25,8 +27,7 @@ describe('@daffodil/design/sidebar | DaffSidebarHeaderActionDirective', () => {
2527

2628
beforeEach(waitForAsync(() => {
2729
TestBed.configureTestingModule({
28-
declarations: [
29-
DaffSidebarHeaderActionDirective,
30+
imports: [
3031
WrapperComponent,
3132
],
3233
})
@@ -44,11 +45,9 @@ describe('@daffodil/design/sidebar | DaffSidebarHeaderActionDirective', () => {
4445
expect(wrapper).toBeTruthy();
4546
});
4647

47-
describe('[daffSidebarHeaderAction]',() => {
48-
it('should add a class of `daff-sidebar-header__action` to its host element', () => {
49-
expect(de.classes).toEqual(jasmine.objectContaining({
50-
'daff-sidebar-header__action': true,
51-
}));
52-
});
48+
it('should add a class of `daff-sidebar-header__action` to the host element', () => {
49+
expect(de.classes).toEqual(jasmine.objectContaining({
50+
'daff-sidebar-header__action': true,
51+
}));
5352
});
5453
});

libs/design/sidebar/src/sidebar-header/sidebar-header-action/sidebar-header-action.directive.ts

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

66
@Directive({
77
selector: '[daffSidebarHeaderAction]',
8+
standalone: true,
89
})
910
export class DaffSidebarHeaderActionDirective {
1011
/**

libs/design/sidebar/src/sidebar-header/sidebar-header-title/sidebar-header-title.directive.spec.ts

+10-11
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import { By } from '@angular/platform-browser';
1212
import { DaffSidebarHeaderTitleDirective } from './sidebar-header-title.directive';
1313

1414
@Component({
15-
template: `
16-
<h2 daffSidebarHeaderTitle>Title</h2>
17-
`,
15+
template: `<h2 daffSidebarHeaderTitle>Title</h2>`,
16+
standalone: true,
17+
imports: [
18+
DaffSidebarHeaderTitleDirective,
19+
],
1820
})
1921
class WrapperComponent {}
2022

@@ -25,8 +27,7 @@ describe('@daffodil/design/sidebar | DaffSidebarHeaderTitleDirective', () => {
2527

2628
beforeEach(waitForAsync(() => {
2729
TestBed.configureTestingModule({
28-
declarations: [
29-
DaffSidebarHeaderTitleDirective,
30+
imports: [
3031
WrapperComponent,
3132
],
3233
})
@@ -44,11 +45,9 @@ describe('@daffodil/design/sidebar | DaffSidebarHeaderTitleDirective', () => {
4445
expect(wrapper).toBeTruthy();
4546
});
4647

47-
describe('[daffSidebarHeaderTitle]',() => {
48-
it('should add a class of `daff-sidebar-header__title` to its host element', () => {
49-
expect(de.classes).toEqual(jasmine.objectContaining({
50-
'daff-sidebar-header__title': true,
51-
}));
52-
});
48+
it('should add a class of `daff-sidebar-header__title` to the host element', () => {
49+
expect(de.classes).toEqual(jasmine.objectContaining({
50+
'daff-sidebar-header__title': true,
51+
}));
5352
});
5453
});

libs/design/sidebar/src/sidebar-header/sidebar-header-title/sidebar-header-title.directive.ts

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

66
@Directive({
77
selector: '[daffSidebarHeaderTitle]',
8+
standalone: true,
89
})
910
export class DaffSidebarHeaderTitleDirective {
1011
/**

0 commit comments

Comments
 (0)