Skip to content

Commit 2bba7af

Browse files
authored
[List] Deprecate listprops title, headingTag and description (#3537)
* 🔥 Deprecated title, headingTag and description for List * 📝 changeset
1 parent 8f9f313 commit 2bba7af

File tree

7 files changed

+51
-14
lines changed

7 files changed

+51
-14
lines changed

.changeset/lemon-falcons-retire.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@navikt/ds-react": minor
3+
---
4+
5+
List: Marked `title`, `headingTag` and `description` properties as deprecated. These will not be supported in future versions and should be migrated from when possible.

@navikt/core/css/darkside/list.darkside.css

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
.navds-list ul,
22
.navds-list ol {
33
padding: 0;
4-
margin-block: var(--ax-space-16);
5-
}
6-
7-
.navds-list--small ul,
8-
.navds-list--small ol {
9-
margin-block: var(--ax-space-12);
4+
margin: 0;
105
}
116

127
.navds-list {

@navikt/core/react/src/list/ListItem.tsx @navikt/core/react/src/list/List.Item.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import cl from "clsx";
22
import React, { forwardRef, useContext } from "react";
33
import { BodyLong } from "../typography";
4-
import { ListContext } from "./context";
5-
import type { ListItemProps } from "./types";
4+
import { ListContext } from "./List.context";
5+
import type { ListItemProps } from "./List.types";
66

77
/**
88
* @see 🏷️ {@link ListItemProps}

@navikt/core/react/src/list/context.ts @navikt/core/react/src/list/List.context.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createContext } from "react";
2-
import { ListProps } from "./types";
2+
import { ListProps } from "./List.types";
33

44
interface ListContextProps {
55
listType: Exclude<ListProps["as"], undefined>;

@navikt/core/react/src/list/List.tsx

+37-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import cl from "clsx";
22
import React, { forwardRef, useContext } from "react";
3+
import { useThemeInternal } from "../theme/Theme";
34
import { BodyLong, BodyShort, Heading, HeadingProps } from "../typography";
4-
import { ListItem } from "./ListItem";
5-
import { ListContext } from "./context";
5+
import { ListItem } from "./List.Item";
6+
import { ListContext } from "./List.context";
67
// eslint-disable-next-line @typescript-eslint/no-unused-vars
7-
import type { ListItemProps, ListProps } from "./types";
8+
import type { ListItemProps, ListProps } from "./List.types";
89

910
const headingSizeMap: Record<
1011
Exclude<ListProps["size"], undefined>,
@@ -56,7 +57,40 @@ export const List = forwardRef<HTMLDivElement, ListProps>(
5657
) => {
5758
const { size: contextSize } = useContext(ListContext);
5859

60+
const themeContext = useThemeInternal(false);
61+
5962
const listSize = size ?? contextSize;
63+
64+
if (themeContext) {
65+
if (
66+
process.env.NODE_ENV !== "production" &&
67+
(title || description || headingTag)
68+
) {
69+
console.warn(
70+
"List: title, description and headingTag are deprecated and will not work with updated theme for Aksel.",
71+
);
72+
}
73+
74+
return (
75+
<ListContext.Provider
76+
value={{
77+
listType: ListTag,
78+
size: listSize,
79+
}}
80+
>
81+
<BodyLong
82+
as="div"
83+
{...rest}
84+
size={listSize}
85+
ref={ref}
86+
className={cl("navds-list", `navds-list--${listSize}`, className)}
87+
>
88+
<ListTag role="list">{children}</ListTag>
89+
</BodyLong>
90+
</ListContext.Provider>
91+
);
92+
}
93+
6094
return (
6195
<ListContext.Provider
6296
value={{

@navikt/core/react/src/list/types.ts @navikt/core/react/src/list/List.types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ export interface ListProps extends React.HTMLAttributes<HTMLDivElement> {
77
as?: "ul" | "ol";
88
/**
99
* List heading title.
10+
* @deprecated Prop will be removed in future versions.
1011
*/
1112
title?: string;
1213
/**
1314
* List heading description.
15+
* @deprecated Prop will be removed in future versions.
1416
*/
1517
description?: string;
1618
/**
1719
* Allows setting a different HTML h-tag.
1820
* @default "h3"
21+
* @deprecated Prop will be removed in future versions.
1922
*/
2023
headingTag?: React.ElementType<any>;
2124
/**

@navikt/core/react/src/list/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"use client";
22
export { default as List } from "./List";
3-
export type { ListProps, ListItemProps } from "./types";
4-
export { default as ListItem } from "./ListItem";
3+
export type { ListProps, ListItemProps } from "./List.types";
4+
export { default as ListItem } from "./List.Item";

0 commit comments

Comments
 (0)