{"id":13451944,"url":"https://github.com/ebidel/declarative-web-components","last_synced_at":"2025-04-15T17:33:53.090Z","repository":{"id":144761723,"uuid":"91085703","full_name":"ebidel/declarative-web-components","owner":"ebidel","description":"Author web components, declaratively","archived":false,"fork":false,"pushed_at":"2017-07-16T02:47:46.000Z","size":10,"stargazers_count":35,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-01T11:34:32.184Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ebidel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-05-12T11:41:44.000Z","updated_at":"2023-05-04T12:31:50.000Z","dependencies_parsed_at":"2024-01-16T03:46:04.610Z","dependency_job_id":"ad3ea80e-7a21-431e-9c88-d5aef26d76b7","html_url":"https://github.com/ebidel/declarative-web-components","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ebidel%2Fdeclarative-web-components","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ebidel%2Fdeclarative-web-components/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ebidel%2Fdeclarative-web-components/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ebidel%2Fdeclarative-web-components/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ebidel","download_url":"https://codeload.github.com/ebidel/declarative-web-components/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223681406,"owners_count":17184945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T07:01:07.728Z","updated_at":"2024-11-08T12:02:35.099Z","avatar_url":"https://github.com/ebidel.png","language":"JavaScript","readme":"# Author web components, declaratively\n\nCustom elements and shadow DOM should be declarative. Unfortunately, both APIs\nare JavaScript-based.\n\nThis repo shows how to define two custom elements, `\u003cshadow-root\u003e` and `\u003ccustom-element-definition\u003e` which can be used to declaratively author a web component. Custom elements should be declarative\n\nSee [demo](demo/index.html) for full examples and live demos.\n\n## Examples\n\n**Example** - `\u003cshadow-root\u003e` tag\n\n```\n\u003cdiv id=\"shadow-host\"\u003e\n  \u003cb slot=\"name\"\u003eEric's\u003c/b\u003e\n  \u003cshadow-root\u003e\n    \u003ctemplate\u003e\n      \u003cslot name=\"name\"\u003e\u003c/slot\u003e declarative shadow dom!\n    \u003c/template\u003e\n  \u003c/shadow-root\u003e\n\u003c/div\u003e\n```\n\nWhat this does:\n\n- Creates Shadow DOM from a child `\u003ctemplate\u003e` and attaches the shadow root to the parent element. In this example, `\u003cdiv id=\"shadow-host\"\u003e`.\n\n**Example** - `\u003ccustom-element-definition\u003e` tag:\n\n```html\n\u003ccustom-element-definition name=\"basic-element\"\u003e\n  \u003ctemplate\u003e\n    \u003cspan\u003econtent appended by element's author (in light dom)\u003c/span\u003e\n  \u003c/template\u003e\n\u003c/custom-element-definition\u003e\n```\n\nWhat this does:\n\n- Element does not use Shadow DOM\n- Element does not register itself. The page should called `customElements.define('basic-element')`.\n\n\n**Example** - `\u003ccustom-element-definition\u003e` with styles\n\n```html\n\u003ccustom-element-definition name=\"basic-element-styles\"\u003e\n  \u003ctemplate\u003e\n    \u003cstyle\u003e\n      /* CSS selectors are prefixed/scoped b/c we're not using shadow dom. */\n      basic-element h2 {\n        color: blue\n      }\n    \u003c/style\u003e\n    \u003ch2\u003ebasic-element: some content should be blue\u003c/h2\u003e\n  \u003c/template\u003e\n\u003c/custom-element-definition\u003e\n```\n\nWhat this does:\n\n- Element does not use Shadow DOM\n- Element does not register itself. The page should called `customElements.define('basic-element-styles')`.\n- Element defines styles for its light dom.\n\n**Example** - `\u003ccustom-element-definition\u003e` that uses shadow dom and registers itself\n\n```html\n\u003ccustom-element-definition name=\"my-element\"\u003e\n  \u003cshadow-root\u003e\n    \u003ctemplate\u003e\n      \u003cstyle\u003e\n        :host {\n          display: block;\n          color: red;\n        }\n        ::slotted(span) {\n          color: blue;\n        }\n      \u003c/style\u003e\n      \u003cdiv\u003e\n        \u003cb\u003eclick me (in shadow dom)\u003c/b\u003e\u003cbr\u003e\n        \u003cslot\u003e\u003c/slot\u003e\n      \u003c/div\u003e\n    \u003c/template\u003e\n  \u003c/shadow-root\u003e\n  \u003cscript\u003e\n    (class extends HTMLElement {\n      constructor() {\n        super();\n        this.addEventListener('click', this.sayHi);\n      }\n      sayHi() {\n        alert('Hi!');\n      }\n    })\n  \u003c/script\u003e\n\u003c/custom-element-definition\u003e\n```\n\nWhat this does:\n\n- Element uses Shadow DOM\n- Element auto-registers itself when defining a script in `\u003ccustom-element-definition\u003e`.\n\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Febidel%2Fdeclarative-web-components","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Febidel%2Fdeclarative-web-components","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Febidel%2Fdeclarative-web-components/lists"}