Skip to content

Commit

Permalink
feat(design): convert list 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 b54d941 commit 328a70a
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 22 deletions.
4 changes: 2 additions & 2 deletions apps/daffio/src/app/core/nav/sidebar-body/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
Observable,
} from 'rxjs';

import { DaffListModule } from '@daffodil/design/list';
import { DAFF_LIST_COMPONENTS } from '@daffodil/design/list';
import { DaffRouterDataService } from '@daffodil/router';

import { DaffioRouteWithNavLinks } from '../link/route.type';
Expand All @@ -24,7 +24,7 @@ import { DaffioNavLink } from '../link/type';
standalone: true,
imports: [
AsyncPipe,
DaffListModule,
DAFF_LIST_COMPONENTS,
RouterLink,
],
})
Expand Down
43 changes: 42 additions & 1 deletion libs/design/list/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,53 @@
# List
List is a flexible component that can be used to display a series of content. It can be modified to support a range of content types.

## Usage

### Within a standalone component
To use list in a standalone component, import it directly into your custom component:

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

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

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

import { DaffListModule } from '@daffodil/design/list';

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

> This method is deprecated. It's recommended to update all custom components to standalone.
## Basic List
A `<daff-list>` consists of multiple `<daff-list-item>`s.

<design-land-example-viewer-container example="basic-list"></design-land-example-viewer-container>

## Nvigation List
## Navigation List
Use `<daff-nav-list>` for navigation lists. `<daff-list-item>` should be directly added to an anchor tag.

<design-land-example-viewer-container example="nav-list"></design-land-example-viewer-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import {
Component,
} from '@angular/core';

import { DaffListModule } from '@daffodil/design/list';
import { DAFF_LIST_COMPONENTS } from '@daffodil/design/list';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
selector: 'basic-list',
templateUrl: './basic-list.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [DaffListModule],
imports: [
DAFF_LIST_COMPONENTS,
],
})
export class BasicListComponent {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import {
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
import { faInfoCircle } from '@fortawesome/free-solid-svg-icons';

import { DaffPrefixSuffixModule } from '@daffodil/design';
import { DaffListModule } from '@daffodil/design/list';
import { DAFF_LIST_COMPONENTS } from '@daffodil/design/list';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
Expand All @@ -15,9 +14,8 @@ import { DaffListModule } from '@daffodil/design/list';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
DaffListModule,
DAFF_LIST_COMPONENTS,
FaIconComponent,
DaffPrefixSuffixModule,
],
})
export class IconListComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import {
Component,
} from '@angular/core';

import { DaffListModule } from '@daffodil/design/list';
import { DAFF_LIST_COMPONENTS } from '@daffodil/design/list';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
selector: 'multiline-list',
templateUrl: './multiline-list.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [DaffListModule],
imports: [
DAFF_LIST_COMPONENTS,
],
})
export class MultilineListComponent {}
6 changes: 2 additions & 4 deletions libs/design/list/examples/src/nav-list/nav-list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import {
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
import { faChevronRight } from '@fortawesome/free-solid-svg-icons';

import { DaffPrefixSuffixModule } from '@daffodil/design';
import { DaffListModule } from '@daffodil/design/list';
import { DAFF_LIST_COMPONENTS } from '@daffodil/design/list';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
Expand All @@ -15,9 +14,8 @@ import { DaffListModule } from '@daffodil/design/list';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
DaffListModule,
DAFF_LIST_COMPONENTS,
FaIconComponent,
DaffPrefixSuffixModule,
],
})
export class NavListComponent {
Expand Down
7 changes: 5 additions & 2 deletions libs/design/list/src/list-item/list-item.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import { DaffListItemComponent } from './list-item.component';
<daff-list-item>List Item</daff-list-item>
<a daff-list-item>List Item</a>
`,
standalone: true,
imports: [
DaffListItemComponent,
],
})
class WrapperComponent {}

Expand All @@ -30,8 +34,7 @@ describe('@daffodil/design/list | DaffListItemComponent', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
DaffListItemComponent,
imports: [
WrapperComponent,
],
})
Expand Down
7 changes: 7 additions & 0 deletions libs/design/list/src/list-item/list-item.component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NgIf } from '@angular/common';
import {
Component,
ChangeDetectionStrategy,
Expand All @@ -8,6 +9,7 @@ import {

import {
DaffPrefixDirective,
DaffPrefixSuffixModule,
DaffSuffixDirective,
} from '@daffodil/design';

Expand All @@ -17,6 +19,11 @@ import {
'a[daff-list-item]',
templateUrl: './list-item.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
NgIf,
DaffPrefixSuffixModule,
],
})

export class DaffListItemComponent {
Expand Down
6 changes: 3 additions & 3 deletions libs/design/list/src/list.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { DaffPrefixSuffixModule } from '@daffodil/design';
import { DaffListComponent } from './list/list.component';
import { DaffListItemComponent } from './list-item/list-item.component';

/**
* @deprecated in favor of {@link DAFF_LIST_COMPONENTS}
*/
@NgModule({
imports: [
CommonModule,
DaffPrefixSuffixModule,
],
declarations: [
DaffListComponent,
DaffListItemComponent,
],
Expand Down
10 changes: 10 additions & 0 deletions libs/design/list/src/list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { DaffPrefixSuffixModule } from '@daffodil/design';

import { DaffListComponent } from './list/list.component';
import { DaffListItemComponent } from './list-item/list-item.component';

export const DAFF_LIST_COMPONENTS = <const>[
DaffListComponent,
DaffListItemComponent,
DaffPrefixSuffixModule,
];
7 changes: 5 additions & 2 deletions libs/design/list/src/list/list.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import { DaffListComponent } from './list.component';
<daff-list [mode]="mode"></daff-list>
<daff-nav-list></daff-nav-list>
`,
standalone: true,
imports: [
DaffListComponent,
],
})
class WrapperComponent {}

Expand All @@ -29,9 +33,8 @@ describe('@daffodil/design/list | DaffListComponent', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
imports: [
WrapperComponent,
DaffListComponent,
],
})
.compileComponents();
Expand Down
1 change: 1 addition & 0 deletions libs/design/list/src/list/list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum DaffListTypeEnum {
}],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
})

export class DaffListComponent {
Expand Down
1 change: 1 addition & 0 deletions libs/design/list/src/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { DaffListModule } from './list.module';
export { DAFF_LIST_COMPONENTS } from './list';
export * from './list/list.component';
export * from './list-item/list-item.component';

0 comments on commit 328a70a

Please sign in to comment.