"use client" import * as Icons from "@medusajs/icons" import { Container, Input, Text } from "@medusajs/ui" import clsx from "clsx" import { CopyButton } from "docs-ui" import * as React from "react" const iconNames = Object.keys(Icons).filter((name) => name !== "default") const IconSearch = () => { const [query, setQuery] = React.useState("") return (
setQuery(e.target.value)} />
) } const SearchResults = ({ query = "" }: { query?: string }) => { const cleanQuery = escapeStringRegexp(query.trim().replace(/\s/g, " ")) const results = iconNames.filter((name) => new RegExp(`\\b${cleanQuery}`, "gi").test(name) ) if (results.length === 0) { return (
No results found for{" "} {query}
) } return (
{results.map((name) => { return (
Icon named {name}
{React.createElement(Icons[name as keyof typeof Icons])}
) })}
) } // https://github.com/sindresorhus/escape-string-regexp/blob/main/index.js function escapeStringRegexp(string: unknown) { if (typeof string !== "string") { throw new TypeError("Expected a string") } return string.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d") } export { IconSearch }