How to use the carbon-components/es/globals/js/misc/on function in carbon-components

To help you get started, we’ve selected a few carbon-components examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github carbon-design-system / carbon-custom-elements / src / components / pagination / pagination.ts View on Github external
connectedCallback() {
    super.connectedCallback();
    // Manually hooks the event listeners on the host element to make the event names configurable
    this._hChangePage = on(
      this,
      (this.constructor as typeof BXPagination).eventAfterChangePage,
      this._handleChangePage as EventListener
    );
    this._hChangePageSize = on(
      this,
      (this.constructor as typeof BXPagination).eventAfterChangePageSize,
      this._handleChangePageSize as EventListener
    );
  }
github carbon-design-system / carbon-custom-elements / src / globals / mixins / host-listener.ts View on Github external
// Modifies event listener options with `capture` option to use for delegated `focus`/`blur` event
          let massagedOptions: boolean | AddEventListenerOptions = typeof options === 'undefined' ? false : options;
          if (delegatedType) {
            if (Object(options) === options) {
              massagedOptions = {
                ...Object(options),
                capture: !hasFocusin,
              };
            } else {
              massagedOptions = !hasFocusin;
            }
          }

          this._handles.add(
            on(target, (delegatedType || unprefixedType) as keyof HTMLElementEventMap, this[listenerName], massagedOptions)
          );
        });
      });
github carbon-design-system / carbon-custom-elements / src / components / radio-button / radio-button-group.ts View on Github external
connectedCallback() {
    super.connectedCallback();
    // Manually hooks the event listeners on the host element to make the event names configurable
    this._hAfterChangeRadioButton = on(
      this,
      (this.constructor as typeof BXRadioButtonGroup).eventAfterChangeRadioButton,
      this._handleAfterChangeRadioButton as EventListener
    );
  }
github carbon-design-system / carbon-custom-elements / src / components / date-picker / date-picker.ts View on Github external
connectedCallback() {
    super.connectedCallback();
    this._instantiateDatePicker();
    // Manually hooks the event listeners on the host element to make the event names configurable
    this._hAfterChange = on(
      this,
      (this.constructor as typeof BXDatePicker).eventAfterChange,
      this._handleChange as EventListener
    );
  }
github carbon-design-system / carbon-custom-elements / src / components / pagination / pagination.ts View on Github external
connectedCallback() {
    super.connectedCallback();
    // Manually hooks the event listeners on the host element to make the event names configurable
    this._hChangePage = on(
      this,
      (this.constructor as typeof BXPagination).eventAfterChangePage,
      this._handleChangePage as EventListener
    );
    this._hChangePageSize = on(
      this,
      (this.constructor as typeof BXPagination).eventAfterChangePageSize,
      this._handleChangePageSize as EventListener
    );
  }
github carbon-design-system / carbon-custom-elements / src / components / slider / slider.ts View on Github external
connectedCallback() {
    super.connectedCallback();
    if (!this._throttledHandleMousemoveImpl) {
      this._throttledHandleMousemoveImpl = throttle(this._handleMousemoveImpl, 10);
    }
    // Manually hooks the event listeners on the host element to make the event names configurable
    this._hChangeInput = on(
      this,
      (this.constructor as typeof BXSlider).eventAfterChangeInput,
      this._handleChangeInput as EventListener
    );
  }
github carbon-design-system / carbon-website / src / components / ComponentExample / inline-loading-demo-button.js View on Github external
constructor(element) {
    super(element);
    this.manage(
      on(element, 'click', event => {
        this.toggle(event);
      })
    );
    const targetElem = element.ownerDocument.querySelector(
      this.options.selectorTarget
    );
    if (targetElem) {
      this.state = InlineLoading.states.ACTIVE;
      this.target = InlineLoading.create(targetElem).setState(this.state);
    }
  }
github carbon-design-system / carbon-custom-elements / src / globals / wrappers / createReactCustomElementType.ts View on Github external
Object.keys(descriptor).forEach(propName => {
    if (descriptor[propName]) {
      const { event: eventDescriptor } = descriptor[propName];
      const name =
        Object(eventDescriptor) !== eventDescriptor
          ? (eventDescriptor as string)
          : (eventDescriptor as CustomElementEventDescriptor).name;
      const options =
        Object(eventDescriptor) !== eventDescriptor ? undefined : (eventDescriptor as CustomElementEventDescriptor).options;
      if (name) {
        handles.add(
          on(
            elem,
            name,
            event => {
              callback(propName, event);
            },
            options
          )
        );
      }
    }
  });
  return {