Skip to content

Commit

Permalink
feat(design): create injection tokens with factory (#3246)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 authored Oct 14, 2024
1 parent b54761b commit 7b28ecf
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
7 changes: 5 additions & 2 deletions libs/design/media-gallery/src/helpers/media-gallery-token.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { InjectionToken } from '@angular/core';
import { createSingleInjectionToken } from '@daffodil/core';

import { DaffMediaGalleryRegistration } from './media-gallery-registration.interface';

export const DAFF_MEDIA_GALLERY_TOKEN = new InjectionToken<DaffMediaGalleryRegistration>('DAFF_MEDIA_GALLERY_TOKEN');
export const {
token: DAFF_MEDIA_GALLERY_TOKEN,
provider: daffProvideMediaGalleryToken,
} = createSingleInjectionToken<DaffMediaGalleryRegistration>('DAFF_MEDIA_GALLERY_TOKEN');
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { InjectionToken } from '@angular/core';
import { createSingleInjectionToken } from '@daffodil/core';

/**
* A multi provider injection token that marks a component as renderable for the `DaffMediaRendererComponent`.
*/
export const daffThumbnailCompatToken = new InjectionToken<unknown>('thumbnailCompatToken');
export const {
/**
* A multi provider injection token that marks a component as renderable for the `DaffMediaRendererComponent`.
*/
token: daffThumbnailCompatToken,
provider: daffProvidedaffThumbnailCompatToken,
} = createSingleInjectionToken<unknown>('thumbnailCompatToken');
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { DOCUMENT } from '@angular/common';
import {
ElementRef,
InjectionToken,
inject,
} from '@angular/core';

import { createSingleInjectionToken } from '@daffodil/core';

/**
* An interface that enables a user to enable or disable scrolling on sidebars.
*
Expand All @@ -15,25 +16,31 @@ export interface DaffSidebarScroll {
disable(): void;
}

/**
* An injection token that can be used within a sidebar to determine
* what to do enabling and disabling scrolling. By default, the body
* is the element where scrolling is controlled.
*/
export const DAFF_SIDEBAR_SCROLL_TOKEN = new InjectionToken<DaffSidebarScroll>('DAFF_SIDEBAR_SCROLL_TOKEN', {
providedIn: 'root',
factory: () => {
const document = inject(DOCUMENT);
return {
enable: () => {
document.body.style.overflow = null;
},
disable: () => {
document.body.style.overflow = 'hidden';
},
};
export const {
/**
* An injection token that can be used within a sidebar to determine
* what to do enabling and disabling scrolling. By default, the body
* is the element where scrolling is controlled.
*/
token: DAFF_SIDEBAR_SCROLL_TOKEN,
provider: daffProvideSidebarScrollToken,
} = createSingleInjectionToken<DaffSidebarScroll>(
'DAFF_SIDEBAR_SCROLL_TOKEN',
{
providedIn: 'root',
factory: () => {
const document = inject(DOCUMENT);
return {
enable: () => {
document.body.style.overflow = null;
},
disable: () => {
document.body.style.overflow = 'hidden';
},
};
},
},
});
);


/**
Expand Down

0 comments on commit 7b28ecf

Please sign in to comment.