calcite-checkbox.cjs.entry.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 guid = require('./guid-8b6d6cb4.js');
  10. const form = require('./form-11926121.js');
  11. const label = require('./label-165fc611.js');
  12. const interactive = require('./interactive-e294111f.js');
  13. const dom = require('./dom-9ac0341c.js');
  14. const checkboxCss = "@-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([scale=s]){--calcite-checkbox-size:0.75rem}:host([scale=m]){--calcite-checkbox-size:var(--calcite-font-size--1)}:host([scale=l]){--calcite-checkbox-size:1rem}:host{position:relative;display:-ms-inline-flexbox;display:inline-flex;cursor:pointer;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-webkit-tap-highlight-color:transparent}:host .check-svg{pointer-events:none;-webkit-box-sizing:border-box;box-sizing:border-box;display:block;overflow:hidden;background-color:var(--calcite-ui-foreground-1);fill:currentColor;stroke:currentColor;stroke-width:1;-webkit-transition-property:all;transition-property:all;-webkit-transition-duration:150ms;transition-duration:150ms;-webkit-transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);transition-timing-function:cubic-bezier(0.4, 0, 0.2, 1);width:var(--calcite-checkbox-size);height:var(--calcite-checkbox-size);-webkit-box-shadow:inset 0 0 0 1px var(--calcite-ui-border-input);box-shadow:inset 0 0 0 1px var(--calcite-ui-border-input);color:var(--calcite-ui-background)}:host([checked]) .check-svg,:host([indeterminate]) .check-svg{background-color:var(--calcite-ui-brand);-webkit-box-shadow:inset 0 0 0 1px var(--calcite-ui-brand);box-shadow:inset 0 0 0 1px var(--calcite-ui-brand)}:host([hovered]) .toggle .check-svg,:host .toggle:hover .check-svg{-webkit-box-shadow:inset 0 0 0 2px var(--calcite-ui-brand);box-shadow:inset 0 0 0 2px var(--calcite-ui-brand)}:host .toggle:focus .check-svg,:host .toggle:active .check-svg{-webkit-box-shadow:inset 0 0 0 1px var(--calcite-ui-brand), 0 0 0 2px var(--calcite-ui-foreground-1), 0 0 0 4px var(--calcite-ui-brand);box-shadow:inset 0 0 0 1px var(--calcite-ui-brand), 0 0 0 2px var(--calcite-ui-foreground-1), 0 0 0 4px var(--calcite-ui-brand);-webkit-transition:var(--calcite-animation-timing);transition:var(--calcite-animation-timing)}.toggle:focus-visible{outline:none}:host([disabled]){pointer-events:none;cursor:default;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;opacity:var(--calcite-ui-opacity-disabled)}:host([disabled]) ::slotted([calcite-hydrated][disabled]),:host([disabled]) [calcite-hydrated][disabled]{opacity:1}::slotted(input[slot=hidden-form-input]){bottom:0 !important;left:0 !important;margin:0 !important;opacity:0 !important;outline:none !important;padding:0 !important;position:absolute !important;right:0 !important;top:0 !important;-webkit-transform:none !important;transform:none !important;-webkit-appearance:none !important;z-index:-1 !important}";
  15. const Checkbox = class {
  16. constructor(hostRef) {
  17. index.registerInstance(this, hostRef);
  18. this.calciteInternalCheckboxBlur = index.createEvent(this, "calciteInternalCheckboxBlur", 7);
  19. this.calciteCheckboxChange = index.createEvent(this, "calciteCheckboxChange", 7);
  20. this.calciteInternalCheckboxFocus = index.createEvent(this, "calciteInternalCheckboxFocus", 7);
  21. //--------------------------------------------------------------------------
  22. //
  23. // Properties
  24. //
  25. //--------------------------------------------------------------------------
  26. /** The checked state of the checkbox. */
  27. this.checked = false;
  28. /** True if the checkbox is disabled */
  29. this.disabled = false;
  30. /**
  31. * The hovered state of the checkbox.
  32. * @internal
  33. */
  34. this.hovered = false;
  35. /**
  36. * True if the checkbox is initially indeterminate,
  37. * which is independent from its checked state
  38. * https://css-tricks.com/indeterminate-checkboxes/
  39. * */
  40. this.indeterminate = false;
  41. /**
  42. * When true, makes the component required for form-submission.
  43. *
  44. * @internal
  45. */
  46. this.required = false;
  47. /** specify the scale of the checkbox, defaults to m */
  48. this.scale = "m";
  49. //--------------------------------------------------------------------------
  50. //
  51. // Private Properties
  52. //
  53. //--------------------------------------------------------------------------
  54. this.checkedPath = "M5.5 12L2 8.689l.637-.636L5.5 10.727l8.022-7.87.637.637z";
  55. this.indeterminatePath = "M13 8v1H3V8z";
  56. //--------------------------------------------------------------------------
  57. //
  58. // Private Methods
  59. //
  60. //--------------------------------------------------------------------------
  61. this.getPath = () => this.indeterminate ? this.indeterminatePath : this.checked ? this.checkedPath : "";
  62. this.toggle = () => {
  63. if (!this.disabled) {
  64. this.checked = !this.checked;
  65. this.setFocus();
  66. this.indeterminate = false;
  67. this.calciteCheckboxChange.emit();
  68. }
  69. };
  70. this.keyDownHandler = (event) => {
  71. if (event.key === " " || event.key === "Enter") {
  72. this.toggle();
  73. event.preventDefault();
  74. }
  75. };
  76. this.clickHandler = () => {
  77. this.toggle();
  78. };
  79. //--------------------------------------------------------------------------
  80. //
  81. // Event Listeners
  82. //
  83. //--------------------------------------------------------------------------
  84. this.onToggleBlur = () => {
  85. this.calciteInternalCheckboxBlur.emit(false);
  86. };
  87. this.onToggleFocus = () => {
  88. this.calciteInternalCheckboxFocus.emit(true);
  89. };
  90. this.onLabelClick = () => {
  91. this.toggle();
  92. };
  93. }
  94. //--------------------------------------------------------------------------
  95. //
  96. // Public Methods
  97. //
  98. //--------------------------------------------------------------------------
  99. /** Sets focus on the component. */
  100. async setFocus() {
  101. var _a;
  102. (_a = this.toggleEl) === null || _a === void 0 ? void 0 : _a.focus();
  103. }
  104. //--------------------------------------------------------------------------
  105. //
  106. // Lifecycle
  107. //
  108. //--------------------------------------------------------------------------
  109. connectedCallback() {
  110. this.guid = this.el.id || `calcite-checkbox-${guid.guid()}`;
  111. label.connectLabel(this);
  112. form.connectForm(this);
  113. }
  114. disconnectedCallback() {
  115. label.disconnectLabel(this);
  116. form.disconnectForm(this);
  117. }
  118. componentDidRender() {
  119. interactive.updateHostInteraction(this);
  120. }
  121. // --------------------------------------------------------------------------
  122. //
  123. // Render Methods
  124. //
  125. // --------------------------------------------------------------------------
  126. render() {
  127. return (index.h(index.Host, { onClick: this.clickHandler, onKeyDown: this.keyDownHandler }, index.h("div", { "aria-checked": dom.toAriaBoolean(this.checked), "aria-label": label.getLabelText(this), class: "toggle", onBlur: this.onToggleBlur, onFocus: this.onToggleFocus, ref: (toggleEl) => (this.toggleEl = toggleEl), role: "checkbox", tabIndex: this.disabled ? undefined : 0 }, index.h("svg", { class: "check-svg", viewBox: "0 0 16 16" }, index.h("path", { d: this.getPath() })), index.h("slot", null)), index.h(form.HiddenFormInputSlot, { component: this })));
  128. }
  129. get el() { return index.getElement(this); }
  130. };
  131. Checkbox.style = checkboxCss;
  132. exports.calcite_checkbox = Checkbox;