Skip to content

Commit 04f4d54

Browse files
committed
feat(accordion): provide injection token for default input value #80
1 parent 2d2039b commit 04f4d54

File tree

9 files changed

+131
-16
lines changed

9 files changed

+131
-16
lines changed

libs/flowbite-angular/accordion/accordion-content.component.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,23 @@ import {
1111
ChangeDetectionStrategy,
1212
Component,
1313
inject,
14+
InjectionToken,
15+
makeEnvironmentProviders,
1416
model,
1517
ViewEncapsulation,
1618
} from '@angular/core';
1719

20+
export const FLOWBITE_ACCORDION_CONTENT_CUSTOM_STYLE_DEFAULT_VALUE = new InjectionToken<
21+
DeepPartial<AccordionContentTheme>
22+
>('FLOWBITE_ACCORDION_CONTENT_CUSTOM_STYLE_DEFAULT_VALUE');
23+
24+
export const accordionContentDefaultValueProvider = makeEnvironmentProviders([
25+
{
26+
provide: FLOWBITE_ACCORDION_CONTENT_CUSTOM_STYLE_DEFAULT_VALUE,
27+
useValue: {},
28+
},
29+
]);
30+
1831
/**
1932
* @see https://flowbite.com/docs/components/accordion/
2033
*/
@@ -50,7 +63,7 @@ export class AccordionContentComponent extends BaseComponent<AccordionContentCla
5063
/**
5164
* Set the custom style for this accordion content
5265
*/
53-
public customStyle = model<DeepPartial<AccordionContentTheme>>({});
66+
public customStyle = model(inject(FLOWBITE_ACCORDION_CONTENT_CUSTOM_STYLE_DEFAULT_VALUE));
5467
//#endregion
5568

5669
//#region BaseComponent implementation

libs/flowbite-angular/accordion/accordion-panel.component.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,32 @@ import {
1414
Component,
1515
contentChild,
1616
inject,
17+
InjectionToken,
18+
makeEnvironmentProviders,
1719
model,
1820
untracked,
1921
ViewEncapsulation,
2022
} from '@angular/core';
2123

24+
export const FLOWBITE_ACCORDION_PANEL_IS_OPEN_DEFAULT_VALUE = new InjectionToken<boolean>(
25+
'FLOWBITE_ACCORDION_IS_OPEN_DEFAULT_VALUE'
26+
);
27+
28+
export const FLOWBITE_ACCORDION_PANEL_CUSTOM_STYLE_DEFAULT_VALUE = new InjectionToken<
29+
DeepPartial<AccordionPanelTheme>
30+
>('FLOWBITE_ACCORDION_PANEL_CUSTOM_STYLE_DEFAULT_VALUE');
31+
32+
export const accordionPanelDefaultValueProvider = makeEnvironmentProviders([
33+
{
34+
provide: FLOWBITE_ACCORDION_PANEL_IS_OPEN_DEFAULT_VALUE,
35+
useValue: false,
36+
},
37+
{
38+
provide: FLOWBITE_ACCORDION_PANEL_CUSTOM_STYLE_DEFAULT_VALUE,
39+
useValue: {},
40+
},
41+
]);
42+
2243
/**
2344
* @see https://flowbite.com/docs/components/accordion/
2445
*/
@@ -60,11 +81,11 @@ export class AccordionPanelComponent extends BaseComponent<AccordionPanelClass>
6081
*
6182
* @default false
6283
*/
63-
public isOpen = model<boolean>(false);
84+
public isOpen = model(inject(FLOWBITE_ACCORDION_PANEL_IS_OPEN_DEFAULT_VALUE));
6485
/**
6586
* Set the custom style for this accordion panel
6687
*/
67-
public customStyle = model<DeepPartial<AccordionPanelTheme>>({});
88+
public customStyle = model(inject(FLOWBITE_ACCORDION_PANEL_CUSTOM_STYLE_DEFAULT_VALUE));
6889
//#endregion
6990

7091
//#region BaseComponent implementation

libs/flowbite-angular/accordion/accordion-title.component.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,24 @@ import {
1414
ChangeDetectionStrategy,
1515
Component,
1616
inject,
17+
InjectionToken,
18+
makeEnvironmentProviders,
1719
model,
1820
ViewEncapsulation,
1921
} from '@angular/core';
2022
import { DomSanitizer } from '@angular/platform-browser';
2123

