2023-07-26 17:48:22 +02:00
|
|
|
import React, {
|
|
|
|
|
InputHTMLAttributes,
|
|
|
|
|
PropsWithChildren,
|
|
|
|
|
forwardRef,
|
|
|
|
|
} from "react";
|
2023-04-20 14:58:06 +02:00
|
|
|
import classNames from "classnames";
|
2023-05-04 15:04:47 +02:00
|
|
|
import { Field, FieldProps } from ":/components/Forms/Field";
|
2023-04-20 14:58:06 +02:00
|
|
|
|
|
|
|
|
type Props = InputHTMLAttributes<HTMLInputElement> &
|
|
|
|
|
FieldProps & {
|
|
|
|
|
label?: string;
|
|
|
|
|
};
|
|
|
|
|
|
2023-07-26 17:48:22 +02:00
|
|
|
export const Radio = forwardRef<HTMLInputElement, Props>(
|
|
|
|
|
({ label, text, state, ...props }: Props, ref) => {
|
|
|
|
|
return (
|
|
|
|
|
<label
|
|
|
|
|
className={classNames("c__checkbox", "c__radio", {
|
|
|
|
|
"c__checkbox--disabled": props.disabled,
|
|
|
|
|
})}
|
|
|
|
|
>
|
|
|
|
|
<Field text={text} compact={true} state={state}>
|
|
|
|
|
<div className="c__checkbox__container">
|
|
|
|
|
<input type="radio" {...props} ref={ref} />
|
|
|
|
|
{label && <div className="c__checkbox__label">{label}</div>}
|
|
|
|
|
</div>
|
|
|
|
|
</Field>
|
|
|
|
|
</label>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
2023-04-20 14:58:06 +02:00
|
|
|
|
|
|
|
|
export const RadioGroup = ({
|
|
|
|
|
children,
|
|
|
|
|
state,
|
|
|
|
|
text,
|
|
|
|
|
rightText,
|
2023-08-01 15:07:30 +02:00
|
|
|
style,
|
2023-08-10 18:21:04 +02:00
|
|
|
}: PropsWithChildren & FieldProps & { style?: React.CSSProperties }) => {
|
2023-04-20 14:58:06 +02:00
|
|
|
return (
|
|
|
|
|
<Field
|
|
|
|
|
className="c__radio__group c__checkbox__group"
|
|
|
|
|
state={state}
|
|
|
|
|
text={text}
|
|
|
|
|
rightText={rightText}
|
|
|
|
|
compact={true}
|
|
|
|
|
>
|
2023-08-01 15:07:30 +02:00
|
|
|
<div className="c__checkbox__group__list" style={style}>
|
|
|
|
|
{children}
|
|
|
|
|
</div>
|
2023-04-20 14:58:06 +02:00
|
|
|
</Field>
|
|
|
|
|
);
|
|
|
|
|
};
|