Sha256: 7c8a53e5b98a9886894ac6aa260d22919adab910ecfe0b4527c0cea2cb91f0bb

Contents?: true

Size: 779 Bytes

Versions: 13

Compression:

Stored size: 779 Bytes

Contents

class InputBox < Hyperloop::Component
  before_mount { mutate.composition '' }

  def render
    div.row.form_group.input_box.navbar.navbar_inverse.navbar_fixed_bottom do
      div.col_sm_1.white { 'Say: ' }
      textarea.col_sm_5(rows: rows, value: state.composition)
      .on(:change) do |e|
        mutate.composition e.target.value
      end
      .on(:key_down) do |e|
        send! if send_key?(e)
      end
      FormattedDiv class: 'col-sm-5 white', markdown: state.composition
    end
  end

  def rows
    [state.composition.count("\n") + 1, 20].min
  end

  def send_key?(e)
    (e.char_code == 13 || e.key_code == 13) && (e.meta_key || e.ctrl_key)
  end

  def send!
    Operations::Send message: mutate.composition(''), user_name: MessageStore.user_name
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
hyper-operation-0.5.12 examples/chat-app/app/hyperloop/components/input_box.rb
hyper-operation-0.5.11 examples/chat-app/app/hyperloop/components/input_box.rb
hyper-operation-0.5.10 examples/chat-app/app/hyperloop/components/input_box.rb
hyper-operation-0.5.9 examples/chat-app/app/hyperloop/components/input_box.rb
hyper-operation-0.5.8 examples/chat-app/app/hyperloop/components/input_box.rb
hyper-operation-0.5.7 examples/chat-app/app/hyperloop/components/input_box.rb
hyper-operation-0.5.6 examples/chat-app/app/hyperloop/components/input_box.rb
hyper-operation-0.5.5 examples/chat-app/app/hyperloop/components/input_box.rb
hyper-operation-0.5.4 examples/chat-app/app/hyperloop/components/input_box.rb
hyper-operation-0.5.3 examples/chat-app/app/hyperloop/components/input_box.rb
hyper-operation-0.5.2 examples/chat-app/app/hyperloop/components/input_box.rb
hyper-operation-0.5.1 examples/chat-app/app/hyperloop/components/input_box.rb
hyper-operation-0.5.0 examples/chat-app/app/hyperloop/components/input_box.rb