Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ export * from './file-preview/file-preview.js';
export * from './input-file/input-file.js';
export * from './combobox/combobox.js';
export * from './color-picker/color-picker.js';
export * from './split-button/split-button.js';
13 changes: 13 additions & 0 deletions src/components/split-button/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# uui-split-button

Umbraco style split-button component.

## Usage

```javascript
import '@umbraco-ui/uui/components/split-button/split-button.js';
```

```html
<uui-split-button></uui-split-button>
```
157 changes: 157 additions & 0 deletions src/components/split-button/split-button.element.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import { css, html, LitElement } from 'lit';
import { eventOptions, property, query } from 'lit/decorators.js';
import { when } from 'lit/directives/when.js';

import type { UUIInterfaceColor, UUIInterfaceLook } from '../../internal/types/index.js';

Check failure on line 5 in src/components/split-button/split-button.element.ts

View workflow job for this annotation

GitHub Actions / test

Replace `·UUIInterfaceColor,·UUIInterfaceLook·` with `⏎··UUIInterfaceColor,⏎··UUIInterfaceLook,⏎`
import type {
PopoverContainerPlacement,
UUIPopoverContainerElement,
} from '../popover-container/popover-container.js';

import '../button/button.js';
import '../symbol-expand/symbol-expand.js';
import '../popover-container/popover-container.js';
/**
* @element uui-split-button
*/
export class UUISplitButtonElement extends LitElement {
Comment on lines +14 to +17
#open = false;

@property({ type: Boolean, reflect: true })
public get open() {
return this.#open;
}
public set open(value) {
this.#open = value;

if (value === true && this.popoverContainerElement) {
this.openDropdown();
} else {
this.closeDropdown();
}
}

@property()
label?: string;

@property()
look: UUIInterfaceLook = 'default';

@property()
color: UUIInterfaceColor = 'default';

@property()
placement: PopoverContainerPlacement = 'bottom-start';

@property({ type: Boolean })
compact = false;

@property({ type: Boolean, reflect: true })
disabled = false;

@property({ type: Boolean, attribute: 'hide-expand' })
hideExpand = false;

@query('#dropdown-popover')
popoverContainerElement?: UUIPopoverContainerElement;

openDropdown() {
// TODO: This ignorer is just needed for JSON SCHEMA TO WORK, As its not updated with latest TS jet.

Check warning on line 59 in src/components/split-button/split-button.element.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this "TODO" comment.

See more on https://sonarcloud.io/project/issues?id=umbraco_Umbraco.UI&issues=AaHLKgX3bYEQGewY6jiJ&open=AaHLKgX3bYEQGewY6jiJ&pullRequest=1463
// @ts-ignore
this.popoverContainerElement?.showPopover();
this.#open = true;
}

closeDropdown() {
// TODO: This ignorer is just needed for JSON SCHEMA TO WORK, As its not updated with latest TS jet.

Check warning on line 66 in src/components/split-button/split-button.element.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this "TODO" comment.

See more on https://sonarcloud.io/project/issues?id=umbraco_Umbraco.UI&issues=AaHLKgX3bYEQGewY6jiK&open=AaHLKgX3bYEQGewY6jiK&pullRequest=1463
// @ts-ignore
this.popoverContainerElement?.hidePopover();
this.#open = false;
}

#onToggle(event: ToggleEvent) {
// TODO: This ignorer is just needed for JSON SCHEMA TO WORK, As its not updated with latest TS jet.

Check warning on line 73 in src/components/split-button/split-button.element.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this "TODO" comment.

See more on https://sonarcloud.io/project/issues?id=umbraco_Umbraco.UI&issues=AaHLKgX3bYEQGewY6jiL&open=AaHLKgX3bYEQGewY6jiL&pullRequest=1463

// @ts-ignore
this.open = event.newState === 'open';

/*if (this.open) {
this.dispatchEvent(new UmbOpenedEvent());
} else {
this.dispatchEvent(new UmbClosedEvent());
}*/
}

// Capture phase so this runs before a menu item's action opens its modal: WebKit otherwise
// leaves the popovertarget toggle state "open" after the modal light-dismisses the popover,
// and the trigger then stops responding until the page is reloaded.
@eventOptions({ capture: true })
private _onPopoverClickCapture() {
if (this.#open) {
this.closeDropdown();
}
}

