Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

custom-element-decorator

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

custom-element-decorator

@customElement decorator

  • 0.6.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@customElement

Usage

import {customElement} from 'custom-element-decorator';

@customElement()
class MySuperCoolElement extends HTMLElement {}

// Now you can use <my-super-cool-element> anywhere in your app.

Important note: The name of your class may change if you use a minifier, that means <my-super-cool-element> in this example might be renamed to something else in the build. In most case it's fine and won't cause any trouble but if you want to force a name you should pass it as an argument:

@customElement({ name: 'my-super-cool-element' })
class MyElement extends HTMLElement {}

Injection

Sometimes you don't want to bother finding a special DOM location for your app's custom elements.
If you create the object programmatically into your code you can pass the inject argument to automatically inject the object into the DOM.

import {customElement} from 'custom-element-decorator';

@customElement({ inject: true })
class MyServiceElement extends HTMLElement {}

// This object is automatically inserted inside the DOM
// upon creation.
export const service = new MyServiceElement();

Installation

npm add -D custom-element-decorator

Bare version

import {customElement} from 'custom-element-decorator/bare';

@customElement
class MyElement extends HTMLElement {}

Special thanks

to Glenn for the hyphen idea.
to Duske for delegating this npm package name to me.

FAQs

Package last updated on 25 Jun 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc