Skip to content

Commit

Permalink
feat(desing): convert loading icon 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 328a70a commit 708a6fa
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { DaffCartFacade } from '@daffodil/cart/state';
import { DAFF_ACCORDION_COMPONENTS } from '@daffodil/design/accordion';
import { DAFF_CONTAINER_COMPONENTS } from '@daffodil/design/container';
import { DaffLoadingIconModule } from '@daffodil/design/loading-icon';
import { DAFF_LOADING_ICON_COMPONENTS } from '@daffodil/design/loading-icon';
import { DaffPersonalAddress } from '@daffodil/geography';

import { CartSummaryWrapperModule } from '../../../cart/components/cart-summary-wrapper/cart-summary-wrapper.module';
Expand Down Expand Up @@ -52,7 +52,7 @@ import {
CommonModule,
LetDirective,
DAFF_CONTAINER_COMPONENTS,
DaffLoadingIconModule,
DAFF_LOADING_ICON_COMPONENTS,
DAFF_ACCORDION_COMPONENTS,

DemoCheckoutShippingAddressFormComponent,
Expand Down
4 changes: 2 additions & 2 deletions apps/demo/src/app/thank-you/pages/thank-you-view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { DaffCartFacade } from '@daffodil/cart/state';
import { DaffCheckoutPlacedOrderFacade } from '@daffodil/checkout/state';
import { DAFF_ACCORDION_COMPONENTS } from '@daffodil/design/accordion';
import { DAFF_CONTAINER_COMPONENTS } from '@daffodil/design/container';
import { DaffLoadingIconModule } from '@daffodil/design/loading-icon';
import { DAFF_LOADING_ICON_COMPONENTS } from '@daffodil/design/loading-icon';
import { DaffOrder } from '@daffodil/order';

import { CartSummaryWrapperModule } from '../../cart/components/cart-summary-wrapper/cart-summary-wrapper.module';
Expand All @@ -28,7 +28,7 @@ import { ThankYouComponent } from '../components/thank-you/thank-you.component';
DAFF_CONTAINER_COMPONENTS,
CartSummaryWrapperModule,
DAFF_ACCORDION_COMPONENTS,
DaffLoadingIconModule,
DAFF_LOADING_ICON_COMPONENTS,
],
})
export class ThankYouViewComponent implements OnInit {
Expand Down
2 changes: 2 additions & 0 deletions libs/design/button/src/button/button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
DaffColorableDirective,
DaffPrefixSuffixModule,
} from '@daffodil/design';
import { DAFF_LOADING_ICON_COMPONENTS } from '@daffodil/design/loading-icon';

import { DaffButtonSizableDirective } from './button-sizable.directive';

Expand Down Expand Up @@ -99,6 +100,7 @@ enum DaffButtonTypeEnum {
imports: [
NgIf,
DaffPrefixSuffixModule,
DAFF_LOADING_ICON_COMPONENTS,
],
})
export class DaffButtonComponent
Expand Down
41 changes: 41 additions & 0 deletions libs/design/loading-icon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,47 @@ Loading icons are used as an indicator of an event in progress.
## Overview
Loading icons are used to indicate to users that an event is ocurring and is still in progress. They should only be used for short loading processes. For events that can take a considerable amount of time, use the [Progress Bar](/libs/design/progress-bar/README.md) component instead.

## Usage

### Within a standalone component
To use loading icon 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_LOADING_ICON_COMPONENTS,
],
})
export class CustomComponent {}
```

### Within a module (deprecated)
To use loading icon in a module, import `DaffLoadingIconModule` into your custom module:

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

import { DaffLoadingIconModule } from '@daffodil/design/loading-icon';

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

> This method is deprecated. It's recommended to update all custom components to standalone.
## Diameter
The diameter of a loading icon can be defined by using the `diameter` property. By default, the diameter is set to `60`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ReactiveFormsModule,
} from '@angular/forms';

import { DaffLoadingIconModule } from '@daffodil/design/loading-icon';
import { DAFF_LOADING_ICON_COMPONENTS } from '@daffodil/design/loading-icon';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
Expand All @@ -22,7 +22,7 @@ import { DaffLoadingIconModule } from '@daffodil/design/loading-icon';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
DaffLoadingIconModule,
DAFF_LOADING_ICON_COMPONENTS,
ReactiveFormsModule,
NgFor,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import {
Component,
} from '@angular/core';

import { DaffLoadingIconModule } from '@daffodil/design/loading-icon';
import { DAFF_LOADING_ICON_COMPONENTS } from '@daffodil/design/loading-icon';

@Component({
// eslint-disable-next-line @angular-eslint/component-selector
selector: 'loading-icon-diameter',
templateUrl: './loading-icon-diameter.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [DaffLoadingIconModule],
imports: [
DAFF_LOADING_ICON_COMPONENTS,
],
})
export class LoadingIconDiameterComponent { }
5 changes: 3 additions & 2 deletions libs/design/loading-icon/src/loading-icon.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { NgModule } from '@angular/core';

import { DaffLoadingIconComponent } from './loading-icon/loading-icon.component';

/**
* @deprecated in favor of {@link DAFF_LOADING_ICON_COMPONENTS}
*/
@NgModule({
imports: [
CommonModule,
],
declarations: [
DaffLoadingIconComponent,
],
exports: [
Expand Down
5 changes: 5 additions & 0 deletions libs/design/loading-icon/src/loading-icon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { DaffLoadingIconComponent } from './loading-icon/loading-icon.component';

export const DAFF_LOADING_ICON_COMPONENTS = <const> [
DaffLoadingIconComponent,
];
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import { DaffPalette } from '@daffodil/design';

import { DaffLoadingIconComponent } from './loading-icon.component';

@Component({ template: '<daff-loading-icon [color]="color" [diameter]="diameter"></daff-loading-icon>' })
@Component({
template: '<daff-loading-icon [color]="color" [diameter]="diameter"></daff-loading-icon>',
standalone: true,
imports: [
DaffLoadingIconComponent,
],
})
class WrapperComponent {
color: DaffPalette;
diameter = 60;
Expand All @@ -27,9 +33,8 @@ describe('@daffodil/design/loading-icon | DaffLoadingIconComponent', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [
imports: [
WrapperComponent,
DaffLoadingIconComponent,
],
})
.compileComponents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { DaffColorableDirective } from '@daffodil/design';
},
],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
})
export class DaffLoadingIconComponent {

Expand Down
1 change: 1 addition & 0 deletions libs/design/loading-icon/src/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { DaffLoadingIconModule } from './loading-icon.module';
export { DaffLoadingIconComponent } from './loading-icon/loading-icon.component';
export { DAFF_LOADING_ICON_COMPONENTS } from './loading-icon';

0 comments on commit 708a6fa

Please sign in to comment.