UNPKG

@navikt/ds-react

Version:

React components from the Norwegian Labour and Welfare Administration.

27 lines 1.83 kB
import cl from "clsx"; import React, { forwardRef } from "react"; import { useRenameCSS } from "../../theme/Theme.js"; import { BodyShort } from "../../typography/index.js"; import { omit } from "../../util/index.js"; import { useId } from "../../util/hooks/index.js"; import { useRadio } from "./useRadio.js"; export const Radio = forwardRef((props, ref) => { const { cn } = useRenameCSS(); const { inputProps, size, hasError, readOnly } = useRadio(props); const labelId = useId(); const descriptionId = useId(); return (React.createElement("div", { className: cn(props.className, "navds-radio", `navds-radio--${size}`, { "navds-radio--error": hasError, "navds-radio--disabled": inputProps.disabled, "navds-radio--readonly": readOnly, }), "data-color": hasError ? "danger" : props["data-color"] }, React.createElement("input", Object.assign({}, omit(props, ["children", "size", "description", "readOnly"]), omit(inputProps, ["aria-invalid"]), { "aria-labelledby": cl(labelId, !!props["aria-labelledby"] && props["aria-labelledby"], { [descriptionId]: props.description, }), className: cn("navds-radio__input"), ref: ref })), React.createElement("label", { htmlFor: inputProps.id, className: cn("navds-radio__label") }, React.createElement("span", { className: cn("navds-radio__content") }, React.createElement(BodyShort, { as: "span", id: labelId, size: size, "aria-hidden": true }, props.children), props.description && (React.createElement(BodyShort, { as: "span", id: descriptionId, size: size, className: cn("navds-form-field__subdescription navds-radio__description"), "aria-hidden": true }, props.description)))))); }); export default Radio; //# sourceMappingURL=Radio.js.map