Skip to content

Commit

Permalink
Merge branch 'v1/contrib' into feature/inline-button-create-href
Browse files Browse the repository at this point in the history
  • Loading branch information
nielslyngsoe authored Jan 23, 2024
2 parents d577df5 + 7cd20db commit 98e11bf
Show file tree
Hide file tree
Showing 14 changed files with 300 additions and 101 deletions.
8 changes: 4 additions & 4 deletions packages/uui-badge/lib/uui-badge.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
import { css, html, LitElement } from 'lit';
import { property } from 'lit/decorators.js';
import type {
InterfaceColor,
InterfaceLook,
UUIInterfaceColor,
UUIInterfaceLook,
} from '@umbraco-ui/uui-base/lib/types';

/**
Expand All @@ -21,7 +21,7 @@ export class UUIBadgeElement extends LitElement {
* @default "default"
*/
@property({ reflect: true })
color: InterfaceColor = 'default';
color: UUIInterfaceColor = 'default';

/**
* Changes the look of the button to one of the predefined, symbolic looks. For example - set this to positive if you want nice, green "confirm" button.
Expand All @@ -30,7 +30,7 @@ export class UUIBadgeElement extends LitElement {
* @default "default"
*/
@property({ reflect: true })
look: InterfaceLook = 'primary';
look: UUIInterfaceLook = 'primary';

