Sha256: a7b59e1a7428606dd7808ce35df35a39a1373c663ad3a7de5a485086b167b640

Contents?: true

Size: 1.32 KB

Versions: 16

Compression:

Stored size: 1.32 KB

Contents

export default function withAttrs(props = {}) {
  return function (component) {
    return Object.assign(
      component,
      Alpine.reactive({
        getAttr(name) {
          return this.$root.getAttribute(name);
        },

        setAttr(name, value) {
          this.$root.setAttribute(name, value);
          return this;
        },

        hasAttr(name) {
          return this.$root.hasAttribute(name);
        },

        removeAttr(name) {
          component.$root.removeAttribute(name);
          return this;
        },

        assertAttr(name, testValue) {
          return this.$root.getAttribute(name) === String(testValue);
        },

        refuteAttr(name, testValue) {
          return !this.assertAttr(name, testValue);
        },

        getData(name) {
          return this.getAttr(`data-${name}`);
        },

        setData(name, value) {
          return this.setAttr(`data-${name}`, value);
        },

        hasData(name) {
          return this.hasAttr(`data-${name}`);
        },

        removeData(name) {
          return this.removeAttr(`data-${name}`);
        },

        assertData(name, testValue) {
          return this.assertAttr(`data-${name}`, testValue);
        },

        refuteData(name, testValue) {
          return !this.assertData(name, testValue);
        },
      })
    );
  };
}

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
coveragebook_components-0.7.1 app/assets/js/base/mixins/attrs.js
coveragebook_components-0.7.0 app/assets/js/base/mixins/attrs.js
coveragebook_components-0.6.5 app/assets/js/base/mixins/attrs.js
coveragebook_components-0.6.4 app/assets/js/base/mixins/attrs.js
coveragebook_components-0.6.3 app/assets/js/base/mixins/attrs.js
coveragebook_components-0.6.2 app/assets/js/base/mixins/attrs.js
coveragebook_components-0.6.1 app/assets/js/base/mixins/attrs.js
coveragebook_components-0.6.0 app/assets/js/base/mixins/attrs.js
coveragebook_components-0.5.7 app/assets/js/base/mixins/attrs.js
coveragebook_components-0.5.6 app/assets/js/base/mixins/attrs.js
coveragebook_components-0.5.5 app/assets/js/base/mixins/attrs.js
coveragebook_components-0.5.4 app/assets/js/base/mixins/attrs.js
coveragebook_components-0.5.3 app/assets/js/base/mixins/attrs.js
coveragebook_components-0.5.2 app/assets/js/base/mixins/attrs.js
coveragebook_components-0.5.1 app/assets/js/base/mixins/attrs.js
coveragebook_components-0.5.0 app/assets/js/base/mixins/attrs.js