Skip to content

docs: a modal example #47

Description

@mhenrixon

So, one of the main things that I'd like to solve with turbo_boost is to build a modal manager/component.

Currently, I have something like the following (been using flowbite and tailwind):

<% modal_id = dom_id(message, :modal) %>

<tr class="">
  <td class="px-6 py-4">
    <button type="button" data-modal-target="<%= modal_id %>" data-modal-toggle="<%= modal_id %>">Show</a>
  </td>

  <td class="px-6 py-4">
    <%= message.state %>
  </td>

  <td class="px-6 py-4">
    <%= time_ago_in_words(message.created_at) %>
  </td>

  <th scope="row">
    <%= message.to_email %>
  </th>

  <td class="px-6 py-4">
    <%= message.subject %>
  </td>
</tr>

<div id="<%= modal_id %>" tabindex="-1" class="fixed top-0 left-0 right-0 z-50 hidden w-full p-4 overflow-x-hidden overflow-y-auto md:inset-0 h-[calc(100%-1rem)] max-h-full">
  <div class="relative w-full max-w-4xl max-h-full">
    <!-- Modal content -->
    <div class="relative bg-white rounded-lg shadow dark:bg-gray-700">

      <!-- Modal header -->
      <div class="flex items-center justify-between p-5 border-b rounded-t dark:border-gray-600">
        <h3 class="text-xl font-medium text-gray-900 dark:text-white">
          <%= message.subject %>
        </h3>

        <button type="button" class="text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm w-8 h-8 ml-auto inline-flex justify-center items-center dark:hover:bg-gray-600 dark:hover:text-white" data-modal-hide="<%= modal_id %>">
          <svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewbox="0 0 14 14">
            <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6" />
          </svg>
          <span class="sr-only">Close modal</span>
        </button>
      </div>

      <!-- Modal body -->
      <div class="p-6 space-y-6">
        <%= message.body %>
      </div>

      <!-- Modal footer -->
      <div class="flex items-center p-6 space-x-2 border-t border-gray-200 rounded-b dark:border-gray-600">
        <div class="flex items-center space-x-4">
          <%= image_tag(message.gravatar_src, class: "w-10 h-10 rounded-full shadow-lg") %>
          <div class="font-medium dark:text-white">
            <div><%= message.name %></div>
            <div class="text-sm text-gray-500 dark:text-gray-400"><%= time_tag(message.created_at) %></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

My issue with this code is that it generates a lot of unnecessary HTML that could instead be fetched from the server on need.

Is this still a valid use case?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions