How to use carbon-components - 10 common examples

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-charts / packages / core / src / components / essentials / tooltip.ts View on Github external
init() {
		// Grab the tooltip element
		const holder = select(this.services.domUtils.getHolder());
		const chartprefix = Tools.getProperty(this.model.getOptions(), "style", "prefix");
		this.tooltip = DOMUtils.appendOrSelect(holder, `div.${settings.prefix}--${chartprefix}--tooltip`);

		// Apply html content to the tooltip
		const tooltipTextContainer = DOMUtils.appendOrSelect(this.tooltip, "div.content-box");

		// listen to show-tooltip Custom Events to render the tooltip
		this.services.events.addEventListener("show-tooltip", e => {
			// check the type of tooltip and that it is enabled
			if ((e.detail.type === TooltipTypes.DATAPOINT && Tools.getProperty(this.model.getOptions(), "tooltip", "datapoint", "enabled"))
				|| (e.detail.type === TooltipTypes.GRIDLINE && Tools.getProperty(this.model.getOptions(), "tooltip", "gridline", "enabled")) ) {

				let data = select(event.target).datum() as any;

				// if there is a provided tooltip HTML function
				if (Tools.getProperty(this.model.getOptions(), "tooltip", "customHTML")) {
					tooltipTextContainer.html(this.model.getOptions().tooltip.customHTML(data));
				} else if (e.detail.multidata) {
github CarvueJS / carbon-components-vue / components / CaNumberInput / CaNumberInput.vue View on Github external
mounted() {
    this.numberInput = NumberInput.create(this.$el);
    this.numberInput.element.addEventListener('change', (e) => {
      // this.$emit('input', e.target.value)
    });
  },
  methods: {
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-charts / packages / core / src / components / essentials / title.spec.ts View on Github external
const renderCb = () => {
				const title = select(`g.${settings.prefix}--${options.chart.style.prefix}--title`);

				// Remove event listener for when chart render is finished
				chartEventsService.removeEventListener("render-finished", renderCb);

				expect(title.select("text").html()).toEqual(sampleTitle);

				done();
			};
github carbon-design-system / carbon-charts / packages / core / src / services / essentials / dom-utils.ts View on Github external
styleHolderElement() {
		const holderElement = this.getHolder() as HTMLElement;
		const { width, height } = this.model.getOptions();

		// Add class to chart holder
		select(this.getHolder()).classed(`${settings.prefix}--chart-holder`, true);

		// If width exists in options
		if (width) {
			// Apply formatted width attribute to chart
			holderElement.style.width = Tools.formatWidthHeightValues(width);
		}

		// If height exists in options
		if (height) {
			// Apply formatted height attribute to chart
			holderElement.style.height = Tools.formatWidthHeightValues(height);
		}
	}