UNPKG

@engie-group/fluid-design-system-react

Version:

Fluid Design System React

21 lines (18 loc) 1.06 kB
import { jsx, jsxs } from 'react/jsx-runtime'; import React__default, { useContext } from 'react'; import { Utils } from '../../utils/util.js'; import { NJRadioGroupContext } from './NJRadioGroupContext.js'; const NJRadio = React__default.forwardRef(({ scale, label, onChange, labelRef, rootRef, ...htmlProps }, forwardedRef) => { const context = useContext(NJRadioGroupContext); const radioClassName = Utils.classNames('nj-radio', { [`nj-radio--${scale}`]: scale, [`nj-radio--disabled`]: htmlProps.disabled }); const change = (e) => { context.change?.(htmlProps.id ?? 'nj-radio', htmlProps.value, e); onChange?.(e); }; return (jsx("div", { className: radioClassName, ref: rootRef, children: jsxs("label", { htmlFor: htmlProps.id, ref: labelRef, children: [jsx("input", { ...htmlProps, ref: forwardedRef, type: "radio", onChange: change, checked: htmlProps.checked ?? (htmlProps.id ? context.value === htmlProps.id : undefined) }), label] }) })); }); NJRadio.displayName = 'NJRadio'; export { NJRadio };