nb-toggle-skewed

This is a toggle component with skewed (inclined) animation effect 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 NbToggleSkewed or nb-toggle-skewed.

Mode 1
<template>
  <NbToggleSkewed />
</template>
Mode 2
<template>
  <nb-toggle-skewed />
</template>
Mode 3
<template>
  <nb-toggle-skewed></nb-toggle-skewed>
</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.
widthNumber86Defines the toggle width in pixels. Minimum value is 86px.
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
fontWeightNumber400Defines the font-weight
textEnableString'On'Defines the text displayed when toggle is enabled
textDisableString'Off'Defines the text displayed when toggle is disabled
lightTextColorOnString'#4a4a4a'Defines the text color when enabled for light theme. Accepts Hex color only
lightTextColorOnHoverString'#3a3a3a'Defines the text color on hover when enabled for light theme. Accepts Hex color only
lightTextColorOffString'#585858'Defines the text color when disabled for light theme. Accepts Hex color only
lightTextColorOffHoverString'#707070'Defines the text color on hover when disabled for light theme. Accepts Hex color only
lightButtonColorOnString'#f8f8f2'Defines the button background color when enabled for light theme. Accepts Hex color only
lightButtonColorOnHoverString'#e8e8e2'Defines the button background color on hover when enabled for light theme. Accepts Hex color only
lightButtonColorOffString'#d5d5d5'Defines the button background color when disabled for light theme. Accepts Hex color only
lightButtonColorOffHoverString'#c0c0c0'Defines the button background color on hover when disabled for light theme. Accepts Hex color only
darkTextColorOnString'#f8f8f8'Defines the text color when enabled for dark theme. Accepts Hex color only
darkTextColorOnHoverString'#ffffff'Defines the text color on hover when enabled for dark theme. Accepts Hex color only
darkTextColorOffString'#909090'Defines the text color when disabled for dark theme. Accepts Hex color only
darkTextColorOffHoverString'#b0b0b0'Defines the text color on hover when disabled for dark theme. Accepts Hex color only
darkButtonColorOnString'#3d3d3d'Defines the button background color when enabled for dark theme. Accepts Hex color only
darkButtonColorOnHoverString'#4d4d4d'Defines the button background color on hover when enabled for dark theme. Accepts Hex color only
darkButtonColorOffString'#2c2c2c'Defines the button background color when disabled for dark theme. Accepts Hex color only
darkButtonColorOffHoverString'#2d2d2d'Defines the button background color on hover when disabled 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>
  <NbToggleSkewed
    nb-id="toggle-skewed-light"
    theme="light"
    :value="toggleValue"
    @changed="handleChange($event)"
    @current-value="handleCurrentValue($event)"
    @clicked="logEvent()"
  />
</template>

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

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

const toggleValue = ref(false);

const handleChange = (value) => {
  toggleValue.value = value;
  console.log('Toggle changed:', value);
};

const handleCurrentValue = (value) => {
  console.log('Current value:', value);
};

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

Dark Theme

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

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

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

const toggleValue = ref(true);

const handleChange = (value) => {
  toggleValue.value = value;
  console.log('Toggle changed:', value);
};

const handleCurrentValue = (value) => {
  console.log('Current value:', value);
};

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

Light Theme (Custom Colors)

<template>
  <NbToggleSkewed
    nb-id="toggle-skewed-light-custom"
    theme="light"
    :value="toggleValue"
    light-button-color-on="#dbeafe"
    light-button-color-on-hover="#bfdbfe"
    light-button-color-off="#e5e7eb"
    light-button-color-off-hover="#d1d5db"
    light-text-color-on="#1e40af"
    light-text-color-off="#6b7280"
    text-enable="SIM"
    text-disable="NÃO"
    @changed="handleChange($event)"
  />
</template>

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

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

const toggleValue = ref(false);

const handleChange = (value) => {
  toggleValue.value = value;
  console.log('Toggle changed:', value);
};
</script>

Dark Theme (Custom Colors)

<template>
  <NbToggleSkewed
    nb-id="toggle-skewed-dark-custom"
    theme="dark"
    :value="toggleValue"
    dark-button-color-on="#8b5cf6"
    dark-button-color-on-hover="#7c3aed"
    dark-button-color-off="#4b5563"
    dark-button-color-off-hover="#374151"
    dark-text-color-on="#f3f4f6"
    dark-text-color-off="#9ca3af"
    text-enable="YES"
    text-disable="NO"
    @changed="handleChange($event)"
  />
</template>

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

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

const toggleValue = ref(true);

const handleChange = (value) => {
  toggleValue.value = value;
  console.log('Toggle changed:', value);
};
</script>

Disabled State

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

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

Custom Size and Border Radius

<template>
  <NbToggleSkewed
    nb-id="toggle-skewed-custom-size"
    theme="light"
    :value="toggleValue"
    :width="120"
    :border-radius="0.5"
    :padding-x="1.5"
    :padding-y="0.5"
    @changed="handleChange($event)"
  />
</template>

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

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

const toggleValue = ref(false);

const handleChange = (value) => {
  toggleValue.value = value;
};
</script>