class TodoItemComponent < ApplicationComponent def initialize(todo_item:) @todo_item = todo_item end end
class TodoItemComponent < ApplicationComponent def initialize(todo_item:) @todo_item = todo_item end end
<div class="TodoItem"> <%= @todo_item.text %> <%= button_tag("Edit") %> </div>
<div class="TodoItem"> <%= @todo_item.text %> <%= button_tag("Edit") %> </div>
class TodoItemComponent < ApplicationComponent include LiveComponent::Base # <-- add this line def initialize(todo_item:) @todo_item = todo_item end end
class TodoItemComponent < ApplicationComponent include LiveComponent::Base # <-- add this line def initialize(todo_item:) @todo_item = todo_item end end
import { live, LiveController } from "@camertron/live-component"; @live("TodoItemComponent") // this is the Ruby class name export class TodoItemComponent extends LiveController { // nothing in here yet }
import { live, LiveController } from "@camertron/live-component"; @live("TodoItemComponent") // this is the Ruby class name export class TodoItemComponent extends LiveController { // nothing in here yet }
Note that we're using a TypeScript decorator, i.e. @live, in the example above. You'll need to have decorators turned on in your tsconfig.json to get @live to work. Alternatively, you can register your component without using decorators via Application.register, eg:
import { Application, LiveController } from "@camertron/live-component"; export class TodoItemComponent extends LiveController { // nothing in here yet } Application.register("TodoItemComponent", TodoItemComponent);
import { Application, LiveController } from "@camertron/live-component"; export class TodoItemComponent extends LiveController { // nothing in here yet } Application.register("TodoItemComponent", TodoItemComponent);
class TodoItemComponent < ApplicationComponent include LiveComponent::Base def initialize(todo_item:, editing: false) @todo_item = todo_item @editing = editing end end
class TodoItemComponent < ApplicationComponent include LiveComponent::Base def initialize(todo_item:, editing: false) @todo_item = todo_item @editing = editing end end
<div class="TodoItem"> <% if @editing %> <%= form_with(model: @todo_item) do |f| %> <%= f.text_field :text %> <% end %> <% else %> <%= @todo_item.text %> <%= button_tag("Edit") %> <% end %> </div>
<div class="TodoItem"> <% if @editing %> <%= form_with(model: @todo_item) do |f| %> <%= f.text_field :text %> <% end %> <% else %> <%= @todo_item.text %> <%= button_tag("Edit") %> <% end %> </div>
<div class="TodoItem"> <% if @editing %> <%= form_with(model: @todo_item) do |f| %> <%= f.text_field :text %> <%= f.submit %> <% end %> <% else %> <%= @todo_item.text %> <%= button_tag( "Edit", data: { target: "click->todoitemcomponent#edit" } ) %> <% end %> </div>
<div class="TodoItem"> <% if @editing %> <%= form_with(model: @todo_item) do |f| %> <%= f.text_field :text %> <%= f.submit %> <% end %> <% else %> <%= @todo_item.text %> <%= button_tag( "Edit", data: { target: "click->todoitemcomponent#edit" } ) %> <% end %> </div>
import { live, LiveController } from "@camertron/live-component"; @live("TodoItemComponent") // this is the Ruby class name export class TodoItemComponent extends LiveController { edit() { this.render((component) => { component.props.editing = true; }); } }
import { live, LiveController } from "@camertron/live-component"; @live("TodoItemComponent") // this is the Ruby class name export class TodoItemComponent extends LiveController { edit() { this.render((component) => { component.props.editing = true; }); } }
1 | <div class="TodoItem"> |
2 | <% if @editing %> |
3 | <%= form_with(model: @todo_item) do |f| %> |
4 | <%= f.text_field :text %> |
5 | <%= f.submit %> |
6 | <% end %> |
7 | <% else %> |
8 | <%= @todo_item.text %> |
9 | <%= button_tag( |
10 | "Edit", |
11 | data: { action: "click->todoitemcomponent#edit" } |
12 | ) %> |
13 | <% end %> |
14 | </div>
|
1 | <div class="TodoItem"> |
2 | <% if @editing %> |
3 | <%= form_with(model: @todo_item) do |f| %> |
4 | <%= f.text_field :text %> |
5 | <%= f.submit %> |
6 | <% end %> |
7 | <% else %> |
8 | <%= @todo_item.text %> |
9 | <%= button_tag( |
10 | "Edit", |
11 | data: { action: "click->todoitemcomponent#edit" } |
12 | ) %> |
13 | <% end %> |
14 | </div>
|
1 | class TodoItemComponent < ApplicationComponent |
2 | include LiveComponent::Base |
3 | |
4 | def initialize(todo_item:, editing: false) |
5 | @todo_item = todo_item |
6 | @editing = editing |
7 | end
|
8 | end
|
1 | class TodoItemComponent < ApplicationComponent |
2 | include LiveComponent::Base |
3 | |
4 | def initialize(todo_item:, editing: false) |
5 | @todo_item = todo_item |
6 | @editing = editing |
7 | end
|
8 | end
|
1 | import { live, LiveController } from "@camertron/live-component"; |
2 | |
3 | @live("TodoItemComponent") // this is the Ruby class name |
4 | export class TodoItemComponent extends LiveController { |
5 | edit() { |
6 | this.render((component) => { |
7 | component.props.editing = true; |
8 | });
|
9 | }
|
10 | }
|
1 | import { live, LiveController } from "@camertron/live-component"; |
2 | |
3 | @live("TodoItemComponent") // this is the Ruby class name |
4 | export class TodoItemComponent extends LiveController { |
5 | edit() { |
6 | this.render((component) => { |
7 | component.props.editing = true; |
8 | });
|
9 | }
|
10 | }
|