render() {
return html`<uui-button
.look=${this.look}
.color=${this.color}
.label=${this.label ?? ''}
.compact=${this.compact}
?disabled=${this.disabled}>
<slot name="label"></slot>
</uui-button>
${when(
!this.hideExpand,
() =>
html`<uui-button
.look=${this.look}
.color=${this.color}
.compact=${this.compact}
?disabled=${this.disabled}
id="dropdown-button"
popovertarget="dropdown-popover"
data-mark="open-dropdown">
<uui-symbol-expand
id="symbol-expand"
.open=${this.#open}></uui-symbol-expand>
</uui-button>`,
)}
<uui-popover-container
id="dropdown-popover"
.placement=${this.placement}
@toggle=${this.#onToggle}
@click=${this._onPopoverClickCapture}>
<umb-popover-layout>
<slot></slot>
</umb-popover-layout>
</uui-popover-container>`;
}

static override styles = [

Check warning on line 131 in src/components/split-button/split-button.element.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make this public static property readonly.

See more on https://sonarcloud.io/project/issues?id=umbraco_Umbraco.UI&issues=AaHLKgX3bYEQGewY6jiM&open=AaHLKgX3bYEQGewY6jiM&pullRequest=1463
css`
:host {
display: inline-flex;
gap: 1px;
}
:host(:not([hide-expand])) uui-button:first-of-type {
--uui-button-border-radius: var(--uui-border-radius-3) 0 0
var(--uui-border-radius-3);
}
:host(:not([hide-expand])) uui-button:last-of-type {
--uui-button-border-radius: 0 var(--uui-border-radius-3)
var(--uui-border-radius-3) 0;
}

#dropdown-button {
min-width: max-content;
height: 100%;
color: inherit;
}
:host(:not([hide-expand]):not([compact])) #dropdown-button {
--uui-button-padding-left-factor: 2;
--uui-button-padding-right-factor: 2;
}
`,
];
}
54 changes: 54 additions & 0 deletions src/components/split-button/split-button.story.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import './split-button.js';
import '../menu-item/menu-item.js';
import readme from './README.md?raw';
import { html } from 'lit';
import type { Meta, StoryObj } from '@storybook/web-components-vite';
import { spread } from '../../../storyhelpers';

const menuItems = ['Action 1', 'Action 2', 'Action 3'];

const renderSplitButton = (args: Record<string, unknown>) => html`
<uui-split-button ${spread(args)}>
<span slot="label">${args.label}</span>
${menuItems.map(
item => html`<uui-menu-item label=${item}></uui-menu-item>`,
)}
</uui-split-button>
`;

const meta: Meta = {
id: 'uui-split-button',
component: 'uui-split-button',
title: 'Buttons/Split Button',
args: {
label: 'Button',
look: 'primary',
},
render: args => renderSplitButton(args),
parameters: {
readme: { markdown: readme },
},
};

export default meta;
type Story = StoryObj;

export const Default: Story = {};

export const Compact: Story = {
args: {
compact: true,
},
};

export const HiddenExpand: Story = {
args: {
'hide-expand': true,
},
};

export const Disabled: Story = {
args: {
disabled: true,
},
};
24 changes: 24 additions & 0 deletions src/components/split-button/split-button.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import './split-button.js';
import { html } from 'lit';
import { render } from 'vitest-browser-lit';
import { axeRun } from '../../internal/test/a11y.js';
import { UUISplitButtonElement } from './split-button.element';

describe('UUISplitButtonElement', () => {
let element: UUISplitButtonElement;

beforeEach(async () => {
element = render(
html`<uui-split-button></uui-split-button>`,
).container.querySelector('uui-split-button')!;
await element.updateComplete;
});

it('is defined with its own instance', () => {
expect(element).toBeInstanceOf(UUISplitButtonElement);
});

it('passes the a11y audit', async () => {
expect(await axeRun(element)).toHaveNoViolations();
});
});
12 changes: 12 additions & 0 deletions src/components/split-button/split-button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineElement } from '../../internal/registration/index.js';
import { UUISplitButtonElement } from './split-button.element.js';

defineElement('uui-split-button', UUISplitButtonElement);

declare global {
interface HTMLElementTagNameMap {
'uui-split-button': UUISplitButtonElement;
}
}

export * from './split-button.element.js';
Loading