/**
* Bring attention to this badge by applying a bounce animation.
Expand Down
9 changes: 7 additions & 2 deletions packages/uui-base/lib/types/InterfaceColor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
export const InterfaceColorValues: Readonly<InterfaceColor[]> = [
export const UUIInterfaceColorValues: Readonly<UUIInterfaceColor[]> = [
'default',
'positive',
'warning',
'danger',
] as const;

export type InterfaceColor = '' | 'default' | 'positive' | 'warning' | 'danger';
export type UUIInterfaceColor =
| ''
| 'default'
| 'positive'
| 'warning'
| 'danger';
4 changes: 2 additions & 2 deletions packages/uui-base/lib/types/InterfaceHeading.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const InterfaceHeadingValues: Readonly<InterfaceHeading[]> = [
export const UUIInterfaceHeadingValues: Readonly<UUIInterfaceHeading[]> = [
'h1',
'h2',
'h3',
Expand All @@ -7,4 +7,4 @@ export const InterfaceHeadingValues: Readonly<InterfaceHeading[]> = [
'h6',
] as const;

export type InterfaceHeading = '' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
export type UUIInterfaceHeading = '' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
4 changes: 2 additions & 2 deletions packages/uui-base/lib/types/InterfaceLook.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export const InterfaceLookValues: Readonly<InterfaceLook[]> = [
export const UUIInterfaceLookValues: Readonly<UUIInterfaceLook[]> = [
'default',
'primary',
'secondary',
'outline',
'placeholder',
] as const;

export type InterfaceLook =
export type UUIInterfaceLook =
| ''
| 'default'
| 'primary'
Expand Down
4 changes: 2 additions & 2 deletions packages/uui-box/lib/uui-box.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { LitElement, css } from 'lit';
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
import { property, state } from 'lit/decorators.js';
import { UUITextStyles } from '@umbraco-ui/uui-css/lib';
import type { InterfaceHeading } from '@umbraco-ui/uui-base/lib';
import type { UUIInterfaceHeading } from '@umbraco-ui/uui-base/lib';
import { StaticValue, html, literal, unsafeStatic } from 'lit/static-html.js';

function slotHasContent(target: EventTarget | null): boolean {
Expand Down Expand Up @@ -41,7 +41,7 @@ export class UUIBoxElement extends LitElement {
* @default "h5"
*/
@property({ attribute: 'headline-variant' })
set headlineVariant(value: InterfaceHeading) {
set headlineVariant(value: UUIInterfaceHeading) {
if (!value) {
this._headlineVariantTag = literal`h5`;
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/uui-box/lib/uui-box.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, fixture, html } from '@open-wc/testing';

import { UUIBoxElement } from './uui-box.element';
import { InterfaceHeadingValues } from '@umbraco-ui/uui-base/lib/types';
import { UUIInterfaceHeadingValues } from '@umbraco-ui/uui-base/lib/types';

describe('UUIBox', () => {
let element: UUIBoxElement;
Expand All @@ -16,7 +16,7 @@ describe('UUIBox', () => {
});

it('passes the a11y audit', async () => {
for (const headlineVariant of InterfaceHeadingValues) {
for (const headlineVariant of UUIInterfaceHeadingValues) {
element = await fixture(
html` <uui-box
headline="headline"
Expand Down
9 changes: 6 additions & 3 deletions packages/uui-button/lib/uui-button.element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import {
import { css, html, LitElement, nothing, TemplateResult } from 'lit';
import { property, query } from 'lit/decorators.js';
import { ifDefined } from 'lit/directives/if-defined.js';
import { InterfaceColor, InterfaceLook } from '@umbraco-ui/uui-base/lib/types';
import {
UUIInterfaceColor,
UUIInterfaceLook,
} from '@umbraco-ui/uui-base/lib/types';

export type UUIButtonState = undefined | 'waiting' | 'success' | 'failed';

Expand Down Expand Up @@ -74,7 +77,7 @@ export class UUIButtonElement extends FormControlMixin(
* @default "default"
*/
@property({ reflect: true })
look: InterfaceLook = 'default';
look: UUIInterfaceLook = 'default';

/**
* Changes the look of the button to one of the predefined, symbolic looks. For example - set this to positive if you want nice, green "confirm" button.
Expand All @@ -83,7 +86,7 @@ export class UUIButtonElement extends FormControlMixin(
* @default "default"
*/
@property({ reflect: true })
color: InterfaceColor = 'default';
color: UUIInterfaceColor = 'default';

/**
* Makes the left and right padding of the button narrower.
Expand Down
8 changes: 4 additions & 4 deletions packages/uui-button/lib/uui-button.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
oneEvent,
} from '@open-wc/testing';
import {
InterfaceColorValues,
InterfaceLookValues,
UUIInterfaceColorValues,
UUIInterfaceLookValues,
} from '@umbraco-ui/uui-base/lib/types';

import { UUIButtonElement } from './uui-button.element';
Expand Down Expand Up @@ -41,8 +41,8 @@ describe('UuiButton', () => {
});

it('passes the a11y audit', async () => {
for (const color of InterfaceColorValues) {
for (const look of InterfaceLookValues) {
for (const color of UUIInterfaceColorValues) {
for (const look of UUIInterfaceLookValues) {
for (const disabled of [true, false]) {
element = await fixture(
html` <uui-button
Expand Down
73 changes: 59 additions & 14 deletions packages/uui-ref-node/lib/uui-ref-node.element.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
import { demandCustomElement } from '@umbraco-ui/uui-base/lib/utils';
import { ifDefined } from 'lit/directives/if-defined.js';
import { UUIRefElement } from '@umbraco-ui/uui-ref/lib';
import { css, html } from 'lit';
import { css, html, nothing } from 'lit';
import { property, state } from 'lit/decorators.js';

/**
Expand Down Expand Up @@ -36,6 +37,24 @@ export class UUIRefNodeElement extends UUIRefElement {
@property({ type: String })
detail = '';

/**
* Set an href, this will turns the name of the card 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';

@state()
private _iconSlotHasContent = false;

Expand All @@ -48,7 +67,7 @@ export class UUIRefNodeElement extends UUIRefElement {
demandCustomElement(this, 'uui-icon');
}

private _onSlotIconChange(event: Event) {
#onSlotIconChange(event: Event) {
this._iconSlotHasContent =
(event.target as HTMLSlotElement).assignedNodes({ flatten: true })
.length > 0;
Expand All @@ -60,11 +79,37 @@ export class UUIRefNodeElement extends UUIRefElement {
></small>`;
}

private _renderFallbackIcon() {
#renderFallbackIcon() {
return html`<uui-icon .svg="${this.fallbackIcon}"></uui-icon>`;
}

public render() {
#renderContent() {
return html`
<span id="icon">
<slot name="icon" @slotchange=${this.#onSlotIconChange}></slot>
${this._iconSlotHasContent === false ? this.#renderFallbackIcon() : ''}
</span>
<div id="info">
<div id="name">${this.name}</div>
${this.renderDetail()}
</div>
`;
}

#renderLink() {
return html`<a
id="open-part"
tabindex=${this.disabled ? (nothing as any) : '0'}
href=${ifDefined(!this.disabled ? this.href : undefined)}
target=${ifDefined(this.target || undefined)}
rel=${ifDefined(
this.target === '_blank' ? 'noopener noreferrer' : undefined
)}>
${this.#renderContent()}
</a>`;
}

#renderButton() {
return html`
<button
type="button"
Expand All @@ -73,17 +118,14 @@ export class UUIRefNodeElement extends UUIRefElement {
@click=${this.handleOpenClick}
@keydown=${this.handleOpenKeydown}
?disabled=${this.disabled}>
<span id="icon">
<slot name="icon" @slotchange=${this._onSlotIconChange}></slot>
${this._iconSlotHasContent === false
? this._renderFallbackIcon()
: ''}
</span>
<div id="info">
<div id="name">${this.name}</div>
${this.renderDetail()}
</div>
${this.#renderContent()}
</button>
`;
}

public render() {
return html`
${this.href ? this.#renderLink() : this.#renderButton()}
<!-- Select border must be right after #open-part -->
<div id="select-border"></div>
Expand All @@ -102,7 +144,10 @@ export class UUIRefNodeElement extends UUIRefElement {
}
#open-part {
text-decoration: none;
color: inherit;
align-self: stretch;
line-height: normal;
display: flex;
position: relative;
Expand Down
22 changes: 14 additions & 8 deletions packages/uui-ref-node/lib/uui-ref-node.story.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import '.';

import { Story } from '@storybook/web-components';
import { html } from 'lit';

import { ArrayOfUmbracoWords } from '../../../storyhelpers/UmbracoWordGenerator';
import readme from '../README.md?raw';

import './index';
import '@umbraco-ui/uui-tag/lib';
import '@umbraco-ui/uui-action-bar/lib';
import '@umbraco-ui/uui-button/lib';
import '@umbraco-ui/uui-icon/lib';
import '@umbraco-ui/uui-icon-registry-essential/lib';

export default {
id: 'uui-ref-node',
title: 'Displays/References/Node',
Expand All @@ -26,6 +31,8 @@ const Template: Story = props => html`
<uui-ref-node
name="${props.name}"
detail="${props.detail}"
href="${props.href}"
target="${props.target}"
?selectable=${props.selectable}
?selectOnly=${props.selectOnly}
?error=${props.error}
Expand All @@ -42,6 +49,7 @@ export const AAAOverview = Template.bind({});
AAAOverview.args = {
name: 'Rabbit Suit Product Page',
detail: 'path/to/nowhere',
href: 'umbraco.com',
};
AAAOverview.storyName = 'Overview';
AAAOverview.parameters = {
Expand All @@ -62,16 +70,14 @@ AAAOverview.parameters = {
};

export const CustomIcon: Story = () => html`
<essential-icon-registry>
<uui-ref-node-data-type
name="Rabbit Suit Product Page"
detail="path/to/nowhere">
<uui-icon-registry-essential>
<uui-ref-node name="Rabbit Suit Product Page" detail="path/to/nowhere">
<uui-icon slot="icon" name="colorpicker"></uui-icon>
<uui-action-bar slot="actions">
<uui-button label="Remove">Remove</uui-button>
</uui-action-bar>
</uui-ref-node-data-type>
</essential-icon-registry>
</uui-ref-node>
</uui-icon-registry-essential>
`;

CustomIcon.parameters = {
Expand Down
Loading

0 comments on commit 98e11bf

Please sign in to comment.