UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

82 lines (81 loc) 3.15 kB
"use client"; import { rem } from "../../core/utils/units-converters/rem.mjs"; import { noop } from "../../core/utils/noop/noop.mjs"; import { getFontSize, getRadius } from "../../core/utils/get-size/get-size.mjs"; import { createVarsResolver } from "../../core/styles-api/create-vars-resolver/create-vars-resolver.mjs"; import { useProps } from "../../core/MantineProvider/use-props/use-props.mjs"; import { useStyles } from "../../core/styles-api/use-styles/use-styles.mjs"; import { factory } from "../../core/factory/factory.mjs"; import { Box } from "../../core/Box/Box.mjs"; import { UnstyledButton } from "../UnstyledButton/UnstyledButton.mjs"; import TableOfContents_module_default from "./TableOfContents.module.mjs"; import { assignRef, useId, useScrollSpy } from "@mantine/hooks"; import { jsx } from "react/jsx-runtime"; //#region packages/@mantine/core/src/components/TableOfContents/TableOfContents.tsx const defaultProps = { getControlProps: ({ data }) => ({ children: data.value }) }; const varsResolver = createVarsResolver((theme, { color, size, variant, autoContrast, depthOffset, radius }) => { const colors = theme.variantColorResolver({ color: color || theme.primaryColor, theme, variant: variant || "filled", autoContrast }); return { root: { "--toc-bg": variant !== "none" ? colors.background : void 0, "--toc-color": variant !== "none" ? colors.color : void 0, "--toc-size": getFontSize(size), "--toc-depth-offset": rem(depthOffset), "--toc-radius": getRadius(radius) } }; }); const TableOfContents = factory((_props) => { const props = useProps("TableOfContents", defaultProps, _props); const { classNames, className, style, styles, unstyled, vars, color, autoContrast, scrollSpyOptions, initialData, getControlProps, minDepthToOffset, depthOffset, variant, radius, reinitializeRef, attributes, ...others } = props; const getStyles = useStyles({ name: "TableOfContents", classes: TableOfContents_module_default, props, className, style, classNames, styles, unstyled, attributes, vars, varsResolver }); const idBase = useId(); const spy = useScrollSpy(scrollSpyOptions); assignRef(reinitializeRef, spy.reinitialize); const controls = (spy.initialized ? spy.data : initialData || []).map((data, index) => { const controlProps = getControlProps?.({ active: index === spy.active, data: { ...data, getNode: data.getNode || noop } }); return /* @__PURE__ */ jsx(UnstyledButton, { __vars: { "--depth-offset": `${data.depth - (minDepthToOffset || 1)}` }, "data-active": index === spy.active || void 0, variant, ...controlProps, ...getStyles("control", { className: controlProps?.className, style: controlProps?.style }) }, data.id || `${idBase}-${index}`); }); return /* @__PURE__ */ jsx(Box, { variant, ...getStyles("root"), ...others, children: controls }); }); TableOfContents.displayName = "@mantine/core/TableOfContents"; TableOfContents.classes = TableOfContents_module_default; TableOfContents.varsResolver = varsResolver; //#endregion export { TableOfContents }; //# sourceMappingURL=TableOfContents.mjs.map