Skip to content

Commit 7b28ecf

Browse files
authored
feat(design): create injection tokens with factory (#3246)
1 parent b54761b commit 7b28ecf

File tree

3 files changed

+39
-26
lines changed

3 files changed

+39
-26
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import { InjectionToken } from '@angular/core';
1+
import { createSingleInjectionToken } from '@daffodil/core';
22

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

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

3-
/**
4-
* A multi provider injection token that marks a component as renderable for the `DaffMediaRendererComponent`.
5-
*/
6-
export const daffThumbnailCompatToken = new InjectionToken<unknown>('thumbnailCompatToken');
3+
export const {
4+
/**
5+
* A multi provider injection token that marks a component as renderable for the `DaffMediaRendererComponent`.
6+
*/
7+
token: daffThumbnailCompatToken,
8+
provider: daffProvidedaffThumbnailCompatToken,
9+
} = createSingleInjectionToken<unknown>('thumbnailCompatToken');

libs/design/sidebar/src/sidebar-viewport/scroll-token/scroll.token.ts

+26-19
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { DOCUMENT } from '@angular/common';
22
import {
33
ElementRef,
4-
InjectionToken,
54
inject,
65
} from '@angular/core';
76

7+
import { createSingleInjectionToken } from '@daffodil/core';
8+
89
/**
910
* An interface that enables a user to enable or disable scrolling on sidebars.
1011
*
@@ -15,25 +16,31 @@ export interface DaffSidebarScroll {
1516
disable(): void;
1617
}
1718

18-
/**
19-
* An injection token that can be used within a sidebar to determine
20-
* what to do enabling and disabling scrolling. By default, the body
21-
* is the element where scrolling is controlled.
22-
*/
23-
export const DAFF_SIDEBAR_SCROLL_TOKEN = new InjectionToken<DaffSidebarScroll>('DAFF_SIDEBAR_SCROLL_TOKEN', {
24-
providedIn: 'root',
25-
factory: () => {
26-
const document = inject(DOCUMENT);
27-
return {
28-
enable: () => {
29-
document.body.style.overflow = null;
30-
},
31-
disable: () => {
32-
document.body.style.overflow = 'hidden';
33-
},
34-
};
19+
export const {
20+
/**
21+
* An injection token that can be used within a sidebar to determine
22+
* what to do enabling and disabling scrolling. By default, the body
23+
* is the element where scrolling is controlled.
24+
*/
25+
token: DAFF_SIDEBAR_SCROLL_TOKEN,
26+
provider: daffProvideSidebarScrollToken,
27+
} = createSingleInjectionToken<DaffSidebarScroll>(
28+
'DAFF_SIDEBAR_SCROLL_TOKEN',
29+
{
30+
providedIn: 'root',
31+
factory: () => {
32+
const document = inject(DOCUMENT);
33+
return {
34+
enable: () => {
35+
document.body.style.overflow = null;
36+
},
37+
disable: () => {
38+
document.body.style.overflow = 'hidden';
39+
},
40+
};
41+
},
3542
},
36-
});
43+
);
3744

3845

3946
/**

0 commit comments

Comments
 (0)