Skip to content

Commit cb7c2f6

Browse files
authored
Merge branch 'master' into fix/popup-close-button
2 parents c77625e + 9605428 commit cb7c2f6

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

src/components/dropdown/dropdown.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class DropDown extends React.Component<DropDownProps, DropDownState> {
2626
private el: HTMLDivElement;
2727
private content: HTMLDivElement;
2828
private subscriptions: Subscription[];
29+
private isFirstOpen = true;
2930

3031
constructor(props: DropDownProps) {
3132
super(props);
@@ -109,6 +110,38 @@ export class DropDown extends React.Component<DropDownProps, DropDownState> {
109110
return newState;
110111
}
111112

113+
public componentDidUpdate(_prevProps: DropDownProps, prevState: DropDownState) {
114+
// When menu changes from closed to open state
115+
if (!prevState.opened && this.state.opened) {
116+
// Mark as first open
117+
this.isFirstOpen = true;
118+
// Use setTimeout to ensure content has been rendered
119+
setTimeout(() => {
120+
if (this.state.opened && this.content && this.el) {
121+
const newState = this.refreshState();
122+
// Only update state if calculated position differs from current position
123+
if (newState.left !== this.state.left || newState.top !== this.state.top) {
124+
this.setState(newState);
125+
}
126+
this.isFirstOpen = false;
127+
}
128+
}, 0);
129+
}
130+
131+
// If content changes and it's not the first open, recalculate position
132+
if (this.state.opened && !this.isFirstOpen && this.content && this.el) {
133+
// Use setTimeout to ensure calculation happens after DOM updates
134+
setTimeout(() => {
135+
if (this.state.opened) {
136+
const newState = this.refreshState();
137+
if (newState.left !== this.state.left || newState.top !== this.state.top) {
138+
this.setState(newState);
139+
}
140+
}
141+
}, 0);
142+
}
143+
}
144+
112145
private open() {
113146
if (!this.content || !this.el) {
114147
return;

src/components/popup/popup-manager.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import { BehaviorSubject } from 'rxjs';
55
import { PopupProps } from './popup';
66

77
export interface PopupApi {
8-
confirm(title: string, message: string | React.ComponentType): Promise<boolean>;
8+
confirm(
9+
title: string,
10+
message: string | React.ComponentType,
11+
customIcon?: {name: string, color: string},
12+
titleColor?: string,
13+
): Promise<boolean>;
914
prompt(
1015
title: string,
1116
form: (formApi: FormApi) => RenderReturn, settings?: {
@@ -25,7 +30,12 @@ export class PopupManager implements PopupApi {
2530
return this.popupPropsSubject.asObservable();
2631
}
2732

28-
public confirm(title: string, message: string | React.ComponentType): Promise<boolean> {
33+
public confirm(
34+
title: string,
35+
message: string | React.ComponentType,
36+
customIcon?: {name: string, color: string},
37+
titleColor?: string,
38+
): Promise<boolean> {
2939
const content = typeof message === 'string' && (() => (<p>{message}</p>)) || message as React.ComponentType;
3040

3141
return new Promise((resolve) => {
@@ -36,15 +46,17 @@ export class PopupManager implements PopupApi {
3646

3747
this.popupPropsSubject.next({
3848
title: (
39-
<span>{title} <i className='argo-icon-close' onClick={() => closeAndResolve(false)}/></span>
49+
<span style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}><div>{title}</div> <i className='argo-icon-close' onClick={() => closeAndResolve(false)}/></span>
4050
),
4151
content,
4252
footer: (
43-
<div>
53+
<div style={{ display: 'flex', gap: '8px' }}>
4454
<button qe-id='argo-popup-ok-button' className='argo-button argo-button--base' onClick={() => closeAndResolve(true)}>OK</button>
4555
<button qe-id='argo-popup-cancel-button' className='argo-button argo-button--base-o' onClick={() => closeAndResolve(false)}>Cancel</button>
4656
</div>
4757
),
58+
titleColor: titleColor ? titleColor : 'normal',
59+
icon: customIcon ? { name: customIcon?.name, color: customIcon?.color} : undefined,
4860
});
4961
});
5062
}
@@ -79,7 +91,7 @@ export class PopupManager implements PopupApi {
7991
this.popupPropsSubject.next({
8092
children: undefined,
8193
title: (
82-
<span>{title} <i className='argo-icon-close' onClick={() => closeAndResolve(null)}/></span>
94+
<span style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', width: '100%' }}><div>{title}</div> <i className='argo-icon-close' onClick={() => closeAndResolve(null)}/></span>
8395
),
8496
titleColor: titleColor ? titleColor : 'normal',
8597
icon: customIcon ? { name: customIcon?.name, color: customIcon?.color} : undefined,
@@ -97,7 +109,7 @@ export class PopupManager implements PopupApi {
97109
</Form>
98110
),
99111
footer: (
100-
<div>
112+
<div style={{ display: 'flex', gap: '8px' }}>
101113
<button qe-id='prompt-popup-ok-button' className='argo-button argo-button--base' onClick={(e) => formApi.submitForm(e)}>OK</button>
102114
<button qe-id='prompt-popup-cancel-button' className='argo-button argo-button--base-o' onClick={() => closeAndResolve(null)}>Cancel</button>
103115
</div>

src/components/popup/popup.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ $popup-border-radius: 8px;
3434
&__header {
3535
line-height: 60px;
3636
padding-left: 30px;
37+
padding-right: 30px;
3738
height: 60px;
3839
border-top-right-radius: $popup-border-radius;
3940
border-top-left-radius: $popup-border-radius;

0 commit comments

Comments
 (0)