Sha256: a3f2fbe13f8c98315be36ffad49265d201bd69a93e7a467b4d8703fe025d2aca

Contents?: true

Size: 1.19 KB

Versions: 8

Compression:

Stored size: 1.19 KB

Contents

import { getAlpineData } from "../lib/utils";

export default function navGroup() {
  return {
    hidden: false,
    children: [],
    get id() {
      return this.$root.id;
    },
    get open() {
      return this.$store.nav.isOpen(this.id);
    },
    toggle() {
      this.$store.nav.toggle(this.id);
    },
    getChildren() {
      return this.$refs.items
        ? Array.from(this.$refs.items.querySelectorAll(":scope > li > div"))
        : [];
    },
    navigateToFirstChild() {
      if (this.open) {
        const child = this.firstVisibleChild();
        if (child) {
          const link = child.querySelector(":scope > a.nav-link");
          if (link) {
            this.setLocation(link.getAttribute("href"));
          }
        }
      }
    },
    filter(text) {
      this.hidden = true;
      this.getChildren().forEach((child) => {
        const data = getAlpineData(child);
        data.filter(text);
        if (!data.hidden) {
          this.hidden = false;
        }
      });
    },
    firstVisibleChild() {
      return this.getChildren().find((child) => {
        return child._x_dataStack
          ? child._x_dataStack[0].hidden === false
          : false;
      });
    },
  };
}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
lookbook-0.6.1 app/assets/lookbook/js/components/nav-group.js
lookbook-0.6.0 app/assets/lookbook/js/components/nav-group.js
lookbook-0.5.2 app/assets/lookbook/js/components/nav-group.js
lookbook-0.5.1 app/assets/lookbook/js/components/nav-group.js
lookbook-0.5.0 app/assets/lookbook/js/components/nav-group.js
lookbook-0.5.0.beta.2 app/assets/lookbook/js/components/nav-group.js
lookbook-0.5.0.beta.1 app/assets/lookbook/js/components/nav-group.js
lookbook-0.5.0.beta.0 app/assets/lookbook/js/components/nav-group.js