6.8.0 • Published 1 year ago

@justeat/f-searchbox v6.8.0

Weekly downloads
1,060
License
ISC
Repository
github
Last release
1 year ago

f-searchbox

Just Eat's global search box component

Development

Pre-requisites

  • Node v8.9.0 or greater

Install

git clone https://github.com/justeat/f-searchbox.git
cd f-searchbox
yarn install

Commands

  • Build project: npm run build
  • Run tests: npm run test

Vue Component

In this example we create a search component based on the UK tenant configurations.

import Vue from 'vue'
import SearchBox from './src/components/Base'
import { component, copy, service } from './src/tenants/uk'

new Vue({
    el: '#app',
    data: {
        config: component,
        copy,
        service
    },
    components: {
        SearchBox
    },
    template: `
        <search-box
            :config="config"
            :copy="copy"
            :service="service" />
    `
})

Location Service

The service module provides all the necessary functionality to perform autosuggest, location information fetching and custom validation against our preferred location partner(s), i.e. Google Maps, Zipcode Autocomplete.

Example: With validation

import Service from './src/service'

//setup
const service = Service({
  validation: {
    EMPTY_FIELD: (value = '') => !!value.trim(),
    STRING_ERROR: value => typeof value === 'string'
  }
})

// use
service.isValid('EC4M 7RF')   // returns true
service.isValid(5)            // returns ['EMPTY_FIELD', 'STRING_ERROR']

Example: With autosuggest and location details

import Service from './src/service'

// setup
const service = Service({
  autocomplete: 'UK'
})

// use
(async () => {
    const [ firstResult ] = await service.search('EC4M 7RF')
    const details = await service.getLocationDetails(firstResult.place_id)
    console.log(details)
}())

Standalone Use

The component can be used within a webpage without any build setup. Import the distribution build of the desired tenant (e.g. ./dist/uk.js) in your HTML file, then initialise with the global method jeSearchbox.

Example

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>JustEat Global Search Box</title>
  <meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
  <div data-js-searchbox></div>
  <script src="/dist/uk.js"></script>
  <script>jeSearchbox('[data-js-searchbox]')</script>
</body>
</html>

jeSearchbox: Arguments & options

const selector = '#app' // (req) mount to this element
const options = {       // (opt) component settings
  address: '',          // String - override default address field value
  cuisine: '',          // String - override default cuisine field value
  hideShell: false,     // Boolean – hide/show search box shell
  theme: 'base'         // String (base|anz) – overrides default theme if none configured
}

// initialise
jeSearchbox(selector, options)

Testing – Distributions Only

The autosuggest feature and integration testing requires that this component be run on a domain, e.g. localhost rather than the file system. To test locally we begin by installing the serve npm module globally, to host files locally.

npm i -g serve
cd dist
serve

Visiting http://localhost:5000 will show a default search component. To test different distributions, visit dist/index.html and change the script src to the desired tenant code, e.g. it.js, while the jeSearchbox global is available to be configured.

Testing on existing Just Eat codebase

  1. Ensure you're serving the distributions on localhost
  2. Comment out or delete the existing search box markup
  3. Copy the following markup in the deleted content's place
<div data-je-search></div>
<script src="http://localhost:5000/uk.js"></script>
<script>jeSearchbox('[data-je-search]')</script>

Testing in mocked environment

  1. Ensure you're serving the distributions on localhost
  2. Open the browser to the environment with the Just Eat homepage
    • You may have to delete the existing search box markup on the page
    • And delete the script tags containing the current distribution
  3. Copy the following script into the browser console
    • containerSelector is what element you want to place the search box inside
    • tenantCode is what tenant you want to use, e.g. it
    • componentOptions pass the options available to jeSearchbox
!(function () {
    // change as necessary
    const containerSelector = '.hero-banner__content';
    const tenantCode = 'uk';
    const componentOptions = {
        hideShell: true
    };

    // delete old jeSearchbox reference]
    delete jeSearchbox

    // create script
    const script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = `http://localhost:5000/${tenantCode}.js`;
    script.onload = function () {
        // place holding element inside container
        const container = document.querySelector(containerSelector);
        const searchbox = document.createElement('div');
        searchbox.setAttribute('data-js-searchbox', '');
        container.appendChild(searchbox)

        // initialise
        jeSearchbox('[data-js-searchbox]', componentOptions);
    };

    // run
    document.body.appendChild(script);
}());
6.9.1

1 year ago

6.9.0

1 year ago

6.7.1

2 years ago

6.8.0

2 years ago

4.0.0-beta.48

2 years ago

4.0.0-beta.47

3 years ago

4.0.0-beta.44

3 years ago

4.0.0-beta.43

3 years ago

4.0.0-beta.42

3 years ago

4.0.0-beta.41

3 years ago

4.0.0-beta.40

3 years ago

6.7.0

3 years ago

4.0.0-beta.39

3 years ago

4.0.0-beta.38

3 years ago

6.5.0

4 years ago

6.6.1

4 years ago

6.6.0

4 years ago

6.4.0

4 years ago

6.1.0

4 years ago

6.2.0

4 years ago

6.3.0

4 years ago

6.0.0

4 years ago

5.2.0

4 years ago

4.0.0-beta.35

4 years ago

5.0.0

4 years ago

5.1.0

4 years ago

4.0.0-beta.34

4 years ago

5.0.0-beta.0

