2021-06-27 06:17:59 -04:00
|
|
|
import { Circle } from "@styled-icons/boxicons-regular";
|
2021-07-05 06:23:23 -04:00
|
|
|
import styled, { css } from "styled-components";
|
|
|
|
|
|
|
|
import { Children } from "../../types/Preact";
|
2021-06-18 09:20:57 -04:00
|
|
|
|
|
|
|
interface Props {
|
2021-07-05 06:25:20 -04:00
|
|
|
children: Children;
|
|
|
|
description?: Children;
|
2021-06-18 10:57:08 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
checked: boolean;
|
|
|
|
disabled?: boolean;
|
|
|
|
onSelect: () => void;
|
2021-06-18 09:20:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
interface BaseProps {
|
2021-07-05 06:25:20 -04:00
|
|
|
selected: boolean;
|
2021-06-18 09:20:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const RadioBase = styled.label<BaseProps>`
|
2021-07-05 06:25:20 -04:00
|
|
|
gap: 4px;
|
|
|
|
z-index: 1;
|
|
|
|
padding: 4px;
|
|
|
|
display: flex;
|
|
|
|
cursor: pointer;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
font-size: 1rem;
|
|
|
|
font-weight: 600;
|
|
|
|
user-select: none;
|
|
|
|
border-radius: 4px;
|
|
|
|
transition: 0.2s ease all;
|
|
|
|
|
|
|
|
&: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;*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
${(props) =>
|
|
|
|
props.selected &&
|
|
|
|
css`
|
|
|
|
color: white;
|
|
|
|
cursor: default;
|
|
|
|
background: var(--accent);
|
|
|
|
|
|
|
|
> div {
|
|
|
|
background: white;
|
|
|
|
}
|
|
|
|
|
|
|
|
> div svg {
|
|
|
|
color: var(--accent);
|
|
|
|
}
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: var(--accent);
|
|
|
|
}
|
|
|
|
`}
|
2021-06-18 09:20:57 -04:00
|
|
|
`;
|
|
|
|
|
|
|
|
const RadioDescription = styled.span<BaseProps>`
|
2021-07-05 06:25:20 -04:00
|
|
|
font-size: 0.8em;
|
|
|
|
font-weight: 400;
|
|
|
|
color: var(--secondary-foreground);
|
|
|
|
|
|
|
|
${(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-07-05 06:25:20 -04:00
|
|
|
return (
|
|
|
|
<RadioBase
|
|
|
|
selected={props.checked}
|
|
|
|
disabled={props.disabled}
|
|
|
|
onClick={() =>
|
|
|
|
!props.disabled && props.onSelect && props.onSelect()
|
|
|
|
}>
|
|
|
|
<div>
|
|
|
|
<Circle size={12} />
|
|
|
|
</div>
|
|
|
|
<input type="radio" checked={props.checked} />
|
|
|
|
<span>
|
|
|
|
<span>{props.children}</span>
|
|
|
|
{props.description && (
|
|
|
|
<RadioDescription selected={props.checked}>
|
|
|
|
{props.description}
|
|
|
|
</RadioDescription>
|
|
|
|
)}
|
|
|
|
</span>
|
|
|
|
</RadioBase>
|
|
|
|
);
|
2021-06-18 10:57:08 -04:00
|
|
|
}
|