lesli_view 1.1.5 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +8 -0
  3. data/app/assets/stylesheets/lesli_view/{view.tailwind.css → view.css} +303 -1522
  4. data/lib/lesli_view/components/header.html.erb +2 -2
  5. data/lib/lesli_view/components/panel.html.erb +44 -26
  6. data/lib/lesli_view/components/timeline.html.erb +38 -25
  7. data/lib/lesli_view/components/timeline.rb +18 -5
  8. data/lib/lesli_view/components/toolbar.css +12 -8
  9. data/lib/lesli_view/components/toolbar.html.erb +3 -1
  10. data/lib/lesli_view/elements/button.html.erb +2 -0
  11. data/lib/lesli_view/elements/button.rb +4 -0
  12. data/lib/lesli_view/forms/builder_horizontal.rb +4 -0
  13. data/lib/lesli_view/forms/fields.rb +14 -0
  14. data/lib/lesli_view/items/activities.html.erb +5 -1
  15. data/lib/lesli_view/items/activities.rb +111 -11
  16. data/lib/lesli_view/items/attachment.html.erb +45 -0
  17. data/lib/lesli_view/items/attachment.rb +63 -0
  18. data/lib/lesli_view/items/attachments.html.erb +69 -34
  19. data/lib/lesli_view/items/attachments.rb +38 -2
  20. data/lib/lesli_view/items/discussion.html.erb +7 -5
  21. data/lib/lesli_view/items/discussion.rb +26 -0
  22. data/lib/lesli_view/items/discussions.html.erb +32 -17
  23. data/lib/lesli_view/items/discussions.rb +27 -5
  24. data/lib/lesli_view/items/task.html.erb +15 -6
  25. data/lib/lesli_view/items/task.rb +14 -0
  26. data/lib/lesli_view/items/tasks.html.erb +28 -15
  27. data/lib/lesli_view/items/tasks.rb +27 -2
  28. data/lib/lesli_view/layout/navigation_sidebar.css +19 -0
  29. data/lib/lesli_view/layout/navigation_sidebar.html.erb +52 -0
  30. data/lib/lesli_view/layout/navigation_sidebar.rb +24 -0
  31. data/lib/lesli_view/version.rb +2 -2
  32. data/lib/lesli_view.rb +2 -0
  33. data/readme.md +5 -3
  34. metadata +15 -8
  35. data/lib/lesli_view/components/panel.scss +0 -37
@@ -1,6 +1,6 @@
1
1
 
2
2
  <section
3
- class="mx-auto mt-14 mb-10 grid w-full grid-cols-1 gap-5 md:grid-cols-[minmax(0,1fr)_auto] md:items-start"
3
+ class="mx-auto mt-16 mb-12 grid w-full grid-cols-[minmax(0,1fr)_auto] items-start gap-5"
4
4
  <% if title.present? %>aria-labelledby="<%= title_id %>"<% end %>>
5
5
 
6
6
  <div class="min-w-0">
@@ -36,7 +36,7 @@
36
36
 
37
37
  <% if actions? %>
38
38
  <div
39
- class="flex flex-wrap items-center gap-3 md:justify-self-end"
39
+ class="flex flex-wrap items-start justify-self-end gap-3"
40
40
  role="group"
41
41
  aria-label="<%= I18n.t('actions.label', default: 'Page actions') %>">
42
42
  <% if new_path.present? %>
@@ -1,36 +1,54 @@
1
1
 
2
- <% attributes = {} %>
3
- <% attributes[:class] = "lesli-panel" %>
4
- <% attributes[:"x-data"] = "{ status: false }" %>
5
- <% attributes[:"x-cloak"] = true %>
6
- <% attributes[:"@#{id}.window"] = "status = !status" %>
2
+ <%
3
+ panel_title_id = "#{id}-title"
4
+ attributes = {
5
+ id: "#{id}-panel",
6
+ class: "lesli-panel relative z-50",
7
+ "x-data": "{ open: false, trigger: null, openPanel() { this.trigger = document.activeElement; this.open = true; this.$nextTick(() => this.$refs.closeButton.focus()) }, closePanel() { this.open = false; this.$nextTick(() => this.trigger?.focus()) } }",
8
+ "x-cloak": true,
9
+ "@#{id}.window": "openPanel()",
10
+ "@keydown.escape.window": "if (open) closePanel()"
11
+ }
12
+ %>
7
13
 
8
14
  <%= content_tag(:section, **attributes) do %>
9
15
  <% if overlay %>
