-
Notifications
You must be signed in to change notification settings - Fork 113
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 #10930 from 18F/stages/rc-2024-07-11
Deploy RC 396 to Production
- Loading branch information
Showing
44 changed files
with
1,120 additions
and
165 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<%= content_tag('div', **tag_options, class: ['lg-verification-badge', *tag_options[:class]]) do %> | ||
<%= render IconComponent.new(icon:, class: 'text-success') %> | ||
<%= content_tag('div', **tag_options, class: ['lg-verification-badge', border_css_class, *tag_options[:class]]) do %> | ||
<%= render IconComponent.new(icon:, class: icon_css_class) %> | ||
<%= content %> | ||
<% 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
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,14 @@ | ||
# frozen_string_literal: true | ||
|
||
class TooltipComponent < BaseComponent | ||
attr_reader :tooltip_text, :tag_options | ||
|
||
def initialize(tooltip_text:, **tag_options) | ||
@tooltip_text = tooltip_text | ||
@tag_options = tag_options | ||
end | ||
|
||
def call | ||
content_tag(:'lg-tooltip', content, **tag_options, 'tooltip-text': tooltip_text) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@forward 'usa-tooltip'; | ||
|
||
// The USWDS tooltip component does not handle child elements gracefully. Prevent non-interactive | ||
// child elements from triggering event handlers to avoid errors. | ||
// | ||
// See: https://github.com/uswds/uswds/pull/5263#issuecomment-2191808834 | ||
lg-tooltip .usa-icon { | ||
pointer-events: none; | ||
} |
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 @@ | ||
import '@18f/identity-tooltip/tooltip-element'; |
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,24 @@ | ||
# `@18f/identity-tooltip` | ||
|
||
Custom element for a tooltip component. | ||
|
||
## Usage | ||
|
||
Importing the element will register the `<lg-tooltip>` custom element: | ||
|
||
```ts | ||
import '@18f/identity-tooltip/tooltip-element'; | ||
``` | ||
|
||
The custom element will implement behaviors for showing tooltip text on hover or focus, but all markup must already exist. | ||
|
||
> [!WARNING] | ||
> Due to existing issues with the U.S. Web Design System Tooltip component, there are a few limitations to be aware of: | ||
> 1. Content must be wrapped in a wrapper element, such as a `<span>` tag. | ||
> 2. Any other nested child elements must be non-interactive, using `pointer-events: none;`. | ||
```html | ||
<lg-tooltip tooltip-text="Your identity has been verified."> | ||
<span>Verified</span> | ||
</lg-tooltip> | ||
``` |
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,11 @@ | ||
{ | ||
"name": "@18f/identity-tooltip", | ||
"version": "1.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"@18f/identity-design-system": "^9.3.0" | ||
}, | ||
"sideEffects": [ | ||
"./tooltip-element.ts" | ||
] | ||
} |
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,27 @@ | ||
import { screen, getByText, waitFor } from '@testing-library/dom'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { computeAccessibleDescription } from 'dom-accessibility-api'; | ||
import './tooltip-element'; | ||
|
||
describe('TooltipElement', () => { | ||
function createAndConnectElement({ tooltipText = '', innerHTML = '<span>Verified</span>' } = {}) { | ||
const element = document.createElement('lg-tooltip'); | ||
element.setAttribute('tooltip-text', tooltipText); | ||
element.innerHTML = innerHTML; | ||
document.body.appendChild(element); | ||
return element; | ||
} | ||
|
||
it('initializes tooltip element', async () => { | ||
const tooltipText = 'Your identity has been verified'; | ||
const element = createAndConnectElement({ tooltipText }); | ||
|
||
const content = getByText(element, 'Verified'); | ||
|
||
await userEvent.hover(content); | ||
expect(computeAccessibleDescription(content)).to.be.equal(tooltipText); | ||
await waitFor(() => { | ||
expect(screen.getByText(tooltipText).classList.contains('is-visible')).to.be.true(); | ||
}); | ||
}); | ||
}); |
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,32 @@ | ||
import { tooltip } from '@18f/identity-design-system'; | ||
|
||
class TooltipElement extends HTMLElement { | ||
connectedCallback() { | ||
this.tooltipElement.setAttribute('title', this.tooltipText); | ||
this.tooltipElement.classList.add('usa-tooltip'); | ||
tooltip.on(this.tooltipElement); | ||
} | ||
|
||
get tooltipElement(): HTMLElement { | ||
return this.firstElementChild as HTMLElement; | ||
} | ||
|
||
/** | ||
* Retrieves the text to be shown in the tooltip. | ||
*/ | ||
get tooltipText(): string { | ||
return this.getAttribute('tooltip-text')!; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'lg-tooltip': TooltipElement; | ||
} | ||
} | ||
|
||
if (!customElements.get('lg-tooltip')) { | ||
customElements.define('lg-tooltip', TooltipElement); | ||
} | ||
|
||
export default TooltipElement; |
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 |
---|---|---|
@@ -1,7 +1,3 @@ | ||
<% if @presenter.show_unphishable_badge? %> | ||
<%= render BadgeComponent.new(icon: :lock).with_content(t('headings.account.unphishable')) %> | ||
<% end %> | ||
<% if @presenter.show_verified_badge? %> | ||
<%= render BadgeComponent.new(icon: :check_circle).with_content(t('headings.account.verified_account')) %> | ||
<% end %> |
Oops, something went wrong.