@navikt/ds-react
Version:
React components from the Norwegian Labour and Welfare Administration.
36 lines • 2.78 kB
JavaScript
import cl from "clsx";
import React, { forwardRef } from "react";
import { useRenameCSS, useThemeInternal } from "../../theme/Theme.js";
import { BodyShort } from "../../typography/index.js";
import { omit, useId } from "../../util/index.js";
import { useRadio } from "./useRadio.js";
export const Radio = forwardRef((props, ref) => {
const { cn } = useRenameCSS();
const { inputProps, size, hasError, readOnly } = useRadio(props);
const descriptionId = useId();
const themeContext = useThemeInternal(false);
if (themeContext === null || themeContext === void 0 ? void 0 : themeContext.isDarkside) {
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-describedby"]), { "aria-describedby": cl(inputProps["aria-describedby"], {
[descriptionId]: props.description,
}) || undefined, className: cn("navds-radio__input"), ref: ref })),
React.createElement(BodyShort, { as: "label", htmlFor: inputProps.id, className: cn("navds-radio__label"), size: size }, props.children),
props.description && (React.createElement(BodyShort, { id: descriptionId, size: size, className: cn("navds-form-field__subdescription navds-radio__description") }, props.description))));
}
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"]), { 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", size: size }, props.children),
props.description && (React.createElement(BodyShort, { as: "span", size: size, className: cn("navds-form-field__subdescription navds-radio__description") }, props.description))))));
});
export default Radio;
//# sourceMappingURL=Radio.js.map