nb-checkbox

This is a checkbox group component for Vue.js 3+.

Loading component...

Installation

Yarn
yarn add @vlalg-nimbus/nb-inputs
NPM
npm install @vlalg-nimbus/nb-inputs

Usage

Vue 3
import { createApp } from 'vue'
import App from './App.vue'

import NbInputComponents from '@vlalg-nimbus/nb-inputs'
import "@vlalg-nimbus/nb-inputs/dist/style.css";

const app = createApp(App)
app.use(NbInputComponents)
app.mount('#app')
Nuxt 3
import NbInputComponents from '@vlalg-nimbus/nb-inputs'
import "@vlalg-nimbus/nb-inputs/dist/style.css";

export default defineNuxtPlugin(context => {
  context.vueApp.use(NbInputComponents)
})

To use, simply call the component, in this case it will be NbCheckbox or nb-checkbox.

Mode 1
<template>
  <NbCheckbox />
</template>
Mode 2
<template>
  <nb-checkbox />
</template>
Mode 3
<template>
  <nb-checkbox></nb-checkbox>
</template>

Preview & Playground

Select the component you want to edit/test

Loading Sandbox...

Props

Items with an (*) mean they are required

nameValue typeDefaultDescription
nbId (*)StringSets the id attribute to differentiate from other components
displayString'b'Defines the display type. Accepts ib and b.
tabIndexNumber, Array0Defines the tab index. Can be a number (applied to all items) or an array (one value per item). Set this property to make the checkboxes focusable by the keyboard.
hasTabIndexEnterBooleantrueEnables the checkboxes to be activated with the Enter key when focused.
hasTabIndexSpaceBooleantrueEnables the checkboxes to be activated with the Space key when focused.
ariaLabelString'Alternate Text Button'Defines the aria-label attribute for screen readers.
ariaAttrsObject{}Allows passing custom aria attributes as an object. Keys will automatically receive the aria- prefix. Example: { 'describedby': 'help-id', 'required': 'true' }
disabledBooleanfalseDefines if the checkbox is disabled
groupNameString''Defines checkbox group name
optionsArrayDefines the list of values. It is an array of objects { value: 'Value', text: 'Text' }
currentOptionArrayDefines an array of selected values string. The value must exist in the list options, in the key field
themeString'light'Defines the theme. Accepts dark and light. When theme is set, uses theme-specific color props.
borderRadiusNumber0Defines border-radius for type box.
hoverEffectBooleanfalseDefines whether the hover effect exists when passing over the checkbox without it being selected.
activeHoverEffectBooleanfalseDefines whether the hover effect exists when passing over the checkbox while it is selected.
itemGapNumber15Defines the space between checkbox options.
internalGapNumber6Defines the space between the checkbox and the text.
scaleNumber1Defines component scale (size).
typeString'box'Defines the checkbox type. Accepts box and circle.
backgroundBooleanfalseDefines if the checkbox is background type.
fontFamilyString"'Lato', sans-serif"Defines the font-family
fontSizeString'1.6em'Defines the font-size
fontWeightNumber400Defines the font-weight
lightTextColorString'#333333'Defines the text color for light theme. Accepts Color name and Hex
lightColorString'#cccccc'Defines the checkbox color for light theme. Accepts Hex color only
lightColorHoverString'#bbbbbb'Defines the checkbox hover color for light theme. Accepts Hex color only
darkTextColorString'#e0e0e0'Defines the text color for dark theme. Accepts Color name and Hex
darkColorString'#555555'Defines the checkbox color for dark theme. Accepts Hex color only
darkColorHoverString'#666666'Defines the checkbox hover color for dark theme. Accepts Hex color only

Events

nameReturn typeDescription
current-valuevalueFired when an update to the selected value is made, returns selected value.
changedvalueFired when an update to the selected value is made, returns selected value.
clickednothingFired when a checkbox is clicked, returns nothing.

Example

Light Theme (default)

<template>
  <NbCheckbox
    nb-id="checkbox-light"
    display="b"
    group-name="checkbox-group-light"
    theme="light"
    :options="checkboxOptions"
    :current-option="currentCheckboxValues"
    light-text-color="#1e40af"
    light-color="#3b82f6"
    light-color-hover="#60a5fa"
    :hover-effect="true"
    :active-hover-effect="true"
    :border-radius="4"
    type="box"
    :background="false"
    @current-value="handleCheckboxChange($event)"
    @changed="handleCheckboxChange($event)"
    @clicked="logEvent()"
  />
</template>

<script setup>
import { ref } from 'vue';

defineOptions({
  name: 'CompCheckbox',
});

const checkboxOptions = [
  { value: 'option1', text: 'Option 1' },
  { value: 'option2', text: 'Option 2' },
  { value: 'option3', text: 'Option 3' }
];

const currentCheckboxValues = ref(['option1']);

const handleCheckboxChange = (value) => {
  currentCheckboxValues.value = value;
  console.log('Checkbox changed:', value);
};

const logEvent = () => {
  console.log('clicked');
};
</script>

Dark Theme

<template>
  <NbCheckbox
    nb-id="checkbox-dark"
    display="b"
    group-name="checkbox-group-dark"
    theme="dark"
    :options="checkboxOptions"
    :current-option="currentCheckboxValues"
    dark-text-color="#a78bfa"
    dark-color="#8b5cf6"
    dark-color-hover="#7c3aed"
    :hover-effect="true"
    :active-hover-effect="true"
    :border-radius="4"
    type="circle"
    :background="true"
    @current-value="handleCheckboxChange($event)"
    @changed="handleCheckboxChange($event)"
    @clicked="logEvent()"
  />
</template>

<script setup>
import { ref } from 'vue';

defineOptions({
  name: 'CompCheckboxDark',
});

const checkboxOptions = [
  { value: 'option1', text: 'Option 1' },
  { value: 'option2', text: 'Option 2' },
  { value: 'option3', text: 'Option 3' }
];

const currentCheckboxValues = ref(['option2']);

const handleCheckboxChange = (value) => {
  currentCheckboxValues.value = value;
  console.log('Checkbox changed:', value);
};

const logEvent = () => {
  console.log('clicked');
};
</script>