rx/presenters

View on GitHub
views/mdc/components/chip.erb

Summary

Maintainability
Test Coverage
<%
  require_relative "drag_and_drop/drag_and_drop"
  if comp
    leading_icon = comp.icons.select { |i| i.position.select { |p| eq(p, :left) }.any? }.first
    trailing_icon = comp.icons.select { |i| i.position.select { |p| eq(p, :right) }.any? }.first
    child_events = (leading_icon&.events || trailing_icon&.events || comp.text&.events || []).any?
%>
  <% if comp.menu %>
    <div class="mdc-menu-anchor">
  <% end %>

  <button id="<%= comp.id %>"
          <% if comp.tag %>
          data-input-tag="<%= comp.tag %>"
          <% end %>
          class="v-chip v-input mdc-chip
              <%= color_classname(comp) %>
              <%= 'mdc-chip--selected' if comp.selected %>
              v-menu-click
              <% if comp.draggable %>v-dnd-draggable
            <% end %>"
          <% if comp.name %>
          data-name="<%= comp.name %>"
          <% end %>
          <% if comp.value %>
          data-value="<%= comp.value %>"
          <% end %>
          style="<%= color_style(comp, 'background-') %>"
          <%= draggable_attributes(comp) %>
          <%= drop_zone_attributes(comp) %>
          tabindex="0"
          <%= erb(:"components/event", locals: {comp: comp,
                                                events: comp.events,
                                                parent_id: comp.id}) %>>
    <%= erb(:"components/icon", :locals => {comp: leading_icon,
                                            class_name: 'mdc-chip__icon mdc-chip__icon--leading',
                                            events: child_events ? (leading_icon&.events || comp.events) : nil}) %>
    <% if comp.chipset_variant == 'filter' %>
    <span class="mdc-chip__checkmark">
      <svg class="mdc-chip__checkmark-svg" viewBox="-2 -3 30 30">
        <path class="mdc-chip__checkmark-path" fill="none" stroke="black"
              d="M1.73,12.91 8.1,19.28 22.79,4.59"/>
      </svg>
    </span>
    <% end %>

    <%= erb :"components/typography", :locals => {comp: comp.text, type: 'chip-text', class_name: 'mdc-chip__text'} %>
    <%= erb(:"components/icon", locals: {comp: trailing_icon,
                                         class_name: 'mdc-chip__icon mdc-chip__icon--trailing',
                                         events: child_events ? (trailing_icon&.events || comp.events) : nil}) %>
  </button>
  <% if comp.menu %>
    <%= erb :"components/list/menu", :locals => {:comp => comp.menu} %>
    </div>
  <% end %>
  <%= erb :"components/tooltip", :locals => {comp: comp.tooltip, parent_id: comp.id} %>
<% end %>