aboutsummaryrefslogtreecommitdiff
path: root/src/settings/components/ui/Radio.tsx
blob: c0d4dd960efd44562621bb5118151b4986e8f782 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import React from "react";
import styled from "styled-components";

const Container = styled.div`
  font-family: system-ui;
`;

interface Props extends React.InputHTMLAttributes<HTMLInputElement> {
  label: string;
  onValueChange?: (name: string, value: string) => void;
}

const Radio: React.FC<Props> = (props) => {
  const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
    if (props.onValueChange) {
      props.onValueChange(e.target.name, e.target.value);
    }
  };

  const pp = { ...props };
  delete pp.onValueChange;

  return (
    <Container>
      <label htmlFor={props.id}>
        <input type="radio" onChange={onChange} {...pp} />
        {props.label}
      </label>
    </Container>
  );
};

export default Radio;