nb-toggle-light

This is a toggle component with light design for Vue.js 3+.

Loading component...

Installation

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

Usage

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

import NbSelectComponents from '@vlalg-nimbus/nb-selects'
import "@vlalg-nimbus/nb-selects/dist/style.css";

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

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

To use, simply call the component, in this case it will be NbToggleLight or nb-toggle-light.

Mode 1
<template>
  <NbToggleLight />
</template>
Mode 2
<template>
  <nb-toggle-light />
</template>
Mode 3
<template>
  <nb-toggle-light></nb-toggle-light>
</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
valueBooleanfalseDefines the initial state of the toggle (checked/unchecked)
disabledBooleanfalseDefines if the toggle is disabled
tabIndexNumber0Defines the tab index. Set this property to make the toggle focusable by the keyboard.
hasTabIndexEnterBooleantrueEnables the toggle to be activated with the Enter key when focused.
hasTabIndexSpaceBooleantrueEnables the toggle 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' }
themeString'light'Defines the theme. Accepts dark and light. When theme is set, uses theme-specific color props.
borderRadiusNumber0Defines the border-radius in rem units.
widthNumber55Defines the toggle width in pixels. Minimum value is 55px.
paddingXNumber1Defines the horizontal padding in rem units.
paddingYNumber0.2Defines the vertical padding in rem units.
fontFamilyString"'Lato', sans-serif"Defines the font-family
fontSizeString'1.6em'Defines the font-size
fontWeightNumber200Defines the font-weight
hasAnimationBooleanfalseDefines if the toggle should have text animation
textEnableString'On'Defines the text displayed when toggle is enabled
textDisableString'Off'Defines the text displayed when toggle is disabled
buttonSizeNumber30Defines the button size percentage (0-50)
lightTextColorString'#8e8e8e'Defines the text color for light theme. Accepts Hex color only
lightButtonColorString'#eaeaea'Defines the button background color for light theme. Accepts Hex color only
lightTextBgColorString'#f8f8f2'Defines the text background color for light theme. Accepts Hex color only
darkTextColorString'#e0e0e0'Defines the text color for dark theme. Accepts Hex color only
darkButtonColorString'#2d2d2d'Defines the button background color for dark theme. Accepts Hex color only
darkTextBgColorString'#3d3d3d'Defines the text background color for dark theme. Accepts Hex color only

Events

nameReturn typeDescription
current-valueBooleanFired when an update to the value is made, returns the current value.
clickednothingFired when the toggle is clicked, returns nothing.

Example

Light Theme (default)

<template>
  <NbToggleLight
    nb-id="toggle-light-example"
    theme="light"
    :value="toggleValue"
    @clicked="logEvent()"
    @current-value="handleCurrentValue($event)"
  />
</template>

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

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

const toggleValue = ref(false);

const handleCurrentValue = (value) => {
  toggleValue.value = value;
  console.log('current-value', value);
};

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

Dark Theme

<template>
  <NbToggleLight
    nb-id="toggle-light-dark"
    theme="dark"
    :value="toggleValue"
    @clicked="logEvent()"
    @current-value="handleCurrentValue($event)"
  />
</template>

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

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

const toggleValue = ref(true);

const handleCurrentValue = (value) => {
  toggleValue.value = value;
  console.log('current-value', value);
};

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

Light Theme (Custom Colors)

<template>
  <NbToggleLight
    nb-id="toggle-light-light-custom"
    theme="light"
    :value="toggleValue"
    light-text-color="#1e40af"
    light-button-color="#dbeafe"
    light-text-bg-color="#bfdbfe"
    text-enable="SIM"
    text-disable="NÃO"
    @clicked="logEvent()"
    @current-value="handleCurrentValue($event)"
  />
</template>

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

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

const toggleValue = ref(false);

const handleCurrentValue = (value) => {
  toggleValue.value = value;
  console.log('current-value', value);
};

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

Dark Theme (Custom Colors)

<template>
  <NbToggleLight
    nb-id="toggle-light-dark-custom"
    theme="dark"
    :value="toggleValue"
    dark-text-color="#f3f4f6"
    dark-button-color="#8b5cf6"
    dark-text-bg-color="#7c3aed"
    text-enable="YES"
    text-disable="NO"
    @clicked="logEvent()"
    @current-value="handleCurrentValue($event)"
  />
</template>

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

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

const toggleValue = ref(true);

const handleCurrentValue = (value) => {
  toggleValue.value = value;
  console.log('current-value', value);
};

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

Disabled State

<template>
  <div>
    <NbToggleLight
      nb-id="toggle-light-disabled-off"
      theme="light"
      :value="false"
      :disabled="true"
    />
    <NbToggleLight
      nb-id="toggle-light-disabled-on"
      theme="light"
      :value="true"
      :disabled="true"
    />
  </div>
</template>

<script setup>
defineOptions({
  name: 'CompToggleLightDisabled',
});
</script>

With Animation

<template>
  <NbToggleLight
    nb-id="toggle-light-animation"
    theme="light"
    :value="toggleValue"
    :has-animation="true"
    @clicked="logEvent()"
    @current-value="handleCurrentValue($event)"
  />
</template>

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

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

const toggleValue = ref(false);

const handleCurrentValue = (value) => {
  toggleValue.value = value;
};

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

Custom Size and Border Radius

<template>
  <NbToggleLight
    nb-id="toggle-light-custom-size"
    theme="light"
    :value="toggleValue"
    :width="100"
    :border-radius="0.5"
    :padding-x="1.5"
    :padding-y="0.5"
    :button-size="35"
    @clicked="logEvent()"
    @current-value="handleCurrentValue($event)"
  />
</template>

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

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

const toggleValue = ref(false);

const handleCurrentValue = (value) => {
  toggleValue.value = value;
};

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