From f607958b0e67d53372a17f1c18d3d24e86221987 Mon Sep 17 00:00:00 2001 From: Arman Ozak Date: Mon, 22 Jun 2020 13:29:30 +0300 Subject: [PATCH] feat: add styles provider to theme basic package --- .../theme-basic/src/lib/providers/index.ts | 1 + .../src/lib/providers/styles.provider.ts | 42 +++++++++++++++++++ .../packages/theme-basic/src/public-api.ts | 3 +- 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 npm/ng-packs/packages/theme-basic/src/lib/providers/index.ts create mode 100644 npm/ng-packs/packages/theme-basic/src/lib/providers/styles.provider.ts diff --git a/npm/ng-packs/packages/theme-basic/src/lib/providers/index.ts b/npm/ng-packs/packages/theme-basic/src/lib/providers/index.ts new file mode 100644 index 0000000000..607efd62a5 --- /dev/null +++ b/npm/ng-packs/packages/theme-basic/src/lib/providers/index.ts @@ -0,0 +1 @@ +export * from './styles.provider'; diff --git a/npm/ng-packs/packages/theme-basic/src/lib/providers/styles.provider.ts b/npm/ng-packs/packages/theme-basic/src/lib/providers/styles.provider.ts new file mode 100644 index 0000000000..ab6ea9cd1e --- /dev/null +++ b/npm/ng-packs/packages/theme-basic/src/lib/providers/styles.provider.ts @@ -0,0 +1,42 @@ +import { AddReplaceableComponent, CONTENT_STRATEGY, DomInsertionService } from '@abp/ng.core'; +import { APP_INITIALIZER } from '@angular/core'; +import { Store } from '@ngxs/store'; +import { AccountLayoutComponent } from '../components/account-layout/account-layout.component'; +import { ApplicationLayoutComponent } from '../components/application-layout/application-layout.component'; +import { EmptyLayoutComponent } from '../components/empty-layout/empty-layout.component'; +import styles from '../constants/styles'; +import { eThemeBasicComponents } from '../enums/components'; + +export const BASIC_THEME_STYLES_PROVIDERS = [ + { + provide: APP_INITIALIZER, + useFactory: configureStyles, + deps: [DomInsertionService, Store], + multi: true, + }, +]; + +export function configureStyles(domInsertion: DomInsertionService, store: Store) { + return () => { + domInsertion.insertContent(CONTENT_STRATEGY.AppendStyleToHead(styles)); + + initLayouts(store); + }; +} + +function initLayouts(store: Store) { + store.dispatch([ + new AddReplaceableComponent({ + key: eThemeBasicComponents.ApplicationLayout, + component: ApplicationLayoutComponent, + }), + new AddReplaceableComponent({ + key: eThemeBasicComponents.AccountLayout, + component: AccountLayoutComponent, + }), + new AddReplaceableComponent({ + key: eThemeBasicComponents.EmptyLayout, + component: EmptyLayoutComponent, + }), + ]); +} diff --git a/npm/ng-packs/packages/theme-basic/src/public-api.ts b/npm/ng-packs/packages/theme-basic/src/public-api.ts index 580366dbcb..680c00ebbb 100644 --- a/npm/ng-packs/packages/theme-basic/src/public-api.ts +++ b/npm/ng-packs/packages/theme-basic/src/public-api.ts @@ -2,10 +2,11 @@ * Public API Surface of theme-basic */ -export * from './lib/theme-basic.module'; export * from './lib/actions'; export * from './lib/components'; export * from './lib/enums'; export * from './lib/models'; +export * from './lib/providers'; export * from './lib/services'; export * from './lib/states'; +export * from './lib/theme-basic.module';