@amsterdam/design-system-react
Version:
All React components from the Amsterdam Design System. Use it to compose pages in your website or application.
20 lines (19 loc) • 1.04 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
* @license EUPL-1.2+
* Copyright Gemeente Amsterdam
*/
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, invalid, ...restProps }, ref) => {
const 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: id, ref: ref, type: "radio" }), _jsxs("label", { className: "ams-radio__label", htmlFor: id, children: [_jsx("span", { className: "ams-radio__icon-container", children: icon ?? _jsx(RadioIcon, {}) }), children] })] }));
});
Radio.displayName = 'Radio';