import { useMemo, useState } from "react"; import { Accordion, Badge, Button, Code, Group, Popover, ScrollArea, Stack, Text, TextInput } from "@mantine/core"; import { IconComponents, IconSearch } from "@tabler/icons-react"; import { customJsxAuthoringCatalog, getCustomJsxComponentProps } from "../core/component-catalog"; export interface ComponentReferenceMessages { action: string; search: string; empty: string; count(count: number): string; } const enabledComponents = customJsxAuthoringCatalog.components.filter((component) => component.safety !== "denied"); export function ComponentReference({ messages }: { messages: ComponentReferenceMessages }) { const [query, setQuery] = useState(""); const components = useMemo(() => { const normalized = query.trim().toLocaleLowerCase(); if (!normalized) return enabledComponents; return enabledComponents.filter((component) => [ component.name, component.package, component.category, component.description ?? "", ...getCustomJsxComponentProps(component.name).map(({ name, type }) => `${name} ${type}`), ].some((value) => value.toLocaleLowerCase().includes(normalized)), ); }, [query]); return ( setQuery(event.currentTarget.value)} placeholder={messages.search} aria-label={messages.search} leftSection={} /> {components.map((component) => { const props = getCustomJsxComponentProps(component.name); return ( {component.name} {component.bind && bind: {component.bind.type}} {component.category} {component.description && {component.description}} {component.package} · {props.length} props {component.blockedProps.map((prop) => ( {prop.name}: {prop.reason} ))} {props.map((prop) => ( {prop.name} {prop.type} {prop.required ? " · required" : ""} ))} {component.accessibilityRequirements.map((requirement) => ( {requirement} ))} ); })} {components.length === 0 && ( {messages.empty} )} {messages.count(enabledComponents.length)} · Mantine {customJsxAuthoringCatalog.mantineVersion} ); }