Skip to content

Commit

Permalink
fix: add global configuartion mutation capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
Bagusajieiswara committed Dec 17, 2024
1 parent 0a32357 commit 79210b1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/primitives/accordion/src/configs/accordion-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export interface NgxPrimerAccordionConfig {
theme: {
builtIn: boolean;
};
// Overloaded method signatures
updateConfig(callbackFn: (config: NgxPrimerAccordionConfig) => Partial<NgxPrimerAccordionConfig>): void;
updateConfig(newConfig: Partial<NgxPrimerAccordionConfig>): void;
resetConfig(target: NgxPrimerAccordionConfig): void
}
export const defaultAccordionConfig: () => NgxPrimerAccordionConfig = () => ({
type: 'Multiple',
Expand All @@ -27,6 +31,17 @@ export const defaultAccordionConfig: () => NgxPrimerAccordionConfig = () => ({
theme: {
builtIn: true,
},
updateConfig(callbackFn: Partial<NgxPrimerAccordionConfig> | ((config: NgxPrimerAccordionConfig) => Partial<NgxPrimerAccordionConfig>)): void {
if (typeof callbackFn === 'function') {
const updatedConfig = callbackFn(this);
Object.assign(this, {...updatedConfig});
} else {
Object.assign(this, {...callbackFn});
}
},
resetConfig(target: NgxPrimerAccordionConfig): void {
Object.assign(target, defaultAccordionConfig());
}
});
export function provideAccordionConfig(
config: Partial<NgxPrimerAccordionConfig>
Expand Down

0 comments on commit 79210b1

Please sign in to comment.