handle.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.97
  5. */
  6. import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client/index.js';
  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 = "@keyframes in{0%{opacity:0}100%{opacity:1}}@keyframes in-down{0%{opacity:0;transform:translate3D(0, -5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-up{0%{opacity:0;transform:translate3D(0, 5px, 0)}100%{opacity:1;transform:translate3D(0, 0, 0)}}@keyframes in-scale{0%{opacity:0;transform:scale3D(0.95, 0.95, 1)}100%{opacity: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;animation-fill-mode:both;animation-duration:var(--calcite-animation-timing)}.calcite-animate__in{animation-name:in}.calcite-animate__in-down{animation-name:in-down}.calcite-animate__in-up{animation-name:in-up}.calcite-animate__in-scale{animation-name:in-scale}@media (prefers-reduced-motion: reduce){:root{--calcite-internal-duration-factor:0.01}}:root{--calcite-floating-ui-transition:var(--calcite-animation-timing)}:host([hidden]){display:none}:host{display:flex}.handle{display:flex;cursor:move;align-items:center;justify-content:center;align-self:stretch;border-style:none;background-color:transparent;outline-color:transparent;color:var(--calcite-ui-border-input);padding-block:0.75rem;padding-inline: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", 6);
  23. // --------------------------------------------------------------------------
  24. //
  25. // Properties
  26. //
  27. // --------------------------------------------------------------------------
  28. /**
  29. * @internal
  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. event.preventDefault();
  46. break;
  47. case "ArrowUp":
  48. case "ArrowDown":
  49. if (!this.activated) {
  50. return;
  51. }
  52. event.preventDefault();
  53. const direction = event.key.toLowerCase().replace("arrow", "");
  54. this.calciteHandleNudge.emit({ handle: this.el, direction });
  55. break;
  56. }
  57. };
  58. this.handleBlur = () => {
  59. this.activated = false;
  60. };
  61. }
  62. // --------------------------------------------------------------------------
  63. //
  64. // Methods
  65. //
  66. // --------------------------------------------------------------------------
  67. /** Sets focus on the component. */
  68. async setFocus() {
  69. var _a;
  70. (_a = this.handleButton) === null || _a === void 0 ? void 0 : _a.focus();
  71. }
  72. // --------------------------------------------------------------------------
  73. //
  74. // Render Methods
  75. //
  76. // --------------------------------------------------------------------------
  77. render() {
  78. return (
  79. // Needs to be a span because of https://github.com/SortableJS/Sortable/issues/1486
  80. h("span", { "aria-pressed": toAriaBoolean(this.activated), class: { [CSS.handle]: true, [CSS.handleActivated]: this.activated }, onBlur: this.handleBlur, onKeyDown: this.handleKeyDown, ref: (el) => {
  81. this.handleButton = el;
  82. }, role: "button", tabindex: "0", title: this.textTitle }, h("calcite-icon", { icon: ICONS.drag, scale: "s" })));
  83. }
  84. get el() { return this; }
  85. static get style() { return handleCss; }
  86. }, [1, "calcite-handle", {
  87. "activated": [1540],
  88. "textTitle": [513, "text-title"],
  89. "setFocus": [64]
  90. }]);
  91. function defineCustomElement() {
  92. if (typeof customElements === "undefined") {
  93. return;
  94. }
  95. const components = ["calcite-handle", "calcite-icon"];
  96. components.forEach(tagName => { switch (tagName) {
  97. case "calcite-handle":
  98. if (!customElements.get(tagName)) {
  99. customElements.define(tagName, Handle);
  100. }
  101. break;
  102. case "calcite-icon":
  103. if (!customElements.get(tagName)) {
  104. defineCustomElement$1();
  105. }
  106. break;
  107. } });
  108. }
  109. defineCustomElement();
  110. export { Handle as H, defineCustomElement as d };