npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sanity-search

v1.0.4

Published

A lightweight and configurable search component for Sanity.io and Next.js websites, built with React and TypeScript.

Readme

Sanity Search Component

A lightweight and configurable search component for Sanity.io and Next.js websites, built with React and TypeScript.

✨ Features

  • 🔍 Instant Search with Debouncing
  • 🔥 Highlight Matched Keywords
  • 🎨 Customizable UI & Icons
  • Pluggable Search Query Generator

💻 Demo

Live Demo

🚀 Installation

npm install sanity-search
# or
yarn add sanity-search

🛠 Usage

Basic Implementation

First, create a server action that returns a list of search results.

// actions/search.ts
"use server";
import { createSanitySearchQuery } from "sanity-search";

const MINIMUM_SEARCH_LENGTH = 2;

export default async function search(searchTerm: string) {
  if (!searchTerm || searchTerm.length < MINIMUM_SEARCH_LENGTH) {
    return [];
  }

  try {
    const { query, params } = createSanitySearchQuery({
      documentFragment: `{
        title,
        description,
        body,
        "href": slug.current
      }`,
      documentType: "blog.post",
      searchTerm,
      searchableFields: ["title", "description", "body"],
    });

    const data = await loadQuery<any[]>({
      params,
      query,
    });

    if (!data) {
      return [];
    }

    return data;
  } catch (error) {
    console.error("Error searching blog posts:", error);
    return [];
  }
}

Then, use the SanitySearch component in your search component, passing in the search server action.

// components/search.tsx
"use client";

import Link from "next/link";
import { SanitySearch } from "sanity-search";

import search from "../actions/search";

export default function Search() {
  return (
    <SanitySearch 
      config={{
        behavior: {
          searchDebounceDelay: 500,
          minimumSearchLength: 2,
        },
        ui: {
          placeholder: "Search",
          noResultsText: "No results found. Please try a different search.",
          searchIcon: "🔍",
          loadingIcon: "⏳",
        },
      }} 
      onSearch={search}
      LinkComponent={Link}
    />
  );
}

📌 Props

<SanitySearch />

| Prop | Type | Required | Description | |---------------|-----------------------------------------|----------|-------------| | config | SanitySearchConfig | ✅ | Search behavior & UI config | | onSearch | (searchTerm: string) => Promise<SearchResult[]> | ✅ | Function to fetch search results | | className | string | ❌ | Custom class for styling | | LinkComponent | `React.ComponentType | ❌ | Custom link component |

SanitySearchConfig

| Property | Type | Default | Description | |------------------------|----------------|---------|-------------| | behavior.searchDebounceDelay | number | 500 | Delay before search triggers | | behavior.minimumSearchLength | number | 2 | Min. characters to start searching | | ui.placeholder | string | "Search" | Input placeholder text | | ui.noResultsText | string | "No results found. Please try a different search." | Text when no results | | ui.searchIcon | React.ReactNode | null | Custom search icon | | ui.loadingIcon | React.ReactNode | null | Custom loading icon | | ui.isHighlightEnabled | boolean | true | Highlight search matches |

🔗 API Helpers

createSanitySearchQuery

Generates a structured GROQ query to fetch data from Sanity.io and returns the query and params.

const {query, params} = createSanitySearchQuery({
  documentType: "post",
  documentFragment: "{ title, description, body, href }",
  searchableFields: ["title", "description", "body"],
  searchTerm: "example",
});

🎨 Styling

You can customize the component using classes, here is a list of classes you can use:

  • sanity_search
  • sanity_search__input_container
  • sanity_search__input
  • sanity_search__icon_container
  • sanity_search__dropdown
  • sanity_search__result_item
  • sanity_search__result_title
  • sanity_search__result_description
  • sanity_search__no_results

📜 License

MIT License © 2025 Imad Attif

🌟 Contributions

PRs and feedback are welcome! 🚀