@limetech/lime-elements
Version:
223 lines (222 loc) • 6.34 kB
JavaScript
import { Host, h } from '@stencil/core';
/**
* A split button is a button with two components:
* a button and a side-menu attached to it.
*
* Clicking on the button runs a default action,
* and clicking on the arrow opens up a list of other possible actions.
*
* :::warning
* - Never use a split button for navigation purposes, such as going to next page.
* The button should only be used for performing commands!
* - Never use this component instead of a Select or Menu component!
* :::
*
* @exampleComponent limel-example-split-button-basic
* @exampleComponent limel-example-split-button-loading
* @exampleComponent limel-example-split-button-repeat-default-command
*/
export class SplitButton {
constructor() {
this.renderMenu = () => {
if (this.items.length === 0) {
return;
}
return (h("limel-menu", { class: {
primary: this.primary,
}, disabled: this.disabled || this.loading, items: this.items, openDirection: "bottom" }, h("button", { class: "menu-trigger", slot: "trigger", disabled: this.disabled }, "\u22EE")));
};
this.filterClickWhenDisabled = (e) => {
if (this.disabled) {
e.preventDefault();
}
};
this.label = undefined;
this.primary = false;
this.icon = undefined;
this.disabled = false;
this.loading = false;
this.loadingFailed = false;
this.items = [];
}
render() {
return (h(Host, { class: {
'has-menu': this.items.length > 0,
}, onClick: this.filterClickWhenDisabled }, h("limel-button", { label: this.label, primary: this.primary, icon: this.icon, disabled: this.disabled, loading: this.loading, loadingFailed: this.loadingFailed }), this.renderMenu()));
}
static get is() { return "limel-split-button"; }
static get encapsulation() { return "shadow"; }
static get delegatesFocus() { return true; }
static get originalStyleUrls() {
return {
"$": ["split-button.scss"]
};
}
static get styleUrls() {
return {
"$": ["split-button.css"]
};
}
static get properties() {
return {
"label": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "The text to show on the default action part of the button."
},
"attribute": "label",
"reflect": true
},
"primary": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Set to `true` to make the button primary."
},
"attribute": "primary",
"reflect": true,
"defaultValue": "false"
},
"icon": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Set icon for the button"
},
"attribute": "icon",
"reflect": true
},
"disabled": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Set to `true` to disable the button."
},
"attribute": "disabled",
"reflect": true,
"defaultValue": "false"
},
"loading": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Set to `true` to put the button in the `loading` state.\nThis also disables the button."
},
"attribute": "loading",
"reflect": true,
"defaultValue": "false"
},
"loadingFailed": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Set to `true` to indicate failure instead of success when the button is\nno longer in the `loading` state."
},
"attribute": "loading-failed",
"reflect": true,
"defaultValue": "false"
},
"items": {
"type": "unknown",
"mutable": false,
"complexType": {
"original": "Array<MenuItem | ListSeparator>",
"resolved": "(ListSeparator | MenuItem<any>)[]",
"references": {
"Array": {
"location": "global"
},
"MenuItem": {
"location": "import",
"path": "../menu/menu.types"
},
"ListSeparator": {
"location": "import",
"path": "../list/list-item.types"
}
}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "A list of items and separators to show in the menu."
},
"defaultValue": "[]"
}
};
}
static get events() {
return [{
"method": "select",
"name": "select",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": "Is emitted when a menu item is selected."
},
"complexType": {
"original": "MenuItem",
"resolved": "MenuItem<any>",
"references": {
"MenuItem": {
"location": "import",
"path": "../menu/menu.types"
}
}
}
}];
}
}
//# sourceMappingURL=split-button.js.map