-
Notifications
You must be signed in to change notification settings - Fork 742
feat: Add tooltips to glossary term links with their definition #6969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 @@ | ||
| .tooltip-wrapper { | ||
| position: relative; | ||
|
|
||
| a.tooltip-target { | ||
| color: inherit; | ||
| text-decoration: underline; | ||
| text-decoration-style: dotted; | ||
| } | ||
|
|
||
| .tooltip { | ||
| visibility: hidden; | ||
|
|
||
| display: flex; | ||
| position: absolute; | ||
| z-index: var(--site-z-floating); | ||
| top: 100%; | ||
| left: 50%; | ||
| transform: translateX(-50%); | ||
|
|
||
| flex-flow: column nowrap; | ||
| width: 16rem; | ||
|
|
||
| background: var(--site-raised-bgColor); | ||
| border: 0.05rem solid rgba(0, 0, 0, .125); | ||
| border-radius: 0.75rem; | ||
| box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, .15); | ||
| padding: 0.8rem; | ||
|
|
||
| font-size: 1rem; | ||
| font-weight: normal; | ||
| font-style: normal; | ||
|
|
||
| .tooltip-header { | ||
| font-size: 1.2rem; | ||
| font-weight: 500; | ||
| margin-bottom: 0.25rem; | ||
| } | ||
|
|
||
| .tooltip-content { | ||
| font-size: 0.875rem; | ||
| color: var(--site-secondary-textColor); | ||
| } | ||
| } | ||
|
|
||
| // On non-touch devices, show tooltip on hover or focus. | ||
| @media all and not (pointer: coarse) { | ||
| &:hover .tooltip { | ||
| visibility: visible; | ||
| } | ||
|
|
||
| &:focus-within .tooltip { | ||
| visibility: visible; | ||
| } | ||
| } | ||
|
|
||
| // On touch devices, show tooltip on click (see global_scripts.dart). | ||
| @media all and (pointer: coarse) { | ||
| .tooltip.visible { | ||
| visibility: visible; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,98 @@ | ||
| // Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
| // for details. All rights reserved. Use of this source code is governed by a | ||
| // BSD-style license that can be found in the LICENSE file. | ||
|
|
||
| import 'package:jaspr/jaspr.dart'; | ||
| import 'package:jaspr_content/jaspr_content.dart'; | ||
|
|
||
| import '../pages/glossary.dart'; | ||
| import '../util.dart'; | ||
|
|
||
| /// A node-processing, page extension for Jaspr Content that looks for links to | ||
| /// glossary entries and enhances them with interactive glossary tooltips. | ||
| class GlossaryLinkProcessor implements PageExtension { | ||
| const GlossaryLinkProcessor(); | ||
|
|
||
| @override | ||
| Future<List<Node>> apply(Page page, List<Node> nodes) async { | ||
| final glossary = Glossary.fromList(page.data['glossary'] as List<Object?>); | ||
| return _processNodes(nodes, glossary); | ||
| } | ||
|
|
||
| List<Node> _processNodes(List<Node> nodes, Glossary glossary) { | ||
| final processedNodes = <Node>[]; | ||
|
|
||
| for (final node in nodes) { | ||
| if (node is ElementNode && | ||
| node.tag == 'a' && | ||
| node.attributes['href']?.startsWith('/resources/glossary') == true) { | ||
| // Found a glossary link, extract its id from the url and | ||
| // create the tooltip component. | ||
|
|
||
| final id = Uri.parse(node.attributes['href']!).fragment; | ||
| final entry = glossary.entries.where((e) => e.id == id).firstOrNull; | ||
|
|
||
| if (entry == null) { | ||
| // If the glossary entry is not found, keep the original node. | ||
| processedNodes.add(node); | ||
| continue; | ||
| } | ||
|
|
||
| processedNodes.add( | ||
| ElementNode( | ||
| 'span', | ||
| {'class': 'tooltip-wrapper'}, | ||
| [ | ||
| ElementNode('a', { | ||
| ...node.attributes, | ||
| 'class': [ | ||
| ?node.attributes['class'], | ||
| 'tooltip-target', | ||
| ].toClasses, | ||
| }, node.children), | ||
| ComponentNode(GlossaryTooltip(entry: entry)), | ||
| ], | ||
| ), | ||
| ); | ||
| } else if (node is ElementNode && node.children != null) { | ||
| processedNodes.add( | ||
| ElementNode( | ||
| node.tag, | ||
| node.attributes, | ||
| _processNodes(node.children!, glossary), | ||
| ), | ||
| ); | ||
| } else { | ||
| processedNodes.add(node); | ||
| } | ||
| } | ||
|
|
||
| return processedNodes; | ||
| } | ||
| } | ||
|
|
||
| class GlossaryTooltip extends StatelessComponent { | ||
| const GlossaryTooltip({required this.entry}); | ||
|
|
||
| final GlossaryEntry entry; | ||
|
|
||
| @override | ||
| Component build(BuildContext context) { | ||
| return span(classes: 'tooltip', [ | ||
| span(classes: 'tooltip-header', [text(entry.term)]), | ||
| span(classes: 'tooltip-content', [ | ||
| text(entry.shortDescription), | ||
parlough marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| text(' '), | ||
| a( | ||
| href: '/resources/glossary#${entry.id}', | ||
| attributes: { | ||
| 'title': | ||
| 'Learn more about \'${entry.term}\' and ' | ||
| 'find related resources.', | ||
| }, | ||
| [text('Learn more')], | ||
| ), | ||
| ]), | ||
| ]); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.