Skip to content

Commit

Permalink
Update component-basics for octane polish quest (#637)
Browse files Browse the repository at this point in the history
  • Loading branch information
Frozenfire92 authored and jenweber committed Mar 18, 2019
1 parent e40f1ca commit 925c147
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions guides/release/components/component-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ Like we mentioned in the section on [Templates](../../templates/handlebars-basic
can have both a template and a class definition, like so:

```handlebars {data-filename=app/templates/components/hello-button.hbs}
<button onclick={{this.sayHello}}>
<button {{action this.sayHello}}>
{{@buttonText}}
</button>
```

```js {data-filename=app/components/hello-button.js}
```javascript {data-filename=app/components/hello-button.js}
import Component from '@glimmer/component';
import action from '@ember/object';
import { action } from '@ember/object';

export default class HelloButton extends Component {
@action
Expand All @@ -29,7 +29,7 @@ export default class HelloButton extends Component {

And they can be used in other templates:

```handlebars
```handlebars {data-filename=app/templates/application.hbs}
<HelloButton @buttonText="Say Hello!"/>
```

Expand All @@ -44,12 +44,12 @@ following HTML output wherever it was used:
</button>
```

And when we click on the button, it triggers its `onclick` handler, logging
And when we click on the button, it triggers the `sayHello` action, logging
"Hello, world!" to the console. We can reuse this component as many times as we
like, and we can even change the text via the value that we pass to it,
`@buttonText`, which is known as an _argument_:

```handlebars
```handlebars {data-filename=app/templates/application.hbs}
<HelloButton @buttonText="Say Hello!"/>
<HelloButton @buttonText="Di Hola!"/>
<HelloButton @buttonText="Dis Bonjour!"/>
Expand Down Expand Up @@ -77,16 +77,13 @@ counterpart, _actions_ - later on.
You can also use template helpers, modifiers, and other components within your
component template:

```handlebars
{{#if @useCustomButton}}
<CustomButton @onClick={{@sayHello}}>
{{this.buttonText}}
</CustomButton>
{{else}}
<button onclick={{@sayHello}}>
{{this.buttonText}}
</button>
{{/if}}
```handlebars {data-filename=app/templates/components/hello-button.hbs}
<button {{action this.sayHello}}>
{{#if @iconType}}
<Icon @type={{@iconType}} />
{{/if}}
{{concat @buttonText "!"}}
</button>
```

This allows you to have some logic in your templates, and to nest components
Expand All @@ -98,19 +95,19 @@ inspect it using the [Ember Inspector](../../ember-inspector/).

Components can also have blocks and children, just like standard HTML elements.
We could update the `HelloButton` component to render its button text from its
block instead of the `@buttonText` argument, by adding the `{{yields}}` keyword
block instead of the `@buttonText` argument, by adding the `{{yield}}` helper
to its template where we want to place its block:

```handlebars {data-filename=app/templates/components/hello-button.hbs}
<button onclick={{this.sayHello}}>
<button {{action this.sayHello}}>
{{yield}}
</button>
```

And then invoking the component in block form, with the text we want to be
rendered in the button:

```handlebars
```handlebars {data-filename=app/templates/application.hbs}
<HelloButton>
Say Hello!
</HelloButton>
Expand Down Expand Up @@ -141,5 +138,8 @@ In the following guides we'll talk about:

- **Yields**, block invocation in components, and how to pass values to blocks.

- **Interacting with the DOM**, some libraries require direct DOM manipulation,
which Ember fully supports

- **Contextual Components**, which can be used dynamically to pass components
around as values, and allow them to be invoked in different locations.

0 comments on commit 925c147

Please sign in to comment.