{"id":18940314,"url":"https://github.com/donejs/done-component","last_synced_at":"2025-04-15T19:31:16.791Z","repository":{"id":32444196,"uuid":"36022506","full_name":"donejs/done-component","owner":"donejs","description":"A plugin for creating \u003ccan-component\u003es","archived":false,"fork":false,"pushed_at":"2020-05-23T12:03:45.000Z","size":130,"stargazers_count":8,"open_issues_count":11,"forks_count":2,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-04-12T04:33:50.453Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/done-component","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/donejs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-21T15:54:41.000Z","updated_at":"2019-06-20T16:47:13.000Z","dependencies_parsed_at":"2022-07-17T20:41:45.840Z","dependency_job_id":null,"html_url":"https://github.com/donejs/done-component","commit_stats":null,"previous_names":["stealjs/system-component"],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donejs%2Fdone-component","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donejs%2Fdone-component/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donejs%2Fdone-component/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/donejs%2Fdone-component/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/donejs","download_url":"https://codeload.github.com/donejs/done-component/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249138724,"owners_count":21218933,"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-11-08T12:21:54.761Z","updated_at":"2025-04-15T19:31:16.525Z","avatar_url":"https://github.com/donejs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/donejs/done-component.svg?branch=master)](https://travis-ci.org/stealjs/done-component)\n[![npm version](https://badge.fury.io/js/done-component.svg)](http://badge.fury.io/js/done-component)\n\n# done-component\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/donejs/done-component.svg)](https://greenkeeper.io/)\n\nA [StealJS](http://stealjs.com/) plugin for [CanJS](http://canjs.com/) components.  done-component allows you to easily define your component completely from a single `.component` file:\n\n## Install\n\n```\nnpm install done-component --save\n```\n\n## Usage\n\nDefine a can.Component in a separate file:\n\n### hello.component\n\n```mustache\n\u003ccan-component tag=\"hello-world\"\u003e\n\t\u003cstyle type=\"text/less\"\u003e\n\t\ti {\n\t\t\tcolor: red;\n\t\t}\n\t\u003c/style\u003e\n\t\u003ctemplate\u003e\n\t\t{{#if visible}}\u003cb\u003e{{message}}\u003c/b\u003e{{else}}\u003ci\u003eClick me\u003c/i\u003e{{/if}}\n\t\u003c/template\u003e\n\t\u003cscript type=\"view-model\"\u003e\n\t\texport default {\n\t\t\tvisible: true,\n\t\t\tmessage: \"Hello There!\"\n\t\t};\n\t\u003c/script\u003e\n\t\u003cscript type=\"events\"\u003e\n\t\texport default {\n\t\t\tclick: function(){\n\t\t\t\tthis.viewModel.attr(\"visible\", !this.viewModel.attr(\"visible\"))\n\t\t\t}\n\t\t};\n\t\u003c/script\u003e\n\u003c/can-component\u003e\n```\n\n### main.stache\n\nIn your template simply import your component and you can start using it:\n\n```mustache\n\u003ccan-import from=\"hello-world.component!\"/\u003e\n\n\u003chello-world\u003e\u003c/hello-world\u003e\n```\n\n## API\n\n### tag\n\nThe tag name is specified on the `can-component` element. This corresponds to `tag` when defining a Component in JavaScript.\n\n```html\n\u003ccan-component tag=\"foo-bar\"\u003e\n\n\u003c/can-component\u003e\n```\n\nThis defines a custom element \"foo-bar\" when you can use in your templates:\n\n```js\n\u003cfoo-bar\u003e\u003c/foo-bar\u003e\n```\n\n### leak-scope\n\nThe **leak-scope** attribute is equivalent to setting `leakScope: true` using [can-component](http://canjs.github.io/canjs/doc/can-component.html) directly.\n\n```html\n\u003ccan-component tag=\"foo-bar\" leak-scope\u003e\n\n\u003c/can-component\u003e\n```\n\nIs equivalent to writing:\n\n```js\nComponent.extend({\n\ttag: \"foo-bar\",\n\tleakScope: true\n});\n```\n\n### style\n\nThe `\u003cstyle\u003e` tag lets you include CSS specific to your component. By default it will use the CSS plugin but you can use preprocessors by specifying:\n\n#### type\n\nThe style type lets you use an alternative to CSS such as Less:\n\n```html\n\u003cstyle type=\"text/less\"\u003e\n  span {\n    color: red\n  }\n\u003c/style\u003e\n```\n\nNot that when using Less your style is automatically wrapped with the Component's tag name, so that it is scoped to only your component.\n\n### template\n\nThe `\u003ctemplate\u003e` tag is where you put your Stache template.\n\n### view-model\n\nThe `\u003cview-model\u003e` or `\u003cscript type=\"view-model\"\u003e` is where you put your viewModel. You can use either method, but the `\u003cscript\u003e` method is more compatible with your editor.\n\n### events\n\nThe `\u003cevents\u003e` or `\u003cscript type=\"events\"\u003e` is where you put your events object.\n\n### helpers\n\nThe `\u003chelpers\u003e` or `\u003cscript type=\"helpers\"\u003e` is where you put Stache helpers.\n\n### from\n\nEach of the subtags (style, template, view-model, events, and helpers) can optionally take a `from=` attribute that allows you to define that in a separate module. It's useful if one part is longer and you want to separate that out into it's own file:\n\n```html\n\u003ccan-component tag=\"foo\"\u003e\n  \u003cview-model from=\"foo/view_model\"/\u003e\n\u003c/can-component\u003e\n```\n\n## Exported Object\n\nYour `.component` will export an object that contains properties for `Component` which is the can.Component constructor, `ViewModel` which is a can.Map of your exported ViewModel.  This is useful for when testing:\n\n```js\nvar QUnit = require(\"steal-qunit\");\nvar HelloVM = require(\"hello-world.component!\").ViewModel;\n\nQUnit.test(\"view model works\", function(){\n  var map = new HelloVM();\n  ...\n});\n\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdonejs%2Fdone-component","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdonejs%2Fdone-component","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdonejs%2Fdone-component/lists"}