Sha256: 9663dd9250f3fd432e31d22ce0a84a4ee8a607181d96ae80487bf8f58f4ae393

Contents?: true

Size: 1.16 KB

Versions: 48

Compression:

Stored size: 1.16 KB

Contents

export default function navComponent(store) {
  return {
    empty: false,

    children: [],

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

    isOpen(id) {
      return store.open.includes(id);
    },

    setOpen(id) {
      store.open.push(id);
    },

    setClosed(id) {
      const index = store.open.indexOf(id);
      if (index > -1) {
        store.open.splice(index, 1);
      }
    },

    closeAll() {
      store.open.length = 0;
    },

    toggleOpen(id) {
      this.isOpen(id) ? this.setClosed(id) : this.setOpen(id);
    },

    async filter(text) {
      this.debug(`Filter text: ${text}`);

      await this.$nextTick();
      const filteredStates = await Promise.all(
        this.children.map(async (child) => {
          const data = Alpine.$data(child);
          await data.filter(text);
          return data.filteredOut;
        })
      );

      const matchedChildCount = filteredStates.filter((s) => !s).length;
      this.empty = matchedChildCount === 0;

      this.debug(
        `Children matching filter: ${matchedChildCount}/${this.children.length}`
      );
    },
  };
}

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
lookbook-2.3.4 app/components/lookbook/nav/component.js
lookbook-2.3.3 app/components/lookbook/nav/component.js
lookbook-2.3.2 app/components/lookbook/nav/component.js
lookbook-2.3.0 app/components/lookbook/nav/component.js
lookbook-2.2.2 app/components/lookbook/nav/component.js
lookbook-2.2.1 app/components/lookbook/nav/component.js
lookbook-2.2.0 app/components/lookbook/nav/component.js
lookbook-2.1.1 app/components/lookbook/nav/component.js
lookbook-2.1.0 app/components/lookbook/nav/component.js
lookbook-2.0.5 app/components/lookbook/nav/component.js
lookbook-2.0.4 app/components/lookbook/nav/component.js
lookbook-2.0.3 app/components/lookbook/nav/component.js
lookbook-2.0.2 app/components/lookbook/nav/component.js
lookbook-2.0.1 app/components/lookbook/nav/component.js
lookbook-2.0.0 app/components/lookbook/nav/component.js
lookbook-2.0.0.rc.3 app/components/lookbook/nav/component.js
lookbook-1.5.5 app/components/lookbook/nav/component.js
lookbook-1.5.4 app/components/lookbook/nav/component.js
lookbook-2.0.0.rc.2 app/components/lookbook/nav/component.js
lookbook-2.0.0.rc.1 app/components/lookbook/nav/component.js