The Color Facet component renders a box with color preview for each value.

Tag

The tag for this component is <hawksearch-color-facet>.

Event-Binding Attributes

Note: For Event-Binding attributes common to all facet type components, see BaseFacetComponent.

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="color-facet">
<div class="row row--tight color-facet__items">
{{#each values}}
{{#if visible}}
<div hawksearch-facet-value="{{value}}" class="column column--2 color-facet__item{{attribute ' color-facet__item--selected' selected}}">
{{#if color.imageUrl}}
<img src="{{color.imageUrl}}" class="color-facet__item__image" alt="{{color.name}}" title="{{color.name}}" />
{{else}}
<div class="color-facet__item__box" style="background: {{color.hex}};"></div>
{{/if}}
{{#if @root.excludeEnabled}}
<span class="color-facet__item__actions">
{{#if excluded}}
<span hawksearch-facet-value-include="{{value}}" class="color-facet__item__actions__item" title="{{strings.include}}">
<hawksearch-icon name="plus"></hawksearch-icon>
</span>
{{else}}
<span hawksearch-facet-value-exclude="{{value}}" class="color-facet__item__actions__item" title="{{strings.exclude}}">
<hawksearch-icon name="minus"></hawksearch-icon>
</span>
{{/if}}
</span>
{{/if}}
</div>
{{/if}}
{{/each}}
</div>
{{#if showToggle}}
<span hawksearch-facet-toggle class="link facet__toggle">{{strings.toggle}}</span>
{{/if}}
</div>

Hierarchy

Properties

bindFromEvent: boolean = false
componentName: keyof HawkSearchComponents = 'color-facet'
configOverride?: ColorFacetComponentConfig

Optional instance-level configuration to override the global configuration

The data bound to the Handlebars template.

data?: Facet

The data bound to the component.

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

The Handlebars reference shared by all HawkSearch components.

state: FacetState

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

Methods

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

    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;.