{"id":13837706,"url":"https://github.com/nativew/nativeweb","last_synced_at":"2025-07-10T19:30:22.402Z","repository":{"id":57308867,"uuid":"230481605","full_name":"nativew/nativeweb","owner":"nativew","description":"🤳 Tiny library for simple web components. [1kB]","archived":false,"fork":false,"pushed_at":"2021-06-05T02:20:00.000Z","size":151,"stargazers_count":99,"open_issues_count":0,"forks_count":4,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-06-15T04:08:53.707Z","etag":null,"topics":["components","framework","javascript","js","native-web","web-components"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nativew.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}},"created_at":"2019-12-27T17:02:20.000Z","updated_at":"2025-01-09T14:23:26.000Z","dependencies_parsed_at":"2022-09-01T06:31:50.902Z","dependency_job_id":null,"html_url":"https://github.com/nativew/nativeweb","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/nativew/nativeweb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nativew%2Fnativeweb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nativew%2Fnativeweb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nativew%2Fnativeweb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nativew%2Fnativeweb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nativew","download_url":"https://codeload.github.com/nativew/nativeweb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nativew%2Fnativeweb/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264639832,"owners_count":23642313,"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":["components","framework","javascript","js","native-web","web-components"],"created_at":"2024-08-04T15:01:21.366Z","updated_at":"2025-07-10T19:30:22.067Z","avatar_url":"https://github.com/nativew.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e\n    \u003cbr\u003e\n    \u003cp\u003e\n        \u003ca href=\"https://github.com/nativew/nativeweb\"\u003e\n            \u003cimg src=\"https://raw.githubusercontent.com/nativew/nativeweb/1e9405c629e3a6491bb59df726044eb3823967bb/logo-rectangle_nativeweb.svg\" alt=\"Native Web\"\u003e\n        \u003c/a\u003e\n    \u003c/p\u003e\n    \u003cp\u003e\n        Tiny library for simple web components. \u003cbr\u003e\n        \u003csub\u003e\u003ccode\u003e1kB\u003c/code\u003e\u003c/sub\u003e\n    \u003c/p\u003e\n    \u003cbr\u003e\n\u003c/div\u003e\n\n\u003cbr\u003e\n\n```js\nimport { component, property, Element } from 'nativeweb';\n\n@component('hey-internet')\nclass Component extends Element {\n    @property() emoji;\n\n    render() {\n        return `\n            \u003ch1\u003eHey Internet ${this.emoji}\u003c/h1\u003e\n        `;\n    }\n}\n```\n\n```html\n\u003chey-internet emoji=\"👋\"\u003e\u003c/hey-internet\u003e\n```\n\n\u003cbr\u003e\n\n### Native web components\n\n### Encapsulated styles and scripts\n\n### Simplified with decorators\n\n### Tiny footprint\n\n\u003cbr\u003e\n\n### One command to [start](https://github.com/nativew/start)\n\n```zsh\nnpm init nativeweb\n```\n\n\u003cbr\u003e\n\n### Or add to your existing project\n\n```zsh\nnpm install nativeweb\n```\n\n\u003cbr\u003e\n\n### Decorators\n\n[`@component`](#component)\n\n[`@property`](#property)\n\n[`@event`](#event)\n\n[`@customEvent`](#customevent)\n\n[`@query`](#query)\n\n[`@queryAll`](#queryall)\n\n\u003cbr\u003e\n\n### `@component`\n\nDefine a custom element and add styles. From an external file or the same file. `styles` can be an `array` of styles.\n\n```js\nimport { component, Element } from 'nativeweb';\nimport styles from './hey-styles.css.js';\n\n@component('some-styles', styles)\nclass Component extends Element {\n    render() {\n        return `\n            \u003ch1\u003eSome Styles\u003c/h1\u003e\n        `;\n    }\n}\n```\n\n```js\nimport { css } from 'nativeweb';\n\nexport default css`\n    h1 {\n        color: orange;\n    }\n`;\n```\n\n```html\n\u003chey-styles\u003e\u003c/hey-styles\u003e\n```\n\n\u003cbr\u003e\n\n### `@property`\n\nGet an attribute converted to the specified type or define a property with an optional default value.  \n`String`, `Boolean`, `Number`, `Array` or `Object`.\n\n```js\nimport { component, property, Element } from 'nativeweb';\n\n@component('cool-property')\nclass Component extends Element {\n    @property() cool = 'Cool Prop';\n    @property(String) title = 'Default Title';\n    @property(Number) multiplier;\n\n    render() {\n        return `\n            \u003ch1\u003e${this.title}\u003c/h1\u003e\n            \u003ch2\u003e${this.cool} ➡️ ${2 * this.multiplier}\u003c/h2\u003e\n        `;\n    }\n}\n```\n\n```html\n\u003ccool-property title=\"Cool Title 🤙\" multiplier=\"3\"\u003e\u003c/cool-property\u003e\n```\n\n\u003cbr\u003e\n\n### `@event`\n\nAdd an event listener to a component, a child element named `@name` or an external component event.\n\n```js\nimport { component, event, Element } from 'nativeweb';\n\n@component('easy-event')\nclass Component extends Element {\n    @event() mouseenter = this.onHover();\n    @event() click = {\n        '@title': this.onClick(),\n        '@button': this.onClick()\n    };\n    @event() ready = {\n        'other-component': this.onReady()\n    };\n\n    onHover() {\n        console.log('Hover Component');\n    }\n    onClick(e) {\n        console.log(e.currentTarget);\n    }\n    onReady({ detail }) {\n        console.log(detail);\n    }\n\n    render() {\n        return `\n            \u003ch1 @title\u003eEasy Event\u003c/h1\u003e\n            \u003cbutton @button\u003eClick Me\u003c/button\u003e\n        `;\n    }\n}\n```\n\n```html\n\u003ceasy-event\u003e\u003c/easy-event\u003e\n```\n\n\u003cbr\u003e\n\n### `@customEvent`\n\nCreate a custom global event, namespaced with the component name. Ready to be dispatched. The listener is in the [component above](#event).\n\n```js\nimport { component, customEvent, Element } from 'nativeweb';\n\n@component('other-component')\nclass Component extends Element {\n    @customEvent() ready = 'Ready 🚀';\n\n    connected() {\n        dispatchEvent(this.ready);\n    }\n\n    render() {\n        return `\n            \u003ch1\u003eOther Component\u003c/h1\u003e\n        `;\n    }\n}\n```\n\n```html\n\u003cother-component\u003e\u003c/other-component\u003e\n```\n\n\u003cbr\u003e\n\n### `@query`\n\nQuery selector an `@name` child element.\n\n```js\nimport { component, query, Element } from 'nativeweb';\n\n@component('simple-query')\nclass Component extends Element {\n    @query() title;\n\n    connected() {\n        this.title.innerText = 'Better Title 💯';\n    }\n\n    render() {\n        return `\n            \u003ch1 @title\u003eGood Title\u003c/h1\u003e\n        `;\n    }\n}\n```\n\n```html\n\u003csimple-query\u003e\u003c/simple-query\u003e\n```\n\n\u003cbr\u003e\n\n### `@queryAll`\n\nQuery selector all `@name` child elements.\n\n```js\nimport { component, queryAll, Element } from 'nativeweb';\n\n@component('all-query')\nclass Component extends Element {\n    @queryAll() title;\n\n    connected() {\n        this.title.forEach(el =\u003e (el.style.color = 'lightgreen'));\n    }\n\n    render() {\n        return `\n            \u003ch1 @title\u003eOne Title\u003c/h1\u003e\n            \u003ch2 @title\u003eOther Title\u003c/h2\u003e\n        `;\n    }\n}\n```\n\n```html\n\u003call-query\u003e\u003c/all-query\u003e\n```\n\n\u003cbr\u003e\n\n### Lifecycle\n\n`render()` \u0026nbsp; → \u0026nbsp; Renders the component.\n\n`connected()` \u0026nbsp; → \u0026nbsp; Called when the component is inserted in the DOM.\n\n`disconnected()` \u0026nbsp; → \u0026nbsp; Called when the component is removed from the DOM.\n\n`adopted()` \u0026nbsp; → \u0026nbsp; Called when the component is moved to a new document.\n\n`attributeChanged()` \u0026nbsp; → \u0026nbsp; Called when an observed attribute changes.\n\n\u003cbr\u003e\n\n### Methods\n\n`this.update()` \u0026nbsp; → \u0026nbsp; Rerenders the component.\n\n\u003cbr\u003e\n\n### Properties\n\n`this.properties` \u0026nbsp; → \u0026nbsp; Get all attributes.\n\n\u003cbr\u003e\n\n### Tips\n\n[Shared style](#shared-style)\n\n[Composition](#composition)\n\n[Conditional](#conditional)\n\n[Loop](#loop)\n\n[Variable element](#variable-element)\n\n\u003cbr\u003e\n\n### Shared style\n\nInclude global styles in a component.\n\n```js\nimport { css } from 'nativeweb';\nimport global from '../global-style.css.js';\n\nexport default [\n    global,\n    css`\n        h1 {\n            color: orange;\n        }\n    `\n];\n```\n\n\u003cbr\u003e\n\n### Composition\n\nComponent composition with default slot and named slot.\n\n```js\nimport { component, Element } from 'nativeweb';\n\n@component('slot-example')\nclass Component extends Element {\n    render() {\n        return `\n            \u003cheader\u003e\n                \u003ch1\u003e\u003cslot name=\"title\"\u003e\u003c/slot\u003e\u003c/h1\u003e\n                \u003cslot\u003e\u003c/slot\u003e\n            \u003c/header\u003e\n        `;\n    }\n}\n```\n\n```html\n\u003cslot-example\u003e\n    \u003cspan slot=\"title\"\u003eNamed slot\u003c/span\u003e\n    \u003cp\u003eDefault slot\u003c/p\u003e\n\u003c/slot-example\u003e\n```\n\n\u003cbr\u003e\n\n### Conditional\n\nConditional rendering in vanilla JS.\n\n```js\nimport { component, property, Element } from 'nativeweb';\n\n@component('condition-example')\nclass Component extends Element {\n    @property() isGood = false;\n\n    render() {\n        return `\n            ${this.isGood ? `\u003ch1\u003eGood\u003c/h1\u003e` : ``}\n        `;\n    }\n}\n```\n\n\u003cbr\u003e\n\n### Loop\n\nRender loop in vanilla JS.\n\n```js\nimport { component, property, Element } from 'nativeweb';\n\n@component('loop-example')\nclass Component extends Element {\n    @property() emojis = ['🤳', '🧨', '🧱'];\n\n    render() {\n        return `\n            ${this.emojis.map(item =\u003e `\u003cspan\u003e${item}\u003c/span\u003e`).join('')}\n        `;\n    }\n}\n```\n\n\u003cbr\u003e\n\n### Variable element\n\nRender an element from a property.\n\n```js\nimport { component, property, Element } from 'nativeweb';\n\n@component('element-example')\nclass Component extends Element {\n    @property() as = 'p';\n\n    render() {\n        return `\n            \u003c${this.as}\u003eHeading 1\u003c/${this.as}\u003e\n        `;\n    }\n}\n```\n\n```html\n\u003celement-example as=\"h1\"\u003e\u003c/element-example\u003e\n```\n\n\u003cbr\u003e\n\n\u003cdiv align=\"center\"\u003e\n    \u003cbr\u003e\n    \u003cp\u003e\n        \u003ca href=\"https://github.com/nativew/nativeweb\"\u003e\n            \u003cimg src=\"https://raw.githubusercontent.com/nativew/nativeweb/1e9405c629e3a6491bb59df726044eb3823967bb/logo-square_nativeweb.svg\" alt=\"Native Web\"\u003e\n        \u003c/a\u003e\n    \u003c/p\u003e\n\u003c/div\u003e\n\n\u003cbr\u003e\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnativew%2Fnativeweb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnativew%2Fnativeweb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnativew%2Fnativeweb/lists"}