10
- <div
11
- class="lesli-panel-background overlay"
12
- x-transition
13
- x-show="status"
14
- x-on:click="status = !status">
16
+ <div
17
+ class="fixed inset-0 z-40 bg-slate-950/25"
18
+ aria-hidden="true"
19
+ x-show="open"
20
+ x-transition.opacity
21
+ @click="closePanel()">
15
22
  </div>
16
23
  <% end %>
17
- <div
18
- class="lesli-panel-container box p-0"
19
- x-show="status"
20
- x-transition>
21
- <div class="lesli-panel-header is-flex">
22
- <div class="is-flex-grow-1">
23
- <h5 class="is-size-5">
24
- <%= title %>
25
- </h5>
26
- </div>
27
- <div class="hover" x-on:click="status = !status">
28
- <span class="material-symbols md-24">
29
- arrow_forward_ios
30
- </span>
31
- </div>
24
+
25
+ <div
26
+ class="fixed inset-y-0 right-0 z-50 flex h-dvh max-h-dvh w-full flex-col overflow-y-auto overscroll-contain bg-white shadow-2xl sm:max-w-2xl lg:max-w-3xl"
27
+ role="dialog"
28
+ aria-modal="<%= overlay %>"
29
+ aria-labelledby="<%= panel_title_id %>"
30
+ x-show="open"
31
+ x-transition:enter="transform transition ease-out duration-150"
32
+ x-transition:enter-start="translate-x-8 opacity-0"
33
+ x-transition:enter-end="translate-x-0 opacity-100"
34
+ x-transition:leave="transform transition ease-in duration-100"
35
+ x-transition:leave-start="translate-x-0 opacity-100"
36
+ x-transition:leave-end="translate-x-8 opacity-0">
37
+ <div class="sticky top-0 z-10 flex items-center justify-between gap-4 border-b border-slate-200 bg-white px-4 py-3 sm:px-6">
38
+ <h2 id="<%= panel_title_id %>" class="min-w-0 truncate text-lg font-semibold text-slate-900">
39
+ <%= title %>
40
+ </h2>
41
+ <button
42
+ type="button"
43
+ class="inline-flex size-11 shrink-0 items-center justify-center rounded-lg text-slate-500 transition-colors hover:bg-slate-100 hover:text-slate-700 focus-visible:outline-none focus-visible:ring-4 focus-visible:ring-sky-500/20"
44
+ aria-label="Close panel"
45
+ x-ref="closeButton"
46
+ @click="closePanel()">
47
+ <span class="material-symbols text-xl leading-none" aria-hidden="true">arrow_forward_ios</span>
48
+ </button>
32
49
  </div>
33
- <div class="lesli-panel-body p-4">
50
+
51
+ <div class="min-w-0 flex-1 p-4 sm:p-6">
34
52
  <%= content %>
35
53
  </div>
36
54
  </div>
@@ -1,29 +1,42 @@
1
1
  <div class="lesli-timelines py-6">
2
- <ul class="m-0 w-full list-none p-0">
3
- <% activities.each do |activity| %>
4
- <li class="group grid grid-cols-[1.5rem_minmax(0,1fr)] gap-x-4 md:grid-cols-[minmax(8rem,auto)_1.5rem_minmax(0,1fr)] md:gap-x-6">
5
- <div class="col-start-2 mb-2 min-w-0 text-xs font-bold uppercase tracking-[0.2em] text-slate-500 md:col-start-1 md:row-start-1 md:mb-0 md:pt-1 md:text-right">
6
- <span><%= activity['date'] %></span>
7
- </div>
2
+ <% if activities.any? %>
3
+ <ul class="m-0 w-full list-none p-0">
4
+ <% activities.each do |activity| %>
5
+ <li class="group grid grid-cols-[1.5rem_minmax(0,1fr)] gap-x-4 md:grid-cols-[minmax(8rem,auto)_1.5rem_minmax(0,1fr)] md:gap-x-6">
6
+ <div class="col-start-2 mb-2 min-w-0 text-xs font-bold uppercase tracking-[0.2em] text-slate-500 md:col-start-1 md:row-start-1 md:mb-0 md:pt-1 md:text-right">
7
+ <time><%= activity["date"] %></time>
8
8
 
