├── .eleventyignore
├── .github
└── ISSUE_TEMPLATE
│ ├── config.yml
│ ├── demo.yaml
│ ├── general.yaml
│ ├── spec.yaml
│ ├── topic.yaml
│ └── use_case.yaml
├── .gitignore
├── .nvmrc
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── LICENSE.md
├── README.md
├── docs
├── _data
│ ├── footer.json
│ └── site.cjs
├── _includes
│ ├── _joiningBlocks
│ │ ├── footer
│ │ │ └── 10-menu.njk
│ │ └── head
│ │ │ └── 20-icons.njk
│ ├── base.njk
│ ├── layout-about.njk
│ ├── layout-articles.njk
│ ├── layout-home.njk
│ └── sections
│ │ ├── drawer-about.njk
│ │ ├── drawer-articles.njk
│ │ ├── drawer-home.njk
│ │ ├── footer.njk
│ │ ├── head.njk
│ │ ├── header.njk
│ │ └── scripts.njk
├── about
│ ├── index.md
│ ├── introduction.md
│ ├── libraries.md
│ ├── resources.md
│ └── specifications.md
├── articles
│ ├── index.md
│ ├── main
│ │ ├── getting-started.md
│ │ └── index.md
│ └── using
│ │ ├── index.md
│ │ └── styling-shadow.md
├── assets
│ ├── icons
│ │ ├── icon-128x128.png
│ │ ├── icon-144x144.png
│ │ ├── icon-152x152.png
│ │ ├── icon-16x16.png
│ │ ├── icon-192x192.png
│ │ ├── icon-32x32.png
│ │ ├── icon-384x384.png
│ │ ├── icon-512x512.png
│ │ ├── icon-72x72.png
│ │ └── icon-96x96.png
│ ├── logo.svg
│ ├── style.css
│ └── webmanifest.json
├── index.md
├── light-dark.css
├── markdown.css
├── site.css
├── styles.css
└── theme.css
├── eleventy.config.js
├── package-lock.json
├── package.json
└── plan
├── README.md
└── outline.md
/.eleventyignore:
--------------------------------------------------------------------------------
1 | node_modules/**
2 | /docs/_assets
3 | /docs/_includes
4 | /docs/_data
5 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: false
2 | contact_links:
3 | - name: Questions or discussion?
4 | url: https://join.slack.com/t/webcomponentcommunity/shared_invite/zt-uinb2qud-cDvio5cC7IllxZfcTFf4QQ
5 | about: Please post general questions or discussion topics here.
6 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/demo.yaml:
--------------------------------------------------------------------------------
1 | name: Request for demo content
2 | description: Request to add demo content
3 | title: '[demo] '
4 | labels: [demo, documentation]
5 | body:
6 | - type: checkboxes
7 | id: terms
8 | attributes:
9 | label: Code of conduct
10 | description: By submitting this issue, you agree to follow our [code of conduct](https://www.w3.org/Consortium/cepc/).
11 | options:
12 | - label: I agree to follow this project's code of conduct.
13 | required: true
14 | - type: textarea
15 | id: details
16 | attributes:
17 | label: Description of request
18 | description: Please tell us about the content you would like to see added to this project. You can attach images or files by clicking this area to highlight it and then dragging files in.
19 | - type: input
20 | id: link
21 | attributes:
22 | label: Related link(s)
23 | - type: checkboxes
24 | id: author
25 | attributes:
26 | label: Are you interested in authoring this content?
27 | options:
28 | - label: "Yes"
29 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/general.yaml:
--------------------------------------------------------------------------------
1 | name: General request
2 | labels: ['question']
3 | body:
4 | - type: checkboxes
5 | id: terms
6 | attributes:
7 | label: Code of conduct
8 | description: By submitting this issue, you agree to follow our [code of conduct](https://www.w3.org/Consortium/cepc/).
9 | options:
10 | - label: I agree to follow this project's code of conduct.
11 | required: true
12 | - type: textarea
13 | id: details
14 | attributes:
15 | label: Description of request
16 | description: You can attach images or files by clicking this area to highlight it and then dragging files in.
17 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/spec.yaml:
--------------------------------------------------------------------------------
1 | name: Specification request for inclusion
2 | description: Request to add specification content
3 | labels: [spec, documentation]
4 | title: '[spec] '
5 | body:
6 | - type: checkboxes
7 | id: terms
8 | attributes:
9 | label: Code of conduct
10 | description: By submitting this issue, you agree to follow our [code of conduct](https://www.w3.org/Consortium/cepc/).
11 | options:
12 | - label: I agree to follow this project's code of conduct.
13 | required: true
14 | - type: textarea
15 | id: details
16 | attributes:
17 | label: Description of request
18 | description: Please tell us about the content you would like to see added to this project. You can attach images or files by clicking this area to highlight it and then dragging files in.
19 | - type: input
20 | id: link
21 | attributes:
22 | label: Related link(s)
23 | - type: checkboxes
24 | id: author
25 | attributes:
26 | label: Are you interested in authoring this content?
27 | options:
28 | - label: "Yes"
29 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/topic.yaml:
--------------------------------------------------------------------------------
1 | name: Topic content request
2 | description: Request to add topic content
3 | labels: [topic, documentation]
4 | title: '[topic] '
5 | body:
6 | - type: checkboxes
7 | id: terms
8 | attributes:
9 | label: Code of conduct
10 | description: By submitting this issue, you agree to follow our [code of conduct](https://www.w3.org/Consortium/cepc/).
11 | options:
12 | - label: I agree to follow this project's code of conduct.
13 | required: true
14 | - type: textarea
15 | id: details
16 | attributes:
17 | label: Description of request
18 | description: Please tell us about the content you would like to see added to this project. You can attach images or files by clicking this area to highlight it and then dragging files in.
19 | - type: input
20 | id: link
21 | attributes:
22 | label: Related link(s)
23 | - type: checkboxes
24 | id: author
25 | attributes:
26 | label: Are you interested in authoring this content?
27 | options:
28 | - label: "Yes"
29 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/use_case.yaml:
--------------------------------------------------------------------------------
1 | name: Use-case content request
2 | description: Request to add use-case content
3 | labels: ["use case", documentation]
4 | title: '[use case] '
5 | body:
6 | - type: checkboxes
7 | id: terms
8 | attributes:
9 | label: Code of conduct
10 | description: By submitting this issue, you agree to follow our [code of conduct](https://www.w3.org/Consortium/cepc/).
11 | options:
12 | - label: I agree to follow this project's code of conduct.
13 | required: true
14 | - type: textarea
15 | id: details
16 | attributes:
17 | label: Description of request
18 | description: Please tell us about the content you would like to see added to this project. You can attach images or files by clicking this area to highlight it and then dragging files in.
19 | - type: input
20 | id: link
21 | attributes:
22 | label: Related link(s)
23 | - type: checkboxes
24 | id: author
25 | attributes:
26 | label: Are you interested in authoring this content?
27 | options:
28 | - label: "Yes"
29 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## editors
2 | /.idea
3 | /.vscode
4 |
5 | ## system files
6 | .DS_Store
7 |
8 |
9 | ## npm
10 | node_modules
11 | npm-debug.log
12 | yarn-error.log
13 |
14 | ## temp folders
15 | /.tmp/
16 |
17 | ## build output
18 | dist
19 | dist-types
20 | stats.html
21 | *.tsbuildinfo
22 |
23 | ## Rocket ignore files (need to be the full relative path to the folders)
24 | docs/_merged_data/
25 | docs/_merged_assets/
26 | docs/_merged_includes/
27 | _site
28 | _site-dev
29 |
--------------------------------------------------------------------------------
/.nvmrc:
--------------------------------------------------------------------------------
1 | v20
2 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Code of Conduct
2 |
3 | The [Web Components Community Group](https://www.w3.org/community/webcomponents/) documentation repository, being work of the [World Wide Web Consortium (W3C)](https://www.w3.org/), is subject to the [W3C Code of Ethics and Professional Conduct](https://www.w3.org/Consortium/cepc/).
4 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributor Guidelines
2 |
3 | Thank you for your interest in contributing to the [Web Components Community Group](https://www.w3.org/community/webcomponents/)!
4 |
5 | Contributions to this repository are intended to become part of documents governed by the:
6 |
7 | * [W3C Patent Policy](https://www.w3.org/Consortium/Patent-Policy-20200915/)
8 | * [Software and Document License](https://www.w3.org/Consortium/Legal/copyright-software)
9 |
10 | To make substantive contributions to specifications, you must either participate
11 | in the relevant W3C Working Group or make a non-member patent licensing commitment.
12 |
13 | ## Issue disclosure and discussion
14 |
15 | The first step for any substantive contribution is to either:
16 |
17 | 1. [Find an existing issue](https://github.com/w3c/csswg-drafts/issues) directly related to the contribution
18 | 2. [Add a new issue](https://github.com/w3c/csswg-drafts/issues/new)
19 |
20 | Issues are where individual reports and Community Group discussions come together such
21 | that the eventual consensus can be turned into official language.
22 |
23 | ## Goals and Non-Goals
24 |
25 | The main goal of the Web Components Community Group docs-and-guides effort is to provide explanation, advocacy, and documentation of shared web components concepts in a common location that is not tied to any specific web components library.
26 |
27 | This documentation should be ideal for readers interested in learning about web components first - before thinking about libraries; and for web component libraries to reference to cover the standard web components foundations without writing it all themselves.
28 |
29 | ### Goals
30 | * Provide a polished landing page for web components, similar in spirit to homepages for frameworks.
31 | * Explain what web components are and why they are useful
32 | * Advocate for web components in a library-neutral way
33 | * Document core web component technical concepts
34 | * Educate readers on useful library-agnostic patterns and best practices
35 | * Orient readers to the broader web components ecosystem, including standards work, resources, communities, libraries, tools, and components.
36 |
37 | ### Non-Goals
38 | * Duplicate MDN references of the web components APIs
39 | * Document or advocate specific web components libraries
40 |
41 | ## Normative and/or substantive contributions
42 |
43 | The Web Components Community Group operates via the consensus of its membership, and discusses all significant matters prior to implementation.
44 |
45 | Aside from managing issues and PRs on GitHub, the Community Group discusses recommendations, goals, and planning via events available on [this shared calendar](https://calendar.google.com/calendar/u/0/embed?src=o25bim5rvcu42mfnqilirpmp44@group.calendar.google.com).
46 |
47 | ### Contribution
48 |
49 | Please follow the [Pull Request template](https://github.com/w3c/csswg-drafts/blob/master/.github/PULL_REQUEST_TEMPLATE.md) when contributing to the repository.
50 |
51 | ## Non-substantive contributions
52 |
53 | For simple spelling, grammar, or markup fixes unrelated to the substance of a
54 | specification, issuing a pull request without a corresponding issue is acceptable.
55 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Creative Commons Legal Code
2 |
3 | CC0 1.0 Universal
4 |
5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
12 | HEREUNDER.
13 |
14 | Statement of Purpose
15 |
16 | The laws of most jurisdictions throughout the world automatically confer
17 | exclusive Copyright and Related Rights (defined below) upon the creator
18 | and subsequent owner(s) (each and all, an "owner") of an original work of
19 | authorship and/or a database (each, a "Work").
20 |
21 | Certain owners wish to permanently relinquish those rights to a Work for
22 | the purpose of contributing to a commons of creative, cultural and
23 | scientific works ("Commons") that the public can reliably and without fear
24 | of later claims of infringement build upon, modify, incorporate in other
25 | works, reuse and redistribute as freely as possible in any form whatsoever
26 | and for any purposes, including without limitation commercial purposes.
27 | These owners may contribute to the Commons to promote the ideal of a free
28 | culture and the further production of creative, cultural and scientific
29 | works, or to gain reputation or greater distribution for their Work in
30 | part through the use and efforts of others.
31 |
32 | For these and/or other purposes and motivations, and without any
33 | expectation of additional consideration or compensation, the person
34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she
35 | is an owner of Copyright and Related Rights in the Work, voluntarily
36 | elects to apply CC0 to the Work and publicly distribute the Work under its
37 | terms, with knowledge of his or her Copyright and Related Rights in the
38 | Work and the meaning and intended legal effect of CC0 on those rights.
39 |
40 | 1. Copyright and Related Rights. A Work made available under CC0 may be
41 | protected by copyright and related or neighboring rights ("Copyright and
42 | Related Rights"). Copyright and Related Rights include, but are not
43 | limited to, the following:
44 |
45 | i. the right to reproduce, adapt, distribute, perform, display,
46 | communicate, and translate a Work;
47 | ii. moral rights retained by the original author(s) and/or performer(s);
48 | iii. publicity and privacy rights pertaining to a person's image or
49 | likeness depicted in a Work;
50 | iv. rights protecting against unfair competition in regards to a Work,
51 | subject to the limitations in paragraph 4(a), below;
52 | v. rights protecting the extraction, dissemination, use and reuse of data
53 | in a Work;
54 | vi. database rights (such as those arising under Directive 96/9/EC of the
55 | European Parliament and of the Council of 11 March 1996 on the legal
56 | protection of databases, and under any national implementation
57 | thereof, including any amended or successor version of such
58 | directive); and
59 | vii. other similar, equivalent or corresponding rights throughout the
60 | world based on applicable law or treaty, and any national
61 | implementations thereof.
62 |
63 | 2. Waiver. To the greatest extent permitted by, but not in contravention
64 | of, applicable law, Affirmer hereby overtly, fully, permanently,
65 | irrevocably and unconditionally waives, abandons, and surrenders all of
66 | Affirmer's Copyright and Related Rights and associated claims and causes
67 | of action, whether now known or unknown (including existing as well as
68 | future claims and causes of action), in the Work (i) in all territories
69 | worldwide, (ii) for the maximum duration provided by applicable law or
70 | treaty (including future time extensions), (iii) in any current or future
71 | medium and for any number of copies, and (iv) for any purpose whatsoever,
72 | including without limitation commercial, advertising or promotional
73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
74 | member of the public at large and to the detriment of Affirmer's heirs and
75 | successors, fully intending that such Waiver shall not be subject to
76 | revocation, rescission, cancellation, termination, or any other legal or
77 | equitable action to disrupt the quiet enjoyment of the Work by the public
78 | as contemplated by Affirmer's express Statement of Purpose.
79 |
80 | 3. Public License Fallback. Should any part of the Waiver for any reason
81 | be judged legally invalid or ineffective under applicable law, then the
82 | Waiver shall be preserved to the maximum extent permitted taking into
83 | account Affirmer's express Statement of Purpose. In addition, to the
84 | extent the Waiver is so judged Affirmer hereby grants to each affected
85 | person a royalty-free, non transferable, non sublicensable, non exclusive,
86 | irrevocable and unconditional license to exercise Affirmer's Copyright and
87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the
88 | maximum duration provided by applicable law or treaty (including future
89 | time extensions), (iii) in any current or future medium and for any number
90 | of copies, and (iv) for any purpose whatsoever, including without
91 | limitation commercial, advertising or promotional purposes (the
92 | "License"). The License shall be deemed effective as of the date CC0 was
93 | applied by Affirmer to the Work. Should any part of the License for any
94 | reason be judged legally invalid or ineffective under applicable law, such
95 | partial invalidity or ineffectiveness shall not invalidate the remainder
96 | of the License, and in such case Affirmer hereby affirms that he or she
97 | will not (i) exercise any of his or her remaining Copyright and Related
98 | Rights in the Work or (ii) assert any associated claims and causes of
99 | action with respect to the Work, in either case contrary to Affirmer's
100 | express Statement of Purpose.
101 |
102 | 4. Limitations and Disclaimers.
103 |
104 | a. No trademark or patent rights held by Affirmer are waived, abandoned,
105 | surrendered, licensed or otherwise affected by this document.
106 | b. Affirmer offers the Work as-is and makes no representations or
107 | warranties of any kind concerning the Work, express, implied,
108 | statutory or otherwise, including without limitation warranties of
109 | title, merchantability, fitness for a particular purpose, non
110 | infringement, or the absence of latent or other defects, accuracy, or
111 | the present or absence of errors, whether or not discoverable, all to
112 | the greatest extent permissible under applicable law.
113 | c. Affirmer disclaims responsibility for clearing rights of other persons
114 | that may apply to the Work or any use thereof, including without
115 | limitation any person's Copyright and Related Rights in the Work.
116 | Further, Affirmer disclaims responsibility for obtaining any necessary
117 | consents, permissions or other rights required for any use of the
118 | Work.
119 | d. Affirmer understands and acknowledges that Creative Commons is not a
120 | party to this document and has no duty or obligation with respect to
121 | this CC0 or use of the Work.
122 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | All documents in this Repository are licensed by contributors
2 | under the
3 | [W3C Software and Document License](https://www.w3.org/Consortium/Legal/copyright-software).
4 |
5 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # All about web components
2 |
3 | This repository brought to you by the [Web Components Community Group](https://www.w3.org/community/webcomponents/); the goal being to collect and share documentation and guides for web component best practices.
4 |
--------------------------------------------------------------------------------
/docs/_data/footer.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "name": "Discover",
4 | "children": [
5 | {
6 | "text": "Help and Feedback",
7 | "href": "https://github.com/webcomponents-cg/docs-and-guides/issues"
8 | }
9 | ]
10 | },
11 | {
12 | "name": "Follow",
13 | "children": [
14 | {
15 | "text": "GitHub",
16 | "href": "https://github.com/webcomponents-cg/docs-and-guides"
17 | }
18 | ]
19 | },
20 | {
21 | "name": "Support",
22 | "children": [
23 | {
24 | "text": "Contribute",
25 | "href": "https://github.com/webcomponents-cg/docs-and-guides/blob/main/CONTRIBUTING.md"
26 | }
27 | ]
28 | }
29 | ]
30 |
--------------------------------------------------------------------------------
/docs/_data/site.cjs:
--------------------------------------------------------------------------------
1 | module.exports = function () {
2 | return {
3 | dir: 'ltr',
4 | lang: 'en',
5 | name: 'Web Components Community Group at W3C',
6 | description: 'Collect and share documentation and guides for web component best practices',
7 | socialLinks: [
8 | {
9 | name: 'GitHub',
10 | url: 'https://github.com/webcomponents-cg/docs-and-guides',
11 | },
12 | ],
13 | gitSiteUrl: 'https://github.com/webcomponents-cg/docs-and-guides',
14 | gitBranch: 'master',
15 | helpUrl: 'https://github.com/webcomponents-cg/docs-and-guides/issues',
16 | logoAlt: 'Web Components Community Group Logo',
17 | iconColorMaskIcon: '#3f93ce',
18 | iconColorMsapplicationTileColor: '#1d3557',
19 | iconColorThemeColor: '#1d3557',
20 | };
21 | };
22 |
--------------------------------------------------------------------------------
/docs/_includes/_joiningBlocks/footer/10-menu.njk:
--------------------------------------------------------------------------------
1 |
20 | This group is for collaboration between people working on web components libraries, tools, documentation and standards.
21 |
22 |
23 |
Collaborate
24 | Areas we expect to work on include gap analysis, design principles, common protocols, discoverability and quality, documentation, tooling, and more.
25 |
26 |
27 |
Common Problems
28 | We will work together on projects of shared interest in order to enhance interoperability, solve common problems, build shared community resources, and ultimately continue to grow a cooperative, productive, and happy web components ecosystem.
29 |
30 |
31 | {{ content | safe }}
32 |
33 |
24 |
--------------------------------------------------------------------------------
/docs/_includes/sections/scripts.njk:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/docs/about/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: layout-about.njk
3 | ---
4 |
5 | # About
6 |
7 | Web components!
--------------------------------------------------------------------------------
/docs/about/introduction.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: layout-about.njk
3 | ---
4 |
5 | # Introduction
6 |
7 | ## What are web components?
8 | Web components are a set of web platform APIs that allow you to create new custom, reusable, encapsulated HTML tags to use in web pages and web apps. Custom components and widgets build on the Web Component standards, will work across modern browsers, and can be used with any JavaScript library or framework that works with HTML.
9 |
10 | Web components are based on existing web standards. Features to support web components are currently being added to the HTML and DOM specs, letting web developers easily extend HTML with new elements with encapsulated styling and custom behavior.
11 |
12 | ## Specifications
13 | Web components are based on four main specifications:
14 |
15 | ### Custom Elements
16 | The Custom Elements specification lays the foundation for designing and using new types of DOM elements.
17 |
18 | ### Shadow DOM
19 | The shadow DOM specification defines how to use encapsulated style and markup in web components.
20 |
21 | ### ES Modules
22 | The ES Modules specification defines the inclusion and reuse of JS documents in a standards based, modular, performant way.
23 |
24 | ### HTML Template
25 | The HTML template element specification defines how to declare fragments of markup that go unused at page load, but can be instantiated later on at runtime.
26 |
27 | ## How do I use a web component?
28 | The components on this site provide new HTML elements that you can use in your web pages and web applications.
29 |
30 | Using a custom element is as simple as importing it, and using the new tags in an HTML document. For example, to use the paper-button element:
31 |
32 | ```html
33 |
34 | ...
35 | raised
36 | ```
37 |
38 | There are a number of ways to install custom elements. When you find an element you want to use, look at its README for the commands to install it. Most elements today can be installed with NPM. NPM also handles installing the components' dependencies. For more information on NPM, see npmjs.com.
39 |
40 | For example, the paper-button overview describes the install process with npm:
41 |
42 | ```bash
43 | mkdir my-new-app && cd my-new-app
44 | npm install --save @polymer/paper-button
45 | ```
46 |
47 | ## How do I define a new HTML element?
48 | This section describes the syntax for the cross-browser version of the Web Components specification.
49 |
50 | Use JavaScript to define a new HTML element and its tag with the customElements global. Call customElements.define() with the tag name you want to create and a JavaScript class that extends the base HTMLElement.
51 |
52 | For example, to define a mobile drawer panel, :
53 |
54 | ```js
55 | class AppDrawer extends HTMLElement {...}
56 | window.customElements.define('app-drawer', AppDrawer);
57 | ```
58 |
59 | To use the new tag:
60 |
61 | ```html
62 |
63 | ```
64 |
65 | Using a custom element is no different to using a
or any other element. Instances can be declared on the page, created dynamically in JavaScript, event listeners can be attached, etc.
66 |
67 | ```html
68 |
76 | ```
77 |
78 | ## Creating and using a shadow root
79 | This section describes the syntax for creating shadow DOM with the new cross-browser version (v1) of the shadow DOM specification. Shadow DOM is a new DOM feature that helps you build components. You can think of shadow DOM as a scoped subtree inside your element.
80 |
81 | A shadow root is a document fragment that gets attached to a "host" element. The act of attaching a shadow root is how the element gains its shadow DOM. To create shadow DOM for an element, call element.attachShadow():
82 |
83 | ```js
84 | const header = document.createElement('header');
85 | const shadowRoot = header.attachShadow({mode: 'open'});
86 | shadowRoot.innerHTML = '
Hello Shadow DOM
'; // Could also use appendChild().
87 | // header.shadowRoot === shadowRoot
88 | // shadowRoot.host === header
89 | ```
90 |
91 | ## Libraries for building web components
92 | Many libraries already exist that make it easier to build web components. The libraries section of the site has additional details but here are some you can try out:
93 |
94 | - Hybrids is a UI library for creating Web Components with simple and functional API.
95 | - LitElement uses lit-html to render into the element's Shadow DOM and adds API to help manage element properties and attributes.
96 | - Polymer provides a set of features for creating custom elements.
97 | - Slim.js is an opensource lightweight web component library that provides data-binding and extended capabilities for components, using es6 native class inheritance.
98 | - Stencil is an opensource compiler that generates standards-compliant web components.
99 |
--------------------------------------------------------------------------------
/docs/about/libraries.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: layout-about.njk
3 | ---
4 |
5 | # Libraries
6 |
7 | ## Why use a web component library?
8 | Web Components can be hard to write from scratch. There’s a lot to think about, and writing a component can require a lot of boilerplate code. Fortunately, there are some great libraries that can make creating custom elements more straightforward, and save you a lot of time and effort.
9 |
10 | It’s important to note that you don’t need to use a library to build and share a custom element! Raw custom elements are great if your task is limited to one or a few elements, allowing a more streamlined implementation and preventing library lock-in.
11 |
12 | However, if you’re writing lots and lots of custom elements, using a library can make your code simpler and cleaner, and your workflow more efficient.
13 |
14 | ## What should you look for in a web component library?
15 | When choosing a web component library, make sure it has a large enough featureset to cover all of your use cases. Interoperability is also important - does the library leak implementation details? A good web component library should produce a web component that “just works” like any other HTML element. Good libraries also have a high value-to-payload ratio - that is, they provide a lot of value for their download size. Libraries which support ES modules, Custom Element, Shadow DOM and Template are listed below.
16 |
17 | # Some web component libraries
18 | This list has been compiled by the community and can be modified via pull request under the community repository for this website. Projects are listed alphabetically and are known to support all four aspects of the web components specification.
19 |
20 | - Hybrids is a UI library for creating web components with simple and functional API. The library uses plain objects and pure functions for defining custom elements, which allow very flexible composition. It provides built-in cache mechanism, template engine based on tagged template literals, and integration with developer tools.
21 | - LitElement uses lit-html to render into the element's Shadow DOM and adds API to help manage element properties and attributes. LitElement reacts to changes in properties and renders declaratively using lit-html.
22 | - Polymer is a web component library built by Google, with a simple element creation API. Polymer offers one- and two-way data binding into element templates, and provides shims for better cross-browser performance.
23 | - Skate.js is a library built on top of the W3C web component specs that enables you to write functional and performant web components with a very small footprint. Skate is inherently cross-framework compatible. For example, it works seamlessly with - and complements - React and other frameworks.
24 | - Slim.js Slim.js is a lightweight web component library that provides extended capabilities for components, such as data binding, using es6 native class inheritance. This library is focused for providing the developer the ability to write robust and native web components without the hassle of dependencies and an overhead of a framework.
25 | - Stencil is an opensource compiler that generates standards-compliant web components.
--------------------------------------------------------------------------------
/docs/about/resources.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: layout-about.njk
3 | ---
4 |
5 | # Resources
6 |
7 | The WebComponents.org Resources section is a place to showcase useful tools and boilerplates to easily start hacking on your own custom elements.
8 |
9 | ## 1. Learn
10 | Web Components is a set of specs that introduce powerful new capabilities to the web platform. Before getting started with your first custom element, it will be helpful to understand the scope of these new features. The Introduction section contains an overview of these APIs. The Community section is also a great way to catch up on the latest goings-on in the Web Components world. We’d also recommend starting out by reading the Getting Started sections of:
11 |
12 | - Polymer's documentation;
13 | - Slim.js's documentation.
14 | - Skate.js's documentation.
15 | These will give you an idea on how these libraries for building web components work and what might be best for you. Another incredible resource is the web-components-todo repo which has the same to-do list app created in an ever growing list of web component and component compatible library methodologies. It's a great way to learn from the differences in techniques across libraries and see which one is right for your needs.
16 |
17 | ## 2. Create
18 | Once you’ve learned about Web Components, it's time to create your own element! There are a number of different jumping-off points for getting started using a Web Component library, or just using the vanilla Web Component APIs directly:
19 |
20 | - Polymer Boilerplate
21 | - VanillaJS Boilerplate.
22 | In these boilerplates, we solve the same problem using different libraries (Polymer / SkateJS / LitElement / SlimJS) or no library at all (VanillaJS), with the same tools and directory structure.
23 |
24 | We encourage a series of best practices like setting up a live demo, documenting your API, maintaining a changelog for release purposes, and sharing your component on NPM. The boilerplates form small, opinionated starter-kits with all you need included, from polyfills to automated tasks.
25 |
26 | You’ll still need to make some manual changes after forking each boilerplate, like changing an element's name in different files. In order to automate this process, we created a Yeoman Generator and a Slush Generator that can scaffold a web component using the command-line:
27 |
28 | - Element Generator for Yeoman
29 | - Element Generator for Slush
30 | - RHElement Generator
31 | The generators help ensure an even more seamless start, helping with tasks like validating your element's name according to W3C's spec rules and checking if there's a similarly-named project on NPM.
32 |
33 | Some projects also have command-line tools to help automate the scaffolding of web components and applications:
34 |
35 | - Polymer CLI - CLI + build Polymer 3 & scaffold full applications
36 | - StencilJS - CLI & Compiler to generate VanillaJS elements
37 | - Web Component Factory - CLI to produce boilerplate VanillaJS, SlimJS, StencilJS, Polmer 3, LitElement
38 |
39 | ## 3. Share
40 | Now that you’ve finished your element it's time to share it with the world! The web component ecosystem is growing quickly, and there are thousands of other developers out there who may benefit from your work.
41 |
42 | The best way to share a component is by making it available for use with one of the current JavaScript package managers. Currently most web component libraries have great support for Bower, and are working on improving support for npm.
43 |
44 | And make sure to publish your element to webcomponents.org! Check out the Publish page to learn how to publish your element.
--------------------------------------------------------------------------------
/docs/about/specifications.md:
--------------------------------------------------------------------------------
1 | ---
2 | layout: layout-about.njk
3 | ---
4 |
5 | # Specifications
6 |
7 | Web components is a meta-specification made possible by four other specifications:
8 |
9 | - The Custom Elements specification
10 | - The shadow DOM specification
11 | - The HTML Template specification
12 | - The ES Module specification
13 |
14 | These four specifications can be used on their own but combined allow developers to define their own tags (custom element), whose styles are encapsulated and isolated (shadow dom), that can be restamped many times (template), and have a consistent way of being integrated into applications (es module).
15 |
16 | ## The Custom Elements specification
17 | This section applies to the cross-browser version of the Custom Elements specification (v1). See Eric Bidelman’s articles on Custom Elements v1.
18 |
19 | The Custom Elements specification lays the foundation for designing and using new types of DOM elements that are fully-featured and conforming. Following the Custom Elements spec, authors can define behaviors and styles for new HTML elements.
20 |
21 | - Autonomous custom elements are new HTML tags, defined entirely by the author. They have none of the semantics of existing HTML elements, so all behaviors need to be defined by the author.
22 | - Customized built-ins extend existing HTML elements with custom functionality. They inherit semantics from the elements they extend. The specification for customized built-ins is still a work in progress, and at present is only supported by Chrome.
23 |
24 | ### Create a custom button as an autonomous custom element
25 | To create an autonomous custom element, extend HTMLElement. The Custom Elements syntax is:
26 |
27 | ```js
28 | class AutonomousButton extends HTMLElement {
29 | ...
30 | }
31 | customElements.define("autonomous-button", AutonomousButton);
32 | ```
33 |
34 | To use the element:
35 | ```html
36 | Click Me :)
37 | ```
38 | When the browser sees the tag, it constructs and renders a new instance of the AutonomousButton class. However, this element will not behave like an HTML