|
1 | 1 | import cl from "clsx";
|
2 | 2 | import React, { forwardRef, useContext } from "react";
|
| 3 | +import { useThemeInternal } from "../theme/Theme"; |
3 | 4 | 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"; |
6 | 7 | // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
7 |
| -import type { ListItemProps, ListProps } from "./types"; |
| 8 | +import type { ListItemProps, ListProps } from "./List.types"; |
8 | 9 |
|
9 | 10 | const headingSizeMap: Record<
|
10 | 11 | Exclude<ListProps["size"], undefined>,
|
@@ -56,7 +57,40 @@ export const List = forwardRef<HTMLDivElement, ListProps>(
|
56 | 57 | ) => {
|
57 | 58 | const { size: contextSize } = useContext(ListContext);
|
58 | 59 |
|
| 60 | + const themeContext = useThemeInternal(false); |
| 61 | + |
59 | 62 | 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 | + |
60 | 94 | return (
|
61 | 95 | <ListContext.Provider
|
62 | 96 | value={{
|
|
0 commit comments