2021-06-18 09:20:57 -04:00
|
|
|
import { Children } from "../../types/Preact";
|
2021-06-18 10:57:08 -04:00
|
|
|
import styled, { css } from "styled-components";
|
2021-06-18 09:20:57 -04:00
|
|
|
import { CircleFill } from "@styled-icons/bootstrap";
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
children: Children;
|
|
|
|
description?: Children;
|
2021-06-18 10:57:08 -04:00
|
|
|
|
2021-06-18 09:20:57 -04:00
|
|
|
checked: boolean;
|
|
|
|
disabled?: boolean;
|
|
|
|
onSelect: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface BaseProps {
|
2021-06-18 10:57:08 -04:00
|
|
|
selected: boolean;
|
2021-06-18 09:20:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const RadioBase = styled.label<BaseProps>`
|
|
|
|
gap: 4px;
|
|
|
|
z-index: 1;
|
|
|
|
padding: 4px;
|
|
|
|
display: flex;
|
|
|
|
cursor: pointer;
|
|
|
|
align-items: center;
|
2021-06-18 10:57:08 -04:00
|
|
|
|
2021-06-18 09:20:57 -04:00
|
|
|
font-size: 1rem;
|
|
|
|
font-weight: 600;
|
|
|
|
user-select: none;
|
|
|
|
border-radius: 4px;
|
2021-06-18 10:57:08 -04:00
|
|
|
transition: 0.2s ease all;
|
2021-06-18 09:20:57 -04:00
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: var(--hover);
|
|
|
|
}
|
|
|
|
|
|
|
|
> input {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
> div {
|
|
|
|
margin: 4px;
|
|
|
|
width: 24px;
|
|
|
|
height: 24px;
|
|
|
|
display: grid;
|
|
|
|
border-radius: 50%;
|
|
|
|
place-items: center;
|
|
|
|
background: var(--foreground);
|
|
|
|
|
|
|
|
svg {
|
|
|
|
color: var(--foreground);
|
|
|
|
stroke-width: 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-18 10:57:08 -04:00
|
|
|
${(props) =>
|
|
|
|
props.selected &&
|
|
|
|
css`
|
|
|
|
color: white;
|
|
|
|
cursor: default;
|
|
|
|
background: var(--accent);
|
2021-06-18 09:20:57 -04:00
|
|
|
|
2021-06-18 10:57:08 -04:00
|
|
|
> div {
|
|
|
|
background: white;
|
|
|
|
}
|
2021-06-18 09:20:57 -04:00
|
|
|
|
2021-06-18 10:57:08 -04:00
|
|
|
> div svg {
|
|
|
|
color: var(--accent);
|
|
|
|
}
|
2021-06-18 09:20:57 -04:00
|
|
|
|
2021-06-18 10:57:08 -04:00
|
|
|
&:hover {
|
|
|
|
background: var(--accent);
|
|
|
|
}
|
|
|
|
`}
|
2021-06-18 09:20:57 -04:00
|
|
|
`;
|
|
|
|
|
|
|
|
const RadioDescription = styled.span<BaseProps>`
|
|
|
|
font-size: 0.8em;
|
|
|
|
font-weight: 400;
|
|
|
|
color: var(--secondary-foreground);
|
|
|
|
|
2021-06-18 10:57:08 -04:00
|
|
|
${(props) =>
|
|
|
|
props.selected &&
|
|
|
|
css`
|
|
|
|
color: white;
|
|
|
|
`}
|
2021-06-18 09:20:57 -04:00
|
|
|
`;
|
|
|
|
|
2021-06-18 10:18:10 -04:00
|
|
|
export default function Radio(props: Props) {
|
2021-06-18 09:20:57 -04:00
|
|
|
return (
|
|
|
|
<RadioBase
|
|
|
|
selected={props.checked}
|
|
|
|
disabled={props.disabled}
|
2021-06-18 10:57:08 -04:00
|
|
|
onClick={() =>
|
|
|
|
!props.disabled && props.onSelect && props.onSelect()
|
|
|
|
}
|
2021-06-18 09:20:57 -04:00
|
|
|
>
|
|
|
|
<div>
|
|
|
|
<CircleFill size={12} />
|
|
|
|
</div>
|
2021-06-18 10:57:08 -04:00
|
|
|
<input type="radio" checked={props.checked} />
|
2021-06-18 09:20:57 -04:00
|
|
|
<span>
|
|
|
|
<span>{props.children}</span>
|
|
|
|
{props.description && (
|
|
|
|
<RadioDescription selected={props.checked}>
|
|
|
|
{props.description}
|
|
|
|
</RadioDescription>
|
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
</RadioBase>
|
|
|
|
);
|
2021-06-18 10:57:08 -04:00
|
|
|
}
|