-
Notifications
You must be signed in to change notification settings - Fork 99
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
Add TooltipIcon component to Related Resources #266
Merged
Merged
Changes from 2 commits
Commits
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 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,9 @@ | ||
<span | ||
data-test-tooltip-icon-trigger | ||
data-test-icon={{this.icon}} | ||
{{tooltip @text class="max-w-[200px]"}} | ||
class="flex text-color-foreground-faint hover:text-color-foreground-primary" | ||
...attributes | ||
> | ||
<FlightIcon @name={{this.icon}} /> | ||
</span> |
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,21 @@ | ||
import Component from "@glimmer/component"; | ||
|
||
interface TooltipIconComponentSignature { | ||
Element: HTMLSpanElement; | ||
Args: { | ||
text: string; | ||
icon?: string; | ||
}; | ||
} | ||
|
||
export default class TooltipIconComponent extends Component<TooltipIconComponentSignature> { | ||
protected get icon(): string { | ||
return this.args.icon ?? "help"; | ||
} | ||
} | ||
|
||
declare module "@glint/environment-ember-loose/registry" { | ||
export default interface Registry { | ||
TooltipIcon: typeof TooltipIconComponent; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -51,6 +51,7 @@ interface TooltipModifierNamedArgs { | |
stayOpenOnClick?: boolean; | ||
delay?: number; | ||
openDuration?: number; | ||
class?: string; | ||
_useTestDelay?: boolean; | ||
} | ||
|
||
|
@@ -171,6 +172,11 @@ export default class TooltipModifier extends Modifier<TooltipModifierSignature> | |
*/ | ||
@tracked stayOpenOnClick = false; | ||
|
||
/** | ||
* Optional classnames to append to the tooltip. | ||
*/ | ||
@tracked class: string | null = null; | ||
|
||
/** | ||
* An asserted-to-exist reference to the reference element. | ||
*/ | ||
|
@@ -240,6 +246,11 @@ export default class TooltipModifier extends Modifier<TooltipModifierSignature> | |
*/ | ||
this.tooltip = document.createElement("div"); | ||
this.tooltip.classList.add("hermes-floating-ui-content", "hermes-tooltip"); | ||
|
||
if (this.class) { | ||
this.tooltip.classList.add(this.class); | ||
} | ||
|
||
this.tooltip.setAttribute("id", `tooltip-${this.id}`); | ||
this.tooltip.setAttribute("role", "tooltip"); | ||
|
||
|
@@ -283,7 +294,7 @@ export default class TooltipModifier extends Modifier<TooltipModifierSignature> | |
middleware: [ | ||
offset(8), | ||
flip(), | ||
shift(), | ||
shift({ padding: 20 }), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This prevents the tooltip from hitting the edge of the viewport by 20px. |
||
arrow({ | ||
element: this.arrow, | ||
padding: 10, | ||
|
@@ -473,6 +484,10 @@ export default class TooltipModifier extends Modifier<TooltipModifierSignature> | |
this.placement = named.placement; | ||
} | ||
|
||
if (named.class) { | ||
this.class = named.class; | ||
} | ||
|
||
if (named.stayOpenOnClick) { | ||
this.stayOpenOnClick = named.stayOpenOnClick; | ||
} | ||
|
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ import { | |
fillIn, | ||
find, | ||
render, | ||
triggerEvent, | ||
waitFor, | ||
waitUntil, | ||
} from "@ember/test-helpers"; | ||
|
@@ -53,9 +54,12 @@ const ADD_EXTERNAL_RESOURCE_ERROR_SELECTOR = | |
"[data-test-add-external-resource-error]"; | ||
const EDIT_EXTERNAL_RESOURCE_ERROR_SELECTOR = | ||
"[data-test-external-resource-title-error]"; | ||
const TOOLTIP_TRIGGER_SELECTOR = "[data-test-tooltip-icon-trigger]"; | ||
const TOOLTIP_SELECTOR = ".hermes-tooltip"; | ||
|
||
interface DocumentSidebarRelatedResourcesTestContext extends MirageTestContext { | ||
document: HermesDocument; | ||
body: HTMLElement; | ||
} | ||
|
||
module( | ||
|
@@ -73,6 +77,8 @@ module( | |
}); | ||
|
||
this.set("document", this.server.schema.document.first().attrs); | ||
const bodyDiv = document.createElement("div"); | ||
this.set("body", bodyDiv); | ||
}); | ||
|
||
test("it renders the related resources list", async function (this: DocumentSidebarRelatedResourcesTestContext, assert) { | ||
|
@@ -98,6 +104,7 @@ module( | |
@headerTitle="Test title" | ||
@modalHeaderTitle="Add related resource" | ||
@modalInputPlaceholder="Paste a URL or search documents..." | ||
@scrollContainer={{this.body}} | ||
/> | ||
`); | ||
|
||
|
@@ -113,6 +120,13 @@ module( | |
.dom(HEADER_SELECTOR) | ||
.hasText("Test title", "the header title is correct"); | ||
|
||
assert.dom(TOOLTIP_SELECTOR).doesNotExist(); | ||
assert.dom(TOOLTIP_TRIGGER_SELECTOR).exists(); | ||
await triggerEvent(TOOLTIP_TRIGGER_SELECTOR, "mouseenter"); | ||
assert | ||
.dom(".hermes-tooltip") | ||
.hasText("Documents and links that are relevant to this work."); | ||
|
||
assert.dom(BADGE_SELECTOR).hasText("New", "the 'new' badge is rendered'"); | ||
|
||
assert | ||
|
@@ -163,6 +177,7 @@ module( | |
@headerTitle="Test title" | ||
@modalHeaderTitle="Add related resource" | ||
@modalInputPlaceholder="Paste a URL or search documents..." | ||
@scrollContainer={{this.body}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These lines fix Glint errors in the test. |
||
/> | ||
`); | ||
|
||
|
@@ -194,6 +209,7 @@ module( | |
@headerTitle="Test title" | ||
@modalHeaderTitle="Add related resource" | ||
@modalInputPlaceholder="Paste a URL or search documents..." | ||
@scrollContainer={{this.body}} | ||
/> | ||
`); | ||
|
||
|
@@ -224,6 +240,7 @@ module( | |
@headerTitle="Test title" | ||
@modalHeaderTitle="Test header" | ||
@modalInputPlaceholder="Paste a URL or search documents..." | ||
@scrollContainer={{this.body}} | ||
/> | ||
`); | ||
|
||
|
@@ -251,6 +268,7 @@ module( | |
@headerTitle="Test title" | ||
@modalHeaderTitle="Test header" | ||
@modalInputPlaceholder="Paste a URL or search documents..." | ||
@scrollContainer={{this.body}} | ||
/> | ||
`); | ||
|
||
|
@@ -289,6 +307,7 @@ module( | |
@headerTitle="Test title" | ||
@modalHeaderTitle="Add related resource" | ||
@modalInputPlaceholder="Paste a URL or search documents..." | ||
@scrollContainer={{this.body}} | ||
/> | ||
`); | ||
|
||
|
@@ -325,6 +344,7 @@ module( | |
@headerTitle="Test title" | ||
@modalHeaderTitle="Add related resource" | ||
@modalInputPlaceholder="Paste a URL or search documents..." | ||
@scrollContainer={{this.body}} | ||
/> | ||
`); | ||
|
||
|
@@ -352,6 +372,7 @@ module( | |
@headerTitle="Test title" | ||
@modalHeaderTitle="Add related resource" | ||
@modalInputPlaceholder="Test placeholder" | ||
@scrollContainer={{this.body}} | ||
/> | ||
`); | ||
|
||
|
@@ -420,6 +441,7 @@ module( | |
@headerTitle="Test title" | ||
@modalHeaderTitle="Add related resource" | ||
@modalInputPlaceholder="Test placeholder" | ||
@scrollContainer={{this.body}} | ||
/> | ||
`); | ||
|
||
|
@@ -462,6 +484,7 @@ module( | |
@headerTitle="Test title" | ||
@modalHeaderTitle="Add related resource" | ||
@modalInputPlaceholder="Test placeholder" | ||
@scrollContainer={{this.body}} | ||
/> | ||
`); | ||
|
||
|
@@ -483,6 +506,7 @@ module( | |
@headerTitle="Test title" | ||
@modalHeaderTitle="Add related resource" | ||
@modalInputPlaceholder="Test placeholder" | ||
@scrollContainer={{this.body}} | ||
/> | ||
`); | ||
|
||
|
@@ -534,6 +558,7 @@ module( | |
@headerTitle="Test title" | ||
@modalHeaderTitle="Add related resource" | ||
@modalInputPlaceholder="Test placeholder" | ||
@scrollContainer={{this.body}} | ||
/> | ||
`); | ||
|
||
|
@@ -564,6 +589,7 @@ module( | |
@headerTitle="Test title" | ||
@modalHeaderTitle="Test header" | ||
@modalInputPlaceholder="Paste a URL or search documents..." | ||
@scrollContainer={{this.body}} | ||
/> | ||
`); | ||
|
||
|
@@ -604,6 +630,7 @@ module( | |
@headerTitle="Test title" | ||
@modalHeaderTitle="Test header" | ||
@modalInputPlaceholder="Paste a URL or search documents..." | ||
@scrollContainer={{this.body}} | ||
/> | ||
`); | ||
|
||
|
@@ -679,6 +706,7 @@ module( | |
@headerTitle="Test title" | ||
@modalHeaderTitle="Test header" | ||
@modalInputPlaceholder="Paste a URL or search documents..." | ||
@scrollContainer={{this.body}} | ||
/> | ||
`); | ||
|
||
|
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,50 @@ | ||
import { module, test } from "qunit"; | ||
import { setupRenderingTest } from "ember-qunit"; | ||
import { TestContext, render, triggerEvent } from "@ember/test-helpers"; | ||
import { hbs } from "ember-cli-htmlbars"; | ||
|
||
interface TooltipIconComponentTestContext extends TestContext { | ||
icon?: string; | ||
} | ||
|
||
const TRIGGER_SELECTOR = "[data-test-tooltip-icon-trigger]"; | ||
const TOOLTIP_SELECTOR = ".hermes-tooltip"; | ||
|
||
module("Integration | Component | tooltip-icon", function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test("it renders correctly", async function (this: TooltipIconComponentTestContext, assert) { | ||
this.set("icon", undefined); | ||
|
||
await render<TooltipIconComponentTestContext>(hbs` | ||
<TooltipIcon | ||
@text="This is a tooltip" | ||
@icon={{this.icon}} | ||
class="foo" | ||
/> | ||
`); | ||
|
||
assert | ||
.dom(TRIGGER_SELECTOR) | ||
.hasAttribute("data-test-icon", "help", "default icon shown") | ||
.hasClass("foo", "splattributes handled"); | ||
|
||
assert.dom(TOOLTIP_SELECTOR).doesNotExist(); | ||
|
||
this.set("icon", "smile"); | ||
|
||
assert | ||
.dom(TRIGGER_SELECTOR) | ||
.hasAttribute( | ||
"data-test-icon", | ||
"smile", | ||
"default icon can be overridden" | ||
); | ||
|
||
await triggerEvent(TRIGGER_SELECTOR, "mouseenter"); | ||
|
||
assert | ||
.dom(TOOLTIP_SELECTOR) | ||
.hasText("This is a tooltip", "tooltip text shown"); | ||
}); | ||
}); |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reversed the order to be consistent with the tooltip text.