-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dropdown-button-icon/custom components (#163)
- Loading branch information
Showing
22 changed files
with
328 additions
and
82 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
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 { css, html, LitElement } from 'lit'; | ||
import { DropdownOpenerMixin } from '@brightspace-ui/core/components/dropdown/dropdown-opener-mixin.js'; | ||
import { highlightBorderStyles, highlightButtonStyles } from './d2l-navigation-styles.js'; | ||
|
||
class NavigationDropdownButtonCustom extends DropdownOpenerMixin(LitElement) { | ||
|
||
static get styles() { | ||
return [highlightBorderStyles, highlightButtonStyles, css` | ||
:host { | ||
display: inline-block; | ||
height: 100%; | ||
position: relative; | ||
} | ||
:host([hidden]) { | ||
display: none; | ||
} | ||
`]; | ||
} | ||
|
||
getOpenerElement() { | ||
return this.shadowRoot && this.shadowRoot.querySelector('button'); | ||
} | ||
|
||
render() { | ||
return html` | ||
<button type="button"> | ||
<span class="d2l-navigation-highlight-border"></span> | ||
<slot name="opener"></slot> | ||
</button> | ||
<slot></slot> | ||
`; | ||
} | ||
|
||
} | ||
|
||
customElements.define('d2l-navigation-dropdown-button-custom', NavigationDropdownButtonCustom); |
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,85 @@ | ||
import '@brightspace-ui/core/components/icons/icon.js'; | ||
import '@brightspace-ui/core/components/tooltip/tooltip.js'; | ||
import './d2l-navigation-notification-icon.js'; | ||
import { css, html, LitElement, nothing } from 'lit'; | ||
import { DropdownOpenerMixin } from '@brightspace-ui/core/components/dropdown/dropdown-opener-mixin.js'; | ||
import { getUniqueId } from '@brightspace-ui/core/helpers/uniqueId.js'; | ||
import { ifDefined } from 'lit/directives/if-defined.js'; | ||
import { offscreenStyles } from '@brightspace-ui/core/components/offscreen/offscreen.js'; | ||
import { highlightBorderStyles, highlightButtonStyles } from './d2l-navigation-styles.js'; | ||
|
||
class NavigationDropdownButtonIcon extends DropdownOpenerMixin(LitElement) { | ||
|
||
static get properties() { | ||
return { | ||
icon: { type: String }, | ||
hasNotification: { attribute: 'has-notification', reflect: true, type: Boolean }, | ||
text: { type: String }, | ||
notificationText: { attribute: 'notification-text', type: String } | ||
}; | ||
} | ||
|
||
static get styles() { | ||
return [highlightBorderStyles, highlightButtonStyles, offscreenStyles, css` | ||
:host { | ||
display: inline-block; | ||
height: 100%; | ||
position: relative; | ||
} | ||
:host([hidden]) { | ||
display: none; | ||
} | ||
.icon-container { | ||
display: inline-block; | ||
position: relative; | ||
} | ||
`]; | ||
} | ||
|
||
constructor() { | ||
super(); | ||
this.hasNotification = false; | ||
this._buttonId = getUniqueId(); | ||
this._describedById = getUniqueId(); | ||
} | ||
|
||
getOpenerElement() { | ||
return this.shadowRoot && this.shadowRoot.querySelector('button'); | ||
} | ||
|
||
render() { | ||
const { ariaDescribedBy, ariaDescription, contents } = this._getRenderSettings(); | ||
const highlightBorder = !this.disabled ? html`<span class="d2l-navigation-highlight-border"></span>` : nothing; | ||
const tooltip = !this.dropdownOpened ? html`<d2l-tooltip close-on-click for="${this._buttonId}" for-type="label" position="bottom">${this.text}</d2l-tooltip>` : nothing; | ||
return html` | ||
<button | ||
aria-describedby="${ifDefined(ariaDescribedBy)}" | ||
aria-label="${this.text}" | ||
?disabled="${this.disabled}" | ||
id="${this._buttonId}" | ||
type="button">${highlightBorder}${contents}</button> | ||
${ariaDescription} | ||
${tooltip} | ||
<slot></slot> | ||
`; | ||
} | ||
|
||
_getRenderSettings() { | ||
const icon = html`<d2l-icon icon="${this.icon}"></d2l-icon>`; | ||
if (this.hasNotification) { | ||
return { | ||
ariaDescribedBy: this._describedById, | ||
ariaDescription: html`<span class="d2l-offscreen" id="${this._describedById}">${this.notificationText}</span>`, | ||
contents: html`<span class="icon-container">${icon}<d2l-navigation-notification-icon></d2l-navigation-notification-icon></span>` | ||
}; | ||
} | ||
return { | ||
ariaDescribedBy: undefined, | ||
ariaDescription: nothing, | ||
contents: icon | ||
}; | ||
} | ||
|
||
} | ||
|
||
customElements.define('d2l-navigation-dropdown-button-icon', NavigationDropdownButtonIcon); |
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,44 +1,54 @@ | ||
import '@brightspace-ui/core/components/colors/colors.js'; | ||
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js'; | ||
import { RtlMixin } from '@brightspace-ui/core/mixins/rtl-mixin.js'; | ||
import { css, html, LitElement } from 'lit'; | ||
|
||
/** | ||
* @customElement | ||
* @polymer | ||
*/ | ||
class NavigationNotificationIcon extends PolymerElement { | ||
static get template() { | ||
return html` | ||
<style is="custom-style"> | ||
:host { | ||
display: inline-block; | ||
height: 100%; | ||
position: absolute; | ||
right: calc(-100% + 11px); | ||
top: calc(-50% + 11px); | ||
width: 100%; | ||
} | ||
:host([hidden]){ | ||
display: none; | ||
} | ||
:host(:dir(rtl)) { | ||
left: calc(-50% - 4px); | ||
right: auto; | ||
} | ||
.d2l-navigation-notification-icon-indicator { | ||
background: var(--d2l-color-primary-accent-indicator); | ||
border: 2px solid white; | ||
height: 10px; | ||
width: 10px; | ||
border-radius: 50%; | ||
} | ||
:host([thin-border]) .d2l-navigation-notification-icon-indicator { | ||
border-width: 1px; | ||
} | ||
</style> | ||
<div class="d2l-navigation-notification-icon-indicator"></div> | ||
class NavigationNotificationIcon extends RtlMixin(LitElement) { | ||
|
||
static get properties() { | ||
return { | ||
thinBorder: { attribute: 'thin-border', reflect: true, type: Boolean } | ||
}; | ||
} | ||
|
||
static get styles() { | ||
return css` | ||
:host { | ||
display: inline-block; | ||
height: 100%; | ||
position: absolute; | ||
right: calc(-100% + 11px); | ||
top: calc(-50% + 11px); | ||
width: 100%; | ||
} | ||
:host([hidden]) { | ||
display: none; | ||
} | ||
:host([dir="rtl"]) { | ||
left: calc(-50% - 4px); | ||
right: auto; | ||
} | ||
.d2l-navigation-notification-icon-indicator { | ||
background: var(--d2l-color-primary-accent-indicator); | ||
border: 2px solid white; | ||
border-radius: 50%; | ||
height: 10px; | ||
width: 10px; | ||
} | ||
:host([thin-border]) .d2l-navigation-notification-icon-indicator { | ||
border-width: 1px; | ||
} | ||
`; | ||
} | ||
|
||
constructor() { | ||
super(); | ||
this.thinBorder = false; | ||
} | ||
|
||
render() { | ||
return html`<div class="d2l-navigation-notification-icon-indicator"></div>`; | ||
} | ||
|
||
} | ||
|
||
window.customElements.define('d2l-navigation-notification-icon', NavigationNotificationIcon); |
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.