import React, { useEffect } from "react"; import { Box, Container, IconButton, List, ListItem, ListItemIcon, ListItemText, Tooltip, Typography, useTheme, Link as MuiLink, } from "@mui/material"; import Highlight from "react-highlight"; import LocalLibraryIcon from "@mui/icons-material/LocalLibrary"; import InputIcon from "@mui/icons-material/Input"; import { DocItem } from "../../types/nix"; import CodeIcon from "@mui/icons-material/Code"; import ReactMarkdown from "react-markdown"; import ExpandLessIcon from "@mui/icons-material/ExpandLess"; import styles from "./preview.module.css"; import rehypeHighlight from "rehype-highlight"; import nix from "highlight.js/lib/languages/nix"; import Link from "next/link"; import { idText } from "typescript"; import { TrendingUpSharp } from "@mui/icons-material"; interface PreviewProps { docItem: DocItem; closeComponent?: React.ReactNode; handleClose?: () => void; } export const Preview = (props: PreviewProps) => { const { docItem, handleClose, closeComponent = undefined } = props; const { name, description, category, example, fn_type, id } = docItem; const theme = useTheme(); useEffect(() => { if (theme.palette.mode === "dark") { // @ts-ignore - dont check type of css module import("highlight.js/styles/github-dark.css"); } else { // @ts-ignore - dont check type of css module import("highlight.js/styles/github.css"); } }, [theme]); const prefix = category.split(/([\/.])/gm).at(4) || "builtins"; const libName = category .match(/(?:[a-zA-Z]*)\.nix/gm)?.[0] ?.replace(".nix", ""); const libDocsRef = `https://nixos.org/manual/nixpkgs/stable/#function-library-lib.${libName}.${name}`; const builtinsDocsRef = `https://nixos.org/manual/nix/stable/language/builtins.html#builtins-${name}`; return ( {`${id}`} {closeComponent || ( handleClose?.()} > )} {prefix !== "builtins" && ( {`short form: lib.${name}`} )} {"github:NixOS/nixpkgs/" + category.replace("./", "")} ) : ( "github:NixOS/nix/" + category.replace("./", "") ) } secondary={ {Array.isArray(description) ? description.map((d, idx) => ( {d} )) : description && ( {description} )} } /> {example && ( Example } secondary={ pre": { width: "100%", }, }} > {example} } /> )} ); };