4 years ago

4.0.0-beta.33

4 years ago

4.0.0-beta.32

4 years ago

4.1.0

4 years ago

4.0.0

4 years ago

3.13.1

4 years ago

3.13.0

4 years ago

3.12.4

4 years ago

4.0.0-beta.30

4 years ago

3.12.3

4 years ago

3.12.1

4 years ago

4.0.0-beta.29

4 years ago

3.12.2

4 years ago

3.12.0

4 years ago

3.11.0

4 years ago

3.10.4

4 years ago

3.10.3

4 years ago

4.0.0-beta.26

4 years ago

3.10.2

4 years ago

3.10.1

4 years ago

4.0.0-beta.24

4 years ago

4.0.0-beta.23

4 years ago

3.10.0

4 years ago

4.0.0-beta.22

4 years ago

4.0.0-beta.20

4 years ago

4.0.0-beta.19

4 years ago

4.0.0-beta.17

4 years ago

4.0.0-beta.15

5 years ago

4.0.0-beta.16

5 years ago

4.0.0-beta.14

5 years ago

4.0.0-beta.13

5 years ago

3.9.0

5 years ago

4.0.0-beta.11

5 years ago

3.8.0

5 years ago

4.0.0-beta.12

5 years ago

3.7.0

5 years ago

4.0.0-beta.9

5 years ago

3.6.0

5 years ago

4.0.0-beta.7

5 years ago

4.0.0-beta.5

5 years ago

3.5.0

5 years ago

3.4.0

5 years ago

3.3.0

5 years ago

3.2.0

5 years ago

3.1.0

5 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.5.2

5 years ago

2.5.1

5 years ago

2.5.0

5 years ago

2.4.0

5 years ago

3.0.0-beta.0

5 years ago

2.3.0

5 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.1

5 years ago

1.51.0

5 years ago

1.52.0

5 years ago

1.49.3

5 years ago

1.49.2

5 years ago

1.49.1

5 years ago

1.48.0

5 years ago

1.47.2

5 years ago

1.47.1

5 years ago

1.47.0

5 years ago

1.46.1

5 years ago

1.45.1

5 years ago

1.46.0

5 years ago

1.45.0

5 years ago

1.44.2

5 years ago

1.44.1

5 years ago

1.44.0

5 years ago

1.43.2

5 years ago

1.43.1

5 years ago

1.43.0

5 years ago

1.42.1

5 years ago

1.42.0

5 years ago

1.41.2

5 years ago

1.41.1

5 years ago

1.41.0

5 years ago

1.39.2

5 years ago

1.40.0

5 years ago

1.37.0

5 years ago

1.35.1

5 years ago

1.35.0

5 years ago

1.33.0

5 years ago

1.32.0

5 years ago

1.30.0

5 years ago

1.29.1

5 years ago

1.29.0

5 years ago

1.28.0

5 years ago

1.25.0

5 years ago

1.25.1

5 years ago

1.23.0

5 years ago

1.21.0

5 years ago

1.19.1

5 years ago

1.19.0

5 years ago

1.18.0

5 years ago

1.17.2

5 years ago

1.17.1

5 years ago

1.17.0

5 years ago

1.16.0

5 years ago

1.15.0

5 years ago

1.14.0

5 years ago

1.13.0

5 years ago

1.12.0

5 years ago

1.11.0

5 years ago

1.10.0

5 years ago

1.7.4

5 years ago

1.7.3

5 years ago

1.7.2

5 years ago

1.7.1

5 years ago

1.7.0

5 years ago

2.0.0

5 years ago

1.6.0

5 years ago

1.5.0

6 years ago

1.4.12

6 years ago

1.4.10

6 years ago

1.4.9

6 years ago

1.4.8

6 years ago

1.4.7

6 years ago

1.4.5

6 years ago

1.4.4

6 years ago

1.4.3

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.7

6 years ago

1.2.6

6 years ago

1.2.5

6 years ago

1.2.4

6 years ago

1.2.3

6 years ago

1.2.2

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

1.0.0-beta.23

6 years ago

1.0.0-beta.21

6 years ago

0.27.1

6 years ago

1.0.0-beta.20

6 years ago

1.0.0-beta.19

6 years ago

0.27.0

6 years ago

1.0.0-beta.18

6 years ago

1.0.0-beta.17

6 years ago

1.0.0-beta.16

6 years ago

0.26.2

6 years ago

1.0.0-beta.15

6 years ago

1.0.0-beta.14

6 years ago

0.26.1

6 years ago

1.0.0-beta.13

6 years ago

1.0.0-beta.12

6 years ago

0.26.0

6 years ago

1.0.0-beta.11

6 years ago

0.22.0-beta.10

6 years ago

0.22.0-beta.9

6 years ago

0.22.0-beta.8

6 years ago

0.22.0-beta.7

6 years ago

0.22.0-beta.6

6 years ago

0.22.0-beta.5

6 years ago

0.25.0

6 years ago

0.24.2

6 years ago

0.22.0-beta.4

6 years ago

0.22.0-beta.3

6 years ago

0.22.0-beta.2

6 years ago

0.22.1

6 years ago

0.22.0

6 years ago

0.22.0-beta.1

6 years ago

0.22.0-beta.0

6 years ago

0.21.0

6 years ago

0.20.0

6 years ago

0.14.0

7 years ago

0.13.0

7 years ago