24+
export const FLOWBITE_ACCORDION_TITLE_CUSTOM_STYLE_DEFAULT_VALUE = new InjectionToken<
25+
DeepPartial<AccordionTitleTheme>
26+
>('FLOWBITE_ACCORDION_TITLE_CUSTOM_STYLE_DEFAULT_VALUE');
27+
28+
export const accordionTitleDefaultValueProvider = makeEnvironmentProviders([
29+
{
30+
provide: FLOWBITE_ACCORDION_TITLE_CUSTOM_STYLE_DEFAULT_VALUE,
31+
useValue: {},
32+
},
33+
]);
34+
2235
/**
2336
* @see https://flowbite.com/docs/components/accordion/
2437
*/
@@ -69,7 +82,7 @@ export class AccordionTitleComponent extends BaseComponent<AccordionTitleClass>
6982
/**
7083
* Set the custom style for this accordion title
7184
*/
72-
public customStyle = model<DeepPartial<AccordionTitleTheme>>({});
85+
public customStyle = model(inject(FLOWBITE_ACCORDION_TITLE_CUSTOM_STYLE_DEFAULT_VALUE));
7386
//#endregion
7487

7588
//#region BaseComponent implementation

libs/flowbite-angular/accordion/accordion.component.ts

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,47 @@ import {
1111
Component,
1212
contentChildren,
1313
inject,
14+
InjectionToken,
15+
makeEnvironmentProviders,
1416
model,
1517
ViewEncapsulation,
1618
} from '@angular/core';
1719

