{"id":25049110,"url":"https://github.com/rodydavis/dart-web-components","last_synced_at":"2025-10-31T15:30:23.291Z","repository":{"id":275833276,"uuid":"927337941","full_name":"rodydavis/dart-web-components","owner":"rodydavis","description":"Dart + Web Components","archived":false,"fork":false,"pushed_at":"2025-02-14T07:51:48.000Z","size":716,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-14T08:33:22.546Z","etag":null,"topics":["dart","flutter","html","js","signals","wasm","web"],"latest_commit_sha":null,"homepage":"https://rodydavis.github.io/dart-web-components/","language":"Dart","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/rodydavis.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-04T19:42:34.000Z","updated_at":"2025-02-14T07:51:51.000Z","dependencies_parsed_at":"2025-02-04T20:33:48.312Z","dependency_job_id":"9bea688b-c8fb-403c-a9c5-040e25a72e91","html_url":"https://github.com/rodydavis/dart-web-components","commit_stats":null,"previous_names":["rodydavis/dart-web-components"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodydavis%2Fdart-web-components","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodydavis%2Fdart-web-components/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodydavis%2Fdart-web-components/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodydavis%2Fdart-web-components/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rodydavis","download_url":"https://codeload.github.com/rodydavis/dart-web-components/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239207403,"owners_count":19599966,"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":["dart","flutter","html","js","signals","wasm","web"],"created_at":"2025-02-06T08:02:27.255Z","updated_at":"2025-10-31T15:30:23.259Z","avatar_url":"https://github.com/rodydavis.png","language":"Dart","funding_links":[],"categories":["Dart"],"sub_categories":[],"readme":"# Dart Web Components\n\nHow to create [web components](https://developer.mozilla.org/en-US/docs/Web/API/Web_components) with Dart that compile to WASM and JS.\n\nYou can use them in any framework or library that supports HTML.\n\n\u003e Disclaimer: This is not an official Google project.\n\n## Getting Started\n\n### 1. Extend the WebComponent class\n\n```dart\nimport 'package:html_web_components/html_web_components.dart';\n\nclass MyComponent extends WebComponent {\n  ...\n}\n```\n\n### 2. Define the component\n\nUse the connectedCallback to define the component setup logic instead of the constructor.\n\n```dart\nimport 'package:html_web_components/html_web_components.dart';\n\nclass MyComponent extends WebComponent {\n  @override\n  void connectedCallback() {\n    element.innerText = \"Hello World!\";\n  }\n}\n```\n\n### 3. Register the component\n\n```dart\nimport 'package:html_web_components/html_web_components.dart';\n...\n\nvoid main() {\n  WebComponent.define('my-component', MyComponent.new);\n}\n```\n\n## Mixins\n\nThere are some helper mixins to make it easier to work with web components.\n\n### WebComponentCleanupMixin\n\nThis mixin adds an array of callbacks that will be disposed when the component is disconnected.\n\n```dart\nimport 'package:html_web_components/html_web_components.dart';\nimport 'package:html_web_components/helpers.dart';\n\nclass MyComponent extends WebComponent with WebComponentCleanupMixin {\n  @override\n  void connectedCallback() {\n    this.cleanup.add(() =\u003e print('cleaned up!'));\n  }\n}\n```\n\n### WebComponentShadowDomMixin\n\nThis mixin adds a shadow root to the component.\n\n```dart\nimport 'package:html_web_components/html_web_components.dart';\nimport 'package:html_web_components/helpers.dart';\n\nclass MyComponent extends WebComponent with WebComponentShadowDomMixin {\n  @override\n  void connectedCallback() {\n    getRoot\u003cShadowRoot\u003e().innerHtml = '\u003ch1\u003eHello World\u003c/h1\u003e';\n  }\n}\n```\n\n### WebComponentAdoptedStylesMixin\n\nThis mixin adds adopted styles to the component. This only works with the shadow dom.\n\n```dart\nimport 'package:html_web_components/html_web_components.dart';\nimport 'package:html_web_components/helpers.dart';\nimport 'package:signals_core/signals_core.dart';\n\nclass MyComponent extends WebComponent with WebComponentShadowDomMixin, WebComponentAdoptedStylesMixin {\n  @override\n  final sheets = computed\u003cList\u003cCSSStyleSheet\u003e\u003e(() {\n    final sheet = CSSStyleSheet();\n    sheet.replaceSync('h1 { color: red; }');\n    return [sheet];\n  });\n\n  @override\n  void connectedCallback() {\n    getRoot\u003cShadowRoot\u003e().innerHtml = '\u003ch1\u003eHello World\u003c/h1\u003e';\n  }\n}\n```\n\n### WebComponentReactiveAttributesMixin\n\nThis mixin adds reactive attributes to the component.\n\n```dart\nimport 'package:html_web_components/html_web_components.dart';\nimport 'package:html_web_components/helpers.dart';\nimport 'package:signals_core/signals_core.dart';\n\nclass MyComponent extends WebComponent with WebComponentReactiveAttributesMixin {\n  @override\n  List\u003cString\u003e observedAttributes = ['name'];\n\n  final src = attr('name');\n\n  @override\n  void connectedCallback() {\n    cleanup.add(effect((){\n      element.innerHtml = '\u003ch1\u003eHello $src\u003c/h1\u003e';\n    }));\n  }\n}\n```\n\n## Links\n\n- [Web Components](https://developer.mozilla.org/en-US/docs/Web/Web_Components)\n- [Are web components used a lot?](https://arewebcomponentsathingyet.com)\n- [Dart Web Components](https://github.com/dart-archive/web-components)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodydavis%2Fdart-web-components","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frodydavis%2Fdart-web-components","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodydavis%2Fdart-web-components/lists"}