Sha256: 20c44150f79d42ed0ebe5ff34acf8b188d3c48d4ad494862c2f09a578014ec26

Contents?: true

Size: 1.5 KB

Versions: 28

Compression:

Stored size: 1.5 KB

Contents

export default function navItemComponent({ id, matchers }) {
  matchers = matchers.map((matcher) =>
    matcher.replace(/\s/g, "").toLowerCase()
  );

  return {
    filteredOut: false,

    get open() {
      return this.isCollection && this.isOpen(id);
    },

    get active() {
      if (this.$refs.link) {
        return (
          this.location &&
          this.location.pathname === this.$refs.link.getAttribute("href")
        );
      }
      return false;
    },

    get children() {
      return this.$refs.items ? Array.from(this.$refs.items.children) : [];
    },

    get isCollection() {
      return !this.$refs.link;
    },

    toggle() {
      this.toggleOpen(id);
    },

    async filter(text) {
      if (this.isCollection) {
        this.filteredOut = true;
        this.children.forEach(async (child) => {
          const data = Alpine.$data(child);
          await data.filter(text);
          if (!data.filteredOut) {
            this.filteredOut = false;
          }
        });
      } else {
        this.filteredOut = !this.match(text);
      }
      return this;
    },

    match(text) {
      if (text.length) {
        const matched = (matchers || []).map((m) => m.includes(text));
        return matched.filter((m) => m).length;
      }
      return true;
    },

    bindings: {
      toggle: {
        ["@click.stop"]: "toggle",
        ["x-ref"]: "toggle",
      },
      link: {
        [":class"]: "{'!bg-lookbook-nav-item-active':active}",
        ["x-ref"]: "link",
      },
    },
  };
}

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
lookbook-2.0.2 app/components/lookbook/nav/item/component.js
lookbook-2.0.1 app/components/lookbook/nav/item/component.js
lookbook-2.0.0 app/components/lookbook/nav/item/component.js
lookbook-2.0.0.rc.3 app/components/lookbook/nav/item/component.js
lookbook-1.5.5 app/components/lookbook/nav/item/component.js
lookbook-1.5.4 app/components/lookbook/nav/item/component.js
lookbook-2.0.0.rc.2 app/components/lookbook/nav/item/component.js
lookbook-2.0.0.rc.1 app/components/lookbook/nav/item/component.js
lookbook-2.0.0.beta.9 app/components/lookbook/nav/item/component.js
lookbook-2.0.0.beta.8 app/components/lookbook/nav/item/component.js
lookbook-2.0.0.beta.7 app/components/lookbook/nav/item/component.js
lookbook-2.0.0.beta.6 app/components/lookbook/nav/item/component.js
lookbook-2.0.0.beta.5 app/components/lookbook/nav/item/component.js
lookbook-2.0.0.beta.4 app/components/lookbook/nav/item/component.js
lookbook-2.0.0.beta.3 app/components/lookbook/nav/item/component.js
lookbook-2.0.0.beta.2 app/components/lookbook/nav/item/component.js
lookbook-1.5.3 app/components/lookbook/nav/item/component.js
lookbook-2.0.0.beta.1 app/components/lookbook/nav/item/component.js
lookbook-1.5.2 app/components/lookbook/nav/item/component.js
lookbook-2.0.0.beta.0 app/components/lookbook/nav/item/component.js