Skip to content

Commit

Permalink
code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
anistouri committed Nov 9, 2023
1 parent b3e0902 commit bf28e5a
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/components/react-hook-form/utils/cancel-button.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
import React from 'react';
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import React, { useMemo } from 'react';
import { Button } from '@mui/material';
import { FormattedMessage } from 'react-intl';
import PropTypes from 'prop-types';

const CancelButton = ({
onClick,
variant,
disabled,
withCustomColor = true,
}) => {
const CancelButton = ({ withCustomColor = true, ...buttonProps }) => {
const colorKey = useMemo(() => {
if (withCustomColor) {
return 'customButton';
} else {
return buttonProps?.color ?? 'primary';
}
}, [withCustomColor, buttonProps?.color]);
return (
<Button
onClick={onClick}
variant={variant}
disabled={disabled}
color={withCustomColor ? 'customButton' : 'primary'}
>
<Button {...buttonProps} color={colorKey}>
<FormattedMessage id="cancel" />
</Button>
);
};

CancelButton.propTypes = {
onClick: PropTypes.func.isRequired,
variant: PropTypes.string,
disabled: PropTypes.bool,
withCustomColor: PropTypes.bool,
buttonProps: PropTypes.object,
};

export default CancelButton;

0 comments on commit bf28e5a

Please sign in to comment.