handle.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.82
  5. */
  6. import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
  7. import { t as toAriaBoolean } from './dom.js';
  8. import { d as defineCustomElement$1 } from './icon.js';
  9. const CSS = {
  10. handle: "handle",
  11. handleActivated: "handle--activated"
  12. };
  13. const ICONS = {
  14. drag: "drag"
  15. };
  16. const handleCss = "@-webkit-keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in{0%{opacity:0}100%{opacity:1}}@-webkit-keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-down{0%{opacity:0;-webkit-transform:translate3D(0, -5px, 0);transform:translate3D(0, -5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;-webkit-transform:translate3D(0, 5px, 0);transform:translate3D(0, 5px, 0)}100%{opacity:1;-webkit-transform:translate3D(0, 0, 0);transform:translate3D(0, 0, 0)}}@-webkit-keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}@keyframes in-scale{0%{opacity:0;-webkit-transform:scale3D(0.95, 0.95, 1);transform:scale3D(0.95, 0.95, 1)}100%{opacity:1;-webkit-transform:scale3D(1, 1, 1);transform:scale3D(1, 1, 1)}}:root{--calcite-animation-timing:calc(150ms * var(--calcite-internal-duration-factor));--calcite-internal-duration-factor:var(--calcite-duration-factor, 1);--calcite-internal-animation-timing-fast:calc(100ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-medium:calc(200ms * var(--calcite-internal-duration-factor));--calcite-internal-animation-timing-slow:calc(300ms * var(--calcite-internal-duration-factor))}.calcite-animate{opacity:0;-webkit-animation-fill-mode:both;animation-fill-mode:both;-webkit-animation-duration:var(--calcite-animation-timing);animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{-webkit-animation-name:in;animation-name:in}.calcite-animate__in-down{-webkit-animation-name:in-down;animation-name:in-down}.calcite-animate__in-up{-webkit-animation-name:in-up;animation-name:in-up}.calcite-animate__in-scale{-webkit-animation-name:in-scale;animation-name:in-scale}:root{--calcite-popper-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{display:-ms-flexbox;display:flex}.handle{display:-ms-flexbox;display:flex;cursor:move;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;-ms-flex-item-align:stretch;align-self:stretch;border-style:none;background-color:transparent;outline-offset:0;outline-color:transparent;-webkit-transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;transition:outline-offset 100ms ease-in-out, outline-color 100ms ease-in-out;color:var(--calcite-ui-border-3);padding:0.75rem 0.25rem;line-height:0}.handle:hover{background-color:var(--calcite-ui-foreground-2);color:var(--calcite-ui-text-1)}.handle:focus{color:var(--calcite-ui-text-1);outline:2px solid var(--calcite-ui-brand);outline-offset:-2px}.handle--activated{background-color:var(--calcite-ui-foreground-3);color:var(--calcite-ui-text-1)}.handle calcite-icon{color:inherit}";
  17. const Handle = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  18. constructor() {
  19. super();
  20. this.__registerHost();
  21. this.__attachShadow();
  22. this.calciteHandleNudge = createEvent(this, "calciteHandleNudge", 7);
  23. // --------------------------------------------------------------------------
  24. //
  25. // Properties
  26. //
  27. // --------------------------------------------------------------------------
  28. /**
  29. * @internal - stores the activated state of the drag handle.
  30. */
  31. this.activated = false;
  32. /**
  33. * Value for the button title attribute
  34. */
  35. this.textTitle = "handle";
  36. // --------------------------------------------------------------------------
  37. //
  38. // Private Methods
  39. //
  40. // --------------------------------------------------------------------------
  41. this.handleKeyDown = (event) => {
  42. switch (event.key) {
  43. case " ":
  44. this.activated = !this.activated;
  45. break;
  46. case "ArrowUp":
  47. case "ArrowDown":
  48. if (!this.activated) {
  49. return;
  50. }
  51. const direction = event.key.toLowerCase().replace("arrow", "");
  52. this.calciteHandleNudge.emit({ handle: this.el, direction });
  53. break;
  54. }
  55. };
  56. this.handleBlur = () => {
  57. this.activated = false;
  58. };
  59. }
  60. // --------------------------------------------------------------------------
  61. //
  62. // Methods
  63. //
  64. // --------------------------------------------------------------------------
  65. /** Sets focus on the component. */
  66. async setFocus() {
  67. this.handleButton.focus();
  68. }
  69. // --------------------------------------------------------------------------
  70. //
  71. // Render Methods
  72. //
  73. // --------------------------------------------------------------------------
  74. render() {
  75. return (
  76. // Needs to be a span because of https://github.com/SortableJS/Sortable/issues/1486
  77. h("span", { "aria-pressed": toAriaBoolean(this.activated), class: { [CSS.handle]: true, [CSS.handleActivated]: this.activated }, onBlur: this.handleBlur, onKeyDown: this.handleKeyDown, ref: (el) => {
  78. this.handleButton = el;
  79. }, role: "button", tabindex: "0", title: this.textTitle }, h("calcite-icon", { icon: ICONS.drag, scale: "s" })));
  80. }
  81. get el() { return this; }
  82. static get style() { return handleCss; }
  83. }, [1, "calcite-handle", {
  84. "activated": [1540],
  85. "textTitle": [513, "text-title"],
  86. "setFocus": [64]
  87. }]);
  88. function defineCustomElement() {
  89. if (typeof customElements === "undefined") {
  90. return;
  91. }
  92. const components = ["calcite-handle", "calcite-icon"];
  93. components.forEach(tagName => { switch (tagName) {
  94. case "calcite-handle":
  95. if (!customElements.get(tagName)) {
  96. customElements.define(tagName, Handle);
  97. }
  98. break;
  99. case "calcite-icon":
  100. if (!customElements.get(tagName)) {
  101. defineCustomElement$1();
  102. }
  103. break;
  104. } });
  105. }
  106. defineCustomElement();
  107. export { Handle as H, defineCustomElement as d };