Develop using the Interface X Components library
In this tutorial, you’ll learn the basics to integrate the Interface X Components library in your own project to craft enticing Vue search experiences for your commerce store in a matter of minutes.
interact
If you are looking to use the ready-to-go project Interface X Archetype as your starting point, see Develop using Interface X Archetype.
For this tutorial, the Empathy Search API is used, but you can use any search API. This step-by-step guide requires a knowledge of JavaScript and Vue.js.
You can find the X Components library in the Interface X open source project in GitHub (opens new window).
Before you begin
To integrate the X Components in a frontend UI, you need:
- Empathy Search API to retrieve search data (or any other search API)
- A search adapter to communicate with the search API.
- Your commerce store built on a Vue project, or on a React project using the React Wrapper (opens new window).
Steps to integrate the X Components in your project:
- Install project dependencies.
- Configure the search adapter.
- Configure the xPlugin.
- Install and initialize the xPlugin.
Installing the dependencies
To build your search and discovery UI, the following project dependencies are required:
x-components library (
@empathyco/x-components
(opens new window)): Interface X Components Vue.js library to implement out-of-the-box search UI components in a couple of minutes.x-adapter-platform (
@empathyco/x-adapter-platform
(opens new window)): A search adapter connector that tells the app how to communicate with the Empathy Search API you’re using, translating the response into understandable information for X Components. If you are not using the Empathy Search API, you need to build your own search adapter. In order to build your own search adapter, you can either extend the x-adapter-platform or create a new one from scratch using the@empathyco/x-adapter
(opens new window) package.x-types (
@empathyco/x-types
(opens new window)): The data model used in the X Components to define types.
Install the project dependencies via npm
as follows:
//Install the dependencies via npm.
npm install --save @empathyco/x-components @empathyco/x-types @empathyco/x-adapter-platform
Configuring the search adapter
You will need the search adapter in the xPlugin configuration.
There are two libraries for making it easier to consume search APIs. The
@empathyco/x-adapter
(opens new window), which is the
interface you can use to build your own adapter for other APIs, and the
@empathyco/x-adapter-platform
(opens new window),
which is the implementation to consume the Empathy Search Platform API, and it can be extended in
case your search API is similar to it.
warning
If you do not use the Empathy Search API, you need to build your own adapter.
For more information, see the Empathy Search Adapter (opens new window) and Empathy Platform Search Adapter (opens new window) libraries.
Configuring the plugin
Plugins are self-contained code that usually add global-level functionality to Vue projects. They’re
specifically objects that expose an install
method, allowing you to keep your components clear and
small.
The xPlugin is designed to connect the X Components to the Vue components in your project.
Import the xPlugin in your Vue instance.
import Vue from 'vue';
import { xPlugin } from '@empathyco/x-components';
import { adapter } from './my-adapter';
import { store } from './my-store';
Then, configure the xPlugin. It has two key options you need to configure:
Adapter: A search adapter is required to connect and communicate with the search API. Here you’re using the
XAdapterPlatform
to communicate specifically with the Empathy Search Platform API. If you are not using the Empathy Search Platform API, you need to build your own adapter. See Configure the search adapter.Store: The Vuex store. If you use a store for Vuex, you need to provide the store you’re currently using for your project to the Vue instance.
warning
If you don’t provide any parameters for the
store
, a default store is created automatically. Leave thestore
blank only if you’re not using any store for Vuex.
Installing and initializing the plugin
Finally, the last step is to install and initialize the xPlugin. You need to do this in the
main.ts
or main.js file
of the project.
//Initialize the plugin. Pass the search adapter and the store you use as parameters.
Vue.use(xPlugin, { adapter, store });
Next steps
Once you have integrated the Interface X Components in your project, you're ready to start building your search and discovery UI:
- Change the configuration of the X Components or create new ones.
- Adapt the design system (opens new window) to your branding.