4.0.0-beta.29 • Published 5 years ago

@justeat/f-searchbox v4.0.0-beta.29

Weekly downloads
1,060
License
Apache-2.0
Repository
github
Last release
5 years ago

PLEASE DO NOT USE THE BETA VERSION OF THIS COMPONENT IN PRODUCTION YET.


npm version CircleCI Coverage Status Known Vulnerabilities

Usage

  1. Install the module using NPM or Yarn:

    yarn add @justeat/f-searchbox
    npm install @justeat/f-searchbox
  2. Import the component

    You can import it in your Vue SFC like this (please note that styles have to be imported separately):

    import VueSearchbox from '@justeat/f-searchbox';
    import '@justeat/f-searchbox/dist/f-searchbox.css';
    
    export default {
        components: {
            VueSearchbox
        }
    }

    If you are using Webpack, you can import the component dynamically to separate the vue-searchbox bundle from the main bundle.client.js:

    import '@justeat/f-searchbox/dist/f-searchbox.css';
    
    export default {
        components: {
            ...
            VueSearchbox: () => import(/* webpackChunkName: "vue-searchbox" */ '@justeat/f-searchbox')
        }
    }

Development

It is recommended to run the following commands at the root of the monorepo in order to install dependencies and allow you to view components in isolation via Storybook.

# cd ./fozzie-components
yarn install

## Testing
Unit / Integration / Contract

