The Recommendations component displays a list of products determined by the rules configured in the HawkSearch admin.

Tag

The tag for this component is <hawksearch-recommendations>.

Attributes

Name Value Required
widget-id string Yes

This attribute specifies which recommendation configuration created in the HawkSearch admin is retrieved from the API.

Event-Binding Attributes

Name Value
hawksearch-carousel

This attribute should be placed on the element that contains each individual item element of a carousel. This is used to bind touch events.

Name Value
hawksearch-carousel-item number

When an element with this attribute is clicked, the carousel will move to display the range of items starting with the given index. This is typically used within pagination for the carousel.

Name Value
hawksearch-next

When an element with this attribute is clicked, the carousel will display the next range of items.

Name Value
hawksearch-previous

When an element with this attribute is clicked, the carousel will display the previous range of items.

Default Template

The following is the default Handlebars template for this component. To create a custom template, it is recommended to use this as a starting point.

<div class="recommendations">
{{#if headingEnabled}}
<h2 class="heading recommendations__heading">{{title}}</h2>
{{/if}}
<div class="recommendations__content">
{{#if (and carousel buttonsEnabled)}}
<a hawksearch-previous class="recommendations__button recommendations__button--previous" title="{{strings.previous}}">
<hawksearch-icon name="chevron-left"></hawksearch-icon>
</a>
{{/if}}
<div class="recommendations__carousel">
<div hawksearch-carousel class="recommendations__list{{attribute ' recommendations__list--carousel' carousel}}" style="left: {{carouselPosition}};">
{{#each items}}
<div class="recommendations__carousel__item" style="width: {{@root.itemWidth}};">
<hawksearch-recommendations-item widget-id="{{@root.id}}" request-id="{{@root.requestId}}"></hawksearch-recommendations-item>
</div>
{{/each}}
</div>
{{#if (and carousel paginationEnabled)}}
<div class="recommendations__pagination">
{{#each paginationItems}}
<span
hawksearch-carousel-item="{{@index}}"
class="recommendations__pagination__item{{attribute ' recommendations__pagination__item--selected' selected}}"
title="{{title}}"
></span>
{{/each}}
</div>
{{/if}}
</div>
{{#if (and carousel buttonsEnabled)}}
<a
hawksearch-next
class="recommendations__button recommendations__button--next{{attribute ' recommendations__button--disabled' (eq nextEnabled false)}}"
title="{{strings.next}}"
>
<hawksearch-icon name="chevron-right"></hawksearch-icon>
</a>
{{/if}}
</div>
</div>

Hierarchy

Constructors

Properties

bindFromEvent: boolean = true
componentName: keyof HawkSearchComponents = 'recommendations'

Optional instance-level configuration to override the global configuration

The data bound to the Handlebars template.

The data bound to the component.

defaultHtml: string = defaultHtml
handlebars: typeof Handlebars = HawkSearch.handlebars

The Handlebars reference shared by all HawkSearch components.

Accessors

  • get configuration(): undefined | TConfig
  • The optional configuration object for this component.

    Returns undefined | TConfig

  • get rootElement(): ParentNode
  • The root element which should be used for querying any child elements. This resolves to this.shadowRoot if the Shadow DOM is enabled, otherwise this.

    Returns ParentNode

  • get observedAttributes(): string[]
  • Returns string[]

Methods

  • Parameters

    • name: string
    • oldValue: null | string
    • newValue: null | string

    Returns void

  • After the component is rendered, this method is called to bind any child components.

    Returns void

  • Returns void

  • Returns void

  • Replaces placeholders in a given string with values from a data object.

    Parameters

    • template: string

      The template string.

    • values: Record<string, string>

      The object containing properties which will be bound to template.

    Returns string

    The template string with all placeholders replaced by the values specified in values.

  • After the component is rendered, this method is called for any additional processing (such as attaching event listeners) which needs to occur.

    Returns void

  • Optional method that can be overwritten to register Handlebars helper functions which can be accessed from the template. For more information, see Custom Helpers.

    Returns void

  • Determines whether the data meets the necessary conditions to perform data binding and render content.

    Returns boolean

    Whether the component should be rendered. If false, the component will have empty contents and be set to display: none;.

  • Type Parameters

    • T

    Parameters

    • name: string
    • data: T

    Returns void