9
- <div class="relative col-start-1 row-span-2 row-start-1 flex justify-center md:col-start-2">
10
- <span
11
- class="material-symbols-outlined relative z-10 bg-white text-xl leading-none text-[var(--lesli-color-primary)]"
12
- aria-hidden="true">
13
- <%= icons.dig(activity['icon']&.to_sym) || 'radio_button_checked' %>
14
- </span>
15
- <span class="absolute top-7 bottom-0 left-1/2 w-px -translate-x-1/2 bg-slate-300 group-last:hidden" aria-hidden="true"></span>
16
- </div>
9
+ <% if activity["actor"].present? %>
10
+ <span class="mt-1 block font-normal normal-case tracking-normal text-slate-400">
11
+ <%= activity["actor"] %>
12
+ </span>
13
+ <% end %>
14
+ </div>
17
15
 
18
- <div class="col-start-2 row-start-2 min-w-0 pb-10 md:col-start-3 md:row-start-1">
19
- <h6 class="text-base font-semibold text-slate-800">
20
- <%= activity['operation'] %>
21
- </h6>
22
- <p class="mt-1 text-sm leading-6 text-slate-600">
23
- <%= activity['description'] %>
24
- </p>
25
- </div>
26
- </li>
27
- <% end %>
28
- </ul>
16
+ <div class="relative col-start-1 row-span-2 row-start-1 flex justify-center md:col-start-2">
17
+ <span
18
+ class="material-symbols-outlined relative z-10 bg-white text-xl leading-none text-[var(--lesli-color-primary)]"
19
+ aria-hidden="true">
20
+ <%= icon_for(activity) %>
21
+ </span>
22
+ <span class="absolute top-7 bottom-0 left-1/2 w-px -translate-x-1/2 bg-slate-300 group-last:hidden" aria-hidden="true"></span>
23
+ </div>
24
+
25
+ <div class="col-start-2 row-start-2 min-w-0 pb-10 md:col-start-3 md:row-start-1">
26
+ <h6 class="text-base font-semibold text-slate-800">
27
+ <%= activity["operation"] %>
28
+ </h6>
29
+
30
+ <% if activity["description"].present? %>
31
+ <p class="mt-1 text-sm leading-6 text-slate-600">
32
+ <%= activity["description"] %>
33
+ </p>
34
+ <% end %>
35
+ </div>
36
+ </li>
37
+ <% end %>
38
+ </ul>
39
+ <% else %>
40
+ <%= render LesliView::Elements::Empty.new(text: empty_text) %>
41
+ <% end %>
29
42
  </div>
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "lesli_view/elements/empty"
4
+
3
5
  =begin
4
6
 
5
7
  Lesli
@@ -35,12 +37,23 @@ Building a better future, one line of code at a time.
35
37
  module LesliView
36
38
  module Components
37
39
  class Timeline < ViewComponent::Base
38
- attr_reader :activities, :icons
40
+ DEFAULT_ICON = "radio_button_checked"
41
+
42
+ attr_reader :activities, :empty_text, :icons
43
+
44
+ def initialize(
45
+ activities: [],
46
+ icons: {},
47
+ empty_text: "No activities have been recorded yet."
48
+ )
49
+ @activities = Array(activities)
50
+ @icons = icons.transform_keys(&:to_sym)
51
+ @empty_text = empty_text
52
+ end
39
53
 
40
- def initialize(activities: nil, icons:{})
41
- @icons=icons
42
- @activities = activities
54
+ def icon_for(activity)
55
+ icons.fetch(activity["icon"]&.to_sym, DEFAULT_ICON)
43
56
  end
44
- end
57
+ end
45
58
  end
46
59
  end
@@ -2,23 +2,27 @@
2
2
 
