/* * Copyright (c) 2020 - present Cloudogu GmbH * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Affero General Public License as published by the Free * Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more * details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see https://www.gnu.org/licenses/. */ import React, { ChangeEvent, FC, FocusEvent, useMemo } from "react"; import classNames from "classnames"; import { Help } from "../index"; import { createFormFieldWrapper, FieldProps, FieldType, isLegacy, isUsingRef } from "./FormFieldTypes"; import { createA11yId } from "../createA11yId"; type BaseProps = { label?: string; name?: string; value?: string; checked?: boolean; disabled?: boolean; helpText?: string; defaultChecked?: boolean; className?: string; readOnly?: boolean; ariaLabelledby?: string; }; const InnerRadio: FC> = ({ name, defaultChecked, readOnly, ariaLabelledby, ...props }) => { const id = useMemo(() => ariaLabelledby || createA11yId("radio"), [ariaLabelledby]); const helpId = useMemo(() => createA11yId("radio"), []); const renderHelp = () => { const helpText = props.helpText; if (helpText) { return ; } }; const handleChange = (event: ChangeEvent) => { if (props.onChange) { if (isUsingRef(props)) { props.onChange(event); } else if (isLegacy(props)) { props.onChange(Boolean(event.target.checked), name); } } }; const handleBlur = (event: FocusEvent) => { if (props.onBlur) { if (isUsingRef(props)) { props.onBlur(event); } else if (isLegacy(props)) { props.onBlur(Boolean(event.target.checked), name); } } }; const labelElement = props.label ? {props.label} : null; return (
{/* we have to ignore the next line, because jsx label does not the custom disabled attribute but bulma does. // @ts-ignore */}
); }; /** * @deprecated */ // @ts-ignore const Radio: FieldType = createFormFieldWrapper(InnerRadio); export default Radio;