@amsterdam/design-system-react
Version:
All React components from the Amsterdam Design System. Use it to compose pages in your website or application.
16 lines (15 loc) • 1.04 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { clsx } from 'clsx';
import { forwardRef, useId } from 'react';
import RadioIcon from './RadioIcon';
/**
* @see {@link https://designsystem.amsterdam/?path=/docs/components-forms-radio--docs Radio docs at Amsterdam Design System}
*/
export const Radio = forwardRef(({ children, className, icon = RadioIcon, id, invalid, ...restProps }, ref) => {
const inputId = id || useId();
return (
// This div is here because NVDA doesn't match the input to the label
// without a containing element
_jsxs("div", { className: clsx('ams-radio', className), children: [_jsx("input", { ...restProps, "aria-invalid": invalid || undefined, className: "ams-radio__input", id: inputId, ref: ref, type: "radio" }), _jsxs("label", { className: "ams-radio__label", htmlFor: inputId, children: [_jsx("span", { className: "ams-radio__icon-container", hidden: true, children: typeof icon === 'function' ? icon() : icon }), children] })] }));
});
Radio.displayName = 'Radio';