3
3
  @layer components {
4
4
  .lesli-toolbar {
5
- @apply mb-6 flex w-full flex-col gap-2 sm:flex-row sm:items-center;
5
+ @apply mb-6 flex w-full flex-wrap items-center gap-2;
6
6
  }
7
7
 
8
8
  .lesli-toolbar__form {
9
- @apply flex min-w-0 flex-1 flex-col gap-2 sm:flex-row sm:items-center;
9
+ @apply flex min-w-0 flex-[1_1_24rem] flex-wrap items-center gap-2;
10
10
  }
11
11
 
12
12
  .lesli-toolbar__search {
13
- @apply relative min-w-0 flex-1;
13
+ @apply relative min-w-0 flex-[1_1_14rem];
14
14
  }
15
15
 
16
16
  .lesli-toolbar__input {
17
- @apply h-10 w-full rounded-lg border border-slate-300 bg-white py-2 pl-10 pr-10 text-sm text-slate-900 outline-none transition placeholder:text-slate-400 hover:border-slate-400 focus:border-sky-500 focus:ring-2 focus:ring-sky-500/10;
17
+ @apply block h-10 w-full rounded-lg border border-slate-300 bg-white py-2 pl-10 pr-10 text-sm text-slate-900 outline-none transition placeholder:text-slate-400 hover:border-slate-400 focus:border-sky-500 focus:ring-2 focus:ring-sky-500/10;
18
18
  }
19
19
 
20
20
  .lesli-toolbar__search-icon {
21
- @apply pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-lg leading-none text-slate-400;
21
+ @apply pointer-events-none absolute inset-y-0 left-3 flex items-center text-slate-400;
22
+ }
23
+
24
+ .lesli-toolbar__search-icon .material-symbols {
25
+ @apply text-lg leading-none;
22
26
  }
23
27
 
24
28
  .lesli-toolbar__clear {
@@ -30,12 +34,12 @@
30
34
  }
31
35
 
32
36
  .lesli-toolbar__filters {
33
- @apply flex flex-wrap items-center gap-2;
37
+ @apply flex max-w-full flex-wrap items-center gap-2;
34
38
  }
35
39
 
36
40
  .lesli-toolbar__filters select,
37
41
  .lesli-toolbar__filters input {
38
- @apply h-10 rounded-lg border border-slate-300 bg-white px-3 text-sm text-slate-700 outline-none transition hover:border-slate-400 focus:border-sky-500 focus:ring-2 focus:ring-sky-500/10;
42
+ @apply h-10 min-w-0 max-w-full rounded-lg border border-slate-300 bg-white px-3 text-sm text-slate-700 outline-none transition hover:border-slate-400 focus:border-sky-500 focus:ring-2 focus:ring-sky-500/10;
39
43
  }
40
44
 
41
45
  .lesli-toolbar__submit {
@@ -47,6 +51,6 @@
47
51
  }
48
52
 
49
53
  .lesli-toolbar__actions {
50
- @apply flex shrink-0 flex-wrap items-center gap-2;
54
+ @apply ml-auto flex max-w-full flex-wrap items-center justify-end gap-2;
51
55
  }
52
56
  }
@@ -3,7 +3,9 @@
3
3
  <div class="lesli-toolbar__search">
4
4
  <%= label_tag(search_name, search_label, class: "sr-only") %>
5
5
 
6
- <span class="lesli-toolbar__search-icon material-symbols" aria-hidden="true">search</span>
6
+ <span class="lesli-toolbar__search-icon" aria-hidden="true">
7
+ <span class="material-symbols">search</span>
8
+ </span>
7
9
 
8
10
  <%= text_field_tag(
9
11
  search_name,
@@ -29,6 +29,8 @@
29
29
  <%= content_tag(
30
30
  :button,
31
31
  type: button_type,
32
+ name: @name,
33
+ value: @value,
32
34
  disabled: disabled?,
33
35
  **common_attributes
34
36
  ) do %>
@@ -59,6 +59,8 @@ module LesliView
59
59
  aria_label: nil,
60
60
  disabled: false,
61
61
  type: :button,
62
+ name: nil,
63
+ value: nil,
62
64
  data: {}
63
65
  )
64
66
  @label = label
@@ -79,6 +81,8 @@ module LesliView
79
81
  @aria_label = aria_label
80
82
  @disabled = disabled
81
83
  @button_type = type
84
+ @name = name
85
+ @value = value
82
86
  @data = data
83
87
  end
84
88
 
@@ -25,6 +25,10 @@ module LesliView
25
25
  super(attribute, label: label, message: message, category: category, icon: icon, horizontal: true, **options)
26
26
  end
27
27
 
28
+ def field_control_textarea_rich(attribute, label: nil, message: nil, category: nil, icon: nil, **options)
29
+ super(attribute, label: label, message: message, category: category, icon: icon, horizontal: true, **options)
30
+ end
31
+
28
32
  def field_textarea(attribute, **options)
29
33
  field_control_textarea(attribute, **options)
30
34
  end
@@ -81,6 +81,20 @@ module LesliView
81
81
  end
82
82
 
83
83
  def field_control_textarea(attribute, label: nil, message: nil, category: nil, icon: nil, horizontal: false, **options)
84
+ label_html = label == false ? nil : label(attribute, label)
85
+ control_html = text_area(attribute, options)
86
+
87
+ field_control_builder(
88
+ label_html: label_html,
89
+ control_html: control_html,
90
+ message_text: message,
91
+ category: category,
92
+ horizontal: horizontal,
93
+ icon: icon
94
+ )
95
+ end
96
+
97
+ def field_control_textarea_rich(attribute, label: nil, message: nil, category: nil, icon: nil, horizontal: false, **options)
84
98
  label_html = label == false ? nil : label(attribute, label)