```bash
# Run Unit / Integration / Contract tests for all components
cd ./fozzie-components
yarn test

OR

# Run Unit / Integration / Contract tests for f-searchbox
cd ./fozzie-components/packages/f-searchbox
yarn test

Component Tests

# Run Component tests for all components
# Note: Ensure Storybook is not running when running the following commands
cd ./fozzie-components

yarn storybook:build
yarn storybook:serve-static
yarn test-component:chrome

OR

# Run Component tests for f-searchbox
# Note: Ensure Storybook is not running when running the following commands
cd ./fozzie-components/packages/f-searchbox
yarn test-component:chrome

Documentation to be completed once module is in stable state.

Configuration

Vuex namespacing

The Vuex store in this application uses fSearchboxModule as its namespace. When registering modules in your own application please be mindful that naming a Vuex store in your application the same as the one that's registered here will cause Vuex errors.

Config example

To apply these configs, pass them through as part of an optional config prop.

E.g.

<template>
    <vue-search-box
        locale="en-GB"
        :config="{
            isShellHidden: true,
            shouldSetCookies: false
        }" />
</template>
const config = {                 // (opt) component settings
  address: '',                    // String - override default address field value
  cuisine: '',                    // String - override default cuisine field value
  isShellHidden: false,           // Boolean – hide/show search box shell
  isCompressed: false,            // Boolean - hide/show compressed searchbox
  query: '',                      // String - override default query field value
  queryParams: {},                // Object - Query parameter overrides as key value pairs
  onSubmit: a => void,            // Function - called when user selects a valid address, prevents f-searchbox from generating and submitting a custom post request and instead allows the consuming app to handle its own custom submit.
  shouldSetCookies: false,              // Boolean - sets je default location cookies
  shouldAutoPopulateAddress: true,      // Boolean - should the address value be auto-populated?
  shouldClearAddressOnValidSubmit: true // Boolean - should the address be cleared when a valid form is submitted?
}

Props

f-searchbox has a number of props that allow you to customise its functionality.

The props that can be defined are as follows:

PropRequiredTypeDefaultDescription
localefalsestringen-GBSets the locale of the component (which determines what theme and translations to use
configfalseobject{}When passed in f-searchbox will allow presentational & functional customisation (see options section)
dependentApiPromisefalseobject{}Allows a Promise to be passed through to f-searchbox so the client can resolve it.
copyOverridefalseobject{}Allows copy override within the component, see Override copy section for example.

Events

Example usage

f-searchbox exposes a number of hooks that can be used to trigger functions in the consuming application.

<search-box
    @searchbox-error="handleSearchboxError"
    @address-search-focus="addressFocus"
    @submit-saved-address="validSavedAddressSearch"
    @submit-valid-address="validSearch"
    @track-postcode-changed="onPostcodeChanged"/>

Available Events

EventDescription
@searchbox-errorFires when an error is thrown by f-searchbox.
@address-search-focusFires when the address input is focused.
@submit-saved-addressFires if user submits an address with the same address as previously recorded by the f-searchbox.
@submit-valid-addressFires if an address is submitted with no errors.
@track-postcode-changedFires when the address input value has changed from a previous address to a new valid address.

config.queryParams

Applies query parameters to the form URL to enable filters and other options on the search results page.

Format

<vue-search-box
    :config="{
        queryString: {
           [param]: value
        }
    }"
/>

Example

<vue-search-box
    :config="{
        queryString: {
           refine: 'halal' // Users are redirected to /:search-url?refine=halal
        }
    }"
/>

Override copy

You can override the f-searchbox copy using copy-override. This will also work with the headings.

<template>
    <search-box
        locale="en-GB"
        :copy-override="{ buttonText: 'Confirm' }" />
</template>
const copyOverrides = {
    buttonText: "Confirm",
    fieldLabel: "Enter your address",
    // ...
}

CSS styles

The component is using utility css styles from fozzie package. You need to make sure to @include trumps-utilities(); mixin to your application styles if you use beta version of fozzie package (>= v5.0.0-beta.0). If you are using main version (v4.X.X) styles should come out of the box.

Non-Vue Applications

This module can be ran as a micro front-end for applications that don't make use of the Vue framework.

The following rudimentary example can be used as a guide for implementing this component in an existing static application.

NOTE: You need to provide Vue with an instance of Vuex for f-searchbox to work correctly. This should be added after Vue has been included. Including the unpkg Vuex script, like the below example, will automatically install Vuex.

The version of Vuex required must be no earlier than vuex@3.2.0 as f-searchbox under the hood registers the store module using this.$store.hasModule('searchbox'), hasModule was added in v3.2.0, earlier Vuex versions will break store registration.

<!doctype html>
<html lang="en">
<head>
    <title>f-searchbox example standalone</title>
    <link rel="stylesheet" href="https://unpkg.com/@justeat/f-searchbox/dist/f-searchbox.css">
</head>
<body>
    <div data-app>
        <vue-searchbox locale="en-GB" />
    </div>
    <script src="https://unpkg.com/vue@2.6.11/dist/vue.js"></script>
    <script src="https://unpkg.com/vuex@3.2.0/dist/vuex.js"></script>
    <script src="https://unpkg.com/@justeat/f-searchbox/dist/f-searchbox.umd.min.js"></script>
    <script>
        (function() {
            if (typeof Vue === 'undefined') return null;

            Vue.config.devtools = false;
            Vue.config.productionTip = false;

            return new Vue({
                store: new Vuex.Store({}), // init empty Vuex store here.
                el: '[data-app]'
            });
    	})();
    </script>
</body>
</html>
6.9.1

2 years ago

6.9.0

2 years ago

6.7.1

2 years ago

6.8.0

2 years ago

4.0.0-beta.48

3 years ago

4.0.0-beta.47

3 years ago

4.0.0-beta.44

3 years ago

4.0.0-beta.43

4 years ago

4.0.0-beta.42

4 years ago

4.0.0-beta.41

4 years ago

4.0.0-beta.40

4 years ago

6.7.0

4 years ago

4.0.0-beta.39

4 years ago

4.0.0-beta.38

4 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

5 years ago

3.13.1

5 years ago

3.13.0

5 years ago

3.12.4

5 years ago

4.0.0-beta.30

5 years ago

3.12.3

5 years ago

3.12.1

5 years ago

4.0.0-beta.29

5 years ago

3.12.2

5 years ago

3.12.0

5 years ago

3.11.0

5 years ago

3.10.4

5 years ago

3.10.3

5 years ago

4.0.0-beta.26

5 years ago

3.10.2

5 years ago

3.10.1

5 years ago

4.0.0-beta.24

5 years ago

4.0.0-beta.23

5 years ago

3.10.0

5 years ago

4.0.0-beta.22

5 years ago

4.0.0-beta.20

5 years ago

4.0.0-beta.19

5 years ago

4.0.0-beta.17

5 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

6 years ago

1.35.0

6 years ago

1.33.0

6 years ago

1.32.0

6 years ago

1.30.0

6 years ago

1.29.1

6 years ago

1.29.0

6 years ago

1.28.0

6 years ago

1.25.0

6 years ago

1.25.1

6 years ago

1.23.0

6 years ago

1.21.0

6 years ago

1.19.1

6 years ago

1.19.0

6 years ago

1.18.0

6 years ago

1.17.2

6 years ago

1.17.1

6 years ago

1.17.0

6 years ago

1.16.0

6 years ago

1.15.0

6 years ago

1.14.0

6 years ago

1.13.0

6 years ago

1.12.0

6 years ago

1.11.0

6 years ago

1.10.0

6 years ago

1.7.4

6 years ago

1.7.3

6 years ago

1.7.2

6 years ago

1.7.1

6 years ago

1.7.0

6 years ago

2.0.0

6 years ago

1.6.0

6 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

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

1.0.0-beta.23

7 years ago

1.0.0-beta.21

7 years ago

0.27.1

7 years ago

1.0.0-beta.20

7 years ago

1.0.0-beta.19

7 years ago

0.27.0

7 years ago

1.0.0-beta.18

7 years ago

1.0.0-beta.17

7 years ago

1.0.0-beta.16

7 years ago

0.26.2

7 years ago

1.0.0-beta.15

7 years ago

1.0.0-beta.14

7 years ago

0.26.1

7 years ago

1.0.0-beta.13

7 years ago

1.0.0-beta.12

7 years ago

0.26.0

7 years ago

1.0.0-beta.11

7 years ago

0.22.0-beta.10

7 years ago

0.22.0-beta.9

7 years ago

0.22.0-beta.8

7 years ago

0.22.0-beta.7

7 years ago

0.22.0-beta.6

7 years ago

0.22.0-beta.5

7 years ago

0.25.0

7 years ago

0.24.2

7 years ago

0.22.0-beta.4

7 years ago

0.22.0-beta.3

7 years ago

0.22.0-beta.2

7 years ago

0.22.1

7 years ago

0.22.0

7 years ago

0.22.0-beta.1

7 years ago

0.22.0-beta.0

7 years ago

0.21.0

7 years ago

0.20.0

7 years ago

0.14.0

7 years ago

0.13.0

7 years ago