Skip to content

Commit

Permalink
[#55581] lookbook proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
EinLama committed Nov 27, 2024
1 parent 7679081 commit 9c47122
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
20 changes: 17 additions & 3 deletions lookbook/docs/patterns/25-hover-cards.md.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The HoverCard is a pattern related to the `Primer::Beta::Popover` and is used to show additional contexual information on certain kinds of resources like work packages and users. The hover card is opened by hovering over a certain trigger. When hovering outside of the card or its trigger, the popover is closed again.
The HoverCard is a pattern related to the `Primer::Beta::Popover` and is used to show additional contextual information on certain kinds of resources like work packages and users. The hover card is opened by hovering over a certain trigger. When hovering outside of the card or its trigger, the popover is closed again.

## Overview

Expand Down Expand Up @@ -27,7 +27,7 @@ The HoverCard always consists of two basic parts:
## Used in

- WorkPackage preview when linking via `#ID`
- Soon: User preview when hovering the avatar
- User preview when hovering the avatar

## Technical notes

Expand Down Expand Up @@ -61,13 +61,27 @@ Additionally, the trigger element needs to pass the URL for the `turboFrame` as
class="op-hover-card--preview-trigger">
#14
</a>

<!-- This is how it would look like to provide a hover card trigger to a picture of a user. In reality, you would
probably apply the trigger to an <op-principal> tag. -->
<a href="users/14"
data-hover-card-url="users/14/hover_card"
class="op-hover-card--preview-trigger">
<img src="user_avatar.png" alt="">
</a>
```

Note that the user example is simplified. For actual use in the application, it is recommended to use the `AvatarComponent`, which offers an option for hover cards.

**Actually rendered card content**:
```html
<!-- app/components/work_packages/hover_card/show.html.erb -->
<turbo-frame id="op-hover-card-body">
&lt;%= render WorkPackages::HoverCardComponent.new(id: 14) %&gt;
</turbo-frame>
%&gt;

<!-- app/components/users/hover_card/show.html.erb -->
<turbo-frame id="op-hover-card-body">
&lt;%= render Users::HoverCardComponent.new(id: 14) %&gt;
</turbo-frame>
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ class AvatarComponentPreview < Lookbook::Preview
# @param size select { choices: [default, medium, mini] }
# @param link toggle
# @param show_name toggle
def default(size: :default, link: true, show_name: true)
# @param hover_card toggle
# @param hover_card_target select { choices: [default, custom] }
def default(size: :default, link: true, show_name: true, hover_card: true, hover_card_target: :default)
user = FactoryBot.build_stubbed(:user)
render(Users::AvatarComponent.new(user:, size:, link:, show_name:))
render(Users::AvatarComponent.new(user:, size:, link:, show_name:,
hover_card: { active: hover_card, target: hover_card_target }))
end

def sizes
Expand Down

0 comments on commit 9c47122

Please sign in to comment.