calcite-handle.entry.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 { r as registerInstance, c as createEvent, h, g as getElement } from './index-1f9b54dc.js';
  7. import { t as toAriaBoolean } from './dom-8f0a9ff2.js';
  8. import './resources-9c476cb6.js';
  9. import './guid-9f15e57a.js';
  10. const CSS = {
  11. handle: "handle",
  12. handleActivated: "handle--activated"
  13. };
  14. const ICONS = {
  15. drag: "drag"
  16. };
  17. 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}";
  18. const Handle = class {
  19. constructor(hostRef) {
  20. registerInstance(this, hostRef);
  21. this.calciteHandleNudge = createEvent(this, "calciteHandleNudge", 6);
  22. // --------------------------------------------------------------------------
  23. //
  24. // Properties
  25. //
  26. // --------------------------------------------------------------------------
  27. /**
  28. * @internal
  29. */
  30. this.activated = false;
  31. /**
  32. * Value for the button title attribute
  33. */
  34. this.textTitle = "handle";
  35. // --------------------------------------------------------------------------
  36. //
  37. // Private Methods
  38. //
  39. // --------------------------------------------------------------------------
  40. this.handleKeyDown = (event) => {
  41. switch (event.key) {
  42. case " ":
  43. this.activated = !this.activated;
  44. event.preventDefault();
  45. break;
  46. case "ArrowUp":
  47. case "ArrowDown":
  48. if (!this.activated) {
  49. return;
  50. }
  51. event.preventDefault();
  52. const direction = event.key.toLowerCase().replace("arrow", "");
  53. this.calciteHandleNudge.emit({ handle: this.el, direction });
  54. break;
  55. }
  56. };
  57. this.handleBlur = () => {
  58. this.activated = false;
  59. };
  60. }
  61. // --------------------------------------------------------------------------
  62. //
  63. // Methods
  64. //
  65. // --------------------------------------------------------------------------
  66. /** Sets focus on the component. */
  67. async setFocus() {
  68. var _a;
  69. (_a = this.handleButton) === null || _a === void 0 ? void 0 : _a.focus();
  70. }
  71. // --------------------------------------------------------------------------
  72. //
  73. // Render Methods
  74. //
  75. // --------------------------------------------------------------------------
  76. render() {
  77. return (
  78. // Needs to be a span because of https://github.com/SortableJS/Sortable/issues/1486
  79. h("span", { "aria-pressed": toAriaBoolean(this.activated), class: { [CSS.handle]: true, [CSS.handleActivated]: this.activated }, onBlur: this.handleBlur, onKeyDown: this.handleKeyDown, ref: (el) => {
  80. this.handleButton = el;
  81. }, role: "button", tabindex: "0", title: this.textTitle }, h("calcite-icon", { icon: ICONS.drag, scale: "s" })));
  82. }
  83. get el() { return getElement(this); }
  84. };
  85. Handle.style = handleCss;
  86. export { Handle as calcite_handle };