calcite-handle.cjs.entry.js 5.9 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.82
  5. */
  6. 'use strict';
  7. Object.defineProperty(exports, '__esModule', { value: true });
  8. const index = require('./index-5c65e149.js');
  9. const dom = require('./dom-9ac0341c.js');
  10. require('./guid-8b6d6cb4.js');
  11. const CSS = {
  12. handle: "handle",
  13. handleActivated: "handle--activated"
  14. };
  15. const ICONS = {
  16. drag: "drag"
  17. };
  18. 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}";
  19. const Handle = class {
  20. constructor(hostRef) {
  21. index.registerInstance(this, hostRef);
  22. this.calciteHandleNudge = index.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. index.h("span", { "aria-pressed": dom.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 }, index.h("calcite-icon", { icon: ICONS.drag, scale: "s" })));
  80. }
  81. get el() { return index.getElement(this); }
  82. };
  83. Handle.style = handleCss;
  84. exports.calcite_handle = Handle;