/* * MIT License * * Copyright (c) 2020-present Cloudogu GmbH and Contributors * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ 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 */}
); }; const Radio: FieldType = createFormFieldWrapper(InnerRadio); export default Radio;