Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(design): create injection tokens with factory #3246

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading