@navikt/ds-react 2.4.1 → 2.4.2

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/list/List.js CHANGED
@@ -49,13 +49,17 @@ exports.ListContext = (0, react_1.createContext)({
49
49
  exports.List = (0, react_1.forwardRef)((_a, ref) => {
50
50
  var { children, className, as: ListTag = "ul", title, description, headingTag = "h3" } = _a, rest = __rest(_a, ["children", "className", "as", "title", "description", "headingTag"]);
51
51
  const ariaId = (0, useId_1.useId)();
52
+ const { isNested } = (0, react_1.useContext)(ListItem_1.ListItemContext);
52
53
  return (react_1.default.createElement(exports.ListContext.Provider, { value: {
53
54
  listType: ListTag,
54
55
  } },
55
- react_1.default.createElement("div", Object.assign({}, rest, { ref: ref, className: (0, clsx_1.default)("navds-list", className) }),
56
+ react_1.default.createElement("div", Object.assign({}, rest, { ref: ref, className: (0, clsx_1.default)("navds-list", className, {
57
+ "navds-list--nested": isNested,
58
+ }) }),
56
59
  title && (react_1.default.createElement(typography_1.Heading, { id: `tittel-${ariaId}`, size: "small", as: headingTag }, title)),
57
60
  description && (react_1.default.createElement(typography_1.BodyShort, { id: `description-${ariaId}` }, description)),
58
61
  react_1.default.createElement(ListTag, { "aria-labelledby": title && `tittel-${ariaId}`, "aria-describedby": description && `description-${ariaId}` }, children))));
59
62
  });
60
63
  exports.List.Item = ListItem_1.ListItem;
64
+ exports.List.componentType = "list";
61
65
  exports.default = exports.List;
@@ -37,22 +37,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.ListItem = void 0;
40
+ exports.ListItem = exports.ListItemContext = void 0;
41
41
  const clsx_1 = __importDefault(require("clsx"));
42
42
  const react_1 = __importStar(require("react"));
43
43
  const typography_1 = require("../typography");
44
44
  const List_1 = require("./List");
45
+ exports.ListItemContext = (0, react_1.createContext)({
46
+ isNested: false,
47
+ });
45
48
  exports.ListItem = (0, react_1.forwardRef)((_a, ref) => {
49
+ var _b;
46
50
  var { className, children, title, icon } = _a, rest = __rest(_a, ["className", "children", "title", "icon"]);
47
51
  const { listType } = (0, react_1.useContext)(List_1.ListContext);
48
- return (react_1.default.createElement("li", Object.assign({}, rest, { ref: ref, className: (0, clsx_1.default)("navds-list__item", className) }),
49
- listType === "ul" && (react_1.default.createElement("div", { className: (0, clsx_1.default)({
50
- "navds-list__item-marker--icon": icon,
51
- "navds-list__item-marker--bullet": !icon,
52
- }) }, icon ? (icon) : (react_1.default.createElement("svg", { width: "6", height: "6", viewBox: "0 0 6 6", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": true, focusable: false, role: "img" },
53
- react_1.default.createElement("rect", { width: "6", height: "6", rx: "3", fill: "currentColor" }))))),
54
- react_1.default.createElement(typography_1.BodyShort, { as: "div", size: "small", className: "navds-list__item-content" },
55
- title && (react_1.default.createElement(typography_1.Label, { as: "p", size: "small" }, title)),
56
- children)));
52
+ if (listType === "ol" && icon) {
53
+ console.warn("<List />: Icon prop is not supported for ordered lists. Please remove the icon prop.");
54
+ }
55
+ const hasNestedList = (_b = react_1.default.Children.toArray(children)) === null || _b === void 0 ? void 0 : _b.some((child) => { var _a; return ((_a = child === null || child === void 0 ? void 0 : child.type) === null || _a === void 0 ? void 0 : _a.componentType) === "list"; });
56
+ return (react_1.default.createElement(exports.ListItemContext.Provider, { value: { isNested: hasNestedList } },
57
+ react_1.default.createElement("li", Object.assign({}, rest, { ref: ref, className: (0, clsx_1.default)("navds-list__item", className, {
58
+ "navds-list__item--noMargin": hasNestedList,
59
+ }) }),
60
+ listType === "ul" && (react_1.default.createElement("div", { className: (0, clsx_1.default)({
61
+ "navds-list__item-marker--icon": icon,
62
+ "navds-list__item-marker--bullet": !icon,
63
+ }) }, icon ? (icon) : (react_1.default.createElement("svg", { width: "6", height: "6", viewBox: "0 0 6 6", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": true, focusable: false, role: "img" },
64
+ react_1.default.createElement("rect", { width: "6", height: "6", rx: "3", fill: "currentColor" }))))),
65
+ react_1.default.createElement(typography_1.BodyShort, { as: "div", size: "small", className: "navds-list__item-content" },
66
+ title && (react_1.default.createElement(typography_1.Label, { as: "p", size: "small" }, title)),
67
+ children))));
57
68
  });
58
69
  exports.default = exports.ListItem;
@@ -21,8 +21,9 @@ export interface ListProps extends React.HTMLAttributes<HTMLDivElement> {
21
21
  */
22
22
  headingTag?: React.ElementType<any>;
23
23
  }
24
- interface ListComponent extends React.ForwardRefExoticComponent<ListProps> {
24
+ export interface ListComponent extends React.ForwardRefExoticComponent<ListProps> {
25
25
  Item: ListItemType;
26
+ componentType: string;
26
27
  }
27
28
  interface ListContextProps {
28
29
  listType: "ul" | "ol";
package/esm/list/List.js CHANGED
@@ -10,24 +10,28 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import cl from "clsx";
13
- import React, { createContext, forwardRef } from "react";
13
+ import React, { createContext, forwardRef, useContext } from "react";
14
14
  import { BodyShort, Heading } from "../typography";
15
15
  import { useId } from "../util/useId";
16
- import { ListItem } from "./ListItem";
16
+ import { ListItem, ListItemContext } from "./ListItem";
17
17
  export const ListContext = createContext({
18
18
  listType: "ul",
19
19
  });
20
20
  export const List = forwardRef((_a, ref) => {
21
21
  var { children, className, as: ListTag = "ul", title, description, headingTag = "h3" } = _a, rest = __rest(_a, ["children", "className", "as", "title", "description", "headingTag"]);
22
22
  const ariaId = useId();
23
+ const { isNested } = useContext(ListItemContext);
23
24
  return (React.createElement(ListContext.Provider, { value: {
24
25
  listType: ListTag,
25
26
  } },
26
- React.createElement("div", Object.assign({}, rest, { ref: ref, className: cl("navds-list", className) }),
27
+ React.createElement("div", Object.assign({}, rest, { ref: ref, className: cl("navds-list", className, {
28
+ "navds-list--nested": isNested,
29
+ }) }),
27
30
  title && (React.createElement(Heading, { id: `tittel-${ariaId}`, size: "small", as: headingTag }, title)),
28
31
  description && (React.createElement(BodyShort, { id: `description-${ariaId}` }, description)),
29
32
  React.createElement(ListTag, { "aria-labelledby": title && `tittel-${ariaId}`, "aria-describedby": description && `description-${ariaId}` }, children))));
30
33
  });
31
34
  List.Item = ListItem;
35
+ List.componentType = "list";
32
36
  export default List;
33
37
  //# sourceMappingURL=List.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"List.js","sourceRoot":"","sources":["../../src/list/List.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,MAAM,CAAC;AACtB,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAgB,MAAM,YAAY,CAAC;AAgCpD,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAmB;IACzD,QAAQ,EAAE,IAAI;CACf,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,IAAI,GAAG,UAAU,CAC5B,CACE,EAQC,EACD,GAAG,EACH,EAAE;QAVF,EACE,QAAQ,EACR,SAAS,EACT,EAAE,EAAE,OAAO,GAAG,IAAI,EAClB,KAAK,EACL,WAAW,EACX,UAAU,GAAG,IAAI,OAElB,EADI,IAAI,cAPT,qEAQC,CADQ;IAIT,MAAM,MAAM,GAAG,KAAK,EAAE,CAAC;IAEvB,OAAO,CACL,oBAAC,WAAW,CAAC,QAAQ,IACnB,KAAK,EAAE;YACL,QAAQ,EAAE,OAAO;SAClB;QAED,6CAAS,IAAI,IAAE,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,CAAC,YAAY,EAAE,SAAS,CAAC;YAC5D,KAAK,IAAI,CACR,oBAAC,OAAO,IAAC,EAAE,EAAE,UAAU,MAAM,EAAE,EAAE,IAAI,EAAC,OAAO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;YACL,QAAQ,EAAE,OAAO;SAClB;QAED,6CACM,IAAI,IACR,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CAAC,YAAY,EAAE,SAAS,EAAE;gBACrC,oBAAoB,EAAE,QAAQ;aAC/B,CAAC;YAED,KAAK,IAAI,CACR,oBAAC,OAAO,IAAC,EAAE,EAAE,UAAU,MAAM,EAAE,EAAE,IAAI,EAAC,OAAO,EAAC,EAAE,EAAE,UAAU,IACzD,KAAK,CACE,CACX;YACA,WAAW,IAAI,CACd,oBAAC,SAAS,IAAC,EAAE,EAAE,eAAe,MAAM,EAAE,IAAG,WAAW,CAAa,CAClE;YACD,oBAAC,OAAO,uBACW,KAAK,IAAI,UAAU,MAAM,EAAE,sBAC1B,WAAW,IAAI,eAAe,MAAM,EAAE,IAEvD,QAAQ,CACD,CACN,CACe,CACxB,CAAC;AACJ,CAAC,CACe,CAAC;AAEnB,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC;AACrB,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC;AAE5B,eAAe,IAAI,CAAC"}
@@ -12,5 +12,9 @@ export interface ListItemProps extends React.HTMLAttributes<HTMLLIElement> {
12
12
  }
13
13
  export interface ListItemType extends React.ForwardRefExoticComponent<ListItemProps & React.RefAttributes<HTMLLIElement>> {
14
14
  }
15
+ interface ListItemContextProps {
16
+ isNested: boolean;
17
+ }
18
+ export declare const ListItemContext: React.Context<ListItemContextProps>;
15
19
  export declare const ListItem: ListItemType;
16
20
  export default ListItem;
@@ -10,21 +10,32 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import cl from "clsx";
13
- import React, { forwardRef, useContext } from "react";
13
+ import React, { createContext, forwardRef, useContext } from "react";
14
14
  import { BodyShort, Label } from "../typography";
15
15
  import { ListContext } from "./List";
16
+ export const ListItemContext = createContext({
17
+ isNested: false,
18
+ });
16
19
  export const ListItem = forwardRef((_a, ref) => {
20
+ var _b;
17
21
  var { className, children, title, icon } = _a, rest = __rest(_a, ["className", "children", "title", "icon"]);
18
22
  const { listType } = useContext(ListContext);
19
- return (React.createElement("li", Object.assign({}, rest, { ref: ref, className: cl("navds-list__item", className) }),
20
- listType === "ul" && (React.createElement("div", { className: cl({
21
- "navds-list__item-marker--icon": icon,
22
- "navds-list__item-marker--bullet": !icon,
23
- }) }, icon ? (icon) : (React.createElement("svg", { width: "6", height: "6", viewBox: "0 0 6 6", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": true, focusable: false, role: "img" },
24
- React.createElement("rect", { width: "6", height: "6", rx: "3", fill: "currentColor" }))))),
25
- React.createElement(BodyShort, { as: "div", size: "small", className: "navds-list__item-content" },
26
- title && (React.createElement(Label, { as: "p", size: "small" }, title)),
27
- children)));
23
+ if (listType === "ol" && icon) {
24
+ console.warn("<List />: Icon prop is not supported for ordered lists. Please remove the icon prop.");
25
+ }
26
+ const hasNestedList = (_b = React.Children.toArray(children)) === null || _b === void 0 ? void 0 : _b.some((child) => { var _a; return ((_a = child === null || child === void 0 ? void 0 : child.type) === null || _a === void 0 ? void 0 : _a.componentType) === "list"; });
27
+ return (React.createElement(ListItemContext.Provider, { value: { isNested: hasNestedList } },
28
+ React.createElement("li", Object.assign({}, rest, { ref: ref, className: cl("navds-list__item", className, {
29
+ "navds-list__item--noMargin": hasNestedList,
30
+ }) }),
31
+ listType === "ul" && (React.createElement("div", { className: cl({
32
+ "navds-list__item-marker--icon": icon,
33
+ "navds-list__item-marker--bullet": !icon,
34
+ }) }, icon ? (icon) : (React.createElement("svg", { width: "6", height: "6", viewBox: "0 0 6 6", fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": true, focusable: false, role: "img" },
35
+ React.createElement("rect", { width: "6", height: "6", rx: "3", fill: "currentColor" }))))),
36
+ React.createElement(BodyShort, { as: "div", size: "small", className: "navds-list__item-content" },
37
+ title && (React.createElement(Label, { as: "p", size: "small" }, title)),
38
+ children))));
28
39
  });
29
40
  export default ListItem;
30
41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CAAE,aAAa,MAAK,MAAM,CAAA,EAAA,CACtD,CAAC;IAEF,OAAO,CACL,oBAAC,eAAe,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,aAAa,EAAE;QAC1D,4CACM,IAAI,IACR,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,EAAE,CAAC,kBAAkB,EAAE,SAAS,EAAE;gBAC3C,4BAA4B,EAAE,aAAa;aAC5C,CAAC;YAED,QAAQ,KAAK,IAAI,IAAI,CACpB,6BACE,SAAS,EAAE,EAAE,CAAC;oBACZ,+BAA+B,EAAE,IAAI;oBACrC,iCAAiC,EAAE,CAAC,IAAI;iBACzC,CAAC,IAED,IAAI,CAAC,CAAC,CAAC,CACN,IAAI,CACL,CAAC,CAAC,CAAC,CACF,6BACE,KAAK,EAAC,GAAG,EACT,MAAM,EAAC,GAAG,EACV,OAAO,EAAC,SAAS,EACjB,IAAI,EAAC,MAAM,EACX,KAAK,EAAC,4BAA4B,uBAElC,SAAS,EAAE,KAAK,EAChB,IAAI,EAAC,KAAK;gBAEV,8BAAM,KAAK,EAAC,GAAG,EAAC,MAAM,EAAC,GAAG,EAAC,EAAE,EAAC,GAAG,EAAC,IAAI,EAAC,cAAc,GAAG,CACpD,CACP,CACG,CACP;YAED,oBAAC,SAAS,IAAC,EAAE,EAAC,KAAK,EAAC,IAAI,EAAC,OAAO,EAAC,SAAS,EAAC,0BAA0B;gBAClE,KAAK,IAAI,CACR,oBAAC,KAAK,IAAC,EAAE,EAAC,GAAG,EAAC,IAAI,EAAC,OAAO,IACvB,KAAK,CACA,CACT;gBACA,QAAQ,CACC,CACT,CACoB,CAC5B,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,QAAQ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@navikt/ds-react",
3
- "version": "2.4.1",
3
+ "version": "2.4.2",
4
4
  "description": "Aksel react-components for NAV designsystem",
5
5
  "author": "Aksel | NAV designsystem team",
6
6
  "license": "MIT",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@floating-ui/react": "0.17.0",
40
- "@navikt/ds-icons": "^2.4.1",
40
+ "@navikt/ds-icons": "^2.4.2",
41
41
  "@radix-ui/react-tabs": "1.0.0",
42
42
  "@radix-ui/react-toggle-group": "1.0.0",
43
43
  "clsx": "^1.2.1",
package/src/list/List.tsx CHANGED
@@ -1,8 +1,8 @@
1
1
  import cl from "clsx";
2
- import React, { createContext, forwardRef } from "react";
2
+ import React, { createContext, forwardRef, useContext } from "react";
3
3
  import { BodyShort, Heading } from "../typography";
4
4
  import { useId } from "../util/useId";
5
- import { ListItem, ListItemType } from "./ListItem";
5
+ import { ListItem, ListItemContext, ListItemType } from "./ListItem";
6
6
 
7
7
  export interface ListProps extends React.HTMLAttributes<HTMLDivElement> {
8
8
  children: React.ReactNode;
@@ -26,8 +26,10 @@ export interface ListProps extends React.HTMLAttributes<HTMLDivElement> {
26
26
  headingTag?: React.ElementType<any>;
27
27
  }
28
28
 
29
- interface ListComponent extends React.ForwardRefExoticComponent<ListProps> {
29
+ export interface ListComponent
30
+ extends React.ForwardRefExoticComponent<ListProps> {
30
31
  Item: ListItemType;
32
+ componentType: string;
31
33
  }
32
34
 
33
35
  interface ListContextProps {
@@ -53,13 +55,22 @@ export const List = forwardRef<HTMLDivElement, ListProps>(
53
55
  ) => {
54
56
  const ariaId = useId();
55
57
 
58
+ const { isNested } = useContext(ListItemContext);
59
+
60
+
56
61
  return (
57
62
  <ListContext.Provider
58
63
  value={{
59
64
  listType: ListTag,
60
65
  }}
61
66
  >
62
- <div {...rest} ref={ref} className={cl("navds-list", className)}>
67
+ <div
68
+ {...rest}
69
+ ref={ref}
70
+ className={cl("navds-list", className, {
71
+ "navds-list--nested": isNested,
72
+ })}
73
+ >
63
74
  {title && (
64
75
  <Heading id={`tittel-${ariaId}`} size="small" as={headingTag}>
65
76
  {title}
@@ -81,5 +92,6 @@ export const List = forwardRef<HTMLDivElement, ListProps>(
81
92
  ) as ListComponent;
82
93
 
83
94
  List.Item = ListItem;
95
+ List.componentType = "list";
84
96
 
85
97
  export default List;
@@ -1,5 +1,5 @@
1
1
  import cl from "clsx";
2
- import React, { forwardRef, useContext } from "react";
2
+ import React, { createContext, forwardRef, useContext } from "react";
3
3
  import { BodyShort, Label } from "../typography";
4
4
  import { ListContext } from "./List";
5
5
 
@@ -13,7 +13,7 @@ export interface ListItemProps extends React.HTMLAttributes<HTMLLIElement> {
13
13
  */
14
14
  title?: string;
15
15
  /*
16
- * Icon to be used as list marker
16
+ * Icon to be used as list marker for unordered lists.
17
17
  */
18
18
  icon?: React.ReactNode;
19
19
  }
@@ -23,47 +23,73 @@ export interface ListItemType
23
23
  ListItemProps & React.RefAttributes<HTMLLIElement>
24
24
  > {}
25
25
 
26
+ interface ListItemContextProps {
27
+ isNested: boolean;
28
+ }
29
+
30
+ export const ListItemContext = createContext<ListItemContextProps>({
31
+ isNested: false,
32
+ });
33
+
26
34
  export const ListItem: ListItemType = forwardRef(
27
35
  ({ className, children, title, icon, ...rest }, ref) => {
28
36
  const { listType } = useContext(ListContext);
29
37
 
30
- return (
31
- <li {...rest} ref={ref} className={cl("navds-list__item", className)}>
32
- {listType === "ul" && (
33
- <div
34
- className={cl({
35
- "navds-list__item-marker--icon": icon,
36
- "navds-list__item-marker--bullet": !icon,
37
- })}
38
- >
39
- {icon ? (
40
- icon
41
- ) : (
42
- <svg
43
- width="6"
44
- height="6"
45
- viewBox="0 0 6 6"
46
- fill="none"
47
- xmlns="http://www.w3.org/2000/svg"
48
- aria-hidden
49
- focusable={false}
50
- role="img"
51
- >
52
- <rect width="6" height="6" rx="3" fill="currentColor" />
53
- </svg>
54
- )}
55
- </div>
56
- )}
38
+ if (listType === "ol" && icon) {
39
+ console.warn(
40
+ "<List />: Icon prop is not supported for ordered lists. Please remove the icon prop."
41
+ );
42
+ }
57
43
 
58
- <BodyShort as="div" size="small" className="navds-list__item-content">
59
- {title && (
60
- <Label as="p" size="small">
61
- {title}
62
- </Label>
44
+ const hasNestedList = React.Children.toArray(children)?.some(
45
+ (child: any) => child?.type?.componentType === "list"
46
+ );
47
+
48
+ return (
49
+ <ListItemContext.Provider value={{ isNested: hasNestedList }}>
50
+ <li
51
+ {...rest}
52
+ ref={ref}
53
+ className={cl("navds-list__item", className, {
54
+ "navds-list__item--noMargin": hasNestedList,
55
+ })}
56
+ >
57
+ {listType === "ul" && (
58
+ <div
59
+ className={cl({
60
+ "navds-list__item-marker--icon": icon,
61
+ "navds-list__item-marker--bullet": !icon,
62
+ })}
63
+ >
64
+ {icon ? (
65
+ icon
66
+ ) : (
67
+ <svg
68
+ width="6"
69
+ height="6"
70
+ viewBox="0 0 6 6"
71
+ fill="none"
72
+ xmlns="http://www.w3.org/2000/svg"
73
+ aria-hidden
74
+ focusable={false}
75
+ role="img"
76
+ >
77
+ <rect width="6" height="6" rx="3" fill="currentColor" />
78
+ </svg>
79
+ )}
80
+ </div>
63
81
  )}
64
- {children}
65
- </BodyShort>
66
- </li>
82
+
83
+ <BodyShort as="div" size="small" className="navds-list__item-content">
84
+ {title && (
85
+ <Label as="p" size="small">
86
+ {title}
87
+ </Label>
88
+ )}
89
+ {children}
90
+ </BodyShort>
91
+ </li>
92
+ </ListItemContext.Provider>
67
93
  );
68
94
  }
69
95
  );
@@ -117,3 +117,32 @@ export const Icons = {
117
117
  );
118
118
  },
119
119
  };
120
+
121
+ export const Nested = {
122
+ render: () => {
123
+ return (
124
+ <List>
125
+ <List.Item title="Sed Do Eiusmod Tempor Incididunt">
126
+ Beskrivelsen på punkter er nærmere forklart <a href="/">her</a>
127
+ <List>
128
+ <List.Item title="Lorem Ipsum Dolor Sit Amet">
129
+ Beskrivelsen på punkter er nærmere forklart <a href="/">her</a>
130
+ </List.Item>
131
+ <List.Item title="Consectetur Adipiscing Elit">
132
+ Beskrivelsen på punkter er nærmere forklart <a href="/">her</a>
133
+ </List.Item>
134
+ <List.Item>
135
+ Beskrivelsen på punkter er nærmere forklart <a href="/">her</a>
136
+ </List.Item>
137
+ <List.Item>
138
+ Beskrivelsen på punkter er nærmere forklart <a href="/">her</a>
139
+ </List.Item>
140
+ </List>
141
+ </List.Item>
142
+ <List.Item>
143
+ Beskrivelsen på punkter er nærmere forklart <a href="/">her</a>
144
+ </List.Item>
145
+ </List>
146
+ );
147
+ },
148
+ };