-
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 5 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,36 @@ Changes `<hello-world>Hi There</hello-world>` into: | |
<hello-world><h1>Hi There</h1></hello-world> | ||
``` | ||
|
||
Essentially, the children of the component tag will be treated as it's [can-component/content], | ||
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.
|
||
to be rendered wherever the tag is provided in the component view. | ||
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. the (You might want to be explicit about which tag). |
||
|
||
If no view is provided to a Component, it will render it's content naively. | ||
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. Are you trying to say:
We don't call the LIGHT DOM a By Also 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. I think maybe it's more accurate to say if there is no view property on a Component, that Component will simply render its LIGHT_DOM |
||
|
||
A component like this: | ||
|
||
```js | ||
Component.extend({ | ||
tag: "can-el", | ||
ViewModel: { | ||
hovMessage: { | ||
default: "I'm from can-el viewModel", | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
Can be rendered like: `<can-el>Here's my content!</can-el>` into exactly what it looks like: | ||
|
||
```html | ||
<can-el>Here's my content!</can-el> | ||
``` | ||
|
||
or you can render viewModel properties using magic tags like : `<can-el>{{hovMessage}}</can-el>`, which renders like: | ||
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. you can't do this without |
||
|
||
```html | ||
<can-el>I'm from can-el viewModel</can-el> | ||
``` | ||
|
||
### ViewModel | ||
|
||
A component’s [can-component::ViewModel ViewModel] defines a constructor that creates | ||
|
@@ -621,6 +651,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 +722,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 +757,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 +806,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 |
---|---|---|
|
@@ -35,3 +35,29 @@ Component.extend( { | |
view: "<h1><content>Hi There!</content></h1>" | ||
} ); | ||
``` | ||
|
||
The children of `<content>` can be used as a default value for rendering in the case that no content is passed. | ||
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. Instead of "no content is passed", I think we probably should introduce the LIGHT_DOM and SHADOW_DOM concepts? Or for CanJS, maybe these should be |
||
|
||
for example: | ||
```js | ||
Component.extend( { | ||
tag: "my-tag", | ||
view: stache( "<h1><content>Hello world</content></h1>" ) | ||
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. lets remove the |
||
} ); | ||
``` | ||
|
||
used like `<my-tag></my-tag>` | ||
|
||
will render: | ||
|
||
```html | ||
<my-tag><h1>Hello world</h1></my-tag> | ||
``` | ||
|
||
When the content is specified, those children will be ignored: | ||
|
||
`<my-tag>Hello friend</my-tag>` will render: | ||
|
||
```html | ||
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. it would be cool if these were <my-tag>Hello Friend</my-tag>
<script type="module">
import {Component} from "can";
...
</script> |
||
<my-tag><h1>Hello friend</h1></my-tag> | ||
``` |
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,38 @@ it produces: | |
```html | ||
<my-greeting><h1>Hello World</h1></my-greeting> | ||
``` | ||
|
||
### Omitting view entirely | ||
|
||
If the user does not provide a view property, | ||
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. Maybe:
|
||
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> | ||
``` | ||
|
||
and | ||
|
||
```js | ||
Component.extend({ | ||
tag: "my-greeting", | ||
content: "Hello World" | ||
}) | ||
``` | ||
|
||
to 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