UNPKG

@navikt/ds-react

Version:

React components from the Norwegian Labour and Welfare Administration.

66 lines 3.32 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 React, { forwardRef, useContext } from "react"; import { useRenameCSS, useThemeInternal } from "../theme/Theme.js"; import { BodyLong, BodyShort, Heading } from "../typography/index.js"; import { ListItem } from "./List.Item.js"; import { ListContext } from "./List.context.js"; const headingSizeMap = { small: "xsmall", medium: "small", large: "medium", }; /** * A list component * * @see [📝 Documentation](https://aksel.nav.no/komponenter/core/list) * @see 🏷️ {@link ListProps | Props} * * @example * ```jsx * <List> * <List.Item>Coffee</List.Item> * <List.Item>Tea</List.Item> * <List.Item>Milk</List.Item> * </List> * ``` */ export const List = forwardRef((_a, ref) => { var { children, className, as: ListTag = "ul", title, description, headingTag, size, "aria-label": _ariaLabel, "aria-labelledby": _ariaLabelledBy } = _a, rest = __rest(_a, ["children", "className", "as", "title", "description", "headingTag", "size", "aria-label", "aria-labelledby"]); const { size: contextSize } = useContext(ListContext); const { cn } = useRenameCSS(); const themeContext = useThemeInternal(false); const listSize = size !== null && size !== void 0 ? size : contextSize; if (themeContext === null || themeContext === void 0 ? void 0 : themeContext.isDarkside) { if (process.env.NODE_ENV !== "production" && (title || description || headingTag)) { console.warn("List: title, description and headingTag are deprecated and will not work with updated theme for Aksel."); } return (React.createElement(ListContext.Provider, { value: { listType: ListTag, size: listSize, } }, React.createElement(BodyLong, Object.assign({ as: "div" }, rest, { size: listSize, ref: ref, className: cn("navds-list", `navds-list--${listSize}`, className) }), React.createElement(ListTag, { role: "list", "aria-label": _ariaLabel, "aria-labelledby": _ariaLabelledBy }, children)))); } return (React.createElement(ListContext.Provider, { value: { listType: ListTag, size: listSize, } }, React.createElement(BodyLong, Object.assign({ as: "div" }, rest, { size: listSize, ref: ref, className: cn("navds-list", `navds-list--${listSize}`, className) }), title && (React.createElement(Heading, { size: headingSizeMap[listSize], as: headingTag !== null && headingTag !== void 0 ? headingTag : "h3" }, title)), description && React.createElement(BodyShort, { size: listSize }, description), React.createElement(ListTag, { role: "list", "aria-label": _ariaLabel, "aria-labelledby": _ariaLabelledBy }, children)))); }); List.Item = ListItem; export default List; //# sourceMappingURL=List.js.map