OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Document hover card pattern
Henriette Dargef5ddc1d06da6
diff --git a/app/assets/images/lookbook/hover_card.png b/app/assets/images/lookbook/hover_card.pngnew file mode 100644index 00000000000..8dde8feb902Binary files /dev/null and b/app/assets/images/lookbook/hover_card.png differdiff --git a/lookbook/docs/patterns/25-hover-cards.md.erb b/lookbook/docs/patterns/25-hover-cards.md.erbnew file mode 100644index 00000000000..21db2e76b90--- /dev/null+++ b/lookbook/docs/patterns/25-hover-cards.md.erb@@ -0,0 +1,74 @@+The HoverCard is a pattern related to the `Primer::Beta::Popover` and is used to show additional information on any kind of resource. The hover card is opened by hovering a certain trigger. When hovering outside of the card or its trigger, the popover is closed again.++## Overview++ %>)++## Anatomy++The HoverCard always consists of two basic parts:++1. A trigger: That can be anything that is hoverable+2. The actual card: A small popover is opened directly next to the trigger. The actual content of the card depends on the resource that is hovered.+++## Best practices++**Do**++- Have a slight delay between hovering and opening the card+- Keep the content of the card simple+++**Don't**++- Put interactive elements inside of the card. As the popover closes as soon as you move the mouse out, it will trigger users confusion.+- Put too many triggers on one page, as it can otherwise become annoying.++## Used in++- WorkPackage preview when linking via `#ID`+- Soon: User preview when hovering the avatar++## Technical notes++Unfortunately, we could not easily use the `Primer::Beta::Popover` component.+That is why, the `HoverCard` is technically an Angular modal which renders inside a `turboFrame`.+This modal is triggered by a class called `op-hover-card--preview-trigger` which can be set in any element.+A global event listener is registered on all elements with this class and triggers the modal when being hovered.+Additionally, the trigger element needs to pass the URL for the `turboFrame` as a data attribute called `data-hover-card-url`.++### Code structure++**Angular modal**:+```html+ <!-- frontend/src/app/shared/components/modals/preview-modal/hover-card-modal/hover-card.modal.html -->+<div+ class="op-hover-card"+>+ <turbo-frame+ loading="lazy"+ id="op-hover-card-body"+ [src]="turboFrameSrc">+ </turbo-frame>+</div>+```++**Trigger**:+```html+ <!-- app/views/module_a/index.html.erb -->+ <a href="work_packages/14/activity"+ data-hover-card-url="work_packages/14/hover_card"+ class="op-hover-card--preview-trigger">+ #14+ </a>+```++**Actually rendered card content**:+```html+ <!-- app/components/work_packages/hover_card/show.html.erb -->+ <turbo-frame id="op-hover-card-body">+ <%= render WorkPackages::HoverCardComponent.new(id: 14) %>+ </turbo-frame>+ %>+```