Skip to content

Commit

Permalink
feat(split-button): add loading properties
Browse files Browse the repository at this point in the history
  • Loading branch information
LucyChyzhova committed Jul 29, 2024
1 parent d3dc006 commit 5f756b1
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
4 changes: 4 additions & 0 deletions etc/lime-elements.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,8 @@ export namespace Components {
"icon": string;
"items": Array<MenuItem | ListSeparator>;
"label": string;
"loading": boolean;
"loadingFailed": boolean;
"primary": boolean;
}
export interface LimelSwitch {
Expand Down Expand Up @@ -1574,6 +1576,8 @@ namespace JSX_2 {
"icon"?: string;
"items"?: Array<MenuItem | ListSeparator>;
"label"?: string;
"loading"?: boolean;
"loadingFailed"?: boolean;
"onSelect"?: (event: LimelSplitButtonCustomEvent<MenuItem>) => void;
"primary"?: boolean;
}
Expand Down
70 changes: 70 additions & 0 deletions src/components/split-button/examples/split-button-loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Component, h, State } from '@stencil/core';
import { ListSeparator, MenuItem } from '@limetech/lime-elements';

/**
* Split button with loading
*
*
*/
@Component({
tag: 'limel-example-split-button-loading',
shadow: true,
})
export class SplitButtonLoadingExample {
@State()
private loading = false;

@State()
private disabled = false;

@State()
private loadingFailed = false;
private items: Array<ListSeparator | MenuItem> = [
{ text: 'Later today', secondaryText: 'at 16:45' },
{ text: 'Tomorrow', secondaryText: 'at 08:00' },
];

public render() {
return (
<limel-split-button
primary={true}
loading={this.loading}
loadingFailed={this.loadingFailed}
disabled={this.disabled}
label="Send"
icon="send"
items={this.items}
onClick={this.onClick}
onSelect={this.handleSelect}
/>
);
}

private onClick = () => {
console.log('Button clicked.');
this.disabled = true;
this.loading = true;
this.loadingFailed = false;

const TIME_LOADING = 2000;
setTimeout(() => {
this.loading = false;
this.disabled = false;
this.loadingFailed = false;
}, TIME_LOADING);
};

private handleSelect = (event: CustomEvent<MenuItem>) => {
console.log('Menu item chosen', event.detail.text);
this.loading = true;
this.disabled = true;
this.loadingFailed = false;

const TIME_LOADING = 2000;
setTimeout(() => {
this.loading = false;
this.disabled = false;
this.loadingFailed = false;
}, TIME_LOADING);
};
}
1 change: 1 addition & 0 deletions src/components/split-button/split-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

:host(limel-split-button.has-menu) {
--button-padding-right: 2rem;
--button-padding-left: 1rem;
}

:host(limel-split-button) {
Expand Down
19 changes: 18 additions & 1 deletion src/components/split-button/split-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { MenuItem } from '../menu/menu.types';
* :::
*
* @exampleComponent limel-example-split-button-basic
* @exampleComponent limel-example-split-button-loading
* @exampleComponent limel-example-split-button-repeat-default-command
*/
@Component({
Expand Down Expand Up @@ -48,6 +49,20 @@ export class SplitButton {
@Prop({ reflect: true })
public disabled = false;

/**
* Set to `true` to put the button in the `loading` state.
* This also disables the button.
*/
@Prop({ reflect: true })
public loading = false;

/**
* Set to `true` to indicate failure instead of success when the button is
* no longer in the `loading` state.
*/
@Prop({ reflect: true })
public loadingFailed = false;

/**
* A list of items and separators to show in the menu.
*/
Expand All @@ -73,6 +88,8 @@ export class SplitButton {
primary={this.primary}
icon={this.icon}
disabled={this.disabled}
loading={this.loading}
loadingFailed={this.loadingFailed}
/>
{this.renderMenu()}
</Host>
Expand All @@ -89,7 +106,7 @@ export class SplitButton {
class={{
primary: this.primary,
}}
disabled={this.disabled}
disabled={this.disabled || this.loading}
items={this.items}
openDirection="bottom"
>
Expand Down

0 comments on commit 5f756b1

Please sign in to comment.