Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
@polymer/polymer
Advanced tools
[![Build Status](https://travis-ci.org/Polymer/polymer.svg?branch=master)](https://travis-ci.org/Polymer/polymer)
@polymer/polymer is a library for building web components using the Polymer framework. It provides a set of features to create reusable, encapsulated HTML elements with custom behavior.
Define a Custom Element
This feature allows you to define a custom HTML element with specific properties and behaviors. The example shows how to create a custom element named 'my-element' with a property 'myProperty'.
class MyElement extends Polymer.Element {
static get is() { return 'my-element'; }
static get properties() {
return {
myProperty: {
type: String,
value: 'default value'
}
};
}
}
customElements.define(MyElement.is, MyElement);
Data Binding
This feature allows you to bind data to your custom element's template. The example shows how to bind the 'myProperty' value to a div inside the custom element's template.
<dom-module id="my-element">
<template>
<div>{{myProperty}}</div>
</template>
<script>
class MyElement extends Polymer.Element {
static get is() { return 'my-element'; }
static get properties() {
return {
myProperty: {
type: String,
value: 'default value'
}
};
}
}
customElements.define(MyElement.is, MyElement);
</script>
</dom-module>
Event Handling
This feature allows you to handle events within your custom element. The example shows how to handle a click event on a button inside the custom element's template.
<dom-module id="my-element">
<template>
<button on-click="handleClick">Click me</button>
</template>
<script>
class MyElement extends Polymer.Element {
static get is() { return 'my-element'; }
handleClick() {
console.log('Button clicked');
}
}
customElements.define(MyElement.is, MyElement);
</script>
</dom-module>
LitElement is a simple base class for creating fast, lightweight web components. It uses lit-html to render templates and provides a reactive property system. Compared to @polymer/polymer, LitElement is more lightweight and has a smaller API surface.
Stencil is a compiler that generates Web Components and builds high-performance web apps. It combines the best concepts of the most popular frameworks into a simple build-time tool. Stencil is more focused on performance and modern web standards compared to @polymer/polymer.
SkateJS is a library for building web components that focuses on being small and performant. It provides a simple API for defining custom elements and managing their lifecycle. SkateJS is more minimalistic and performance-oriented compared to @polymer/polymer.
Polymer lets you build encapsulated, re-usable elements that work just like standard HTML elements, to use in building web applications.
<!-- Polyfill Web Components for older browsers -->
<script src="webcomponentsjs/webcomponents-lite.min.js"></script>
<!-- Import element -->
<link rel="import" href="google-map.html">
<!-- Use element -->
<google-map latitude="37.790" longitude="-122.390"></google-map>
Check out polymer-project.org for all of the library documentation, including getting started guides, tutorials, developer reference, and more.
Or if you'd just like to download the library, check out our releases page.
Polymer is a lightweight library built on top of the web standards-based Web Components API's, and makes it easier to build your very own custom HTML elements. Creating re-usable custom elements - and using elements built by others - can make building complex web applications easier and more efficient. By being based on the Web Components API's built in the browser (or polyfilled where needed), Polymer elements are interoperable at the browser level, and can be used with other frameworks or libraries that work with modern browsers.
Among many ways to leverage custom elements, they can be particularly useful for building re-usable UI components. Instead of continually re-building a specific navigation bar or button in different frameworks and for different projects, you can define this element once using Polymer, and then reuse it throughout your project or in any future project.
Polymer provides a declarative syntax to easily create your own custom elements, using all standard web technologies - define the structure of the element with HTML, style it with CSS, and add interactions to the element with JavaScript.
Polymer also provides optional two-way data-binding, meaning:
Polymer is designed to be flexible, lightweight, and close to the web platform - the library doesn't invent complex new abstractions and magic, but uses the best features of the web platform in straightforward ways to simply sugar the creation of custom elements.
In addition to the Polymer library for building your own custom elements, the Polymer project includes a collection of pre-built elements that you can drop on a page and use immediately, or use as starting points for your own custom elements.
Polymer adds convenient features to make it easy to build complex elements:
Create and register a custom element
/**
* A not-very-useful inline element
*/
Polymer({
is: 'my-element'
});
<!-- use the element -->
<my-element></my-element>
Add markup to your element
<!-- define the markup that your element will use -->
<dom-module id="my-simple-namecard">
<template>
<div>
Hi! My name is <span>Jane</span>
</div>
</template>
<script>
Polymer({
is: 'my-simple-namecard'
});
</script>
</dom-module>
Configure properties on your element...
// Create an element that takes a property
Polymer({
is: 'my-property-namecard',
properties: {
myName: {
type: String
}
},
ready: function() {
this.textContent = 'Hi! My name is ' + this.myName;
}
});
...and have them set using declarative attributes
<!-- using the element -->
<my-property-namecard my-name="Jim"></my-property-namecard>
Hi! My name is Jim
Bind data into your element using the familiar mustache-syntax
<!-- define markup with bindings -->
<dom-module id="my-bound-namecard">
<template>
<div>
Hi! My name is <span>{{myName}}</span>
</div>
</template>
<script>
Polymer({
is: 'my-bound-namecard',
properties: {
myName: {
type: String
}
}
});
</script>
</dom-module>
<!-- using the element -->
<my-bound-namecard my-name="Josh"></my-bound-namecard>
Hi! My name is Josh
Style the internals of your element, without the style leaking out
<!-- add style to your element -->
<dom-module id="my-styled-namecard">
<template>
<style>
/* This would be crazy in non webcomponents. */
span {
font-weight: bold;
}
</style>
<div>
Hi! My name is <span>{{myName}}</span>
</div>
</template>
<script>
Polymer({
is: 'my-styled-namecard',
properties: {
myName: {
type: String
}
}
});
</script>
</dom-module>
<!-- using the element -->
<my-styled-namecard my-name="Jesse"></my-styled-namecard>
Hi! My name is Jesse
and so much more!
Web components are an incredibly powerful new set of primitives baked into the web platform, and open up a whole new world of possibility when it comes to componentizing front-end code and easily creating powerful, immersive, app-like experiences on the web.
By being based on Web Components, elements built with Polymer are:
The Polymer team loves contributions from the community! Take a look at our contributing guide for more information on how to contribute.
Beyond Github, we try to have a variety of different lines of communication available:
The Polymer library uses a BSD-like license available here
FAQs
The Polymer library makes it easy to create your own web components. Give your element some markup and properties, and then use it on a site. Polymer provides features like dynamic templates and data binding to reduce the amount of boilerplate you need to
The npm package @polymer/polymer receives a total of 105,231 weekly downloads. As such, @polymer/polymer popularity was classified as popular.
We found that @polymer/polymer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 10 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.