%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/emergentqj/actioncivile/pre-auth/def/static/js/common/components/
Upload File :
Create Path :
Current File : /home/emergentqj/actioncivile/pre-auth/def/static/js/common/components/Checkbox.js

import React from "react";
import PropTypes from "prop-types";
import styled from "styled-components";
import { theme } from "styled-tools";

export const StyledCheckbox = styled.input.attrs({
  type: "checkbox",
})`
  /* Fix for global styles causing issues */
  position: relative !important;
  left: 0 !important;
  opacity: 1 !important;

  width: 18px;
  height: 18px;

  padding: 0 !important;
  margin: 0 !important;

  accent-color: ${theme("color.primary")};

  &:focus {
    outline: 2px solid ${theme("color.info")} !important;
  }
`;

export const CheckboxWrapper = styled.div`
  display: flex;
  align-items: center;
`;

export function Checkbox({ onChange, value }) {
  const handleKeyDown = ({ key }) => {
    if (key === "Enter") {
      onChange(!value);
    }
  };

  return (
    <CheckboxWrapper>
      <StyledCheckbox
        checked={value}
        onChange={({ target: { checked: newValue } }) => onChange(newValue)}
        onKeyDown={handleKeyDown}
      />
    </CheckboxWrapper>
  );
}

Checkbox.propTypes = {
  onChange: PropTypes.func.isRequired,
  value: PropTypes.func.isRequired,
};

Zerion Mini Shell 1.0