flowbite-angular
Version:
<div align="center"> <h1>:construction: flowbite-angular (unreleased) :construction:</h1> <p> <a href="https://flowbite.com"> <img alt="Flowbite - Tailwind CSS components" width="350" src="https://flowbite.s3.amazonaws.com/github/logo-github
140 lines (134 loc) • 6.26 kB
JavaScript
import { mergeTheme, SUN_SVG_ICON, MOON_SVG_ICON, createTheme } from 'flowbite-angular/utils';
import * as i0 from '@angular/core';
import { InjectionToken, inject, Injectable, makeEnvironmentProviders, model, Component, ViewEncapsulation, ChangeDetectionStrategy } from '@angular/core';
import { twMerge } from 'tailwind-merge';
import { BaseComponent } from 'flowbite-angular';
import { IconRegistry, IconComponent } from 'flowbite-angular/icon';
import { FlowbiteThemeDirective } from 'flowbite-angular/theme';
import { DomSanitizer } from '@angular/platform-browser';
/**
* `InjectionToken` used to import `DarkThemeToggleTheme` value
*
* @example
* ```
* var theme = inject(FLOWBITE_DARK_THEME_TOGGLE_THEME_TOKEN)
* ```
*/
const FLOWBITE_DARK_THEME_TOGGLE_THEME_TOKEN = new InjectionToken('FLOWBITE_DARK_THEME_TOGGLE_THEME_TOKEN');
class DarkThemeToggleThemeService {
constructor() {
this.baseTheme = inject(FLOWBITE_DARK_THEME_TOGGLE_THEME_TOKEN);
}
getClasses(properties) {
const theme = mergeTheme(this.baseTheme, properties.customStyle);
const output = {
rootClass: twMerge(theme.root.base),
};
return output;
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: DarkThemeToggleThemeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: DarkThemeToggleThemeService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: DarkThemeToggleThemeService, decorators: [{
type: Injectable,
args: [{
providedIn: 'root',
}]
}] });
const FLOWBITE_DARK_THEME_TOGGLE_CUSTOM_STYLE_DEFAULT_VALUE = new InjectionToken('FLOWBITE_DARK_THEME_TOGGLE_CUSTOM_STYLE_DEFAULT_VALUE');
const darkThemeToggleDefaultValueProvider = makeEnvironmentProviders([
{
provide: FLOWBITE_DARK_THEME_TOGGLE_CUSTOM_STYLE_DEFAULT_VALUE,
useValue: {},
},
]);
/**
* Use to toggle light/dark mode accross the site
*/
class DarkThemeToggleComponent extends BaseComponent {
constructor() {
super(...arguments);
/**
* Service injected used to generate class
*/
this.themeService = inject(DarkThemeToggleThemeService);
/**
* `IconRegistry` service
*/
this.iconRegistry = inject(IconRegistry);
/**
* `DomSanitizer` service
*/
this.domSanitizer = inject(DomSanitizer);
/**
* `FlowbiteThemeDirective` directive
*/
this.themeDirective = inject(FlowbiteThemeDirective);
//#region properties
/**
* Set the custom style for this dark-theme-toggle
*/
this.customStyle = model(inject(FLOWBITE_DARK_THEME_TOGGLE_CUSTOM_STYLE_DEFAULT_VALUE));
}
//#endregion
//#region BaseComponent implementation
fetchClass() {
return this.themeService.getClasses({
customStyle: this.customStyle(),
});
}
init() {
this.iconRegistry.addRawSvgIconInNamepsace('flowbite-angular', 'sun', this.domSanitizer.bypassSecurityTrustHtml(SUN_SVG_ICON));
this.iconRegistry.addRawSvgIconInNamepsace('flowbite-angular', 'moon', this.domSanitizer.bypassSecurityTrustHtml(MOON_SVG_ICON));
}
//#endregion
/**
* Toggle between dark and light mode
*/
onClick() {
this.themeDirective.toggleTheme();
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: DarkThemeToggleComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "19.0.4", type: DarkThemeToggleComponent, isStandalone: true, selector: "flowbite-dark-theme-toggle", inputs: { customStyle: { classPropertyName: "customStyle", publicName: "customStyle", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { customStyle: "customStyleChange" }, host: { listeners: { "click": "onClick()" } }, usesInheritance: true, ngImport: i0, template: `
<flowbite-icon
svgIcon="flowbite-angular:moon"
class="h-5 w-5 block dark:hidden" />
<flowbite-icon
svgIcon="flowbite-angular:sun"
class="h-5 w-5 hidden dark:block" />
`, isInline: true, dependencies: [{ kind: "component", type: IconComponent, selector: "flowbite-icon", inputs: ["svgIcon"], outputs: ["svgIconChange"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.4", ngImport: i0, type: DarkThemeToggleComponent, decorators: [{
type: Component,
args: [{
standalone: true,
imports: [IconComponent],
selector: 'flowbite-dark-theme-toggle',
template: `
<flowbite-icon
svgIcon="flowbite-angular:moon"
class="h-5 w-5 block dark:hidden" />
<flowbite-icon
svgIcon="flowbite-angular:sun"
class="h-5 w-5 hidden dark:block" />
`,
host: {
'(click)': 'onClick()',
},
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
}]
}] });
/**
* Default theme for `DarkThemeToggleComponent`
*/
const darkThemeToggleTheme = createTheme({
root: {
base: 'cursor-pointer rounded-lg p-2.5 text-sm text-gray-500 hover:bg-gray-100 focus:outline-none focus:ring-4 focus:ring-gray-200 dark:text-gray-400 dark:hover:bg-gray-700 dark:focus:ring-gray-700',
},
});
/**
* Generated bundle index. Do not edit.
*/
export { DarkThemeToggleComponent, DarkThemeToggleThemeService, FLOWBITE_DARK_THEME_TOGGLE_CUSTOM_STYLE_DEFAULT_VALUE, FLOWBITE_DARK_THEME_TOGGLE_THEME_TOKEN, darkThemeToggleDefaultValueProvider, darkThemeToggleTheme };
//# sourceMappingURL=flowbite-angular-dark-theme-toggle.mjs.map