Search by Algolia
What is end-to-end AI search?
ai

What is end-to-end AI search?

Simplicity is critical for search engines, but building one that enables that simplicity is complex.  Over the last 20+ years ...

Abhijit Mehta

Director of Product Management

Comparing AI search solutions in a crowded market landscape
ai

Comparing AI search solutions in a crowded market landscape

Many new AI-powered search solutions have been released this year, and each promises to provide great results, but as ...

Andy Jones

Marketing Campaign Production Manager

What is B2B ecommerce? Everything you need to know
e-commerce

What is B2B ecommerce? Everything you need to know

When you think of “customer experience,” what comes to mind? People, right? Specifically, consumers. Retail customers. That’s easy; the ...

Vincent Caruana

Sr. SEO Web Digital Marketing Manager

What is ecommerce merchandising? Key components and best practices
e-commerce

What is ecommerce merchandising? Key components and best practices

A potential customer is about to land on the home page of your ecommerce platform, curious to see what cool ...

Catherine Dee

Search and Discovery writer

AI-powered search: From keywords to conversations
ai

AI-powered search: From keywords to conversations

By now, everyone’s had the opportunity to experiment with AI tools like ChatGPT or Midjourney and ponder their inner ...

Chris Stevenson

Director, Product Marketing

Vector vs Keyword Search: Why You Should Care
ai

Vector vs Keyword Search: Why You Should Care

Search has been around for a while, to the point that it is now considered a standard requirement in many ...

Nicolas Fiorini

Senior Machine Learning Engineer

What is AI-powered site search?
ai

What is AI-powered site search?

With the advent of artificial intelligence (AI) technologies enabling services such as Alexa, Google search, and self-driving cars, the ...

John Stewart

VP Corporate Marketing

What is a B2B marketplace?
e-commerce

What is a B2B marketplace?

It’s no secret that B2B (business-to-business) transactions have largely migrated online. According to Gartner, by 2025, 80 ...

Vincent Caruana

Sr. SEO Web Digital Marketing Manager

3 strategies for B2B ecommerce growth: key takeaways from B2B Online - Chicago
e-commerce

3 strategies for B2B ecommerce growth: key takeaways from B2B Online - Chicago

Twice a year, B2B Online brings together industry leaders to discuss the trends affecting the B2B ecommerce industry. At the ...

Elena Moravec

Director of Product Marketing & Strategy

Deconstructing smart digital merchandising
e-commerce

Deconstructing smart digital merchandising

This is Part 2 of a series that dives into the transformational journey made by digital merchandising to drive positive ...

Benoit Reulier
Reshma Iyer

Benoit Reulier &

Reshma Iyer

The death of traditional shopping: How AI-powered conversational commerce changes everything
ai

The death of traditional shopping: How AI-powered conversational commerce changes everything

Get ready for the ride: online shopping is about to be completely upended by AI. Over the past few years ...

Aayush Iyer

Director, User Experience & UI Platform

What is B2C ecommerce? Models, examples, and definitions
e-commerce

What is B2C ecommerce? Models, examples, and definitions

Remember life before online shopping? When you had to actually leave the house for a brick-and-mortar store to ...

Catherine Dee

Search and Discovery writer

What are marketplace platforms and software? Why are they important?
e-commerce

What are marketplace platforms and software? Why are they important?

If you imagine pushing a virtual shopping cart down the aisles of an online store, or browsing items in an ...

Vincent Caruana

Sr. SEO Web Digital Marketing Manager

What is an online marketplace?
e-commerce

What is an online marketplace?

Remember the world before the convenience of online commerce? Before the pandemic, before the proliferation of ecommerce sites, when the ...

Catherine Dee

Search and Discovery writer

10 ways AI is transforming ecommerce
e-commerce

10 ways AI is transforming ecommerce

Artificial intelligence (AI) is no longer just the stuff of scary futuristic movies; it’s recently burst into the headlines ...

Catherine Dee

Search and Discovery writer

AI as a Service (AIaaS) in the era of "buy not build"
ai

AI as a Service (AIaaS) in the era of "buy not build"

Imagine you are the CTO of a company that has just undergone a massive decade long digital transformation. You’ve ...

Sean Mullaney

CTO @Algolia

By the numbers: the ROI of keyword and AI site search for digital commerce
product

By the numbers: the ROI of keyword and AI site search for digital commerce

Did you know that the tiny search bar at the top of many ecommerce sites can offer an outsized return ...

Jon Silvers

Director, Digital Marketing

Using pre-trained AI algorithms to solve the cold start problem
ai

Using pre-trained AI algorithms to solve the cold start problem

Artificial intelligence (AI) has quickly moved from hot topic to everyday life. Now, ecommerce businesses are beginning to clearly see ...

Etienne Martin

VP of Product

Looking for something?

facebookfacebooklinkedinlinkedintwittertwittermailmail

