123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- /*!
- * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
- * v1.0.0-beta.82
- */
- import { Component, Element, Event, Method, Prop, h } from "@stencil/core";
- import { toAriaBoolean } from "../../utils/dom";
- import { CSS, ICONS } from "./resources";
- export class Handle {
- constructor() {
- // --------------------------------------------------------------------------
- //
- // Properties
- //
- // --------------------------------------------------------------------------
- /**
- * @internal - stores the activated state of the drag handle.
- */
- this.activated = false;
- /**
- * Value for the button title attribute
- */
- this.textTitle = "handle";
- // --------------------------------------------------------------------------
- //
- // Private Methods
- //
- // --------------------------------------------------------------------------
- this.handleKeyDown = (event) => {
- switch (event.key) {
- case " ":
- this.activated = !this.activated;
- break;
- case "ArrowUp":
- case "ArrowDown":
- if (!this.activated) {
- return;
- }
- const direction = event.key.toLowerCase().replace("arrow", "");
- this.calciteHandleNudge.emit({ handle: this.el, direction });
- break;
- }
- };
- this.handleBlur = () => {
- this.activated = false;
- };
- }
- // --------------------------------------------------------------------------
- //
- // Methods
- //
- // --------------------------------------------------------------------------
- /** Sets focus on the component. */
- async setFocus() {
- this.handleButton.focus();
- }
- // --------------------------------------------------------------------------
- //
- // Render Methods
- //
- // --------------------------------------------------------------------------
- render() {
- return (
- // Needs to be a span because of https://github.com/SortableJS/Sortable/issues/1486
- h("span", { "aria-pressed": toAriaBoolean(this.activated), class: { [CSS.handle]: true, [CSS.handleActivated]: this.activated }, onBlur: this.handleBlur, onKeyDown: this.handleKeyDown, ref: (el) => {
- this.handleButton = el;
- }, role: "button", tabindex: "0", title: this.textTitle },
- h("calcite-icon", { icon: ICONS.drag, scale: "s" })));
- }
- static get is() { return "calcite-handle"; }
- static get encapsulation() { return "shadow"; }
- static get originalStyleUrls() { return {
- "$": ["handle.scss"]
- }; }
- static get styleUrls() { return {
- "$": ["handle.css"]
- }; }
- static get properties() { return {
- "activated": {
- "type": "boolean",
- "mutable": true,
- "complexType": {
- "original": "boolean",
- "resolved": "boolean",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [{
- "name": "internal",
- "text": "- stores the activated state of the drag handle."
- }],
- "text": ""
- },
- "attribute": "activated",
- "reflect": true,
- "defaultValue": "false"
- },
- "textTitle": {
- "type": "string",
- "mutable": false,
- "complexType": {
- "original": "string",
- "resolved": "string",
- "references": {}
- },
- "required": false,
- "optional": false,
- "docs": {
- "tags": [],
- "text": "Value for the button title attribute"
- },
- "attribute": "text-title",
- "reflect": true,
- "defaultValue": "\"handle\""
- }
- }; }
- static get events() { return [{
- "method": "calciteHandleNudge",
- "name": "calciteHandleNudge",
- "bubbles": true,
- "cancelable": true,
- "composed": true,
- "docs": {
- "tags": [],
- "text": "Emitted when the the handle is activated and the up or down arrow key is pressed."
- },
- "complexType": {
- "original": "any",
- "resolved": "any",
- "references": {}
- }
- }]; }
- 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"; }
- }
|