calcite-handle.entry.js 5.9 KB

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