When crafting a search interface, it’s often enough to use what comes prepackaged with Algolia’s InstantSearch libraries. Each library comes in a different flavor of JavaScript for your ease of use. Each one has all the main pieces you need to craft a strong UI.

Sometimes you want to go beyond what’s available.

At that point, you’re presented with two options: craft your own with our connector APIs or find a pre-built custom widget.

It should come as no surprise to anyone that knows me that when presented with wanting a React date picker, I wanted to write as little code as possible to make it work, but I also wanted the best UI possible for Santa. When it came to bonus challenge number 5, I needed something extra. My first stop? The Algolia Code Exchange!

After a quick search around date components, I found exactly what I needed: the aptly-named @algolia/react-instantsearch-widget-date-range-picker! There’s also a VanillaJS version if you’re not using React.

Setting up the project

If you’d like to follow along, you’ll need to install a new React InstantSearch project. The easiest way to do that is to run the following command:

 npx create-instantsearch-app concert-search \
 --app-id latency \
 --api-key 059c79ddd276568e990286944276464a \
 --index-name concert_events_instantsearchjs \
 --template "React InstantSearch"

This monster command will set up a React InstantSearch project and connect it to Algolia’s hosted concert Index. Change directory into the created folder and run yarn start for a solid starting point.

At this point, you’ve got a full search experience for a set of concerts.

If you want to filter by date, you could set up a <RefinementList> component and set its attribute prop to date, but those dates are Unix timestamps (for easiest comparisons). This isn’t ideal for the user experience. Let’s make that better.

Installing and configuring the widget

To get the date range picker up and running, we need to install a couple of dependencies.

npm install @algolia/react-instantsearch-widget-date-range-picker @duetds/date-picker

This will install the official Algolia React Date picker widget and its dependency the Duet Date picker.

From here, we need to import the packages into our src/App.js file and initialize the Duet Date Picker for use.

// Add right after the imports included in the create-instantsearch-app code

import { DateRangePicker } from '@algolia/react-instantsearch-widget-date-range-picker';  
import { defineCustomElements } from "@duetds/date-picker/dist/loader";

// Defines the custom elements from the date picker for use on the window object  
defineCustomElements(window);

Now that these packages are imported, we’re ready to get this on the page.

Adding the date range picker

To add the picker to the page, we need to select a spot within the <InstantSearch> component. The base of the app is a search-panel. By default, all we have inside this is the results, but we can add a filter panel, as well.

<InstantSearch searchClient={searchClient} indexName="concert_events_instantsearchjs">  
  <div className="search-panel">
    <div className="search-panel__filters"> 
      <DateRangePicker attribute="date" />
    </div>

    <div className="search-panel__results">

      //... Results code

    </div>
  </div>
</InstantSearch>

The DateRangePicker accepts an attribute prop. This prop accepts a date-based attribute from the hits in our Index.

Quick note: The DateRangePicker accepts a Unix timestamp with milliseconds since the Epoch, not seconds. Depending on your data structure, you may need to create a secondary timestamp in your data.

When you view the rendered page, you should now have a date picker. There are a few small UI snags to clean up.

The Duet Date picker uses a slew of CSS Custom Properties for much of its styling. At the start of our src/App.css file, we need to paste those in and configure for our app (as appropriate).

:root {  
  --duet-color-primary: #3c4ee0;  
  --duet-color-text: #333;  
  --duet-color-text-active: #fff;  
  --duet-color-placeholder: #666;  
  --duet-color-button: #f5f5f5;  
  --duet-color-surface: #fff;  
  --duet-color-overlay: rgba(0, 0, 0, 0.8);  
  --duet-color-border: #d6d6e7;  

  --duet-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,  
  Arial, sans-serif;  
  --duet-font-normal: 400;  
  --duet-font-bold: 600;  

  --duet-radius: 3px;  
  --duet-z-index: 600;  
}

The two picker areas are a little close together still, so let’s fix that with a little CSS, as well. This can go in src/App.css but should be closer to the bottom. There are many ways to get the space between the two items, the quick and easy solution is to use CSS Grid and the gap property.

.date-range-picker {  
  display: grid;  
  gap: 1rem;  
}

And with that, we have a functioning, user-friendly date picker. No more dealing with Unix timestamps and conversions.

Take this further

This works great in the small sample dataset, but can also be brought into any Algolia InstantSearch application. If you’re looking to take this example further, create a better UI around each Hit by editing the hit component in src/App.js. You could also show the current filters applied with the CurrentRefinements component.

About the authors
Bryan Robinson

Senior Developer Relations Specialist

githubtwitter
Chuck Meyer

Sr. Developer Relations Engineer

githubtwitter

Recommended Articles

Powered byAlgolia Algolia Recommend

Adding trending recommendations to your existing e-commerce store
engineering

Ashley Huynh

Building a Store Locator in React using Algolia, Mapbox, and Twilio – Part 2
engineering

Clément Sauvage

Software Engineer, Freelance

How to personalize search results and recommendations
engineering

Ashley Huynh