-
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
Conversation
Thanks for the PR! 🎉 We've deployed an automatic preview for this PR - you can see your changes here:
Note The build needs to finish before your changes are deployed. |
components/button/button-add.js
Outdated
/** | ||
* A component for quickly adding items to a specific locaiton. | ||
*/ | ||
class ButtonAdd extends FocusMixin(LocalizeCoreElement(LitElement)) { |
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.
Currently have this as d2l-button-add
. Including inline
was thought to not be great because css-wise it's not actually inline. I looked up synonyms for inline
but didn't fine anything I thought was great. Thoughts?
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.
Also, I didn't use ButtonMixin
. Let me know if there are other pieces of that which are important to a button that I'm missing.
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.
I agree with not using ButtonMixin
-- it just includes too many <button>
attributes that would be confusing to handle here.
components/button/button-add.js
Outdated
static get properties() { | ||
return { | ||
/** | ||
* The text to be shown in the tooltip as a hint when visible-text is false | ||
* @type {string} | ||
*/ | ||
label: { type: String }, | ||
/** | ||
* The text to show in the button when visible-text is true | ||
* @type {string} | ||
*/ | ||
text: { type: String }, | ||
/** | ||
* When true, show the button with icon and visible text. When false, only show icon. | ||
* @type {boolean} | ||
*/ | ||
visibleText: { type: Boolean, attribute: 'visible-text' } |
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.
Most basic component states (demo page is also probably more useful for this):
- Default ->
visible-text
is false, component shows the divider line, an add icon, and a tooltip which contains whatever is inlabel
(design refers to this as "hint") OR "Add Item" as a fallback - Visible Text -> when
visible-text
is true, the component shows the divider, and in the centre is the plus icon and the text specified intext
OR "Add Item" as a fallback.
text
and label
will not be used at the same time (the tooltip will not be shown if the text is visible and vice versa).
An aria description is potentially going to be used as well, I'll be discussing that more with design.
components/button/button-add.js
Outdated
} | ||
|
||
static get styles() { | ||
return [labelStyles, css` |
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.
I didn't use buttonStyles
here as it felt like it complicated things more than made them easier. Let me know if I should be using that.
components/button/button-add.js
Outdated
<button class="d2l-label-text" id="${this._buttonId}"> | ||
<div class="line"></div> | ||
<div class="content"> | ||
<d2l-icon icon="tier1:plus-default"></d2l-icon> | ||
${this.visibleText | ||
? html`<span>${text}</span>` | ||
: html`<d2l-tooltip class="vdiff-target" offset="18" for="${this._buttonId}" for-type="label">${label}</d2l-tooltip>`} | ||
</div> | ||
</button> | ||
`; |
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.
This implements its own button within rather than using subtle and/or icon button because we don't seem to want the focus/hover states that those provide.
components/button/button-add.js
Outdated
|
||
_onClick() { | ||
/** Dispatched when click happens */ | ||
this.dispatchEvent(new CustomEvent('d2l-button-add-click', { |
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.
I made this a component specific click event rather than just firing up click
since list
consumers could be listening for this and just having a generic click
seemed like it could cause confusion.
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.
That makes sense. In that case, we probably want to call e.stopPropagation();
. I'm kinda surprised we aren't doing that here.
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.
I'd like to explore this a little bit... there are lots of components that fire click events, including just clicking on a <span>
or whatever, so hoping we don't need to worry about this.
Either way, does it need to bubble and cross shadow root boundaries?
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.
It would need to bubble and cross shadow root boundaries. The plan is that to use this consumers of list would have something like:
<d2l-list add-button>...</d2l-list>
and then the button-add
component would appear after each list item. We don't want consumers to have to manage adding this component themselves after each item, and behaviour is designed to be consistent (i.e., wouldn't have some list items with button-add
and others that don't have it, etc.).
All that to say, for the list case, consumers of list would want to listen for this event and then handle the click of the add button however they wish to.
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.
Gotcha. In that case, another option: since list is going to be the one rendering <d2l-button-add>
, it could wire up to its click event and then fire its own d2l-list-add-button-click
event.
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.
So consumers would go <d2l-list add-button @d2l-list-add-button-click="{...}">
.
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.
I like that idea - I think that would be more straightforward for consumers.
components/button/button-add.js
Outdated
/** | ||
* A component for quickly adding items to a specific locaiton. | ||
*/ | ||
class ButtonAdd extends FocusMixin(LocalizeCoreElement(LitElement)) { |
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.
I agree with not using ButtonMixin
-- it just includes too many <button>
attributes that would be confusing to handle here.
components/button/button-add.js
Outdated
|
||
_onClick() { | ||
/** Dispatched when click happens */ | ||
this.dispatchEvent(new CustomEvent('d2l-button-add-click', { |
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.
I'd like to explore this a little bit... there are lots of components that fire click events, including just clicking on a <span>
or whatever, so hoping we don't need to worry about this.
Either way, does it need to bubble and cross shadow root boundaries?
…el and just use text, remove labelStyles, remove click event handling
…into inline-add-component
components/button/button-add.js
Outdated
label: { type: String }, | ||
/** | ||
* The text to show in the button when visible-text is true | ||
* 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 }, |
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.
Once the PropertyRequiredMixin
stuff merges, this should likely use it.
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.
Cool!
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 }, | ||
text: { type: String, required: true }, |
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!
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
🎉 This PR is included in version 2.165.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Just remembered randomly: make sure you set type="button"
on this, otherwise it defaults to submit
and will submit forms!
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.
Good catch, thanks! Will fix
Rally Story
This is the initial work on the inline add button component. Its original purpose was for list but it now has the requirement of being a standalone component. I'll add comments throughout, but most of this is up for debate especially naming.
This does not include more detailed documentation on the README (followup story) and also doesn't include the ability to hide when not hovering (will do separately, didn't want to clutter this PR too much).
Also note that there will likely be a different icon use, which will also change on hover and focus.