Skip to content

Commit 23306f4

Browse files
committed
feat: enhance useController in AlertContainer to support customizable confirm dialog properties from config
1 parent 83a4402 commit 23306f4

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/containers/AlertContainer/controller.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,11 @@ export const useController = ({ animationDuration, config }: Props) => {
138138

139139
const confirm = useCallback(
140140
(alert?: ConfirmProps) => {
141-
const title = alert?.title || 'Are you sure?';
141+
const { confirm: confirmConfig } = config || {};
142142

143-
const passedButtons = alert?.buttons;
143+
const title = alert?.title || confirmConfig?.title || 'Are you sure?';
144+
145+
const passedButtons = alert?.buttons || confirmConfig?.buttons;
144146

145147
let buttons: Required<AlertProps<boolean>>['buttons'] = [
146148
{
@@ -172,14 +174,17 @@ export const useController = ({ animationDuration, config }: Props) => {
172174
}
173175

174176
return show({
177+
icon: confirmConfig?.icon,
178+
iconColor: confirmConfig?.iconColor,
179+
iconSize: confirmConfig?.iconSize,
175180
...alert,
176181
buttons,
177182
buttonsDirection: 'row',
178183
title,
179184
});
180185
},
181186

182-
[show]
187+
[show, config]
183188
);
184189

185190
const showError = useCallback(
@@ -200,6 +205,7 @@ export const useController = ({ animationDuration, config }: Props) => {
200205
const success = useCallback(
201206
(alert?: AlertProps) => {
202207
const { success: successConfig } = config || {};
208+
203209
show({
204210
icon: successConfig?.icon ?? SuccessIcon,
205211
iconColor: successConfig?.iconColor ?? 'green',

src/containers/AlertContainer/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,9 @@ export type AlertConfig = {
3535
error?: Partial<
3636
Pick<AlertProps, 'icon' | 'iconColor' | 'iconSize' | 'title'>
3737
>;
38+
confirm?: Partial<
39+
Pick<AlertProps, 'icon' | 'iconColor' | 'iconSize' | 'title'>
40+
> & {
41+
buttons?: string[];
42+
};
3843
};

0 commit comments

Comments
 (0)