![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@lion/switch
Advanced tools
lion-switch
is a component that is used to toggle a property or feature on or off. Toggling the component on or off should have immediate action and should not require pressing any additional buttons (submit) to confirm what just happened. The Switch is not a Checkbox in disguise and should not be used as part of a form.
import { html } from 'lit-html';
import { Validator } from '@lion/form-core';
import { LionSwitch } from './index.js';
import './lion-switch.js';
import '@lion/helpers/sb-action-logger.js';
export default {
title: 'Buttons/Switch',
};
export const main = () => html` <lion-switch label="Label" help-text="Help text"></lion-switch> `;
checked
boolean attributechecked
boolean attributechoiceValue()
npm i --save @lion/switch
import { LionSwitch } from '@lion/switch';
// or
import '@lion/switch/lion-switch.js';
<lion-switch name="airplaneMode" label="Airplane mode" checked></lion-switch>
You can disable switches.
export const disabled = () => html` <lion-switch label="Label" disabled></lion-switch> `;
Simple example that illustrates where validation feedback will be displayed.
export const validation = () => {
const IsTrue = class extends Validator {
static get validatorName() {
return 'IsTrue';
}
execute(value) {
return !value.checked;
}
static async getMessage() {
return "You won't get the latest news!";
}
};
const tagName = 'custom-switch';
if (!customElements.get(tagName)) {
customElements.define(
tagName,
class CustomSwitch extends LionSwitch {
static get validationTypes() {
return [...super.validationTypes, 'info'];
}
},
);
}
return html`
<custom-switch
id="newsletterCheck"
name="newsletterCheck"
label="Subscribe to newsletter"
.validators="${[new IsTrue(null, { type: 'info' })]}"
></custom-switch>
`;
};
You can listen for a checked-changed
event that is fired when the switch is clicked.
export const handler = () => {
const uid = Math.random().toString(36).substr(2, 10);
return html`
<lion-switch
label="Label"
@checked-changed="${e => {
document.getElementById(`logger-${uid}`).log(`Current value: ${e.target.checked}`);
}}"
>
</lion-switch>
<sb-action-logger id="logger-${uid}"></sb-action-logger>
`;
};
FAQs
A Switch is used for switching a property or feature on and off
The npm package @lion/switch receives a total of 248 weekly downloads. As such, @lion/switch popularity was classified as not popular.
We found that @lion/switch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.