-
Notifications
You must be signed in to change notification settings - Fork 25
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
Inline Add Button Component #4270
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
78583ea
Button Add Component: Initial work
margaree 5014f12
add tests
margaree 622671a
get visual diff tests working, simplify code
margaree 4bf83ae
Fix axe tests
margaree c6eac4f
css tweaks
margaree 96efcf0
fix lint
margaree 9007154
reflect visible-text
margaree 4cf9f2d
replace padding-right
margaree e532d55
organize visual diffs
margaree 3cc039e
code review feedback: rename visible-text to text-visible, remove lab…
margaree d9ce259
Merge branch 'main' into inline-add-component
margaree b84a859
fix click event in demo, axe test, and tweak vdiff test names
margaree dce2414
Merge branch 'inline-add-component' of github.com:BrightspaceUI/core …
margaree 370c9cb
code review feedback: use getFocusPseudoClass
margaree a08cbd9
fix lint
margaree 1bc32db
code review feedback: remove unnecessary line from vdiff tests, updat…
margaree a8c06af
fix lint
margaree f95a9ee
Merge branch 'main' into inline-add-component
margaree 2c0bf41
code review feedback: use PropertyRequiredMixin for text
margaree 9fb99a4
Updating vdiff goldens (#4271)
github-actions[bot] 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"browsers": [ | ||
{ | ||
"name": "Chromium", | ||
"version": 117 | ||
"version": 119 | ||
} | ||
] | ||
} |
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,127 @@ | ||
import '../colors/colors.js'; | ||
import '../icons/icon.js'; | ||
import '../tooltip/tooltip.js'; | ||
import { css, html, LitElement, unsafeCSS } from 'lit'; | ||
import { FocusMixin } from '../../mixins/focus/focus-mixin.js'; | ||
import { getFocusPseudoClass } from '../../helpers/focus.js'; | ||
import { getUniqueId } from '../../helpers/uniqueId.js'; | ||
import { ifDefined } from 'lit/directives/if-defined.js'; | ||
import { LocalizeCoreElement } from '../../helpers/localize-core-element.js'; | ||
import { PropertyRequiredMixin } from '../../mixins/property-required/property-required-mixin.js'; | ||
|
||
/** | ||
* A component for quickly adding items to a specific locaiton. | ||
*/ | ||
class ButtonAdd extends PropertyRequiredMixin(FocusMixin(LocalizeCoreElement(LitElement))) { | ||
static get properties() { | ||
return { | ||
/** | ||
* When text-visible is true, the text to show in the button. When text-visible is false, the text to show in the tooltip. | ||
* @type {string} | ||
*/ | ||
text: { type: String, required: true }, | ||
/** | ||
* When true, show the button with icon and visible text. When false, only show icon. | ||
* @type {boolean} | ||
*/ | ||
textVisible: { type: Boolean, reflect: true, attribute: 'text-visible' } | ||
}; | ||
} | ||
|
||
static get styles() { | ||
return css` | ||
:host { | ||
--d2l-button-add-line-style: solid; | ||
} | ||
button { | ||
dbatiste marked this conversation as resolved.
Show resolved
Hide resolved
|
||
align-items: center; | ||
background-color: transparent; | ||
border: 0; | ||
box-shadow: none; | ||
cursor: pointer; | ||
display: flex; | ||
font-family: inherit; | ||
justify-content: center; | ||
outline: none; | ||
padding: 0; | ||
position: relative; | ||
user-select: none; | ||
white-space: nowrap; | ||
width: 100%; | ||
} | ||
|
||
.line { | ||
border-top: 1px var(--d2l-button-add-line-style) var(--d2l-color-mica); | ||
margin: 3px 0; /** hover/click target */ | ||
dbatiste marked this conversation as resolved.
Show resolved
Hide resolved
|
||
width: 100%; | ||
} | ||
button:hover .line, | ||
button:${unsafeCSS(getFocusPseudoClass())} .line { | ||
border-top-color: var(--d2l-color-celestine); | ||
} | ||
|
||
.content { | ||
align-items: center; | ||
background-color: white; | ||
display: flex; | ||
position: absolute; | ||
} | ||
:host([text-visible]) .content { | ||
color: var(--d2l-color-celestine); | ||
height: 1.5rem; | ||
padding: 0 0.3rem; | ||
} | ||
|
||
:host([text-visible]) d2l-icon, | ||
:host(:not([text-visible])) button:hover d2l-icon, | ||
:host(:not([text-visible])) button:${unsafeCSS(getFocusPseudoClass())} d2l-icon { | ||
color: var(--d2l-color-celestine); | ||
} | ||
:host(:not([text-visible])) d2l-icon { | ||
color: var(--d2l-color-galena); | ||
margin: -3px; /** hover/click target */ | ||
padding: 3px; /** hover/click target */ | ||
} | ||
:host([text-visible]) d2l-icon { | ||
padding-inline-end: 0.2rem; | ||
} | ||
|
||
span { | ||
font-size: 0.7rem; | ||
font-weight: 700; | ||
letter-spacing: 0.2px; | ||
line-height: 1rem; | ||
} | ||
`; | ||
} | ||
|
||
constructor() { | ||
super(); | ||
|
||
this.textVisible = false; | ||
this._buttonId = getUniqueId(); | ||
} | ||
|
||
static get focusElementSelector() { | ||
return 'button'; | ||
} | ||
|
||
render() { | ||
const text = this.text || this.localize('components.button-add.addItem'); | ||
const id = !this.textVisible ? this._buttonId : undefined; | ||
|
||
return html` | ||
<button class="d2l-label-text" id="${ifDefined(id)}"> | ||
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. Just remembered randomly: make sure you set 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. Good catch, thanks! Will fix |
||
<div class="line"></div> | ||
<div class="content"> | ||
<d2l-icon icon="tier1:plus-default"></d2l-icon> | ||
${this.textVisible | ||
? html`<span>${text}</span>` | ||
: html`<d2l-tooltip class="vdiff-target" offset="18" for="${this._buttonId}" for-type="label">${text}</d2l-tooltip>`} | ||
</div> | ||
</button> | ||
`; | ||
} | ||
} | ||
customElements.define('d2l-button-add', ButtonAdd); | ||
|
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,73 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta charset="UTF-8"> | ||
<link rel="stylesheet" href="../../demo/styles.css" type="text/css"> | ||
<script type="module"> | ||
import '../../demo/demo-page.js'; | ||
import '../button-add.js'; | ||
</script> | ||
<style> | ||
.d2l-button-add-dashed { | ||
--d2l-button-add-line-style: dashed; | ||
} | ||
</style> | ||
</head> | ||
<body unresolved> | ||
|
||
<d2l-demo-page page-title="d2l-button-add"> | ||
|
||
<h2>Add Button</h2> | ||
|
||
<d2l-demo-snippet> | ||
<template> | ||
<d2l-button-add></d2l-button-add> | ||
</template> | ||
</d2l-demo-snippet> | ||
|
||
<h2>Add Button, dashed line</h2> | ||
|
||
<d2l-demo-snippet> | ||
<template> | ||
<d2l-button-add class="d2l-button-add-dashed"></d2l-button-add> | ||
</template> | ||
</d2l-demo-snippet> | ||
|
||
<h2>Add Button, custom text</h2> | ||
|
||
<d2l-demo-snippet> | ||
<template> | ||
<d2l-button-add text="Custom Tooltip"></d2l-button-add> | ||
</template> | ||
</d2l-demo-snippet> | ||
|
||
|
||
<h2>Add Button, text-visible</h2> | ||
|
||
<d2l-demo-snippet> | ||
<template> | ||
<d2l-button-add text-visible></d2l-button-add> | ||
</template> | ||
</d2l-demo-snippet> | ||
|
||
|
||
<h2>Add Button, text-visible, custom text</h2> | ||
|
||
<d2l-demo-snippet> | ||
<template> | ||
<d2l-button-add text-visible text="Custom Text"></d2l-button-add> | ||
</template> | ||
</d2l-demo-snippet> | ||
|
||
</d2l-demo-page> | ||
|
||
<script> | ||
document.addEventListener('click', e => { | ||
if (e.target.tagName !== 'D2L-BUTTON-ADD') return; | ||
console.log('add button clicked', e.target); | ||
}); | ||
</script> | ||
|
||
</body> | ||
</html> |
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,33 @@ | ||
import '../button-add.js'; | ||
import { expect, fixture, focusElem, html } from '@brightspace-ui/testing'; | ||
|
||
describe('d2l-button-add', () => { | ||
|
||
it('default', async() => { | ||
const el = await fixture(html`<d2l-button-add></d2l-button-add>`); | ||
await expect(el).to.be.accessible(); | ||
}); | ||
|
||
it('text', async() => { | ||
const el = await fixture(html`<d2l-button-add text="Custom Text"></d2l-button-add>`); | ||
await expect(el).to.be.accessible(); | ||
}); | ||
|
||
it('visible text', async() => { | ||
const el = await fixture(html`<d2l-button-add text-visible></d2l-button-add>`); | ||
await expect(el).to.be.accessible(); | ||
}); | ||
|
||
it('focused', async() => { | ||
const el = await fixture(html`<d2l-button-add></d2l-button-add>`); | ||
await focusElem(el); | ||
await expect(el).to.be.accessible(); | ||
}); | ||
|
||
it('focused, visible text', async() => { | ||
const el = await fixture(html`<d2l-button-add text-visible></d2l-button-add>`); | ||
await focusElem(el); | ||
await expect(el).to.be.accessible(); | ||
}); | ||
|
||
}); |
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,36 @@ | ||
import '../button-add.js'; | ||
import { clickElem, expect, fixture, html, oneEvent, runConstructor } from '@brightspace-ui/testing'; | ||
import { createMessage } from '../../../mixins/property-required/property-required-mixin.js'; | ||
|
||
describe('d2l-button-add', () => { | ||
|
||
describe('constructor', () => { | ||
|
||
it('should construct', () => { | ||
runConstructor('d2l-button-add'); | ||
}); | ||
|
||
}); | ||
|
||
describe('events', () => { | ||
|
||
it('dispatches click event when clicked', async() => { | ||
const el = await fixture(html`<d2l-button-add></d2l-button-add>`); | ||
setTimeout(() => clickElem(el)); | ||
await oneEvent(el, 'click'); | ||
}); | ||
|
||
it('throws error when no text', async() => { | ||
const el = await fixture(html`<d2l-button-add></d2l-button-add>`); | ||
expect(() => el.flushRequiredPropertyErrors()) | ||
.to.throw(TypeError, createMessage(el, 'text')); | ||
}); | ||
|
||
it('does not throw when text is provided', async() => { | ||
const el = await fixture(html`<d2l-button-add text="Custom Text"></d2l-button-add>`); | ||
expect(() => el.flushRequiredPropertyErrors()).to.not.throw(); | ||
}); | ||
|
||
}); | ||
|
||
}); |
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,31 @@ | ||
import '../button-add.js'; | ||
import { clickElem, expect, fixture, focusElem, hoverElem, html, oneEvent } from '@brightspace-ui/testing'; | ||
|
||
describe('button-add', () => { | ||
[ true, false ].forEach((textVisible) => { | ||
describe(`text-visible ${textVisible}`, () => { | ||
[ | ||
{ category: 'basic', template: html`<d2l-button-add ?text-visible="${textVisible}"></d2l-button-add>` }, | ||
{ category: 'text', template: html`<d2l-button-add text="Custom Text" ?text-visible="${textVisible}"></d2l-button-add>` }, | ||
{ category: 'dashed line', template: html`<d2l-button-add style="--d2l-button-add-line-style: dashed;" ?text-visible="${textVisible}"></d2l-button-add>` } | ||
].forEach(({ category, template }) => { | ||
|
||
describe(category, () => { | ||
[ | ||
{ name: 'normal' }, | ||
{ name: 'hover', action: hoverElem }, | ||
{ name: 'focus', action: focusElem }, | ||
{ name: 'click', action: clickElem } | ||
].forEach(({ action, name }) => { | ||
it(name, async() => { | ||
const elem = await fixture(template); | ||
if (action) await action(elem); | ||
if ((name === 'hover' || name === 'focus') && !elem.textVisible) await oneEvent(elem, 'd2l-tooltip-show'); | ||
await expect(elem).to.be.golden(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Binary file added
BIN
+5.23 KB
...nents/button/test/golden/button-add/chromium/text-visible-false-basic-click.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.23 KB
...nents/button/test/golden/button-add/chromium/text-visible-false-basic-focus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.23 KB
...nents/button/test/golden/button-add/chromium/text-visible-false-basic-hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+756 Bytes
...ents/button/test/golden/button-add/chromium/text-visible-false-basic-normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.62 KB
...button/test/golden/button-add/chromium/text-visible-false-dashed-line-click.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.62 KB
...button/test/golden/button-add/chromium/text-visible-false-dashed-line-focus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.62 KB
...button/test/golden/button-add/chromium/text-visible-false-dashed-line-hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.77 KB
...utton/test/golden/button-add/chromium/text-visible-false-dashed-line-normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.75 KB
...onents/button/test/golden/button-add/chromium/text-visible-false-text-click.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.75 KB
...onents/button/test/golden/button-add/chromium/text-visible-false-text-focus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+6.75 KB
...onents/button/test/golden/button-add/chromium/text-visible-false-text-hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+756 Bytes
...nents/button/test/golden/button-add/chromium/text-visible-false-text-normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.12 KB
...onents/button/test/golden/button-add/chromium/text-visible-true-basic-click.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.12 KB
...onents/button/test/golden/button-add/chromium/text-visible-true-basic-focus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.12 KB
...onents/button/test/golden/button-add/chromium/text-visible-true-basic-hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.13 KB
...nents/button/test/golden/button-add/chromium/text-visible-true-basic-normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.42 KB
.../button/test/golden/button-add/chromium/text-visible-true-dashed-line-click.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.42 KB
.../button/test/golden/button-add/chromium/text-visible-true-dashed-line-focus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.42 KB
.../button/test/golden/button-add/chromium/text-visible-true-dashed-line-hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.23 KB
...button/test/golden/button-add/chromium/text-visible-true-dashed-line-normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.35 KB
components/button/test/golden/button-add/chromium/text-visible-true-text-click.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.35 KB
components/button/test/golden/button-add/chromium/text-visible-true-text-focus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.35 KB
components/button/test/golden/button-add/chromium/text-visible-true-text-hover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.35 KB
...onents/button/test/golden/button-add/chromium/text-visible-true-text-normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
Oops, something went wrong.
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.
Yay!