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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tomtom-international/web-sdk-plugin-searchbox

v3.2.0

Published

Plugin that provides SearchBox functionality to your map

Downloads

347

Readme

SearchBox Plugin

This plugin provides a search box functionality to your map (@tomtom-international/web-sdk-maps).

As the user starts typing, search results appear in the list below the input field. Results list combines autocomplete and fuzzy search results.

The user keystrokes result in requests to Fuzzy Search and Autocomplete services. A number of calls made to the service can be optimized thanks to the options: idleTimePress and minNumberOfCharacters.

For more details on how to use the configuration options, please refer to the documentation: https://developer.tomtom.com/maps-sdk-web-js/documentation#ttPlugins.SearchBox

Please note that from version 3.0.0 this plugin only works with @tomtom-international/web-sdk-maps@6.*.*, if you are using @tomtom-international/web-sdk-maps@5.*.* please use version 2.*.*

Instalation

Just do:

npm i @tomtom-international/web-sdk-plugin-searchbox

You must also include the search box stylesheet in your project. It's located here:

node_modules/@tomtom-international/web-sdk-plugin-searchbox/dist/SearchBox.css

Usage

There are two ways to include search box into your page.

  1. Embed it into the map.
  2. Get the HTML container and place it wherever you need on your page.

1. Using searchbox with Maps library:

import tt from '@tomtom-international/web-sdk-maps';
import { services } from '@tomtom-international/web-sdk-services';
import SearchBox from '@tomtom-international/web-sdk-plugin-searchbox';

const ttSearchBox = new SearchBox(services, options);
map.addControl(ttSearchBox, 'top-left');

Note, that you need to pass the Tomtom services instance to the search box constructor. The second parameter are the options. They allow you to customize how search box behaves. Options (except searchOptions.key) are not mandatory, we provide default ones. Example options:

{
    idleTimePress: 100,
    minNumberOfCharacters: 0,
    searchOptions: {
        key: '<your-tomtom-search-key>'
        language: 'en-GB'
    },
    autocompleteOptions: {
        key: '<your-tomtom-search-key>'
        language: 'en-GB'
    },
    noResultsMessage: 'No results found.'
}
  • idleTimePress - Search service call delay (in ms) after the last typed character.
  • minNumberOfCharacters - The minimum number of characters to trigger the search call.
  • searchOptions - Options for the fuzzy search service. For full list of options please refer to https://developer.tomtom.com/maps-sdk-web-js/documentation#Services.services.fuzzySearch.
  • autocompleteOptions - Options for the autocomplete service. For full list of options please refer to https://developer.tomtom.com/maps-sdk-web-js/documentation#Services.services.autocomplete. If you pass this option, results list will be extended by the results returned by autocomplete service. When choosen, autocomplete result is used as filter for the fuzzy search.
  • filterSearchResults - Only those fuzzy search results that pass the test implemented in this method will be shown on the results list.
  • noResultsMessage - The message shown when a given query Search service returned no results or they were filtered out.

Using searchbox as independent element

import { services } from '@tomtom-international/web-sdk-services';
import SearchBox from '@tomtom-international/web-sdk-plugin-searchbox';

const ttSearchBox = new SearchBox(services, options);
const searchBoxHTML = ttSearchBox.getSearchBoxHTML();
//Attach searchboxHTML to your page

Handling events

Search box emits 7 different events:

  • tomtom.searchbox.inputrestored - Triggered when the input is restored. This happens when the user uses the arrows to navigate through the suggestions list and navigates back to the input.
  • tomtom.searchbox.resultfocused - Fired when result is focused.
  • tomtom.searchbox.resultscleared - Triggered when the clear button is clicked.
  • tomtom.searchbox.resultselected - Triggered when the user selects an element on the results list. It is fired after either clicking on an element or highlighting it using arrow keys and clicking the Enter button.
  • tomtom.searchbox.resultsfound - Triggered when the search engine finds results.
  • tomtom.searchbox.loadingstarted - Triggered when a request to search services is triggered in the background.
  • tomtom.searchbox.loadingfinished - Triggered when a request to search services is finished(resolved) in the background.

If you want to subscribe for the event:

ttSearchBox.on('tomtom.searchbox.resultsfound', function(data) {
    console.log(data);
});

Updating options programatically

If you have initialized the search box and you want to change options later, you can do the following:

ttSearchBox.getOptions() //if you need old options, you can also retrieve them
ttSearchBox.updateOptions(newOptions)
ttSearchBox.query()

This query method triggers the search with updated options. This is necessary if you want to update results for the user with new options.