-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5439 from solidusio/elia/admin/tooltips
Admin tooltip improvements
- Loading branch information
Showing
6 changed files
with
39 additions
and
133 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
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
93 changes: 8 additions & 85 deletions
93
admin/app/components/solidus_admin/ui/toggletip/component.rb
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,98 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
class SolidusAdmin::UI::Toggletip::Component < SolidusAdmin::BaseComponent | ||
# Icon size: 1rem | ||
# Arrow size: 0.375rem | ||
# Banner padding x: 0.75rem | ||
POSITIONS = { | ||
up: { | ||
arrow: %w[before:top-0 before:left-1/2 before:translate-y-[-50%] before:translate-x-[-50%]], | ||
bubble: %w[translate-x-[calc(-50%+(1rem/2))] translate-y-[calc(0.375rem/2)]] | ||
below: { | ||
arrow: "before:top-0 before:left-1/2 before:translate-y-[-50%] before:translate-x-[-50%]", | ||
bubble: "translate-x-[calc(-50%+(1rem/2))] translate-y-[calc(0.375rem/2)]" | ||
}, | ||
up_right: { | ||
arrow: %w[before:top-0 before:right-0 before:translate-y-[-50%]], | ||
bubble: %w[translate-x-[calc(-100%+0.75rem+(1rem/2)+(0.375rem/2))] translate-y-[calc(0.375rem/2)]] | ||
above: { | ||
arrow: "before:bottom-0 before:left-1/2 before:translate-y-[50%] before:translate-x-[-50%]", | ||
bubble: "translate-x-[calc(-50%+(1rem/2))] translate-y-[calc(-100%-1rem-(0.375rem/2))]" | ||
}, | ||
right: { | ||
arrow: %w[before:top-1/2 before:right-0 before:translate-y-[-50%] before:translate-x-[0.93rem]], | ||
bubble: %w[translate-x-[calc(-100%+(-0.375rem/2))] translate-y-[calc(-50%-(1rem/2))]] | ||
}, | ||
down_right: { | ||
arrow: %w[before:bottom-0 before:right-0 before:translate-y-[50%]], | ||
bubble: %w[translate-x-[calc(-100%+0.75rem+(1rem/2)+(0.376rem/2))] translate-y-[calc(-100%-1rem-(0.375rem/2))]] | ||
}, | ||
down: { | ||
arrow: %w[before:bottom-0 before:left-1/2 before:translate-y-[50%] before:translate-x-[-50%]], | ||
bubble: %w[translate-x-[calc(-50%+(1rem/2))] translate-y-[calc(-100%-1rem-(0.375rem/2))]] | ||
}, | ||
down_left: { | ||
arrow: %w[before:bottom-0 before:left-0 before:translate-y-[50%]], | ||
bubble: %w[translate-x-[calc(-1rem/2)] translate-y-[calc(-100%-0.75rem-0.375rem)]] | ||
}, | ||
left: { | ||
arrow: %w[before:top-1/2 before:left-0 before:translate-y-[-50%] before:translate-x-[-0.93rem]], | ||
bubble: %w[translate-x-[calc(1rem+(0.375rem/2))] translate-y-[calc(-50%-(1rem/2))]] | ||
}, | ||
up_left: { | ||
arrow: %w[before:top-0 before:left-0 before:translate-y-[-50%]], | ||
bubble: %w[translate-x-[calc(-0.75rem+0.375rem)] translate-y-[calc(0.375rem/2)]] | ||
}, | ||
none: { | ||
arrow: %w[before:hidden], | ||
bubble: %w[translate-x-[calc(-50%+0.75rem)]] | ||
} | ||
}.freeze | ||
|
||
THEMES = { | ||
light: { | ||
icon: %w[fill-gray-500], | ||
bubble: %w[text-gray-800 bg-gray-50] | ||
}, | ||
dark: { | ||
icon: %w[fill-gray-800], | ||
bubble: %w[text-white bg-gray-800] | ||
} | ||
}.freeze | ||
|
||
# @param text [String] The toggletip text | ||
# @param position [Symbol] The position of the arrow in relation to the | ||
# toggletip. The latter will be positioned accordingly in relation to the | ||
# help icon. Defaults to `:up`. See `POSITIONS` for available options. | ||
# @param theme [Symbol] The theme of the toggletip. Defaults to `:light`. See | ||
# `THEMES` for available options. | ||
def initialize(text:, position: :down, theme: :light, **attributes) | ||
def initialize(text:, position: :above, **attributes) | ||
@text = text | ||
@position = position | ||
@theme = theme | ||
@attributes = attributes | ||
@attributes[:class] = [ | ||
"relative inline-block", | ||
@attributes[:class], | ||
].join(" ") | ||
end | ||
|
||
def icon_theme_classes | ||
THEMES.fetch(@theme)[:icon].join(" ") | ||
end | ||
|
||
def bubble_theme_classes | ||
THEMES.fetch(@theme)[:bubble].join(" ") | ||
end | ||
|
||
def bubble_position_classes | ||
POSITIONS.fetch(@position)[:bubble].join(" ") | ||
end | ||
|
||
def bubble_arrow_pseudo_element | ||
( | ||
[ | ||
"before:content['']", | ||
"before:absolute", | ||
"before:w-[0.375rem]", | ||
"before:h-[0.375rem]", | ||
"before:rotate-45", | ||
"before:bg-inherit", | ||
] + POSITIONS.fetch(@position)[:arrow] | ||
).join(" ") | ||
@attributes[:class] = "relative inline-block #{@attributes[:class]}" | ||
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
35 changes: 14 additions & 21 deletions
35
...n/spec/components/previews/solidus_admin/ui/toggletip/component_preview/overview.html.erb
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,21 +1,14 @@ | ||
<table class="w-full"> | ||
<legend class="body-title text-center">Click us</legend> | ||
<tr> | ||
<th class="w-[10%]"></th> | ||
<% themes.each do |theme| %> | ||
<th class="px-3 py-1 text-gray-500 text-center"><%= theme.to_s.humanize %></th> | ||
<% end %> | ||
</tr> | ||
<% positions.each do |position| %> | ||
<tr> | ||
<td class="font-bold px-3 py-1"><%= position.to_s.humanize %></td> | ||
<% themes.each do |theme| %> | ||
<td class="py-3"> | ||
<div class="flex justify-center"> | ||
<%= render current_component.new(text: text, theme: theme, position: position) %> | ||
</div> | ||
</td> | ||
<% end %> | ||
</tr> | ||
<% end %> | ||
</table> | ||
<% current_component::POSITIONS.keys.each do |position| %> | ||
<div class="mb-8"> | ||
<h6 class="text-gray-500 mb-3 mt-0"> | ||
<%= position.to_s.humanize %> | ||
</h6> | ||
|
||
<div class="ml-80"> | ||
<%= render current_component.new( | ||
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", | ||
position: position | ||
) %> | ||
</div> | ||
</div> | ||
<% end %> |