rx/presenters

View on GitHub
app/demo/components/lists.pom

Summary

Maintainability
Test Coverage
require_relative '../helpers/indented_grid'

Voom::Presenters.define(:lists) do
  helpers Demo::Helpers::IndentedGrid
  attach :top_nav
  attach :component_drawer
  page_title 'Lists'
  helpers do
    def actors
      [OpenStruct.new(name: "<strong>Bryan Cranston</strong>", episodes: 62, body: 'Bryan Cranston played the role of Walter in Breaking Bad. He is also known for playing Hal in Malcom in the Middle.'),
       OpenStruct.new(name: "Aaron Paul", episodes: 62, body: 'Aaron Paul played the role of Jesse in Breaking Bad. He also featured in the "Need For Speed" Movie'),
       OpenStruct.new(name: "Bob Odenkirk", episodes: 62, body: 'Bob Odinkrik played the role of Saul in Breaking Bad. Due to public fondness for the character, Bob stars in his own show now, called "Better Call Saul".'),
       OpenStruct.new(name: "Giancarlo Esposito", episodes: 24, body: 'Giancarlo Giuseppe Alessandro Esposito played the role of Gustavo "Gus" Fring on the AMC shows Breaking Bad and Better Call Saul.')]
    end
  end

  indented_grid do

    headline 'Simple'
    list do
      actors.each do |actor|
        line do
          text actor.name
        end
      end
    end

    headline 'Simple with Separators'
    list do
      actors.each do |actor|
        line do
          text actor.name
        end
        separator unless actor == actors.last
      end
    end

    headline 'Simple with Selected'
    list do
      actors.each do |actor|
        line selected: actors.first == actor do
          text actor.name
        end
      end
    end


    headline 'Icons'
    list do
      actors.each do |actor|
        line do
          text actor.name
          icon :person
        end
      end
    end


    headline 'Avatars and actions'
    list do
      actors.each do |actor|
        line do
          text actor.name
          avatar :person

          event :click do
            loads 'http://www.yahoo.com', target: '_blank'
          end

          actions do
            icon :stardo do
              tooltip 'Person'
            end
            button icon: :more_vert do
              menu position: :right do
                item 'Some Action' do
                  event :click do
                    snackbar 'Hey there'
                  end
                end
                item 'Another Action'
                divider
                item 'Disabled Action', disabled: true
                item 'Yet Another Action'
              end
            end
          end
        end
      end
    end

    headline 'Avatars and controls'
    list do
      actors.each_with_index do |actor, index|
        line do
          text actor.name
          avatar :person
          actions do
            case index%4
              when 0
                checkbox
              when 1
                radio_button
              when 2
                switch
              when 3
                icon_toggle :star_border, on_icon: :star
            end
          end
        end
      end
    end

    headline 'Multiple controls'
    list do
      actors.each_with_index do |actor, index|
        line do
          text actor.name
          actions do
            case index%4
            when 0
              checkbox
              icon :delete
            when 1
              radio_button
              icon :delete
            when 2
              switch
              icon :delete
            when 3
              icon_toggle :star_border
              icon :delete
            end
          end
        end
      end
    end

    headline 'Two line'

    list do
      actors.each_with_index do |actor, index|
        line do
          text actor.name
          avatar :person
          info 'actor' if index == 0
          actions do
            icon_toggle :star
          end
          subtitle "#{actor.episodes} episodes"
        end
      end
    end

    headline 'Selectable List'
    list selectable: true do
      actors.each do |actor|
        line do
          text actor.name
          avatar :person
          subtitle "#{actor.episodes} episodes"
        end
      end
    end

    attach :code, file: __FILE__
  end
end