Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
  <div class="row">
    <div class="col-sm-10 col-sm-offset-1">
      <form action="#" class="form">

        <div class="logo">
          <img src="https://www.placesapi.co.uk/img/placesapi-logo-white.png">
        </div>
        
        <p>Multiple data sources with Algolia Autocomplete.</p>
        <p>Search for areas of London e.g. Lewisham, Peckham, Westminster etc.</p>

        <div id="search-container"></div>

        <br>
        
        <p style="margin-top:10px;">      <p><strong>Note:</strong> You'll need to add your own PlacesAPI key for this demo to function.</p>
        
      </form>
    </div>
  </div>
</div>
              
            
!

CSS

              
                body {
  background: black;
  color: white;
  padding-top: 60px;
}

.logo {
  margin-bottom: 30px;
}

.logo img {
  height: 40px;
}

p {
  margin: 0;
}

.algolia-autocomplete {
  width: 100%;
}

.algolia-autocomplete .aa-input,
.algolia-autocomplete .aa-hint {
  width: 100%;
}

.algolia-autocomplete .aa-hint {
  color: #999;
}

.algolia-autocomplete .aa-dropdown-menu {
  width: 100%;
  background-color: #fff;
  border: 1px solid #999;
  border-top: none;
}

.algolia-autocomplete .aa-dropdown-menu .aa-suggestion {
  cursor: pointer;
  padding: 5px 4px;
}

.algolia-autocomplete .aa-dropdown-menu .aa-suggestion.aa-cursor {
  background-color: #b2d7ff;
}

.algolia-autocomplete .aa-dropdown-menu .aa-suggestion em {
  font-weight: bold;
  font-style: normal;
}

.aa-Source:first-child {
  margin-bottom: 20px;
}

.aa-Source:nth-child(2) .aa-Item {
  background: #137FA2;
  color: #ffffff;
  margin-bottom: 10px;
  padding: 10px;
}

.aa-Source:last-child .aa-Item:hover,
.aa-Source:last-child .aa-Item[aria-selected="true"] {
  color: #dddddd;
}

#search-container {
  margin-top: 30px;
}
              
            
!

JS

              
                const { autocomplete, getAlgoliaResults } = window["@algolia/autocomplete-js"];

const searchClient = algoliasearch(
  "DM340JGS49",
  "ADD_YOUR_API_KEY_HERE"
);

autocomplete({
  container: "#search-container",
  detachedMediaQuery: "none",
  placeholder: "Search for places...",
  getSources() {
    return [
      {
        sourceId: "places",
        getItems({ query }) {
          return getAlgoliaResults({
            searchClient,
            queries: [
              {
                indexName: "places",
                query,
                params: {
                  aroundLatLng: "51.6, 0",
                  aroundRadius: 3000000,
                  filters: 'NOT country_code:"ie" AND NOT country_code:"us"'
                },
              },
            ],
          });
        },
        onSelect: function (event) {
          event.setQuery(
            event.item.name +
            ", " +
            event.item.county +
            ", " +
            event.item.country
          );
        },
        templates: {
          item({ item }) {
            return `${item.name}, ${item.county}, ${item.country}`;
          },
        },
      },
      {
        sourceId: "restaurants",
        getItems({ query }) {
          return [
            {
              label: "McDowell's Clerkenwell",
              info: "Where hungry developers go to feed.",
            },
            {
              label: "McDowell's Ealing",
              info: "Come on down for the best deals in Ealing.",
            },
            {
              label: "McDowell's Epsom",
              info: "The golden arcs await in Epsom.",
            },
            {
              label: "McDowell's Lewisham",
              info: "Burgers and more in Lewisham.",
            },
            {
              label: "McDowell's Peckham",
              info: "New York, Paris, Peckham.",
            },
            {
              label: "McDowell's Tottenham",
              info: "Open late every day, the best food in Tottenham.",
            },
            {
              label: "McDowell's Twickenham",
              info: "Daily specials for the best food in Twickenham.",
            },
            {
              label: "McDowell's Walthamstow",
              info: "East London's flagship McDowell's restaurant.",
            },
            {
              label: "McDowell's Westminster",
              info: "The city's finest burgers in Westminster.",
            },
          ].filter(({ label }) =>
                   label
                   .toLowerCase()
                   .includes(query.toLowerCase())
                  );
        },
        templates: {
          item({ item }) {
            return `${item.label} - ${item.info}`;
          },
        },
      },
    ];
  },
});
              
            
!
999px

Console