@econnect/webcomponents-library
Documentation
Styleguide
Documentation
Styleguide
  • Getting Started

    • Installation
    • Patch Notes
    • Styleguide
  • Styling

    • e-connect colors
  • UI Components

    • Form

      • Search Field
      • Form Field
      • Forms
    • Filter

      • Filter
      • Search Filter
    • Grid

      • Grid
      • Grid Row
    • Inputs

      • File Input
      • Input Checkbox
      • Input Dropdown
      • Input Date
      • Input Date Time
      • Input Date Time Local
      • Input File
      • Input Label
      • Input Multi Select
      • Input Number
      • Input Radio
      • Input Range
      • Input Select
      • Input Switch
      • Input Slider
      • Input Text
      • Input TextArea
      • Input Time
      • Input Time Range
    • Controls

      • Booleans
      • Button
      • Checkboxes
      • Date Displays
      • Dropdown Lists
      • Text Displays
    • Headers

      • e-header
    • Cards

      • e-card
    • Images

      • Icon
      • Images
      • Flag Image
      • Hamburger
    • Iframe
    • Pager
    • Settings
    • Document Validation
    • Navigation

      • Navigation
      • Navigation Menu
      • Navigation Footer
      • Navigation Button
      • Navigation Button Item
      • Navigation Search Item

Input Checkbox v1.0

The <e-input-checkbox> component is a component that can be used for .

Usage

An e-input-checkbox has attributes that must be provided,

<e-input-checkbox
  id=""
  label=""
  checked=""
  inherit=""
/>

Attributes

id | Type: String | required
label | Type: String | Default: ''
options | Type: Array | Default: selectOptions

Examples

Below a few interactive examples of e-input-checkbox can be found.

Default
<e-input-checkbox
  id="inputCheckbox"
  :label="'inputCheckbox'"
  checked=""
  inherit=""
/>
Labelled, label='checkboxInput with Label'
<div class="input-example-field">
  <e-input-label
    :id="'inputCheckboxWithLabel'"
    :value="'checkboxInput with Label'"
  />
  <e-input-checkbox
    :id="'inputCheckboxWithOptions'"
    :label="'inputCheckboxWithOptions'"
    checked=""
    inherit=""
  />
</div>

Source Code

e-input-checkbox.vue
<script setup lang="ts">
import { computed, ref } from 'vue';

import { EInput_Checkbox } from 'types/e-input/interfaces/EInput_Checkbox';

export type Props = EInput_Checkbox;
const props = withDefaults(defineProps<Props>(), {
  placeholder: '',
  required: false,
  disabled: false,
  meta: () => {
    return {
      disabled: false
    };
  }
});

const emit = defineEmits<{
  (e: 'blur', event: FocusEvent): void;
  (e: 'keyup.enter', event: KeyboardEvent): void;
  (e: 'update:checked', value: boolean): void;
}>();

const input = ref<HTMLInputElement>();

const classes = computed(() => {
  return {
    inherited: props.inherited
  };
});

const isChecked = computed(() => props.checked || props.value == 'true');

const isDisabled = computed(() => props.disabled ?? props.meta?.disabled);

function emitUpdate(event: Event): void {
  const target = event.target as HTMLInputElement;

  emit('update:checked', target.checked);
}
</script>

<template>
  <div class="e-input-checkbox">
    <input
      v-bind="$attrs"
      :id="id"
      ref="input"
      class="input-checkbox"
      :class="classes"
      type="checkbox"
      :checked="isChecked"
      :disabled="isDisabled"
      :required="required"
      @change="emitUpdate"
    />
    <label
      :for="id"
      :title="label"
      v-text="label"
    />
  </div>
</template>

<style scoped lang="scss">
$checkbox-container-width: 50px;
$checkbox-size: calc($checkbox-container-width / 2);
$e-checkbox-light-gray: #e2e8f0;
$e-checkbox-gray: #cbd5e0;
$e-checkbox-dark-gray: #a0aec0;
$e-checkbox-teal: #4fd1c5;
$e-checkbox-dark-teal: #319795;

.e-input-checkbox {
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 0 5px;
  gap: 5px;

  /* Visually hide the checkbox input */
  .input-checkbox {
    &:focus {
      + .checkbox::before {
        border-color: $e-checkbox-gray;
      }

      &:checked {
        + .checkbox::before {
          border-color: $e-checkbox-dark-teal;
        }
      }
    }
  }

  label {
    color: var(--e-body-font-color);
    font-family: var(--e-body-font-family);
    line-height: var(--e-body-font-line-height);
    font-size: var(--e-navigation-button-font-size);
    font-weight: var(--e-body-font-weight);
  }

  &[required] {
    + label::after {
      content: '*';
      padding-left: 2px;
      color: var(--e-required);
      font-weight: bold;
    }
  }
}
</style>
Last Updated:: 10/10/24, 2:56 PM
Contributors: AzureAD\MarcelLommers, Marcel Lommers
Prev
File Input
Next
Input Dropdown