@navikt/ds-react 7.28.0 → 7.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/form/fieldset/Fieldset.js +1 -1
- package/cjs/form/fieldset/Fieldset.js.map +1 -1
- package/cjs/form/fieldset/useFieldset.d.ts +2 -2
- package/cjs/form/fieldset/useFieldset.js +8 -3
- package/cjs/form/fieldset/useFieldset.js.map +1 -1
- package/cjs/form/useFormField.d.ts +1 -0
- package/cjs/form/useFormField.js +53 -4
- package/cjs/form/useFormField.js.map +1 -1
- package/cjs/util/renderStoriesForChromatic.d.ts +13 -0
- package/cjs/util/renderStoriesForChromatic.js +21 -0
- package/cjs/util/renderStoriesForChromatic.js.map +1 -0
- package/esm/form/fieldset/Fieldset.js +1 -1
- package/esm/form/fieldset/Fieldset.js.map +1 -1
- package/esm/form/fieldset/useFieldset.d.ts +2 -2
- package/esm/form/fieldset/useFieldset.js +6 -4
- package/esm/form/fieldset/useFieldset.js.map +1 -1
- package/esm/form/useFormField.d.ts +1 -0
- package/esm/form/useFormField.js +19 -4
- package/esm/form/useFormField.js.map +1 -1
- package/esm/util/renderStoriesForChromatic.d.ts +13 -0
- package/esm/util/renderStoriesForChromatic.js +15 -0
- package/esm/util/renderStoriesForChromatic.js.map +1 -0
- package/package.json +3 -3
- package/src/form/fieldset/Fieldset.tsx +1 -1
- package/src/form/fieldset/useFieldset.ts +13 -5
- package/src/form/useFormField.ts +21 -3
- package/src/util/renderStoriesForChromatic.tsx +24 -0
|
@@ -72,7 +72,7 @@ exports.Fieldset = (0, react_1.forwardRef)((props, ref) => {
|
|
|
72
72
|
disabled: (_c = props.disabled) !== null && _c !== void 0 ? _c : false,
|
|
73
73
|
readOnly,
|
|
74
74
|
} },
|
|
75
|
-
react_1.default.createElement("fieldset", Object.assign({}, (0, util_1.omit)(rest, ["errorId", "error", "size", "readOnly"]),
|
|
75
|
+
react_1.default.createElement("fieldset", Object.assign({}, (0, util_1.omit)(rest, ["errorId", "error", "size", "readOnly"]), inputProps, { ref: ref, className: cn(className, "navds-fieldset", `navds-fieldset--${size}`, {
|
|
76
76
|
"navds-fieldset--error": hasError,
|
|
77
77
|
"navds-fieldset--readonly": readOnly,
|
|
78
78
|
}) }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Fieldset.js","sourceRoot":"","sources":["../../../src/form/fieldset/Fieldset.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAsB;AACtB,+CAA8E;AAC9E,6CAAiD;AACjD,iDAAkE;AAClE,qCAAkC;AAClC,kDAAsE;AAEtE,uCAA4C;AAC5C,+CAA4C;AAyB/B,QAAA,QAAQ,GAAG,IAAA,kBAAU,EAChC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;;IACb,MAAM,EACJ,UAAU,EACV,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,kBAAkB,GACnB,GAAG,IAAA,yBAAW,EAAC,KAAK,CAAC,CAAC;IAEvB,MAAM,EAAE,EAAE,EAAE,GAAG,IAAA,oBAAY,GAAE,CAAC;IAC9B,MAAM,QAAQ,GAAG,IAAA,kBAAU,EAAC,yBAAe,CAAC,CAAC;IAE7C,MAAM,EACJ,QAAQ,EACR,SAAS,EACT,gBAAgB,GAAG,IAAI,EACvB,MAAM,EACN,WAAW,EACX,UAAU,EACV,cAAc,GAAG,IAAI,KAEnB,KAAK,EADJ,IAAI,UACL,KAAK,EATH,sGASL,CAAQ,CAAC;IAEV,OAAO,CACL,8BAAC,yBAAe,CAAC,QAAQ,IACvB,KAAK,EAAE;YACL,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,MAAA,KAAK,CAAC,KAAK,mCAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,KAAK,CAAC,CAAC,CAAC,SAAS;YACpE,OAAO,EAAE,IAAA,cAA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,UAAU;iBAC9B,CAAC,EACF,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,QAAQ,EACtB,EAAE,EAAC,KAAK,IAEP,KAAK,CAAC,WAAW,CACR,CACb;YACA,QAAQ;YACT,uCACE,EAAE,EAAE,OAAO,mBACG,oBAAoB,eACxB,QAAQ,EAClB,SAAS,EAAE,EAAE,CAAC,uBAAuB,CAAC,IAErC,YAAY,IAAI,CACf,8BAAC,yBAAY,IAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,UAC/B,KAAK,CAAC,KAAK,CACC,CAChB,CACG,CACG,CACc,CAC5B,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,kBAAe,gBAAQ,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { type FormFieldProps } from "../useFormField";
|
|
1
2
|
/**
|
|
2
3
|
* Handles props for Fieldset in context with parent Fieldset.
|
|
3
4
|
*/
|
|
4
|
-
export declare const useFieldset: (props:
|
|
5
|
+
export declare const useFieldset: (props: FormFieldProps) => {
|
|
5
6
|
inputProps: {
|
|
6
|
-
"aria-invalid": boolean | undefined;
|
|
7
7
|
"aria-describedby": string | undefined;
|
|
8
8
|
};
|
|
9
9
|
showErrorMsg: boolean;
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.useFieldset = void 0;
|
|
7
|
+
const clsx_1 = __importDefault(require("clsx"));
|
|
4
8
|
const useFormField_1 = require("../useFormField");
|
|
5
9
|
/**
|
|
6
10
|
* Handles props for Fieldset in context with parent Fieldset.
|
|
7
11
|
*/
|
|
8
12
|
const useFieldset = (props) => {
|
|
9
13
|
const formField = (0, useFormField_1.useFormField)(props, "fieldset");
|
|
10
|
-
const { inputProps } = formField;
|
|
11
14
|
return Object.assign(Object.assign({}, formField), { inputProps: {
|
|
12
|
-
|
|
13
|
-
"aria-describedby":
|
|
15
|
+
// We don't include errorId here, because it will be included on each radio/checkbox inside.
|
|
16
|
+
"aria-describedby": (0, clsx_1.default)(props["aria-describedby"], {
|
|
17
|
+
[formField.inputDescriptionId]: props.description && !(0, useFormField_1.containsReadMore)(props.description),
|
|
18
|
+
}) || undefined,
|
|
14
19
|
} });
|
|
15
20
|
};
|
|
16
21
|
exports.useFieldset = useFieldset;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFieldset.js","sourceRoot":"","sources":["../../../src/form/fieldset/useFieldset.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useFieldset.js","sourceRoot":"","sources":["../../../src/form/fieldset/useFieldset.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAsB;AACtB,kDAIyB;AAEzB;;GAEG;AACI,MAAM,WAAW,GAAG,CAAC,KAAqB,EAAE,EAAE;IACnD,MAAM,SAAS,GAAG,IAAA,2BAAY,EAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IAElD,uCACK,SAAS,KACZ,UAAU,EAAE;YACV,4FAA4F;YAC5F,kBAAkB,EAChB,IAAA,cAAE,EAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE;gBAC5B,CAAC,SAAS,CAAC,kBAAkB,CAAC,EAC5B,KAAK,CAAC,WAAW,IAAI,CAAC,IAAA,+BAAgB,EAAC,KAAK,CAAC,WAAW,CAAC;aAC5D,CAAC,IAAI,SAAS;SAClB,IACD;AACJ,CAAC,CAAC;AAdW,QAAA,WAAW,eActB"}
|
|
@@ -49,3 +49,4 @@ export interface FormFieldType {
|
|
|
49
49
|
* Handles props and their state for various form-fields in context with Fieldset
|
|
50
50
|
*/
|
|
51
51
|
export declare const useFormField: (props: FormFieldProps, prefix: string) => FormFieldType;
|
|
52
|
+
export declare function containsReadMore(children: React.ReactNode, checkNested?: boolean): boolean;
|
package/cjs/form/useFormField.js
CHANGED
|
@@ -1,11 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
5
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
39
|
exports.useFormField = void 0;
|
|
40
|
+
exports.containsReadMore = containsReadMore;
|
|
7
41
|
const clsx_1 = __importDefault(require("clsx"));
|
|
8
|
-
const react_1 = require("react");
|
|
42
|
+
const react_1 = __importStar(require("react"));
|
|
43
|
+
const ReadMore_1 = require("../read-more/ReadMore");
|
|
9
44
|
const hooks_1 = require("../util/hooks");
|
|
10
45
|
const context_1 = require("./fieldset/context");
|
|
11
46
|
/**
|
|
@@ -26,7 +61,7 @@ const useFormField = (props, prefix) => {
|
|
|
26
61
|
const ariaInvalid = Object.assign({}, (hasError ? { "aria-invalid": true } : {}));
|
|
27
62
|
if ((props === null || props === void 0 ? void 0 : props.required) && process.env.NODE_ENV !== "production") {
|
|
28
63
|
console.warn("Aksel: Use of 'required' in form-elements is heavily discuouraged. Docs about why here:");
|
|
29
|
-
console.warn("https://aksel.nav.no/god-praksis/artikler/obligatoriske-og-valgfrie-skjemafelter#
|
|
64
|
+
console.warn("https://aksel.nav.no/god-praksis/artikler/obligatoriske-og-valgfrie-skjemafelter#dc7a536235fa");
|
|
30
65
|
}
|
|
31
66
|
return {
|
|
32
67
|
showErrorMsg,
|
|
@@ -36,11 +71,25 @@ const useFormField = (props, prefix) => {
|
|
|
36
71
|
size: (_b = size !== null && size !== void 0 ? size : fieldset === null || fieldset === void 0 ? void 0 : fieldset.size) !== null && _b !== void 0 ? _b : "medium",
|
|
37
72
|
readOnly,
|
|
38
73
|
inputProps: Object.assign(Object.assign({ id }, ariaInvalid), { "aria-describedby": (0, clsx_1.default)(props["aria-describedby"], {
|
|
39
|
-
[inputDescriptionId]:
|
|
74
|
+
[inputDescriptionId]: props.description && !containsReadMore(props.description),
|
|
40
75
|
[errorId]: showErrorMsg,
|
|
41
|
-
[(_c = fieldset === null || fieldset === void 0 ? void 0 : fieldset.errorId) !== null && _c !== void 0 ? _c : ""]: hasError &&
|
|
76
|
+
[(_c = fieldset === null || fieldset === void 0 ? void 0 : fieldset.errorId) !== null && _c !== void 0 ? _c : ""]: hasError && (fieldset === null || fieldset === void 0 ? void 0 : fieldset.error),
|
|
42
77
|
}) || undefined, disabled }),
|
|
43
78
|
};
|
|
44
79
|
};
|
|
45
80
|
exports.useFormField = useFormField;
|
|
81
|
+
function containsReadMore(children, checkNested = true) {
|
|
82
|
+
if (react_1.default.isValidElement(children)) {
|
|
83
|
+
if (children.type === ReadMore_1.ReadMore) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (children.props.children && checkNested) {
|
|
87
|
+
return containsReadMore(children.props.children, false);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else if (Array.isArray(children)) {
|
|
91
|
+
return children.some((child) => containsReadMore(child, checkNested));
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
46
95
|
//# sourceMappingURL=useFormField.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormField.js","sourceRoot":"","sources":["../../src/form/useFormField.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useFormField.js","sourceRoot":"","sources":["../../src/form/useFormField.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkHA,4CAeC;AAjID,gDAAsB;AACtB,+CAA0C;AAC1C,oDAAiD;AACjD,yCAAsC;AACtC,gDAAqD;AAkDrD;;GAEG;AACI,MAAM,YAAY,GAAG,CAC1B,KAAqB,EACrB,MAAc,EACC,EAAE;;IACjB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IAEpD,MAAM,QAAQ,GAAG,IAAA,kBAAU,EAAC,yBAAe,CAAC,CAAC;IAE7C,MAAM,KAAK,GAAG,IAAA,aAAK,GAAE,CAAC;IAEtB,MAAM,EAAE,GAAG,MAAA,KAAK,CAAC,EAAE,mCAAI,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|
|
1
|
+
import { Args } from "@storybook/react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Renderer, StoryContext } from "storybook/internal/types";
|
|
4
|
+
export declare function renderStoriesForChromatic(stories: Record<string, {
|
|
5
|
+
render?: (...args: any[]) => React.ReactNode;
|
|
6
|
+
} | React.FunctionComponent<void>>): {
|
|
7
|
+
render: (args_0: Args, args_1: StoryContext<Renderer, Args>) => React.JSX.Element[];
|
|
8
|
+
parameters: {
|
|
9
|
+
chromatic: {
|
|
10
|
+
disable: boolean;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.renderStoriesForChromatic = renderStoriesForChromatic;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
function renderStoriesForChromatic(stories) {
|
|
9
|
+
return {
|
|
10
|
+
render: (...args) => Object.entries(stories).map(([storyName, story]) => {
|
|
11
|
+
var _a;
|
|
12
|
+
return (react_1.default.createElement("div", { key: storyName },
|
|
13
|
+
react_1.default.createElement("h2", { className: "storyheading" }, storyName),
|
|
14
|
+
typeof story === "function" ? story() : (_a = story.render) === null || _a === void 0 ? void 0 : _a.call(story, ...args)));
|
|
15
|
+
}),
|
|
16
|
+
parameters: {
|
|
17
|
+
chromatic: { disable: false },
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=renderStoriesForChromatic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderStoriesForChromatic.js","sourceRoot":"","sources":["../../src/util/renderStoriesForChromatic.tsx"],"names":[],"mappings":";;;;;AAIA,8DAmBC;AAtBD,kDAA0B;AAG1B,SAAgB,yBAAyB,CACvC,OAIC;IAED,OAAO;QACL,MAAM,EAAE,CAAC,GAAG,IAA0C,EAAE,EAAE,CACxD,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE,EAAE;;YAAC,OAAA,CAClD,uCAAK,GAAG,EAAE,SAAS;gBACjB,sCAAI,SAAS,EAAC,cAAc,IAAE,SAAS,CAAM;gBAC5C,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,MAAA,KAAK,CAAC,MAAM,sDAAG,GAAG,IAAI,CAAC,CAC5D,CACP,CAAA;SAAA,CAAC;QACJ,UAAU,EAAE;YACV,SAAS,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE;SAC9B;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -33,7 +33,7 @@ export const Fieldset = forwardRef((props, ref) => {
|
|
|
33
33
|
disabled: (_c = props.disabled) !== null && _c !== void 0 ? _c : false,
|
|
34
34
|
readOnly,
|
|
35
35
|
} },
|
|
36
|
-
React.createElement("fieldset", Object.assign({}, omit(rest, ["errorId", "error", "size", "readOnly"]),
|
|
36
|
+
React.createElement("fieldset", Object.assign({}, omit(rest, ["errorId", "error", "size", "readOnly"]), inputProps, { ref: ref, className: cn(className, "navds-fieldset", `navds-fieldset--${size}`, {
|
|
37
37
|
"navds-fieldset--error": hasError,
|
|
38
38
|
"navds-fieldset--readonly": readOnly,
|
|
39
39
|
}) }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Fieldset.js","sourceRoot":"","sources":["../../../src/form/fieldset/Fieldset.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,EAAE,EAA0B,UAAU,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,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,6BAA6B,EAAE;oBAC3C,eAAe,EAAE,CAAC,CAAC,UAAU;iBAC9B,CAAC,EACF,EAAE,EAAE,kBAAkB,EACtB,IAAI,EAAE,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,QAAQ,EACtB,EAAE,EAAC,KAAK,IAEP,KAAK,CAAC,WAAW,CACR,CACb;YACA,QAAQ;YACT,6BACE,EAAE,EAAE,OAAO,mBACG,oBAAoB,eACxB,QAAQ,EAClB,SAAS,EAAE,EAAE,CAAC,uBAAuB,CAAC,IAErC,YAAY,IAAI,CACf,oBAAC,YAAY,IAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,UAC/B,KAAK,CAAC,KAAK,CACC,CAChB,CACG,CACG,CACc,CAC5B,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { type FormFieldProps } from "../useFormField.js";
|
|
1
2
|
/**
|
|
2
3
|
* Handles props for Fieldset in context with parent Fieldset.
|
|
3
4
|
*/
|
|
4
|
-
export declare const useFieldset: (props:
|
|
5
|
+
export declare const useFieldset: (props: FormFieldProps) => {
|
|
5
6
|
inputProps: {
|
|
6
|
-
"aria-invalid": boolean | undefined;
|
|
7
7
|
"aria-describedby": string | undefined;
|
|
8
8
|
};
|
|
9
9
|
showErrorMsg: boolean;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import cl from "clsx";
|
|
2
|
+
import { containsReadMore, useFormField, } from "../useFormField.js";
|
|
2
3
|
/**
|
|
3
4
|
* Handles props for Fieldset in context with parent Fieldset.
|
|
4
5
|
*/
|
|
5
6
|
export const useFieldset = (props) => {
|
|
6
7
|
const formField = useFormField(props, "fieldset");
|
|
7
|
-
const { inputProps } = formField;
|
|
8
8
|
return Object.assign(Object.assign({}, formField), { inputProps: {
|
|
9
|
-
|
|
10
|
-
"aria-describedby":
|
|
9
|
+
// We don't include errorId here, because it will be included on each radio/checkbox inside.
|
|
10
|
+
"aria-describedby": cl(props["aria-describedby"], {
|
|
11
|
+
[formField.inputDescriptionId]: props.description && !containsReadMore(props.description),
|
|
12
|
+
}) || undefined,
|
|
11
13
|
} });
|
|
12
14
|
};
|
|
13
15
|
//# sourceMappingURL=useFieldset.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFieldset.js","sourceRoot":"","sources":["../../../src/form/fieldset/useFieldset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"useFieldset.js","sourceRoot":"","sources":["../../../src/form/fieldset/useFieldset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,EAEL,gBAAgB,EAChB,YAAY,GACb,MAAM,iBAAiB,CAAC;AAEzB;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAqB,EAAE,EAAE;IACnD,MAAM,SAAS,GAAG,YAAY,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IAElD,uCACK,SAAS,KACZ,UAAU,EAAE;YACV,4FAA4F;YAC5F,kBAAkB,EAChB,EAAE,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE;gBAC5B,CAAC,SAAS,CAAC,kBAAkB,CAAC,EAC5B,KAAK,CAAC,WAAW,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,WAAW,CAAC;aAC5D,CAAC,IAAI,SAAS;SAClB,IACD;AACJ,CAAC,CAAC"}
|
|
@@ -49,3 +49,4 @@ export interface FormFieldType {
|
|
|
49
49
|
* Handles props and their state for various form-fields in context with Fieldset
|
|
50
50
|
*/
|
|
51
51
|
export declare const useFormField: (props: FormFieldProps, prefix: string) => FormFieldType;
|
|
52
|
+
export declare function containsReadMore(children: React.ReactNode, checkNested?: boolean): boolean;
|
package/esm/form/useFormField.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import cl from "clsx";
|
|
2
|
-
import { useContext } from "react";
|
|
2
|
+
import React, { useContext } from "react";
|
|
3
|
+
import { ReadMore } from "../read-more/ReadMore.js";
|
|
3
4
|
import { useId } from "../util/hooks/index.js";
|
|
4
5
|
import { FieldsetContext } from "./fieldset/context.js";
|
|
5
6
|
/**
|
|
@@ -20,7 +21,7 @@ export const useFormField = (props, prefix) => {
|
|
|
20
21
|
const ariaInvalid = Object.assign({}, (hasError ? { "aria-invalid": true } : {}));
|
|
21
22
|
if ((props === null || props === void 0 ? void 0 : props.required) && process.env.NODE_ENV !== "production") {
|
|
22
23
|
console.warn("Aksel: Use of 'required' in form-elements is heavily discuouraged. Docs about why here:");
|
|
23
|
-
console.warn("https://aksel.nav.no/god-praksis/artikler/obligatoriske-og-valgfrie-skjemafelter#
|
|
24
|
+
console.warn("https://aksel.nav.no/god-praksis/artikler/obligatoriske-og-valgfrie-skjemafelter#dc7a536235fa");
|
|
24
25
|
}
|
|
25
26
|
return {
|
|
26
27
|
showErrorMsg,
|
|
@@ -30,10 +31,24 @@ export const useFormField = (props, prefix) => {
|
|
|
30
31
|
size: (_b = size !== null && size !== void 0 ? size : fieldset === null || fieldset === void 0 ? void 0 : fieldset.size) !== null && _b !== void 0 ? _b : "medium",
|
|
31
32
|
readOnly,
|
|
32
33
|
inputProps: Object.assign(Object.assign({ id }, ariaInvalid), { "aria-describedby": cl(props["aria-describedby"], {
|
|
33
|
-
[inputDescriptionId]:
|
|
34
|
+
[inputDescriptionId]: props.description && !containsReadMore(props.description),
|
|
34
35
|
[errorId]: showErrorMsg,
|
|
35
|
-
[(_c = fieldset === null || fieldset === void 0 ? void 0 : fieldset.errorId) !== null && _c !== void 0 ? _c : ""]: hasError &&
|
|
36
|
+
[(_c = fieldset === null || fieldset === void 0 ? void 0 : fieldset.errorId) !== null && _c !== void 0 ? _c : ""]: hasError && (fieldset === null || fieldset === void 0 ? void 0 : fieldset.error),
|
|
36
37
|
}) || undefined, disabled }),
|
|
37
38
|
};
|
|
38
39
|
};
|
|
40
|
+
export function containsReadMore(children, checkNested = true) {
|
|
41
|
+
if (React.isValidElement(children)) {
|
|
42
|
+
if (children.type === ReadMore) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
if (children.props.children && checkNested) {
|
|
46
|
+
return containsReadMore(children.props.children, false);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
else if (Array.isArray(children)) {
|
|
50
|
+
return children.some((child) => containsReadMore(child, checkNested));
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
39
54
|
//# sourceMappingURL=useFormField.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormField.js","sourceRoot":"","sources":["../../src/form/useFormField.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,
|
|
1
|
+
{"version":3,"file":"useFormField.js","sourceRoot":"","sources":["../../src/form/useFormField.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAkDrD;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,KAAqB,EACrB,MAAc,EACC,EAAE;;IACjB,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IAEpD,MAAM,QAAQ,GAAG,UAAU,CAAC,eAAe,CAAC,CAAC;IAE7C,MAAM,KAAK,GAAG,KAAK,EAAE,CAAC;IAEtB,MAAM,EAAE,GAAG,MAAA,KAAK,CAAC,EAAE,mCAAI,GAAG,MAAM,IAAI,KAAK,EAAE,CAAC;IAC5C,MAAM,OAAO,GAAG,WAAW,aA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
+
export declare function renderStoriesForChromatic(stories: Record<string, {
|
|
5
|
+
render?: (...args: any[]) => React.ReactNode;
|
|
6
|
+
} | React.FunctionComponent<void>>): {
|
|
7
|
+
render: (args_0: Args, args_1: StoryContext<Renderer, Args>) => React.JSX.Element[];
|
|
8
|
+
parameters: {
|
|
9
|
+
chromatic: {
|
|
10
|
+
disable: boolean;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export function renderStoriesForChromatic(stories) {
|
|
3
|
+
return {
|
|
4
|
+
render: (...args) => Object.entries(stories).map(([storyName, story]) => {
|
|
5
|
+
var _a;
|
|
6
|
+
return (React.createElement("div", { key: storyName },
|
|
7
|
+
React.createElement("h2", { className: "storyheading" }, storyName),
|
|
8
|
+
typeof story === "function" ? story() : (_a = story.render) === null || _a === void 0 ? void 0 : _a.call(story, ...args)));
|
|
9
|
+
}),
|
|
10
|
+
parameters: {
|
|
11
|
+
chromatic: { disable: false },
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=renderStoriesForChromatic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderStoriesForChromatic.js","sourceRoot":"","sources":["../../src/util/renderStoriesForChromatic.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,MAAM,UAAU,yBAAyB,CACvC,OAIC;IAED,OAAO;QACL,MAAM,EAAE,CAAC,GAAG,IAA0C,EAAE,EAAE,CACxD,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE,EAAE;;YAAC,OAAA,CAClD,6BAAK,GAAG,EAAE,SAAS;gBACjB,4BAAI,SAAS,EAAC,cAAc,IAAE,SAAS,CAAM;gBAC5C,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,MAAA,KAAK,CAAC,MAAM,sDAAG,GAAG,IAAI,CAAC,CAC5D,CACP,CAAA;SAAA,CAAC;QACJ,UAAU,EAAE;YACV,SAAS,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE;SAC9B;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@navikt/ds-react",
|
|
3
|
-
"version": "7.28.
|
|
3
|
+
"version": "7.28.1",
|
|
4
4
|
"description": "React components from the Norwegian Labour and Welfare Administration.",
|
|
5
5
|
"author": "Aksel, a team part of the Norwegian Labour and Welfare Administration.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -640,8 +640,8 @@
|
|
|
640
640
|
"dependencies": {
|
|
641
641
|
"@floating-ui/react": "0.27.8",
|
|
642
642
|
"@floating-ui/react-dom": "^2.0.9",
|
|
643
|
-
"@navikt/aksel-icons": "^7.28.
|
|
644
|
-
"@navikt/ds-tokens": "^7.28.
|
|
643
|
+
"@navikt/aksel-icons": "^7.28.1",
|
|
644
|
+
"@navikt/ds-tokens": "^7.28.1",
|
|
645
645
|
"clsx": "^2.1.0",
|
|
646
646
|
"date-fns": "^4.0.0",
|
|
647
647
|
"react-day-picker": "9.7.0"
|
|
@@ -72,7 +72,7 @@ export const Fieldset = forwardRef<HTMLFieldSetElement, FieldsetProps>(
|
|
|
72
72
|
>
|
|
73
73
|
<fieldset
|
|
74
74
|
{...omit(rest, ["errorId", "error", "size", "readOnly"])}
|
|
75
|
-
{...
|
|
75
|
+
{...inputProps}
|
|
76
76
|
ref={ref}
|
|
77
77
|
className={cn(
|
|
78
78
|
className,
|
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
import
|
|
1
|
+
import cl from "clsx";
|
|
2
|
+
import {
|
|
3
|
+
type FormFieldProps,
|
|
4
|
+
containsReadMore,
|
|
5
|
+
useFormField,
|
|
6
|
+
} from "../useFormField";
|
|
2
7
|
|
|
3
8
|
/**
|
|
4
9
|
* Handles props for Fieldset in context with parent Fieldset.
|
|
5
10
|
*/
|
|
6
|
-
export const useFieldset = (props) => {
|
|
11
|
+
export const useFieldset = (props: FormFieldProps) => {
|
|
7
12
|
const formField = useFormField(props, "fieldset");
|
|
8
|
-
const { inputProps } = formField;
|
|
9
13
|
|
|
10
14
|
return {
|
|
11
15
|
...formField,
|
|
12
16
|
inputProps: {
|
|
13
|
-
|
|
14
|
-
"aria-describedby":
|
|
17
|
+
// We don't include errorId here, because it will be included on each radio/checkbox inside.
|
|
18
|
+
"aria-describedby":
|
|
19
|
+
cl(props["aria-describedby"], {
|
|
20
|
+
[formField.inputDescriptionId]:
|
|
21
|
+
props.description && !containsReadMore(props.description),
|
|
22
|
+
}) || undefined,
|
|
15
23
|
},
|
|
16
24
|
};
|
|
17
25
|
};
|
package/src/form/useFormField.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import cl from "clsx";
|
|
2
2
|
import React, { useContext } from "react";
|
|
3
|
+
import { ReadMore } from "../read-more/ReadMore";
|
|
3
4
|
import { useId } from "../util/hooks";
|
|
4
5
|
import { FieldsetContext } from "./fieldset/context";
|
|
5
6
|
|
|
@@ -84,7 +85,7 @@ export const useFormField = (
|
|
|
84
85
|
"Aksel: Use of 'required' in form-elements is heavily discuouraged. Docs about why here:",
|
|
85
86
|
);
|
|
86
87
|
console.warn(
|
|
87
|
-
"https://aksel.nav.no/god-praksis/artikler/obligatoriske-og-valgfrie-skjemafelter#
|
|
88
|
+
"https://aksel.nav.no/god-praksis/artikler/obligatoriske-og-valgfrie-skjemafelter#dc7a536235fa",
|
|
88
89
|
);
|
|
89
90
|
}
|
|
90
91
|
|
|
@@ -101,12 +102,29 @@ export const useFormField = (
|
|
|
101
102
|
"aria-describedby":
|
|
102
103
|
cl(props["aria-describedby"], {
|
|
103
104
|
[inputDescriptionId]:
|
|
104
|
-
|
|
105
|
+
props.description && !containsReadMore(props.description),
|
|
105
106
|
[errorId]: showErrorMsg,
|
|
106
|
-
[fieldset?.errorId ?? ""]: hasError &&
|
|
107
|
+
[fieldset?.errorId ?? ""]: hasError && fieldset?.error,
|
|
107
108
|
}) || undefined,
|
|
108
109
|
|
|
109
110
|
disabled,
|
|
110
111
|
},
|
|
111
112
|
};
|
|
112
113
|
};
|
|
114
|
+
|
|
115
|
+
export function containsReadMore(
|
|
116
|
+
children: React.ReactNode,
|
|
117
|
+
checkNested = true,
|
|
118
|
+
): boolean {
|
|
119
|
+
if (React.isValidElement(children)) {
|
|
120
|
+
if (children.type === ReadMore) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
if (children.props.children && checkNested) {
|
|
124
|
+
return containsReadMore(children.props.children, false);
|
|
125
|
+
}
|
|
126
|
+
} else if (Array.isArray(children)) {
|
|
127
|
+
return children.some((child) => containsReadMore(child, checkNested));
|
|
128
|
+
}
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Args } from "@storybook/react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Renderer, StoryContext } from "storybook/internal/types";
|
|
4
|
+
|
|
5
|
+
export function renderStoriesForChromatic(
|
|
6
|
+
stories: Record<
|
|
7
|
+
string,
|
|
8
|
+
| { render?: (...args: any[]) => React.ReactNode }
|
|
9
|
+
| React.FunctionComponent<void>
|
|
10
|
+
>,
|
|
11
|
+
) {
|
|
12
|
+
return {
|
|
13
|
+
render: (...args: [Args, StoryContext<Renderer, Args>]) =>
|
|
14
|
+
Object.entries(stories).map(([storyName, story]) => (
|
|
15
|
+
<div key={storyName}>
|
|
16
|
+
<h2 className="storyheading">{storyName}</h2>
|
|
17
|
+
{typeof story === "function" ? story() : story.render?.(...args)}
|
|
18
|
+
</div>
|
|
19
|
+
)),
|
|
20
|
+
parameters: {
|
|
21
|
+
chromatic: { disable: false },
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|