20+
export const FLOWBITE_ACCORDION_IS_ALWAYS_OPEN_DEFAULT_VALUE = new InjectionToken<boolean>(
21+
'FLOWBITE_ACCORDION_IS_ALWAYS_OPEN'
22+
);
23+
24+
export const FLOWBITE_ACCORDION_COLOR_DEFAULT_VALUE = new InjectionToken<keyof AccordionColors>(
25+
'FLOWBITE_ACCORDION_COLOR_DEFAULT_VALUE'
26+
);
27+
28+
export const FLOWBITE_ACCORDION_IS_FLUSH_DEFAULT_VALUE = new InjectionToken<boolean>(
29+
'FLOWBITE_ACCORDION_IS_FLUSH_DEFAULT_VALUE'
30+
);
31+
32+
export const FLOWBITE_ACCORDION_CUSTOM_STYLE_DEFAULT_VALUE = new InjectionToken<
33+
DeepPartial<AccordionTheme>
34+
>('FLOWBITEèACCORDION_CUSTOM_STYLE_DEFAULT_VALUE');
35+
36+
export const accordionDefaultValueProvider = makeEnvironmentProviders([
37+
{
38+
provide: FLOWBITE_ACCORDION_IS_ALWAYS_OPEN_DEFAULT_VALUE,
39+
useValue: false,
40+
},
41+
{
42+
provide: FLOWBITE_ACCORDION_COLOR_DEFAULT_VALUE,
43+
useValue: 'primary',
44+
},
45+
{
46+
provide: FLOWBITE_ACCORDION_IS_FLUSH_DEFAULT_VALUE,
47+
useValue: false,
48+
},
49+
{
50+
provide: FLOWBITE_ACCORDION_CUSTOM_STYLE_DEFAULT_VALUE,
51+
useValue: {},
52+
},
53+
]);
54+
1855
/**
1956
* @see https://flowbite.com/docs/components/accordion/
2057
*/
@@ -42,23 +79,25 @@ export class AccordionComponent extends BaseComponent<AccordionClass> {
4279
*
4380
* @default false
4481
*/
45-
public isAlwaysOpen = model<boolean>(false);
82+
public isAlwaysOpen = model(inject(FLOWBITE_ACCORDION_IS_ALWAYS_OPEN_DEFAULT_VALUE));
4683
/**
4784
* Set the accordion color and every child default color
4885
*
4986
* @default primary
5087
*/
51-
public color = model<keyof AccordionColors>('primary');
88+
public color = model(inject(FLOWBITE_ACCORDION_COLOR_DEFAULT_VALUE));
5289
/**
5390
* Set the accordion as flush or not
5491
*
5592
* @default false
5693
*/
57-
public isFlush = model<boolean>(false);
94+
public isFlush = model(inject(FLOWBITE_ACCORDION_IS_FLUSH_DEFAULT_VALUE));
5895
/**
5996
* Set the custom style for this accordion
6097
*/
61-
public customStyle = model<DeepPartial<AccordionTheme>>({});
98+
public customStyle = model<DeepPartial<AccordionTheme>>(
99+
inject(FLOWBITE_ACCORDION_CUSTOM_STYLE_DEFAULT_VALUE)
100+
);
62101
//#endregion
63102

64103
//#region BaseComponent implementation

libs/flowbite-angular/accordion/index.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
export { AccordionComponent } from './accordion.component';
1+
export {
2+
AccordionComponent,
3+
FLOWBITE_ACCORDION_IS_ALWAYS_OPEN_DEFAULT_VALUE,
4+
FLOWBITE_ACCORDION_COLOR_DEFAULT_VALUE,
5+
FLOWBITE_ACCORDION_CUSTOM_STYLE_DEFAULT_VALUE,
6+
FLOWBITE_ACCORDION_IS_FLUSH_DEFAULT_VALUE,
7+
accordionDefaultValueProvider,
8+
} from './accordion.component';
29
export type {
310
AccordionProperties,
411
AccordionClass,
@@ -8,7 +15,11 @@ export type {
815
export { accordionTheme } from './accordion.theme';
916
export { AccordionThemeService, FLOWBITE_ACCORDION_THEME_TOKEN } from './accordion.theme.service';
1017

11-
export { AccordionContentComponent } from './accordion-content.component';
18+
export {
19+
AccordionContentComponent,
20+
FLOWBITE_ACCORDION_CONTENT_CUSTOM_STYLE_DEFAULT_VALUE,
21+
accordionContentDefaultValueProvider,
22+
} from './accordion-content.component';
1223
export type {
1324
AccordionContentProperties,
1425
AccordionContentClass,
@@ -20,7 +31,12 @@ export {
2031
FLOWBITE_ACCORDION_CONTENT_THEME_TOKEN,
2132
} from './accordion-content.theme.service';
2233

23-
export { AccordionPanelComponent } from './accordion-panel.component';
34+
export {
35+
AccordionPanelComponent,
36+
FLOWBITE_ACCORDION_PANEL_CUSTOM_STYLE_DEFAULT_VALUE,
37+
FLOWBITE_ACCORDION_PANEL_IS_OPEN_DEFAULT_VALUE,
38+
accordionPanelDefaultValueProvider,
39+
} from './accordion-panel.component';
2440
export type {
2541
AccordionPanelProperties,
2642
AccordionPanelClass,
@@ -32,7 +48,11 @@ export {
3248
FLOWBITE_ACCORDION_PANEL_THEME_TOKEN,
3349
} from './accordion-panel.theme.service';
3450

35-
export { AccordionTitleComponent } from './accordion-title.component';
51+
export {
52+
AccordionTitleComponent,
53+
FLOWBITE_ACCORDION_TITLE_CUSTOM_STYLE_DEFAULT_VALUE,
54+
accordionTitleDefaultValueProvider,
55+
} from './accordion-title.component';
3656
export type {
3757
AccordionTitleProperties,
3858
AccordionTitleTheme,

libs/flowbite-angular/core/flowbite.theme.init.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import {
2+
accordionContentDefaultValueProvider,
23
accordionContentTheme,
34
AccordionContentThemeService,
5+
accordionDefaultValueProvider,
6+
accordionPanelDefaultValueProvider,
47
accordionPanelTheme,
58
AccordionPanelThemeService,
69
accordionTheme,
710
AccordionThemeService,
11+
accordionTitleDefaultValueProvider,
812
accordionTitleTheme,
913
AccordionTitleThemeService,
1014
FLOWBITE_ACCORDION_CONTENT_THEME_TOKEN,
@@ -381,5 +385,12 @@ export function initFlowbite(): EnvironmentProviders {
381385
},
382386
]);
383387

384-
return makeEnvironmentProviders([serviceProviders, themeProviders]);
388+
const defaultValueProvider = makeEnvironmentProviders([
389+
accordionDefaultValueProvider,
390+
accordionPanelDefaultValueProvider,
391+
accordionTitleDefaultValueProvider,
392+
accordionContentDefaultValueProvider,
393+
]);
394+
395+
return makeEnvironmentProviders([serviceProviders, themeProviders, defaultValueProvider]);
385396
}

libs/flowbite-angular/modal/modal.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ export class ModalComponent extends BaseComponent<ModalClass> implements OnDestr
182182
}
183183

184184
onKeydownHandler(event: KeyboardEvent) {
185-
console.log('hello');
186185
if (event.key === 'Escape') {
187186
this.close();
188187
}

libs/flowbite-angular/project.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
"main",
4444
"next",
4545
"next-major",
46-
"+([0-9])?(.{+([0-9]),x}).x",
4746
{
4847
"name": "beta",
4948
"prerelease": true

libs/flowbite-angular/sidebar/sidebar-toggle.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class SidebarToggleComponent extends BaseComponent<SidebarToggleClass> im
5454
*
5555
* @default The injected `SidebarComponent`
5656
*/
57-
public readonly sidebarComponent = model<SidebarComponent>(inject(SidebarComponent));
57+
public readonly sidebarComponent = model(inject(SidebarComponent));
5858

5959
//#region properties
6060
/**

0 commit comments

Comments
 (0)