Skip to content

Commit 9dd6abe

Browse files
committed
fix: drawer
1 parent e3fa1cd commit 9dd6abe

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

.changeset/stale-dots-speak.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@alauda/ui': patch
3+
---
4+
5+
- fix: no default config for using component mode

src/drawer/drawer.service.ts

+25-12
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ import { DrawerRef } from './drawer-ref';
88
import { DrawerOptions, DrawerSize } from './types';
99

1010
const DRAWER_OVERLAY_CLASS = 'aui-drawer-overlay';
11-
const DEFAULT_OPTIONS: DrawerOptions = {
12-
size: DrawerSize.Medium,
13-
offsetY: '0',
14-
showClose: true,
15-
hideOnClickOutside: false,
16-
divider: true,
17-
disposeWhenHide: true,
18-
};
1911

2012
@Injectable()
2113
export class DrawerService<
@@ -31,6 +23,15 @@ export class DrawerService<
3123
DrawerInternalComponent<T, C>
3224
>;
3325

26+
private readonly DEFAULT_OPTIONS: DrawerOptions<T, C> = {
27+
size: DrawerSize.Medium,
28+
offsetY: '0',
29+
showClose: true,
30+
hideOnClickOutside: false,
31+
divider: true,
32+
disposeWhenHide: true,
33+
};
34+
3435
constructor(private readonly overlay: Overlay) {}
3536

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

4849
updateOptions(options: DrawerOptions<T, C>): void {
49-
this.options = {
50-
...(DEFAULT_OPTIONS as DrawerOptions<T, C>),
51-
...options,
52-
};
50+
this.options = merge<DrawerOptions<T, C>>(this.DEFAULT_OPTIONS, options);
5351
}
5452

5553
private createOverlay() {
@@ -135,3 +133,18 @@ export class DrawerService<
135133
this.dispose();
136134
}
137135
}
136+
137+
function merge<T extends object>(target: T, source: T) {
138+
return Object.keys(source).reduce(
139+
(acc, _key) => {
140+
const key = _key as keyof T;
141+
if (source[key] !== undefined) {
142+
acc[key] = source[key];
143+
}
144+
return acc;
145+
},
146+
{
147+
...target,
148+
},
149+
);
150+
}

0 commit comments

Comments
 (0)