-
-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: discreet information (#3592)
* feature: discreet information * wip * wip * lint * refactor i18n * wip * remove old concern * fix mobile cover variant * wip * wip * wip * lint * tests --------- Co-authored-by: Paul Bob <[email protected]>
- Loading branch information
1 parent
2f2e814
commit 6a6d122
Showing
26 changed files
with
352 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<div class="flex gap-2 ml-2 mt-1"> | ||
<% items.each do |item| %> | ||
<%= content_tag element_tag(item), **element_attributes(item), class: "flex gap-1 text-xs font-normal text-gray-600 hover:text-gray-900", title: item.tooltip, data: {tippy: :tooltip, **data(item)} do %> | ||
<%= item.label if item.label.present? %> <%= helpers.svg item.icon, class: "text-2xl h-4" %> | ||
<% end %> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
class Avo::DiscreetInformationComponent < Avo::BaseComponent | ||
prop :payload | ||
|
||
def items | ||
@payload.items.compact | ||
end | ||
|
||
def element_tag(item) | ||
if item.url.present? | ||
:a | ||
else | ||
:div | ||
end | ||
end | ||
|
||
def element_attributes(item) | ||
if item.url.present? | ||
{href: item.url, target: item.url_target} | ||
else | ||
{} | ||
end | ||
end | ||
|
||
def data(item) = item.data || {} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<div class="text-2xl tracking-normal font-semibold text-gray-800 items-center flex flex-1" data-target="title"> | ||
<span class="block w-full text-center sm:text-left"><%= link_to_if @url.present?, @name, @url, target: @target, class: class_names("text-gray-800", @classes) %></span> | ||
<div class="text-2xl tracking-normal font-semibold text-gray-800 items-center flex flex-1 text-center sm:text-left justify-center sm:justify-start" data-target="title"> | ||
<span class="block"><%= link_to_if @url.present?, @name, @url, target: @target, class: class_names("text-gray-800", @classes) %></span> | ||
<%= body %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Avo | ||
module Concerns | ||
module HasDiscreetInformation | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
class_attribute :discreet_information, instance_accessor: false | ||
end | ||
|
||
def discreet_information | ||
::Avo::DiscreetInformation.new resource: self | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
class Avo::DiscreetInformation | ||
extend PropInitializer::Properties | ||
include ActionView::Helpers::TagHelper | ||
|
||
prop :resource, reader: :public | ||
|
||
delegate :record, :view, to: :resource | ||
|
||
def items | ||
Array.wrap(resource.class.discreet_information).map do |item| | ||
if item == :timestamps | ||
timestamp_item(item) | ||
else | ||
parse_payload(item) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def timestamp_item(item) | ||
return if record.created_at.blank? && record.updated_at.blank? | ||
|
||
time_format = "%Y-%m-%d %H:%M:%S" | ||
created_at = record.created_at.strftime(time_format) | ||
updated_at = record.updated_at.strftime(time_format) | ||
|
||
created_at_tag = if record.created_at.present? | ||
I18n.t("avo.created_at_timestamp", created_at:) | ||
end | ||
|
||
updated_at_tag = if record.updated_at.present? | ||
I18n.t("avo.updated_at_timestamp", updated_at:) | ||
end | ||
|
||
DiscreetInformationItem.new( | ||
tooltip: tag.div([created_at_tag, updated_at_tag].compact.join(tag.br), style: "text-align: right;"), | ||
icon: "heroicons/outline/clock" | ||
) | ||
end | ||
|
||
def parse_payload(item) | ||
return unless item.is_a?(Hash) | ||
|
||
args = { | ||
record:, | ||
resource:, | ||
view: | ||
} | ||
|
||
DiscreetInformationItem.new( | ||
tooltip: Avo::ExecutionContext.new(target: item[:tooltip], **args).handle, | ||
icon: Avo::ExecutionContext.new(target: item[:icon], **args).handle, | ||
url: Avo::ExecutionContext.new(target: item[:url], **args).handle, | ||
url_target: Avo::ExecutionContext.new(target: item[:url_target], **args).handle, | ||
data: Avo::ExecutionContext.new(target: item[:data], **args).handle, | ||
label: Avo::ExecutionContext.new(target: item[:label], **args).handle | ||
) | ||
end | ||
|
||
DiscreetInformationItem = Struct.new(:tooltip, :icon, :url, :url_target, :data, :label, keyword_init: true) unless defined?(DiscreetInformationItem) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.