@esri/calcite-components
Version:
Web Components for Esri's Calcite Design System.
308 lines (307 loc) • 8.8 kB
JavaScript
/*!
* All material copyright ESRI, All Rights Reserved, unless otherwise specified.
* See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
* v1.5.0-next.4
*/
import { h } from "@stencil/core";
import { focusElement } from "../../utils/dom";
import { connectInteractive, disconnectInteractive, updateHostInteraction } from "../../utils/interactive";
import { componentLoaded, setComponentLoaded, setUpLoadableComponent } from "../../utils/loadable";
import { CSS, ICONS } from "./resources";
export class Fab {
constructor() {
this.appearance = "solid";
this.kind = "brand";
this.disabled = false;
this.icon = ICONS.plus;
this.iconFlipRtl = false;
this.label = undefined;
this.loading = false;
this.scale = "m";
this.text = undefined;
this.textEnabled = false;
}
//--------------------------------------------------------------------------
//
// Lifecycle
//
//--------------------------------------------------------------------------
connectedCallback() {
connectInteractive(this);
}
componentWillLoad() {
setUpLoadableComponent(this);
}
componentDidLoad() {
setComponentLoaded(this);
}
componentDidRender() {
updateHostInteraction(this);
}
disconnectedCallback() {
disconnectInteractive(this);
}
// --------------------------------------------------------------------------
//
// Methods
//
// --------------------------------------------------------------------------
/** Sets focus on the component. */
async setFocus() {
await componentLoaded(this);
focusElement(this.buttonEl);
}
// --------------------------------------------------------------------------
//
// Render Methods
//
// --------------------------------------------------------------------------
render() {
const { appearance, kind, disabled, loading, scale, textEnabled, icon, label, text, iconFlipRtl } = this;
const title = !textEnabled ? label || text || null : null;
return (h("calcite-button", { appearance: appearance === "solid" ? "solid" : "outline-fill", class: CSS.button, disabled: disabled, iconFlipRtl: iconFlipRtl ? "start" : null, iconStart: icon, kind: kind, label: label, loading: loading, round: true, scale: scale, title: title, type: "button", width: "auto",
// eslint-disable-next-line react/jsx-sort-props
ref: (buttonEl) => {
this.buttonEl = buttonEl;
} }, this.textEnabled ? this.text : null));
}
static get is() { return "calcite-fab"; }
static get encapsulation() { return "shadow"; }
static get originalStyleUrls() {
return {
"$": ["fab.scss"]
};
}
static get styleUrls() {
return {
"$": ["fab.css"]
};
}
static get properties() {
return {
"appearance": {
"type": "string",
"mutable": false,
"complexType": {
"original": "Extract<\"solid\" | \"outline-fill\", Appearance>",
"resolved": "\"outline-fill\" | \"solid\"",
"references": {
"Extract": {
"location": "global"
},
"Appearance": {
"location": "import",
"path": "../interfaces"
}
}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Specifies the appearance style of the component."
},
"attribute": "appearance",
"reflect": true,
"defaultValue": "\"solid\""
},
"kind": {
"type": "string",
"mutable": false,
"complexType": {
"original": "Extract<\"brand\" | \"danger\" | \"inverse\" | \"neutral\", Kind>",
"resolved": "\"brand\" | \"danger\" | \"inverse\" | \"neutral\"",
"references": {
"Extract": {
"location": "global"
},
"Kind": {
"location": "import",
"path": "../interfaces"
}
}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Specifies the kind of the component (will apply to border and background)."
},
"attribute": "kind",
"reflect": true,
"defaultValue": "\"brand\""
},
"disabled": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "When `true`, interaction is prevented and the component is displayed with lower opacity."
},
"attribute": "disabled",
"reflect": true,
"defaultValue": "false"
},
"icon": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [{
"name": "default",
"text": "\"plus\""
}],
"text": "Specifies an icon to display."
},
"attribute": "icon",
"reflect": true,
"defaultValue": "ICONS.plus"
},
"iconFlipRtl": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "When `true`, the icon will be flipped when the element direction is right-to-left (`\"rtl\"`)."
},
"attribute": "icon-flip-rtl",
"reflect": true,
"defaultValue": "false"
},
"label": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Accessible name for the component."
},
"attribute": "label",
"reflect": false
},
"loading": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "When `true`, a busy indicator is displayed."
},
"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 component."
},
"attribute": "scale",
"reflect": true,
"defaultValue": "\"m\""
},
"text": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "Specifies text to accompany the component's icon."
},
"attribute": "text",
"reflect": false
},
"textEnabled": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": "When `true`, displays the `text` value in the component."
},
"attribute": "text-enabled",
"reflect": true,
"defaultValue": "false"
}
};
}
static get methods() {
return {
"setFocus": {
"complexType": {
"signature": "() => Promise<void>",
"parameters": [],
"references": {
"Promise": {
"location": "global"
}
},
"return": "Promise<void>"
},
"docs": {
"text": "Sets focus on the component.",
"tags": []
}
}
};
}
static get elementRef() { return "el"; }
}