diff --git a/packages/uui-button-inline-create/lib/uui-button-inline-create.element.ts b/packages/uui-button-inline-create/lib/uui-button-inline-create.element.ts index 8b4052bcf..ded3f4129 100644 --- a/packages/uui-button-inline-create/lib/uui-button-inline-create.element.ts +++ b/packages/uui-button-inline-create/lib/uui-button-inline-create.element.ts @@ -6,6 +6,7 @@ import { defineElement } from '@umbraco-ui/uui-base/lib/registration'; import { css, html, LitElement } from 'lit'; import { property, state } from 'lit/decorators.js'; import { styleMap } from 'lit/directives/style-map.js'; +import { ifDefined } from 'lit/directives/if-defined.js'; import { UUIButtonInlineCreateEvent } from './UUIButtonInlineCreateEvent'; @@ -37,44 +38,89 @@ export class UUIButtonInlineCreateElement extends LitElement { @property({ type: Boolean, reflect: true }) vertical = false; + /** + * Set an href, this will turns the button into an anchor tag. + * @type {string} + * @attr + * @default undefined + */ + @property({ type: String }) + public href?: string; + + /** + * Set an anchor tag target, only used when using href. + * @type {string} + * @attr + * @default undefined + */ + @property({ type: String }) + public target?: '_blank' | '_parent' | '_self' | '_top'; + private _onMouseMove(e: MouseEvent) { - this._position = this.vertical ? e.offsetY : e.offsetX; + this._position = (this.vertical ? e.offsetY : e.offsetX) - 5; } private _handleClick(e: MouseEvent) { e.preventDefault(); e.stopImmediatePropagation(); + // We do not want to focus the button after click. + (e.target as any)?.blur?.(); + this.dispatchEvent( new UUIButtonInlineCreateEvent(UUIButtonInlineCreateEvent.CLICK) ); } - render() { + #renderContent() { + return html` +
+ + + +
+ `; + } + + #renderLink() { + return html` + ${this.#renderContent()} + `; + } + + #renderButton() { return html` `; } + render() { + return this.href ? this.#renderLink() : this.#renderButton(); + } + static styles = [ UUIBlinkKeyframes, css` @@ -205,12 +251,12 @@ export class UUIButtonInlineCreateElement extends LitElement { } :host(:not([vertical])) #plus { - margin-left: -21px; + margin-left: -18px; } :host([vertical]) #plus { left: -4px; - margin-top: -21px; + margin-top: -18px; } #button-wrapper:focus #plus { diff --git a/packages/uui-button-inline-create/lib/uui-button-inline-create.story.ts b/packages/uui-button-inline-create/lib/uui-button-inline-create.story.ts index 5612ef10e..f28cc4496 100644 --- a/packages/uui-button-inline-create/lib/uui-button-inline-create.story.ts +++ b/packages/uui-button-inline-create/lib/uui-button-inline-create.story.ts @@ -24,6 +24,7 @@ export default { const insertBox = (e: any) => { const div = document.createElement('div'); + const labelDiv = document.createElement('div'); const label = document.createElement('div'); const buttonInline = document.createElement('uui-button-inline-create'); buttonInline.addEventListener('click', insertBox); @@ -33,18 +34,31 @@ const insertBox = (e: any) => { if (e.target.vertical) { buttonInline.setAttribute('vertical', 'true'); - div.style.display = 'grid'; - div.style.gridTemplateColumns = '1fr auto'; + labelDiv.style.display = 'grid'; + labelDiv.style.gridTemplateColumns = '1fr auto'; + buttonInline.style.position = 'absolute'; + buttonInline.style.right = '0'; + buttonInline.style.top = '0'; + } else { + labelDiv.style.display = 'block'; } - div.appendChild(label); div.appendChild(buttonInline); + labelDiv.appendChild(label); + div.appendChild(labelDiv); - e.target.parentElement.insertAdjacentElement('afterend', div); + e.target.parentElement.parentElement.insertBefore( + div, + e.target.parentElement + ); }; const createBox = (vertical: boolean) => html`
+
`; const createBoxes = (count: number, vertical = false) => { @@ -66,6 +76,14 @@ const createBoxes = (count: number, vertical = false) => { for (let index = 0; index < count; index++) { boxes.push(createBox(vertical)); } + boxes.push(html` +
+ +
+ `); return boxes; }; @@ -80,6 +98,7 @@ AAAOverview.parameters = { source: { code: `
+
Item 1
Item 2
@@ -102,6 +121,7 @@ Vertical.parameters = { source: { code: `
+
Item 1
Item 2
@@ -124,6 +144,7 @@ Horizontal.parameters = { source: { code: `
+
Item 1
Item 2
@@ -135,3 +156,41 @@ Horizontal.parameters = { }, }, }; + +export const Href: Story = () => + html`

Using HREF

+
+ +
Item 1
+ +
Item 2
+ +
Item 3
+ +
`; +AAAOverview.storyName = 'Overview'; +AAAOverview.parameters = { + docs: { + source: { + code: ` +
+ +
Item 1
+ +
Item 2
+ +
Item 3
+ +
+ `, + }, + }, +};