Skip to content
Snippets Groups Projects
hy-checkbox.tsx 2.04 KiB
Newer Older
  • Learn to ignore specific revisions
  • import {Component, Host, h, Prop} from '@stencil/core';
    
    import {CheckboxVariants} from '../../utils/utils';
    
    
    @Component({
      tag: 'hy-checkbox',
      styleUrl: 'hy-checkbox.scss',
      shadow: false,
    })
    export class HyCheckbox {
    
      /**
       * Unique id for checkbox element
       */
    
      @Prop() checkboxId: string | number;
    
      /**
       * Value for input element
       */
    
      @Prop() checkboxValue: string | number;
    
      /**
       * Label for input to describe
       */
    
      @Prop() checkboxLabel: string;
    
    druid's avatar
    druid committed
      /**
       * Checked attribute
       */
      @Prop() checkboxChecked: boolean = false;
    
      /**
       * Variant to deifne what style of checkbox to use
       */
      @Prop() variant: CheckboxVariants = CheckboxVariants.default;
    
    
        switch (this.variant) {
          case 'button':
            return (
              <Host class="hy-checkbox--button">
                <input
                  type="checkbox"
                  class="hy-checkbox--button__checkbox"
    
    druid's avatar
    druid committed
                  checked={this.checkboxChecked}
    
                  id={`${this.checkboxId}`}
                  value={`${this.checkboxValue}`}
                />
                <label class="hy-checkbox--button__label" htmlFor={`${this.checkboxId}`}>
                  {this.checkboxLabel}
                  <span class="hy-checkbox--button__checkmark">
                    <hy-icon class="hy-checkbox--button__label-icon" icon={'hy-icon-done'} size={14} aria-hidden="true" />
                  </span>
                </label>
              </Host>
            );
    
          default:
            return (
              <Host class="hy-checkbox">
                <input
                  type="checkbox"
                  class="hy-checkbox__checkbox"
    
    druid's avatar
    druid committed
                  checked={this.checkboxChecked}
    
                  id={`${this.checkboxId}`}
                  value={`${this.checkboxValue}`}
                />
                <label class="hy-checkbox__label" htmlFor={`${this.checkboxId}`}>
                  <span class="hy-checkbox__checkmark">
                    <hy-icon class="hy-checkbox__label-icon" icon={'hy-icon-done'} size={23} aria-hidden="true" />
                  </span>
                  {this.checkboxLabel}
                </label>
              </Host>
            );
        }