Add checkbox component
authorAjay Bura <ajbura@gmail.com>
Thu, 30 Dec 2021 06:07:18 +0000 (11:37 +0530)
committerAjay Bura <ajbura@gmail.com>
Thu, 30 Dec 2021 06:07:18 +0000 (11:37 +0530)
Signed-off-by: Ajay Bura <ajbura@gmail.com>
src/app/atoms/button/Checkbox.jsx [new file with mode: 0644]
src/app/atoms/button/Checkbox.scss [new file with mode: 0644]

diff --git a/src/app/atoms/button/Checkbox.jsx b/src/app/atoms/button/Checkbox.jsx
new file mode 100644 (file)
index 0000000..5bac0c0
--- /dev/null
@@ -0,0 +1,30 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import './Checkbox.scss';
+
+function Checkbox({ variant, isActive, onToggle }) {
+  const className = `checkbox checkbox-${variant}${isActive ? ' checkbox--active' : ''}`;
+  if (onToggle === null) return <span className={className} />;
+  return (
+    // eslint-disable-next-line jsx-a11y/control-has-associated-label
+    <button
+      onClick={() => onToggle(!isActive)}
+      className={className}
+      type="button"
+    />
+  );
+}
+
+Checkbox.defaultProps = {
+  variant: 'primary',
+  isActive: false,
+  onToggle: null,
+};
+
+Checkbox.propTypes = {
+  variant: PropTypes.oneOf(['primary', 'positive', 'caution', 'danger']),
+  isActive: PropTypes.bool,
+  onToggle: PropTypes.func,
+};
+
+export default Checkbox;
diff --git a/src/app/atoms/button/Checkbox.scss b/src/app/atoms/button/Checkbox.scss
new file mode 100644 (file)
index 0000000..5b26b9d
--- /dev/null
@@ -0,0 +1,37 @@
+@use '../../partials/flex';
+
+.checkbox {
+  width: 20px;
+  height: 20px;
+
+  border-radius: calc(var(--bo-radius) / 2);
+  background-color: var(--bg-surface-border);
+  box-shadow: var(--bs-surface-border);
+  cursor: pointer;
+  @extend .cp-fx__row--c-c;
+
+  &--active {
+    background-color: black;
+    &::before {
+      content: "";
+      display: inline-block;
+      width: 12px;
+      height: 6px;
+      border: 6px solid white;
+      border-width: 0 0 3px 3px;
+      transform: rotateZ(-45deg) translate(1px, -1px);
+    }
+  }
+}
+.checkbox-primary.checkbox--active {
+  background-color: var(--bg-primary);
+}
+.checkbox-positive.checkbox--active {
+  background-color: var(--bg-positive);
+}
+.checkbox-caution.checkbox--active {
+  background-color: var(--bg-caution);
+}
+.checkbox-danger.checkbox--active {
+  background-color: var(--bg-danger);
+}
\ No newline at end of file