From 954d11b7c45ecfd1b0e640962fd04534302dbabb Mon Sep 17 00:00:00 2001 From: Daniel C <122758391+danielcj2@users.noreply.github.com> Date: Sat, 27 Jul 2024 14:32:54 -0400 Subject: [PATCH] Checkbox component (#469) * Implemented checkbox component * Added jsdocs and proptypes --- .../src/Components/Inputs/Checkbox/index.css | 15 ++++ .../src/Components/Inputs/Checkbox/index.jsx | 84 +++++++++++++++++++ Client/src/assets/icons/checkbox-filled.svg | 4 + Client/src/assets/icons/checkbox-outline.svg | 3 + 4 files changed, 106 insertions(+) create mode 100644 Client/src/Components/Inputs/Checkbox/index.css create mode 100644 Client/src/Components/Inputs/Checkbox/index.jsx create mode 100644 Client/src/assets/icons/checkbox-filled.svg create mode 100644 Client/src/assets/icons/checkbox-outline.svg diff --git a/Client/src/Components/Inputs/Checkbox/index.css b/Client/src/Components/Inputs/Checkbox/index.css new file mode 100644 index 000000000..320c75f34 --- /dev/null +++ b/Client/src/Components/Inputs/Checkbox/index.css @@ -0,0 +1,15 @@ +.checkbox-wrapper { + border-radius: var(--env-var-radius-1); +} +.checkbox-wrapper:not(:has(.Mui-disabled)):hover { + background-color: var(--env-var-color-15); +} +.checkbox-wrapper span.MuiTypography-root { + font-size: var(--env-var-font-size-medium); + color: var(--env-var-color-2); + line-height: 1; +} +.checkbox-wrapper .MuiButtonBase-root { + margin-right: var(--env-var-spacing-1); + padding: 0; +} diff --git a/Client/src/Components/Inputs/Checkbox/index.jsx b/Client/src/Components/Inputs/Checkbox/index.jsx new file mode 100644 index 000000000..e454bbc6e --- /dev/null +++ b/Client/src/Components/Inputs/Checkbox/index.jsx @@ -0,0 +1,84 @@ +import PropTypes from "prop-types"; +import { FormControlLabel, Checkbox as MuiCheckbox } from "@mui/material"; +import CheckboxOutline from "../../../assets/icons/checkbox-outline.svg?react"; +import CheckboxFilled from "../../../assets/icons/checkbox-filled.svg?react"; + +import "./index.css"; + +/** + * @param {Object} props + * @param {string} props.id - The id attribute for the checkbox input. + * @param {string} props.label - The label to display next to the checkbox. + * @param {('small' | 'medium' | 'large')} - The size of the checkbox. + * @param {boolean} props.isChecked - Whether the checkbox is checked or not. + * @param {string} [props.value] - The value of the checkbox input. + * @param {function} [props.onChange] - The function to call when the checkbox value changes. + * @param {boolean} [props.isDisabled] - Whether the checkbox is disabled or not. + * + * @returns {JSX.Element} + * + * @example + * + */ + +const Checkbox = ({ + id, + label, + size = "medium", + isChecked, + value, + onChange, + isDisabled, +}) => { + const sizes = { small: "14px", medium: "16px", large: "18px" }; + + return ( + } + checkedIcon={} + inputProps={{ + "aria-label": "controlled checkbox", + id: id, + }} + sx={{ + "&:hover": { backgroundColor: "transparent" }, + "& svg": { width: sizes[size], height: sizes[size] }, + }} + /> + } + label={label} + disabled={isDisabled} + sx={{ + p: "5px", + m: "-5px", + "& .MuiButtonBase-root": { + width: "20px", + }, + }} + /> + ); +}; + +Checkbox.propTypes = { + id: PropTypes.string.isRequired, + label: PropTypes.string.isRequired, + size: PropTypes.oneOf(["small", "medium", "large"]), + isChecked: PropTypes.bool.isRequired, + value: PropTypes.string, + onChange: PropTypes.func, + isDisabled: PropTypes.bool, +}; + +export default Checkbox; diff --git a/Client/src/assets/icons/checkbox-filled.svg b/Client/src/assets/icons/checkbox-filled.svg new file mode 100644 index 000000000..8a5be81f0 --- /dev/null +++ b/Client/src/assets/icons/checkbox-filled.svg @@ -0,0 +1,4 @@ + + + + diff --git a/Client/src/assets/icons/checkbox-outline.svg b/Client/src/assets/icons/checkbox-outline.svg new file mode 100644 index 000000000..bf5a7218c --- /dev/null +++ b/Client/src/assets/icons/checkbox-outline.svg @@ -0,0 +1,3 @@ + + +