85
99
  control_html = rich_textarea(attribute, options)
86
100
 
@@ -32,5 +32,9 @@ Building a better future, one line of code at a time.
32
32
  <article
33
33
  class="lesli-items-activities bg-white p-4 sm:p-8"
34
34
  id="lesli-items-activities">
35
- <%= render(LesliView::Components::Timeline.new(activities: @activities, icons: @icons)) %>
35
+ <%= render LesliView::Components::Timeline.new(
36
+ activities: activities,
37
+ empty_text: empty_text,
38
+ icons: icons
39
+ ) %>
36
40
  </article>
@@ -32,17 +32,117 @@ Building a better future, one line of code at a time.
32
32
  module LesliView
33
33
  module Items
34
34
  class Activities < ViewComponent::Base
35
- attr_reader :activities, :icons
36
-
37
- def initialize(resource, icons:{})
38
- @icons=icons
39
- @activities = resource.activities
40
- .select(
41
- :id,
42
- "description as operation",
43
- "activity_code as icon",
44
- Date2.new.db_column('created_at', as:'date')
45
- ).order(id: :desc).as_json
35
+ DEFAULT_LIMIT = 25
36
+ I18N_SCOPE = "lesli.items.activities"
37
+ DATE_FORMAT = "%Y-%m-%d · %H:%M"
38
+
39
+ attr_reader :activities, :empty_text, :icons, :i18n_scope
40
+
41
+ def initialize(
42
+ resource,
43
+ icons: {},
44
+ i18n_scope: I18N_SCOPE,
45
+ limit: DEFAULT_LIMIT,
46
+ empty_text: nil
47
+ )
48
+ @icons = icons
49
+ @i18n_scope = i18n_scope
50
+ @activities = activity_scope(resource, limit).map do |activity|
51
+ activity_to_timeline(activity)
52
+ end
53
+ @empty_text = empty_text || I18n.t(
54
+ "#{i18n_scope}_empty",
55
+ default: "No activities have been recorded yet."
56
+ )
57
+ end
58
+
59
+ private
60
+
61
+ def activity_to_timeline(activity)
62
+ metadata = activity.metadata.is_a?(Hash) ? activity.metadata : {}
63
+
64
+ {
65
+ "actor" => actor_name(activity.actor),
66
+ "date" => I18n.l(activity.created_at, format: DATE_FORMAT),
67
+ "description" => activity_description(activity, metadata),
68
+ "icon" => activity.activity_code.to_s,
69
+ "operation" => activity_operation(activity)
70
+ }
71
+ end
72
+
73
+ def activity_description(activity, metadata)
74
+ I18n.t(
75
+ "#{activity_i18n_key(activity)}_#{description_key(metadata)}",
76
+ from: snapshot_name(metadata_value(metadata, :from)),
77
+ to: snapshot_name(metadata_value(metadata, :to)),
78
+ default: activity.description.to_s
79
+ ).presence
80
+ end
81
+
82
+ def activity_i18n_key(activity)
83
+ "#{i18n_scope}_events_#{activity.activity_code}"
84
+ end
85
+
86
+ def activity_operation(activity)
87
+ I18n.t(
88
+ "#{activity_i18n_key(activity)}_operation",
89
+ default: activity.activity_code.to_s.humanize
90
+ )
91
+ end
92
+
93
+ def activity_scope(resource, limit)
94
+ resource.activities
95
+ .includes(:actor)
96
+ .reorder(created_at: :desc, id: :desc)
97
+ .limit(normalize_limit(limit))
98
+ end
99
+
100
+ def actor_name(actor)
101
+ full_name = actor.full_name if actor.respond_to?(:full_name)
102
+ name = actor.name if actor.respond_to?(:name)
103
+
104
+ full_name.presence || name.presence || I18n.t(
105
+ "#{i18n_scope}_unknown_actor",
106
+ default: "Unknown user"
107
+ )
108
+ end
109
+
110
+ def description_key(metadata)
111
+ has_change = metadata.key?(:from) || metadata.key?("from") ||
112
+ metadata.key?(:to) || metadata.key?("to")
113
+
114
+ return "description" unless has_change
115
+ return "set" if metadata_value(metadata, :from).nil?
116
+ return "removed" if metadata_value(metadata, :to).nil?
117
+
118
+ "changed"
119
+ end
120
+
121
+ def metadata_value(metadata, key)
122
+ return metadata[key] if metadata.key?(key)
123
+
124
+ metadata[key.to_s]
125
+ end
126
+
127
+ def normalize_limit(limit)
128
+ normalized_limit = Integer(limit)
129
+ return normalized_limit if normalized_limit.positive?
130
+
131
+ raise ArgumentError, "limit must be a positive integer"
132
+ rescue TypeError, ArgumentError
133
+ raise ArgumentError, "limit must be a positive integer"
134
+ end
135
+
136
+ def snapshot_name(snapshot)
137
+ return "" if snapshot.nil?
138
+ return snapshot.to_s unless snapshot.is_a?(Hash)
139
+
140
+ [:name, :subject, :uid, :id].each do |key|
141
+ value = metadata_value(snapshot, key)
142
+ return value.to_s if value.present?
143
+ end
144
+
145
+ ""
46
146
  end
