Skip to content

Commit 7706288

Browse files
committed
feat: update processAlertProps to accept config for default button customization in AlertContainer
1 parent 23306f4 commit 7706288

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/containers/AlertContainer/controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const useController = ({ animationDuration, config }: Props) => {
4141
return;
4242
}
4343

44-
alert = processAlertProps(alert);
44+
alert = processAlertProps(alert, config);
4545

4646
if (isShownRef.current) {
4747
queue.current.push({ ...alert, resolve, config });

src/containers/AlertContainer/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,8 @@ export type AlertConfig = {
4040
> & {
4141
buttons?: string[];
4242
};
43+
defaultButton?: {
44+
text: string;
45+
testID?: string;
46+
};
4347
};

src/containers/AlertContainer/utils.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import type { Props as AlertProps } from '../../components/Alert/types';
2+
import type { AlertConfig } from './types';
23

3-
export const processAlertProps = (props: AlertProps) => {
4+
export const processAlertProps = (props: AlertProps, config?: AlertConfig) => {
45
const result = { ...props };
56

67
const shouldAppendOkButton = !result.buttons || !result.buttons?.length;
78

89
if (shouldAppendOkButton) {
9-
result.buttons = [
10-
{
11-
text: 'OK',
12-
testID: 'Alert.button.ok',
13-
},
14-
];
10+
result.buttons = config?.defaultButton
11+
? [config.defaultButton]
12+
: [
13+
{
14+
text: 'OK',
15+
testID: 'Alert.button.ok',
16+
},
17+
];
1518
}
1619

1720
return result;

0 commit comments

Comments
 (0)