import React from "react"; import { Box, Container, IconButton, List, ListItem, ListItemIcon, ListItemText, Tooltip, Typography, useTheme, Link as MuiLink, } from "@mui/material"; import { DocItem } from "../../models/nix"; import CodeIcon from "@mui/icons-material/Code"; import ExpandLessIcon from "@mui/icons-material/ExpandLess"; import LocalLibraryIcon from "@mui/icons-material/LocalLibrary"; import InputIcon from "@mui/icons-material/Input"; import { MarkdownPreview } from "../markdownPreview"; import { CodeHighlight } from "../codeHighlight"; 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(); const prefix = category.split(/([\/.])/gm).at(4) || "builtins"; const libName = category .match(/(?:[a-zA-Z]*)\.nix/gm)?.[0] ?.replace(".nix", ""); const sanitizedName = name.replace("'", "-prime"); const libDocsRef = `https://nixos.org/manual/nixpkgs/stable/#function-library-lib.${libName}.${sanitizedName}`; const builtinsDocsRef = `https://nixos.org/manual/nix/stable/language/builtins.html#builtins-${name}`; return ( {`${id}`} {closeComponent || ( handleClose?.()} > )} {prefix !== "builtins" && id.includes("lib.") && ( {`short form: lib.${name}`} )} {"github:NixOS/nixpkgs/" + category.replace("./", "")} ) : ( "github:NixOS/nix/" + category.replace("./", "") ) } secondary={ {Array.isArray(description) ? description.map((d, idx) => ( )) : description && ( )} } /> ) : ( "no type provided yet." ) } primary="function signature " /> {example && ( Example } secondary={ } /> )} ); };