UNPKG

@navikt/ds-react

Version:

React components from the Norwegian Labour and Welfare Administration.

59 lines 3.12 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 cl from "clsx"; import React, { forwardRef } from "react"; import { useRenameCSS } from "../../theme/Theme.js"; import { BodyLong, ErrorMessage } from "../../typography/index.js"; import { useId } from "../../util/hooks/index.js"; import { Checkbox } from "../checkbox/index.js"; import { useFormField } from "../useFormField.js"; /** * A component that displays a confirmation checkbox with a label. * @deprecated Use `Checkbox` instead. See [new pattern documentation](https://aksel.nav.no/monster-maler/soknadsdialog/introside-for-soknadsdialoger#8346a8cb849b) for more information. * * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/confirmationpanel) * @see 🏷️ {@link ConfirmationPanelProps} * * @example * ```jsx <ConfirmationPanel checked={state} label="Ja, jeg samtykker." onChange={() => setState((x) => !x)} > For å komme videre må du gi oss lov til å hente inn og bruke opplysninger om deg. </ConfirmationPanel> * ``` */ export const ConfirmationPanel = forwardRef((_a, ref) => { var { className, children, label } = _a, props = __rest(_a, ["className", "children", "label"]); const { cn } = useRenameCSS(); const { errorId, showErrorMsg, hasError, size, inputProps } = useFormField(props, "confirmation-panel"); const id = useId(); const currentColor = hasError ? "danger" : props.checked ? "success" : "warning"; return (React.createElement("div", { className: cn("navds-confirmation-panel", "navds-form-field", className, { "navds-confirmation-panel--small": size === "small", "navds-confirmation-panel--error": hasError, "navds-confirmation-panel--checked": !!props.checked, }), "data-color": currentColor }, React.createElement("div", { className: cn("navds-confirmation-panel__inner") }, children && (React.createElement(BodyLong, { size: props.size, className: cn("navds-confirmation-panel__content"), id: `confirmation-panel-${id}`, as: "div" }, children)), React.createElement(Checkbox, Object.assign({ ref: ref }, props, inputProps, { "aria-describedby": cl(inputProps["aria-describedby"], children && `confirmation-panel-${id}`), error: hasError, size: size }), label)), React.createElement("div", { className: cn("navds-form-field__error"), id: errorId, role: "alert" }, showErrorMsg && (React.createElement(ErrorMessage, { size: size, showIcon: true }, props.error))))); }); export default ConfirmationPanel; //# sourceMappingURL=ConfirmationPanel.js.map