47
147
  end
48
148
  end
@@ -0,0 +1,45 @@
1
+ <li
2
+ id="<%= dom_id(resource) %>"
3
+ class="flex flex-col gap-4 rounded-xl border border-slate-200 bg-white p-4 sm:flex-row sm:items-center sm:justify-between">
4
+ <div class="flex min-w-0 items-center gap-3">
5
+ <span
6
+ class="material-symbols-outlined shrink-0 text-3xl text-[var(--lesli-color-primary)]"
7
+ aria-hidden="true">
8
+ attach_file
9
+ </span>
10
+
11
+ <div class="min-w-0">
12
+ <p class="truncate text-sm font-medium text-slate-900" title="<%= filename %>">
13
+ <%= display_name %>
14
+ </p>
15
+ <p class="mt-1 text-xs text-slate-500">
16
+ <%= details %>
17
+ </p>
18
+ </div>
19
+ </div>
20
+
21
+ <div class="flex shrink-0 items-center gap-2">
22
+ <%= link_to(
23
+ I18n.t("lesli.items.attachments_download", default: "Download"),
24
+ path,
25
+ class: "inline-flex items-center gap-2 rounded-lg border border-slate-300 px-3 py-2 text-sm font-medium text-slate-700 transition-colors hover:border-slate-400 hover:bg-slate-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--lesli-color-primary)]",
26
+ data: { turbo: false }
27
+ ) %>
28
+
29
+ <%= button_to(
30
+ I18n.t("lesli.items.attachments_remove", default: "Remove"),
31
+ path,
32
+ method: :delete,
33
+ class: "inline-flex items-center rounded-lg px-3 py-2 text-sm font-medium text-red-600 transition-colors hover:bg-red-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-red-500/40",
34
+ form: {
35
+ class: "inline-flex",
36
+ data: {
37
+ turbo_confirm: I18n.t(
38
+ "lesli.items.attachments_confirm_remove",
39
+ default: "Remove this file?"
40
+ )
41
+ }
42
+ }
43
+ ) %>
44
+ </div>
45
+ </li>
@@ -0,0 +1,63 @@
1
+ =begin
2
+
3
+ Lesli
4
+
5
+ Copyright (c) 2026, Lesli Technologies, S. A.
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program. If not, see http://www.gnu.org/licenses/.
19
+
20
+ Lesli · Ruby on Rails SaaS Development Framework.
21
+
22
+ Made with ♥ by LesliTech
23
+ Building a better future, one line of code at a time.
24
+
25
+ @contact hello@lesli.tech
26
+ @website https://www.lesli.tech
27
+ @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
28
+
29
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
+ // ·
31
+ =end
32
+
33
+ module LesliView
34
+ module Items
35
+ class Attachment < ViewComponent::Base
36
+ attr_reader :resource
37
+
38
+ def initialize(attachment, path: nil)
39
+ @resource = attachment
40
+ @path = path
41
+ end
42
+
43
+ def path
44
+ @path || helpers.polymorphic_path(resource)
45
+ end
46
+
47
+ def filename
48
+ resource.file.filename.to_s
49
+ end
50
+
51
+ def display_name
52
+ resource.respond_to?(:display_name) ? resource.display_name : filename
53
+ end
54
+
55
+ def details
56
+ [
57
+ resource.file.blob.content_type,
58
+ helpers.number_to_human_size(resource.file.blob.byte_size)
59
+ ].compact.join(" · ")
60
+ end
61
+ end
62
+ end
63
+ end