Skip to content

Commit

Permalink
fix: sweet alert darkmode
Browse files Browse the repository at this point in the history
  • Loading branch information
iamtrazy committed Dec 1, 2024
1 parent 5216573 commit 99fffa5
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 29 deletions.
29 changes: 29 additions & 0 deletions src/components/UI/SwalConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

import Swal from 'sweetalert2/dist/sweetalert2.js';

// Default dark theme configuration
export const defaultSwalConfig = {
customClass: {
popup: 'swal2-popup swal2-dark',
confirmButton: 'swal2-confirm',
cancelButton: 'swal2-cancel',
htmlContainer: 'swal2-dark',
title: 'swal2-dark'
},
background: '#1a1a1a',
color: '#ffffff'
};

// Light theme configuration for optional use
export const lightSwalConfig = {
customClass: {
popup: 'swal2-popup swal2-light',
confirmButton: 'swal2-confirm',
cancelButton: 'swal2-cancel'
},
background: '#ffffff',
color: '#000000'
};

// Initialize Swal with default dark theme
Swal.mixin(defaultSwalConfig);
46 changes: 22 additions & 24 deletions src/components/UI/SwalConfirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,26 @@ import Swal from 'sweetalert2/dist/sweetalert2.js';
import withReactContent from 'sweetalert2-react-content';

export const swalConfirm = () => {
const commonConfig = {
showCancelButton: true,
};

const showSwal = (onConfirm: () => void) => {
withReactContent(Swal)
.fire({
title: 'Do you want to delete the item?',
showCancelButton: true,
confirmButtonText: 'Delete',
denyButtonText: 'Cancel',
customClass: {
popup: 'swal2-popup',
confirmButton: 'swal2-confirm',
},
...commonConfig,
})
.then((result: any) => {
if (result.isConfirmed) {
onConfirm();
Swal.fire('Deleted!', '', 'success');
} else if (result.isDenied) {
Swal.fire('Changes are not saved', '', 'info');
Swal.fire({
title: 'Deleted!',
icon: 'success',
...commonConfig,
});
}
});
};
Expand All @@ -30,20 +32,18 @@ export const swalConfirm = () => {
withReactContent(Swal)
.fire({
title: 'Do you want to approve this item?',
showCancelButton: true,
confirmButtonText: 'Approve',
denyButtonText: 'Cancel',
customClass: {
popup: 'swal2-popup',
confirmButton: 'swal2-confirm',
},
...commonConfig,
})
.then((result: any) => {
if (result.isConfirmed) {
onConfirm();
Swal.fire('Approved!', '', 'success');
} else if (result.isDenied) {
Swal.fire('Changes are not saved', '', 'info');
Swal.fire({
title: 'Approved!',
icon: 'success',
...commonConfig,
});
}
});
};
Expand All @@ -52,20 +52,18 @@ export const swalConfirm = () => {
withReactContent(Swal)
.fire({
title: 'Do you want to reject this item?',
showCancelButton: true,
confirmButtonText: 'Reject',
denyButtonText: 'Cancel',
customClass: {
popup: 'swal2-popup',
confirmButton: 'swal2-confirm',
},
...commonConfig,
})
.then((result: any) => {
if (result.isConfirmed) {
onConfirm();
Swal.fire('Rejected!', '', 'success');
} else if (result.isDenied) {
Swal.fire('Changes are not saved', '', 'info');
Swal.fire({
title: 'Rejected!',
icon: 'success',
...commonConfig,
});
}
});
};
Expand Down
4 changes: 0 additions & 4 deletions src/components/UI/SwalSuccess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ export const swalSuccess = ({ message }: SwalSuccessProps) => {
title: message,
icon: 'success',
confirmButtonText: 'OK',
customClass: {
popup: 'swal2-popup',
confirmButton: 'swal2-confirm',
},
});
};

Expand Down
21 changes: 20 additions & 1 deletion src/components/UI/swal.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
.swal2-popup {
background: #1a1a1a !important;
color: #ffffff !important;
box-shadow: 0 0 3px white !important;
border: 1px solid #2d2d2d;
}

.swal2-confirm {
background-color: red !important;
background-color: #28a745 !important;
border-color: red !important;
}

.swal2-dark {
color: #ffffff !important;
}

.swal2-popup.swal2-light {
background: #ffffff !important;
color: #000000 !important;
border: 1px solid #ddd;
}

.swal2-cancel {
background-color: #dc3545 !important;
color: #ffffff !important;
}

0 comments on commit 99fffa5

Please sign in to comment.