Added jsdocs and proptypes

This commit is contained in:
Daniel Cojocea
2024-07-11 20:30:11 -04:00
parent 8bd8c292b8
commit 91abe374f6
2 changed files with 31 additions and 0 deletions

View File

@@ -24,6 +24,9 @@ const icons = {
* @param {'info' | 'error' | 'warning'} props.variant - The type of alert.
* @param {string} [props.title] - The title of the alert.
* @param {string} [props.body] - The body text of the alert.
* @param {boolean} [props.isToast] - Indicates if the alert is used as a toast notification.
* @param {boolean} [props.hasIcon] - Whether to display an icon in the alert.
* @param {function} props.onClick - Toast dismiss function.
* @returns {JSX.Element}
*/
@@ -105,6 +108,16 @@ Alert.propTypes = {
variant: PropTypes.oneOf(["info", "error", "warning"]).isRequired,
title: PropTypes.string,
body: PropTypes.string,
isToast: PropTypes.bool,
hasIcon: PropTypes.bool,
onClick: function (props, propName, componentName) {
if (props.isToast && !props[propName]) {
return new Error(
`Prop '${propName}' is required when 'isToast' is true in '${componentName}'.`
);
}
return null;
},
};
export default Alert;

View File

@@ -1,6 +1,16 @@
import PropTypes from "prop-types";
import { toast } from "react-toastify";
import Alert from "../Components/Alert";
/**
* @param {object} props
* @param {'info' | 'error' | 'warning'} - The variant of the alert (e.g., "info", "error").
* @param {string} props.title - The title of the alert.
* @param {string} props.body - The body/content of the alert.
* @param {boolean} props.hasIcon - Whether the alert should include an icon.
* @param {object} [props.config] - Additional configuration props for the toast.
*/
export const createToast = ({ variant, title, body, hasIcon, config = {} }) => {
const toastConfig = {
position: "bottom-right",
@@ -24,3 +34,11 @@ export const createToast = ({ variant, title, body, hasIcon, config = {} }) => {
toastConfig
);
};
createToast.propTypes = {
variant: PropTypes.oneOf(["info", "error", "warning"]).isRequired,
title: PropTypes.string,
body: PropTypes.string,
hasIcon: PropTypes.bool,
config: PropTypes.object,
};