Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
nude-element
Advanced tools
Composable web component helpers for creating reactive web components that behave just like native HTML elements.
Elements can extend NudeElement
to get the nicest, most declarative syntax,
or import individual mixins as helper functions and use them with any HTMLElement
subclass.
Note: This is a work in progress, developed in the open. Try it and please report issues and provide feedback!
value
default to (this.min + this.max) / 2
in a slider)oneventname
attributes and props, just like native HTML elementsNudeElement
classDefining your element as a subclass of NudeElement
gives you the nicest, most declarative syntax.
import NudeElement from "nude-element";
class MySlider extends NudeElement {
constructor () {
// ...
}
static props = {
min: {
type: Number,
default: 0,
},
max: {
type: Number,
default: 1,
},
step: {
type: Number,
default () {
return Math.abs((this.max - this.min) / 100);
},
},
defaultValue: {
type: Number,
default () {
return (this.min + this.max) / 2;
},
reflect: {
from: "value",
},
},
value: {
type: Number,
defaultProp: "defaultValue",
reflect: false,
},
};
static events = {
// Propagate event from shadow DOM element
change: {
from () {
return this._el.slider;
}
},
// Fire event when specific prop changes (even programmatically)
valuechange: {
propchange: "value",
},
};
static formAssociated = {
like: el => el._el.slider,
role: "slider",
valueProp: "value",
changeEvent: "valuechange",
};
}
If Nude Element taking over your parent class seems too intrusive, you can implement the same API via one-off composable helper functions aka mixins, at the cost of handling some of the plumbing yourself.
Each mixin modifies the base class in a certain way (e.g. adds properties & methods) and returns an init function, to be called once for each element, either at the end of its constructor or when it’s first connected. This is what the example above would look like:
import {
defineProps,
defineEvents,
defineFormAssociated,
} from "nude-element";
class MySlider extends HTMLElement {
constructor () {
// ...
eventHooks.init.call(this);
formAssociatedHooks.init.call(this);
propHooks.init.call(this);
}
}
let propHooks = defineProps(MySlider, {
min: {
type: Number,
default: 0,
},
max: {
type: Number,
default: 1,
},
step: {
type: Number,
default () {
return Math.abs((this.max - this.min) / 100);
},
},
defaultValue: {
type: Number,
default () {
return (this.min + this.max) / 2;
},
reflect: {
from: "value",
},
},
value: {
type: Number,
defaultProp: "defaultValue",
reflect: false,
},
});
let eventHooks = defineEvents(MySlider, {
// Propagate event from shadow DOM element
change: {
from () {
return this._el.slider;
}
},
// Fire event when specific prop changes (even programmatically)
valuechange: {
propchange: "value",
},
});
let formAssociatedHooks = defineFormAssociated(MySlider, {
like: el => el._el.slider,
role: "slider",
valueProp: "value",
changeEvent: "valuechange",
});
Each mixin will also look for a static hooks
property on the element class and add its lifecycle hooks to it if it exists,
so you can make things a little easier by defining such a property:
import { defineProps } from "nude-element";
import Hooks from "nude-element/hooks";
class MyElement extends HTMLElement {
// Caution: if MyElement has subclasses, this will be shared among them!
static hooks = new Hooks();
constructor () {
super();
// Then you can call the hooks at the appropriate times:
this.constructor.hooks.run("init", this);
}
}
defineProps(MyElement, {
// Props…
});
Read more:
FAQs
Composable web component helpers
The npm package nude-element receives a total of 11 weekly downloads. As such, nude-element popularity was classified as not popular.
We found that nude-element demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.