UNPKG

@navikt/ds-react

Version:

React components from the Norwegian Labour and Welfare Administration.

45 lines 2.31 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import React, { forwardRef, useContext } from "react"; import { useRenameCSS } from "../../theme/Theme.js"; import { useId } from "../../util/hooks/index.js"; import { Fieldset } from "../fieldset/index.js"; import { FieldsetContext } from "../fieldset/context.js"; export const RadioGroupContext = React.createContext(null); /** * Form radio group * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/radio) * @see 🏷️ {@link RadioGroupProps} * @example * <RadioGroup legend="Får du AAP nå?"> * <Radio value="ja">Ja</Radio> * <Radio value="Nei">Nei</Radio> * </RadioGroup> */ export const RadioGroup = forwardRef((_a, ref) => { var _b, _c; var { children, className, name, defaultValue, value, onChange = () => { }, required, readOnly } = _a, rest = __rest(_a, ["children", "className", "name", "defaultValue", "value", "onChange", "required", "readOnly"]); const { cn } = useRenameCSS(); const fieldset = useContext(FieldsetContext); const nameId = useId(); return (React.createElement(Fieldset, Object.assign({}, rest, { readOnly: readOnly, ref: ref, className: cn(className, "navds-radio-group", `navds-radio-group--${(_c = (_b = rest.size) !== null && _b !== void 0 ? _b : fieldset === null || fieldset === void 0 ? void 0 : fieldset.size) !== null && _c !== void 0 ? _c : "medium"}`), nativeReadOnly: false }), React.createElement(RadioGroupContext.Provider, { value: { name: name !== null && name !== void 0 ? name : `radioGroupName-${nameId}`, defaultValue, value, onChange, required, } }, React.createElement("div", { className: cn("navds-radio-buttons") }, children)))); }); export default RadioGroup; //# sourceMappingURL=RadioGroup.js.map