go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/analysis/frontend/ui/src/components/confirm_dialog/confirm_dialog.tsx (about) 1 // Copyright 2022 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 import Button from '@mui/material/Button'; 16 import Dialog from '@mui/material/Dialog'; 17 import DialogActions from '@mui/material/DialogActions'; 18 import DialogContent from '@mui/material/DialogContent'; 19 import DialogTitle from '@mui/material/DialogTitle'; 20 import Typography from '@mui/material/Typography'; 21 22 type HandleFunction = () => void; 23 24 interface Props { 25 message?: string; 26 open: boolean; 27 onConfirm: HandleFunction; 28 onCancel: HandleFunction; 29 } 30 31 const ConfirmDialog = ({ 32 message = '', 33 open, 34 onConfirm, 35 onCancel, 36 }: Props) => { 37 return ( 38 <Dialog open={open} maxWidth="xs" fullWidth> 39 <DialogTitle>Are you sure?</DialogTitle> 40 {message && ( 41 <DialogContent> 42 <Typography>{message}</Typography> 43 </DialogContent> 44 ) 45 } 46 <DialogActions> 47 <Button variant="outlined" onClick={onCancel} data-testid="confirm-dialog-cancel">Cancel</Button> 48 <Button variant="contained" onClick={onConfirm} data-testid="confirm-dialog-confirm">Confirm</Button> 49 </DialogActions> 50 </Dialog> 51 ); 52 }; 53 54 export default ConfirmDialog;