JavaScript Switch Button

The LemonadeJS Switch component offers a dynamic and intuitive solution for managing binary states within your web applications. As a versatile and framework-agnostic JavaScript plugin, it seamlessly integrates with popular frameworks like Vue, React, and Angular. This feature-packed Switch component simplifies the implementation of toggle functionality, providing a streamlined user interface for binary choices.

Documentation

Installation

npm install @lemonadejs/switch

Settings

AttributeDescription
text?: StringThe displayed text.
value?: AnyThe current value of the component.
name?: StringThe attribute name assigned to the switch element.
disabled?: BooleanDisables the functionality of the switch.

Examples

JavaScript Switch Example

live
<html>
<script src="https://cdn.jsdelivr.net/npm/lemonadejs/dist/lemonade.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@lemonadejs/switch/dist/index.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@lemonadejs/switch/dist/style.min.css" />

<div id='root'></div>

<script>
function Component() {
    this.value = false;
    return render => render`<div>
        <p>Value: ${this.value}</p>
        <Switch text="Toggle" :bind="this.value" />
    </div>`
}
lemonade.render(Component, document.getElementById('root'));
</script>
</html>

Basic HTML Example

live
<html>
<script src="https://cdn.jsdelivr.net/npm/lemonadejs/dist/lemonade.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@lemonadejs/switch/dist/index.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@lemonadejs/switch/dist/style.min.css" />

<div id='root'></div>

<script>
Switch(document.getElementById('root'), {
    text: 'Toggle'
});
</script>
</html>

Render as Web Component

live
<html>
<script src="https://cdn.jsdelivr.net/npm/lemonadejs/dist/lemonade.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@lemonadejs/switch/dist/index.min.js"></script>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@lemonadejs/switch/dist/style.min.css" />

<lm-switch text="Bitcoin" value="true"></lm-switch><br>
<lm-switch text="Ethereum" value="false"></lm-switch>

</html>