Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

search-modal

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

search-modal

Vanilla JS Search Modal

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-82.14%
Maintainers
1
Weekly downloads
 
Created
Source

Search Modal

This is a simple search modal that can be used in any project. It is built with vanilla JavaScript and CSS.

Installation

yarn add search-modal or npm install search-modal

Configuration

const button = document.querySelector('button.open-search-modal');
    const instance = window.SearchModal({
        // initialize the search modal 
        autoInit: true,
        searchUrl: "", // to search from server 
        searchKey: "query",
        // only applicable when the `searchUrl` is not provided, to search from static data or preloaded data 
        data:[
            {
                title: "Example",
                category: "Category",
                summary: "Summary of example one",
                url: "/example"
            },
            {
                title: "Example 2",
                category: "Category",
                summary: "Another brief example",
                url: "/example-2"
            }
        ],
        // transform the data 
        transform: (data) => data.map(item=>({
            title: item.title, 
            category: item.category, 
            excerpt: item.summary, 
            url: item.url,
        })),
        callback: (event, data) => {
            console.log({ event, data });
        }
    });
    button.addEventListener('click', () => {
        instance.open();
    });

unpkg usage by @dandv


<link rel="stylesheet" href="https://search-modal.msar.me/dist/style.css">
<script type="module">
  import SearchModal from 'https://unpkg.com/search-modal?module';
  const instance = SearchModal({ ... });

  // Activate on Cmd/Ctrl+K
  document.addEventListener("keydown", (event) => {
    if ((event.ctrlKey || event.metaKey) && event.key === "k") {
      event.preventDefault();
      instance.open();
    }
  });
</script>

Example

demo

Demo

To Do

  • Add documentation
  • Proper example

History

This project was inspired from by algolia DocSearch modal which is tightly binded with algolia, that's why we write this package to provide smooth search experience. The design provided by Atiqur Rahman and developed by Saiful Alam

Keywords

FAQs

Package last updated on 12 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc