Skip to content

Commit

Permalink
fix: drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
igauch committed Dec 19, 2023
1 parent e3fa1cd commit 9dd6abe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-dots-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@alauda/ui': patch
---

- fix: no default config for using component mode
37 changes: 25 additions & 12 deletions src/drawer/drawer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ import { DrawerRef } from './drawer-ref';
import { DrawerOptions, DrawerSize } from './types';

const DRAWER_OVERLAY_CLASS = 'aui-drawer-overlay';
const DEFAULT_OPTIONS: DrawerOptions = {
size: DrawerSize.Medium,
offsetY: '0',
showClose: true,
hideOnClickOutside: false,
divider: true,
disposeWhenHide: true,
};

@Injectable()
export class DrawerService<
Expand All @@ -31,6 +23,15 @@ export class DrawerService<
DrawerInternalComponent<T, C>
>;

private readonly DEFAULT_OPTIONS: DrawerOptions<T, C> = {
size: DrawerSize.Medium,
offsetY: '0',
showClose: true,
hideOnClickOutside: false,
divider: true,
disposeWhenHide: true,
};

constructor(private readonly overlay: Overlay) {}

open(options: DrawerOptions<T, C>) {
Expand All @@ -46,10 +47,7 @@ export class DrawerService<
}

updateOptions(options: DrawerOptions<T, C>): void {
this.options = {
...(DEFAULT_OPTIONS as DrawerOptions<T, C>),
...options,
};
this.options = merge<DrawerOptions<T, C>>(this.DEFAULT_OPTIONS, options);
}

private createOverlay() {
Expand Down Expand Up @@ -135,3 +133,18 @@ export class DrawerService<
this.dispose();
}
}

function merge<T extends object>(target: T, source: T) {
return Object.keys(source).reduce(
(acc, _key) => {
const key = _key as keyof T;
if (source[key] !== undefined) {
acc[key] = source[key];
}
return acc;
},
{
...target,
},
);
}

0 comments on commit 9dd6abe

Please sign in to comment.