@esri/calcite-components
Version:
Web Components for Esri's Calcite Design System.
290 lines (289 loc) • 8.01 kB
JavaScript
import { Component, Element, Host, Method, Prop, h } from "@stencil/core";
import { CSS, ICONS } from "./resources";
import { focusElement, getElementDir } from "../../utils/dom";
export class CalciteFab {
constructor() {
// --------------------------------------------------------------------------
//
// Properties
//
// --------------------------------------------------------------------------
/**
* Used to set the button's appearance. Default is outline.
*/
this.appearance = "outline";
/**
* Used to set the button's color. Default is light.
*/
this.color = "light";
/**
* When true, disabled prevents interaction. This state shows items with lower opacity/grayed.
*/
this.disabled = false;
/**
* The name of the icon to display. The value of this property must match the icon name from https://esri.github.io/calcite-ui-icons/.
*/
this.icon = ICONS.plus;
/**
* When true, content is waiting to be loaded. This state shows a busy indicator.
*/
this.loading = false;
/**
* Specifies the size of the fab.
*/
this.scale = "m";
/**
* Indicates whether the text is displayed.
*/
this.textEnabled = false;
}
// --------------------------------------------------------------------------
//
// Methods
//
// --------------------------------------------------------------------------
async setFocus() {
focusElement(this.buttonEl);
}
// --------------------------------------------------------------------------
//
// Render Methods
//
// --------------------------------------------------------------------------
render() {
const { appearance, color, disabled, el, loading, scale, theme, textEnabled, icon, label, text } = this;
const titleText = !textEnabled && text;
const title = label || titleText;
const dir = getElementDir(el);
return (h(Host, null,
h("calcite-button", { appearance: appearance, "aria-label": label, class: CSS.button, color: color, dir: dir, disabled: disabled, iconStart: icon, loading: loading, ref: (buttonEl) => {
this.buttonEl = buttonEl;
}, round: true, scale: scale, theme: theme, title: title, width: "auto" }, this.textEnabled ? this.text : null)));
}
static get is() { return "calcite-fab"; }
static get encapsulation() { return "shadow"; }
static get originalStyleUrls() { return {
"$": ["calcite-fab.scss"]
}; }
static get styleUrls() { return {
"$": ["calcite-fab.css"]
}; }
static get properties() { return {
"appearance": {
"type": "string",
"mutable": false,
"complexType": {
"original": "Appearance",
"resolved": "\"clear\" | \"outline\" | \"solid\"",
"references": {
"Appearance": {
"location": "import",
"path": "../interfaces"
}
}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Used to set the button's appearance. Default is outline."
},
"attribute": "appearance",
"reflect": true,
"defaultValue": "\"outline\""
},
"color": {
"type": "string",
"mutable": false,
"complexType": {
"original": "FabColor",
"resolved": "\"blue\" | \"dark\" | \"light\" | \"red\"",
"references": {
"FabColor": {
"location": "import",
"path": "./interfaces"
}
}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Used to set the button's color. Default is light."
},
"attribute": "color",
"reflect": true,
"defaultValue": "\"light\""
},
"disabled": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "When true, disabled prevents interaction. This state shows items with lower opacity/grayed."
},
"attribute": "disabled",
"reflect": true,
"defaultValue": "false"
},
"icon": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "The name of the icon to display. The value of this property must match the icon name from https://esri.github.io/calcite-ui-icons/."
},
"attribute": "icon",
"reflect": false,
"defaultValue": "ICONS.plus"
},
"label": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "Label of the FAB, exposed on hover. If no label is provided, the label inherits what's provided for the `text` prop."
},
"attribute": "label",
"reflect": false
},
"loading": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "When true, content is waiting to be loaded. This state shows a busy indicator."
},
"attribute": "loading",
"reflect": true,
"defaultValue": "false"
},
"scale": {
"type": "string",
"mutable": false,
"complexType": {
"original": "Scale",
"resolved": "\"l\" | \"m\" | \"s\"",
"references": {
"Scale": {
"location": "import",
"path": "../interfaces"
}
}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Specifies the size of the fab."
},
"attribute": "scale",
"reflect": true,
"defaultValue": "\"m\""
},
"text": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": true,
"docs": {
"tags": [],
"text": "Text that accompanies the FAB icon."
},
"attribute": "text",
"reflect": false
},
"textEnabled": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Indicates whether the text is displayed."
},
"attribute": "text-enabled",
"reflect": true,
"defaultValue": "false"
},
"theme": {
"type": "string",
"mutable": false,
"complexType": {
"original": "Theme",
"resolved": "\"dark\" | \"light\"",
"references": {
"Theme": {
"location": "import",
"path": "../interfaces"
}
}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Used to set the component's color scheme."
},
"attribute": "theme",
"reflect": true
}
}; }
static get methods() { return {
"setFocus": {
"complexType": {
"signature": "() => Promise<void>",
"parameters": [],
"references": {
"Promise": {
"location": "global"
}
},
"return": "Promise<void>"
},
"docs": {
"text": "",
"tags": []
}
}
}; }
static get elementRef() { return "el"; }
}