-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
General documentation fixes (link to parent: CanJS#4116, Component#264, and Component#270) #288
base: master
Are you sure you want to change the base?
Changes from all commits
dae3d9f
eefd91b
14646f2
7719927
65c71ea
2e6e5f7
52e7d59
b65fc93
e5c952a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,7 +189,7 @@ document.body.appendChild( renderer( { } ) ); | |
Check this out here: | ||
|
||
@demo demos/can-component/click_me.html | ||
|
||
@codepen | ||
|
||
Typically, you do not append a single component at a time. Instead, | ||
you’ll render a view with many custom tags like: | ||
|
@@ -273,6 +273,72 @@ Changes `<hello-world>Hi There</hello-world>` into: | |
<hello-world><h1>Hi There</h1></hello-world> | ||
``` | ||
|
||
In the example above, the child (`<h1>Hi There</h1>`) of the component’s element | ||
(`<hello-world>`) is treated as its [can-component/content] and rendered | ||
wherever the `<content />` placeholder is provided in the component’s `view`. | ||
|
||
If a component is defined **without** a [can-component.prototype.view] property, | ||
it will render whatever `LIGHT_DOM` it is given. For example, a component as | ||
follows: | ||
|
||
```js | ||
Component.extend({ | ||
tag: "my-el", | ||
events: { | ||
click: function() { | ||
// Fired when the <my-el> element is clicked | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
…used like so: | ||
|
||
```html | ||
<my-el>Here’s my content!</my-el> | ||
``` | ||
|
||
…will be rendered as: | ||
|
||
```html | ||
<my-el>Here’s my content!</my-el> | ||
``` | ||
|
||
With [can-component.prototype.leakScope] enabled, the component’s ViewModel can | ||
provide data to the LIGHT_DOM it contains, such that components like this: | ||
|
||
```js | ||
Component.extend({ | ||
leakScope: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @justinbmeyer I see your comment here about this only working with But this definitely works without Is it a bug? Here’s the issue I originally filed about this: #270 |
||
tag: "my-el", | ||
ViewModel: { | ||
message: { | ||
default: "I’m from my-el", | ||
} | ||
} | ||
}); | ||
|
||
Component.extend({ | ||
tag: "my-app", | ||
view: "<my-el>{{message}}</my-el>", | ||
ViewModel: { | ||
message: { | ||
default: "I’m from my-app", | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
…will be rendered as: | ||
|
||
```html | ||
<my-app> | ||
<my-el> | ||
I’m from my-el | ||
</my-el> | ||
</my-app> | ||
``` | ||
|
||
### ViewModel | ||
|
||
A component’s [can-component::ViewModel ViewModel] defines a constructor that creates | ||
|
@@ -621,6 +687,8 @@ This would make `helloWorldInstance.element` a fragment with the following struc | |
<hello-world>Hello <em>mundo</em></hello-world> | ||
``` | ||
|
||
|
||
|
||
### scope | ||
|
||
You can also provide a `scope` with which the content should be rendered: | ||
|
@@ -690,6 +758,7 @@ The following demos a tabs widget. Click “Add Vegetables” | |
to add a new tab. | ||
|
||
@demo demos/can-component/tabs.html | ||
@codepen | ||
|
||
An instance of the tabs widget is created by creating `<my-tabs>` and `<my-panel>` | ||
elements like: | ||
|
@@ -724,6 +793,7 @@ vm.addPanel( this.viewModel ); | |
The following tree combo lets people walk through a hierarchy and select locations. | ||
|
||
@demo demos/can-component/treecombo.html | ||
@codepen | ||
|
||
The secret to this widget is the viewModel’s `breadcrumb` property, which is an array | ||
of items the user has navigated through, and `selectableItems`, which represents the children of the | ||
|
@@ -772,6 +842,7 @@ The following example shows 3 | |
widget-like components: a grid, next / prev buttons, and a page count indicator. And, it shows an application component that puts them all together. | ||
|
||
@demo demos/can-component/paginate.html | ||
@codepen | ||
|
||
This demo uses a `Paginate` [can-define/map/map] to assist with maintaining a paginated state: | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ There are three things to understand about a [can-component]’s view: | |
The following example demonstrates all three features: | ||
|
||
@demo demos/can-component/my_greeting_full.html | ||
@codepen | ||
|
||
The following explains how each part works: | ||
|
||
|
@@ -211,3 +212,37 @@ it produces: | |
```html | ||
<my-greeting><h1>Hello World</h1></my-greeting> | ||
``` | ||
|
||
### Omitting view entirely | ||
|
||
If a component does not have a `view` defined, | ||
the content (whether defined or passed inline) will be rendered instead. | ||
|
||
This means a component like this: | ||
|
||
```js | ||
Component.extend({ | ||
tag: "my-greeting", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extra tab here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why this is showing up in Github, it doesn't show on my local text editor |
||
}) | ||
``` | ||
|
||
…will cause `<my-greeting>Hello Friend</my-greeting>` to render like: | ||
|
||
```html | ||
<my-greeting>Hello Friend</my-greeting> | ||
``` | ||
|
||
The following component: | ||
|
||
```js | ||
Component.extend({ | ||
tag: "my-greeting", | ||
view: "Hello World" | ||
}) | ||
``` | ||
|
||
…will render like: | ||
|
||
```html | ||
<my-greeting>Hello World</my-greeting> | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these should work as of this PR: canjs/canjs#4388