InputToggle.vue component is a reusable Vue.js Composition API-based toggle switch. It allows for dynamic toggling of boolean or truthy/falsey states, with customizable sizes and labels. This component is ideal for integrating on/off switches within a Vue application.
Features
Customizable Sizes
Supports predefined sizes and numeric scaling for the toggle dimensions.
Dynamic Labels
Optionally displays a label alongside the toggle.
Usage
Basic Example
Small Toggle
Custom Numeric Scaling
Props
The value bound to the toggle’s state (
true, false, 'yes', 1, and 'on').The input type (not commonly used with this component).
Defines the size of the toggle. Accepts
'small' for 75% scaling or a numeric value for proportional scaling.Label text displayed alongside the toggle (optional).
Example Use Cases
Reactive Toggle
Usev-model to bind the toggle state reactively:
Custom Size Toggle
Define a toggle with a custom scaling factor:Notes
- The
sizeprop allows for flexibility in adjusting the toggle’s dimensions:'small': Scales the toggle to 75% of its default size.- Numeric Value: Proportionally scales the toggle dimensions by the given factor.
- The
labelprop provides descriptive text next to the toggle for improved clarity and accessibility.