From 78583ea937f8f44978f5b64967722370e92399d9 Mon Sep 17 00:00:00 2001 From: Margaree Peacocke Date: Mon, 20 Nov 2023 12:20:09 -0500 Subject: [PATCH 01/17] Button Add Component: Initial work --- components/button/button-add.js | 125 +++++++++++++++++++++++++ components/button/demo/button-add.html | 68 ++++++++++++++ index.html | 1 + lang/en.js | 1 + 4 files changed, 195 insertions(+) create mode 100644 components/button/button-add.js create mode 100644 components/button/demo/button-add.html diff --git a/components/button/button-add.js b/components/button/button-add.js new file mode 100644 index 00000000000..abe922f26ea --- /dev/null +++ b/components/button/button-add.js @@ -0,0 +1,125 @@ +import '../tooltip/tooltip.js'; +import { css, html, LitElement } from 'lit'; +import { getUniqueId } from '../../helpers/uniqueId.js'; +import { labelStyles } from '../typography/styles.js'; +import { LocalizeCoreElement } from '../../helpers/localize-core-element.js'; + +/** + * A component for quickly adding items to a specific locaiton. + * TODO: + * - smarter margin and padding and top + * - focus + * - simplify html and css + */ +class ButtonAdd extends LocalizeCoreElement(LitElement) { + 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' } + }; + } + + static get styles() { + return [labelStyles, css` + :host { + --d2l-button-add-line-style: solid; + } + button { + background-color: transparent; + border: 0; + font-family: inherit; + display: flex; + justify-content: center; + outline: none; + padding: 0; + position: relative; + width: 100%; + } + .line { + border-top: 1px var(--d2l-button-add-line-style) var(--d2l-color-mica); + margin: 3px 0; + width: 100%; + } + :host(:hover) .line, + :host(:focus-visible) .line { + border-top-color: var(--d2l-color-celestine); + } + d2l-icon.icon-no-text { + background-color: white; + color: var(--d2l-color-mica); + padding: 3px; + position: absolute; + top: -8px; + } + :host(:hover) d2l-icon { + color: var(--d2l-color-celestine); + } + .icon-text { + align-items: center; + background-color: white; + color: var(--d2l-color-celestine); + display: flex; + height: 30px; + padding: 0 0.6rem; + position: absolute; + top: -11px; + } + .icon-text d2l-icon { + color: var(--d2l-color-celestine); + padding-right: 3px; + } + `]; + } + + constructor() { + super(); + + this._iconId = getUniqueId(); + this.visibleText = false; + this.addEventListener('click', this._onClick); + } + + render() { + const text = this.text || this.localize('components.button-add.addItem'); + const label = this.label || this.localize('components.button-add.addItem'); + return html` + + `; + } + + _onClick() { + /** Dispatched when click happens */ + this.dispatchEvent(new CustomEvent('d2l-button-add-click', { + bubbles: true, + composed: true + })); + } +} +customElements.define('d2l-button-add', ButtonAdd); + diff --git a/components/button/demo/button-add.html b/components/button/demo/button-add.html new file mode 100644 index 00000000000..221d7df717b --- /dev/null +++ b/components/button/demo/button-add.html @@ -0,0 +1,68 @@ + + + + + + + + + + + + +

Add Button

+ + + + + +

Add Button, dashed line

+ + + + + + +

Add Button, visible-text

+ + + + + + +

Add Button, visible-text, text

+ + + + + +

Add Button, label

+ + + + + +
+ + + + + diff --git a/index.html b/index.html index 96d67f97f61..5209d4f9f35 100644 --- a/index.html +++ b/index.html @@ -36,6 +36,7 @@

Components

Buttons