Skip to content

Commit

Permalink
feat: added the ability to enter an initial configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoninoBonanno authored and astagi committed May 15, 2023
1 parent 43f49cc commit bb3f03b
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 5 deletions.
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,39 @@ npm install design-angular-kit@unstable --save
Procedi a registrare `DesignAngularKitModule` nel tuo **app.module.ts**.

```typescript
import {DesignAngularKitModule} from 'design-angular-kit';

@NgModule({
imports: [
...
DesignAngularKitModule
DesignAngularKitModule.forRoot() // .forRoot obligatorio
]
})
```
<details>
<summary>Configurazione della libreria</summary>

```typescript
import {DesignAngularKitModule, DesignAngularKitInit} from 'design-angular-kit';

// Puoi aggiungere alla libreria una configurazione iniziale
const initConfig: DesignAngularKitInit | undefined = {
/**
* The initial path in the `href` attribute in the `IconComponent` component
* @default './bootstrap-italia/dist/svg/sprites.svg'
*/
iconHref: string | undefined,
};

@NgModule({
imports: [
...
DesignAngularKitModule.forRoot(initConfig) // .forRoot obligatorio
]
})
```
</details>


### Importazione stili bootstrap-italia
Configura gli stili richiesti nel file `styles.scss`. Importa la libreria SCSS come mostrato nell'esempio qui sotto.
Expand Down Expand Up @@ -171,7 +197,7 @@ Modifica nel tuo `app.module.ts`:
},
defaultLanguage: 'it'
}),
DesignAngularKitModule
DesignAngularKitModule.forRoot()
]
})
```
Expand All @@ -188,7 +214,7 @@ Se non utilizzi i file di localizzazione nella tua app, devi aggiungere il provi
@NgModule({
imports: [
...
DesignAngularKitModule,
DesignAngularKitModule.forRoot(),
],
providers: [
TranslateStore
Expand Down
26 changes: 26 additions & 0 deletions projects/design-angular-kit/src/lib/design-angular-kit-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { InjectionToken } from '@angular/core';
import { DesignAngularKitInit } from './interfaces/design-angular-kit-init';

export const DESIGN_ANGULAR_KIT_CONFIG = new InjectionToken<DesignAngularKitConfig>('DesignAngularKitConfig');

export class DesignAngularKitConfig {

/**
* The init config
* @private
*/
private readonly initConfig?: DesignAngularKitInit;

constructor(nextInit?: DesignAngularKitInit) {
this.initConfig = nextInit;
}

/**
* The initial path in the `href` attribute in the `IconComponent` component
* @default './bootstrap-italia/dist/svg/sprites.svg'
*/
get iconHref(): string {
return this.initConfig?.iconHref || './bootstrap-italia/dist/svg/sprites.svg';
}

}
16 changes: 15 additions & 1 deletion projects/design-angular-kit/src/lib/design-angular-kit.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { NgModule } from '@angular/core';
import { ModuleWithProviders, NgModule } from '@angular/core';
import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-translate/core';
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { ComponentsModule } from './components/components.module';
import { DESIGN_ANGULAR_KIT_CONFIG, DesignAngularKitConfig } from './design-angular-kit-config';
import { DesignAngularKitInit } from './interfaces/design-angular-kit-init';

@NgModule({
declarations: [],
Expand All @@ -27,6 +29,18 @@ import { ComponentsModule } from './components/components.module';
})
export class DesignAngularKitModule {

static forRoot(initConfig?: DesignAngularKitInit): ModuleWithProviders<DesignAngularKitModule> {
return {
ngModule: DesignAngularKitModule,
providers: [
{
provide: DESIGN_ANGULAR_KIT_CONFIG,
useValue: new DesignAngularKitConfig(initConfig)
}
]
};
}

constructor(
private readonly translateService: TranslateService
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface DesignAngularKitInit {

/**
* The initial path in the `href` attribute in the `IconComponent` component
* @default './bootstrap-italia/dist/svg/sprites.svg'
*/
iconHref?: string;

}
4 changes: 4 additions & 0 deletions projects/design-angular-kit/src/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
export * from './lib/design-angular-kit.module';
export * from './lib/components/components.module';

// Config
export * from './lib/design-angular-kit-config';

// Core
export * from './lib/components/core/accordion/accordion.component';
Expand Down Expand Up @@ -71,6 +73,8 @@ export * from './lib/services/notifications/notifications.service';
export * from './lib/pipes/mark-matching-text.pipe';

// Interfaces
export * from './lib/interfaces/design-angular-kit-init';

export * from './lib/interfaces/core';
export * from './lib/interfaces/form';
export * from './lib/interfaces/icon';
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { DesignAngularKitModule } from '../../projects/design-angular-kit/src/li
BrowserModule,
BrowserAnimationsModule,
AppRoutingModule,
DesignAngularKitModule
DesignAngularKitModule.forRoot()
],
providers: [
TranslateStore,
Expand Down

0 comments on commit bb3f03b

Please sign in to comment.