Skip to content

Repository files navigation

Norse Search Widget

An embeddable search widget built with Preact, Vite, and Vanilla Extract. This widget can be integrated into any website to provide a customizable search interface.

Features

  • 🚀 Built with Preact for minimal bundle size
  • 🎨 Styled with Vanilla Extract for type-safe, zero-runtime CSS
  • 📦 Bundled with Vite for optimal performance
  • 🔌 Framework-agnostic - works with any website
  • 🎨 Customizable styles - no Shadow DOM, easy to override with CSS
  • 🌐 Configurable per tenant (colors, border radius, text)
  • 📱 Responsive design

Usage

Using UMD Build (Direct Script Tag)

The simplest way to use the widget is with automatic initialization:

<!DOCTYPE html>
<html>
  <head>
    <title>Search Widget Demo</title>
    <!-- Import widget styles -->
    <link
      rel="stylesheet"
      href="https://search-widget.c211.io/latest/search-widget.css"
    />
  </head>
  <body>
    <!-- Container for the widget with tenant ID, API domain, and locale -->
    <div
      id="search-widget"
      tid="your-tenant-id"
      d="https://your-domain.com"
      l="en"
      wid="your-widget-id"
      st="_blank"
      ml="Search for resources at our partner, 211"
    ></div>

    <!-- Load the widget script - it will auto-initialize -->
    <script src="https://search-widget.c211.io/latest/search-widget.umd.js"></script>
  </body>
</html>

The widget will automatically detect the following attributes:

  • tid (required) - Tenant ID
  • d (required) - Domain
  • l (optional) - Locale (defaults to "en")
  • wid (optional) - Widget ID used for analytics tracking
  • st (optional) - Search target (e.g., "_blank", "_self", "_parent", "_top"; defaults to "_blank")
  • ml (optional) - Modal label text to display above search inputs (e.g., "Search for resources at our partner, 211")

The widget will fetch the tenant configuration from the specified domain before rendering. The locale defaults to "en" if not specified.

Changing Locale Dynamically

The widget fetches locale-specific configuration from the CMS when it mounts. To update the locale, the widget needs to be unmounted and remounted with the new locale setting.

A convenient method is exposed on window.searchWidget that handles this automatically:

// Update the widget to Spanish
// This will unmount the current instance and remount with Spanish locale
window.searchWidget.updateLocale("es");

Customizing Styles

The widget uses CSS variables for theming and does not use Shadow DOM, making it easy to customize with your own CSS:

<style>
  /* Override primary color and border radius via CSS variables */
  #search-widget {
    --widget-primary: #764ba2;
    --widget-radius: 12px;
  }

  /* Or target specific widget elements by ID */
  #sw-container {
    background-color: #764ba2 !important;
    padding: 2rem !important;
  }
</style>

Development

Prerequisites

  • Node.js (v24 or higher recommended)
  • npm or yarn

Setup

  1. Clone the repository:
git clone https://github.com/211-Connect/Norse-Search-Widget.git
cd Norse-Search-Widget
  1. Install dependencies:
yarn
  1. Build widget in watch mode:
yarn dev
  1. Serve demo page (index.html) to show search widget:
yarn serve

This will start a local server at http://localhost:4173 with the demo page.

Build

To build the widget for production:

npm run build
# or
yarn build

The built files will be in the dist directory:

  • search-widget.umd.js - UMD build for direct script inclusion
  • search-widget.es.js - ES module build for modern bundlers
  • search-widget.css - Widget styles (required)
  • index.html - demonstration page
  • index.css - styles for the demonstration page

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

Embeddable 211 search widget for any website. Framework-agnostic, accessible, multi-language support, and tiny bundle size. Works with WordPress, React, Vue, or vanilla HTML.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages