Skip to content
Snippets Groups Projects
site-search.tsx 1.11 KiB
Newer Older
  • Learn to ignore specific revisions
  • Markus Kalijärvi's avatar
    Markus Kalijärvi committed
    import {Component, Prop, h, Watch} from '@stencil/core';
    
    import {ComponentLabels} from '../site-header';
    
    import {ColorVariant} from '../../../utils/utils';
    
    
    @Component({
      tag: 'hy-site-search',
      styleUrl: 'site-search.scss',
    
    })
    export class SiteSearch {
    
      @Prop() color: ColorVariant = ColorVariant.black;
    
      @Prop() isAlternative: boolean = false;
    
    Markus Kalijärvi's avatar
    Markus Kalijärvi committed
      @Prop() labels?: ComponentLabels[] | string;
    
      @Prop() showLabel: boolean = false;
    
    Markus Kalijärvi's avatar
    Markus Kalijärvi committed
      private _labels: ComponentLabels[];
    
      @Watch('labels') labelsWatcher(data: ComponentLabels[] | string) {
        this._labels = typeof data === 'string' ? JSON.parse(data) : data;
      }
    
      componentWillRender() {
        this.labelsWatcher(this.labels);
      }
    
    
      render() {
        return (
          <button
    
    Markus Kalijärvi's avatar
    Markus Kalijärvi committed
            aria-label={this._labels['open']}
    
            class={{
              'button--search': true,
    
              'is-open--menu': this.isAlternative,
    
    Markus Kalijärvi's avatar
    Markus Kalijärvi committed
            {this.showLabel ? <span class={'button--search__label'}>{this._labels['label']}</span> : ''}
    
            <hy-icon icon={'hy-icon-search'} size={this.size} fill={this.color} />