Sha256: ebc063210fb8be2f8bd7f738a0848bdfdcb189cc36642b3e00394b07712c9e28

Contents?: true

Size: 1.11 KB

Versions: 21

Compression:

Stored size: 1.11 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);
      }
    },

    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

21 entries across 21 versions & 1 rubygems

Version Path
lookbook-1.0.8 app/components/lookbook/nav/component.js
lookbook-1.0.7 app/components/lookbook/nav/component.js
lookbook-1.0.6 app/components/lookbook/nav/component.js
lookbook-1.0.5 app/components/lookbook/nav/component.js
lookbook-1.0.4 app/components/lookbook/nav/component.js
lookbook-1.0.3 app/components/lookbook/nav/component.js
lookbook-1.0.2 app/components/lookbook/nav/component.js
lookbook-1.0.1 app/components/lookbook/nav/component.js
lookbook-1.0.0 app/components/lookbook/nav/component.js
lookbook-1.0.0.rc.3 app/components/lookbook/nav/component.js
lookbook-1.0.0.rc.2 app/components/lookbook/nav/component.js
lookbook-1.0.0.rc.1 app/components/lookbook/nav/component.js
lookbook-1.0.0.beta.8 app/components/lookbook/nav/component.js
lookbook-1.0.0.beta.7 app/components/lookbook/nav/component.js
lookbook-1.0.0.beta.6 app/components/lookbook/nav/component.js
lookbook-1.0.0.beta.5 app/components/lookbook/nav/component.js
lookbook-1.0.0.beta.4 app/components/lookbook/nav/component.js
lookbook-1.0.0.beta.3 app/components/lookbook/nav/component.js
lookbook-1.0.0.beta.2 app/components/lookbook/nav/component.js
lookbook-1.0.0.beta.1 app/components/lookbook/nav/component.js