Giter Club home page Giter Club logo

bs5-nav-tree's Introduction

BS5-Nav-Tree

v0.3.1 Changelog

  1. Added iconPlace value to config to determine location of group/link icons. It can be 'start' or 'end'.
  2. Link and group icons have ahref attribute.

NOTE: ALL OLD VERSIONS ARE DEPRECATED. PLEASE USE v0.3.

NOTE 2: THIS PROJECT IS OPEN FOR CONTRIBUTION. PLEASE FEEL FREE FOR PULL REQUEST.

How to use bs5-nav-tree v0.3

  1. Create an unordered list as example. Make sure all list items have its own id. If you want to create searchable nav-tree, you have to add data-value attribute to the list items.
<ul id="arbitrary_id" class="arbitrary_class">
  <li id="li0" data-value="li0">
    <a href="#">extra list</a>
  </li>
  <li id="li1" data-value="li1">
    <a href="#">
      Link 1
    </a>
  </li>
  <li id="li2" data-value="li2">
    <span><i class="fas fa-chevron-left"></i></span>
    <a>
      Collapse 1
    </a>
    <span>t</span>
    <ul>
      <li id="li4" data-value="li4">
        <a>
          Collapse 2
        </a>
        <ul>
          <li id="li6" data-value="li6">
            <a href="#">
              Link 2
            </a>
          </li>
          <li id="li7" data-value="li7">
            <a href="#">
              Link 3
            </a>
          </li>
          <li id="li8" data-value="li8">
            <a>
              Collapse 3
            </a>
            <ul>
              <li id="li9" data-value="li9">
                <a href="#">
                  Link 4
                </a>
              </li>
              <li id="li10" data-value="li10">
                <a href="#">
                  Link 5
                </a>
              </li>
            </ul>
          </li>
        </ul>
      </li>
      <li id="li5" data-value="li5">
        <a href="#">
          Link 6
        </a>
      </li>
    </ul>
  </li>
</ul>
  1. There are multiple ways to create NavTree.
NavTree.createBySelector("#nav-tree", {
    searchable: true,
    showEmptyGroups: true,

    groupOpenIconClass: "fas",
    groupOpenIcon: "fa-chevron-down",

    groupCloseIconClass: "fas",
    groupCloseIcon: "fa-chevron-right",

    linkIconClass: "fas",
    linkIcon: "fa-link",

    searchPlaceholderText: "Search",
  });
new NavTree(document.querySelector('#arbitrary_id'), {
    searchable: true,
    showEmptyGroups: true,

    groupOpenIconClass: "fas",
    groupOpenIcon: "fa-chevron-down",

    groupCloseIconClass: "fas",
    groupCloseIcon: "fa-chevron-right",

    linkIconClass: "fas",
    linkIcon: "fa-link",

    searchPlaceholderText: "Search",
  });
NavTree.getOrCreateInstance(document.querySelector('#arbitrary_id'), {
    searchable: true,
    showEmptyGroups: true,

    groupOpenIconClass: "fas",
    groupOpenIcon: "fa-chevron-down",

    groupCloseIconClass: "fas",
    groupCloseIcon: "fa-chevron-right",

    linkIconClass: "fas",
    linkIcon: "fa-link",

    searchPlaceholderText: "Search",
  });

You can access the NavTree instance by using the getOrCreateInstance function in the example above. If an instance has not been created before, it will give you a new instance.

  1. Using data-icon attribute, you can set special icon to the links.
<li data-icon="fas fa-cloud" id="li0" data-value="li0">
  <a href="#">extra list</a>
</li>
  1. If you want to add some special things to the list, you can add them as prefix or suffix. Just wrap them with span and put them before or after than 'a' element.
<li data-icon="fas fa-cloud" id="li0" data-value="li0">
  <span><a href="#">1</a></span>
  <span><i class="fas fa-plane"></i></span>
  <a href="#">extra list</a>
  <span><a href="#">1</a></span>
  <span><i class="fas fa-plane text-danger"></i></span>
</li>
  1. Done! You can experience it using the example in the example folder.

Update the tree

navtree_instance.update(html_string)

bs5-nav-tree's People

Contributors

akalp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

gtbu

bs5-nav-tree's Issues

Less issue more compliment

This is a great piece of work. Thank you.
I wanted to move the icons from left to the right so changed line 100 to append to the end
li_container.appendChild(icon_container)

Be nice to have in config:)
Also be good to have the icons linked too

Collapse does not close

Issue by mistake.
I spend hours getting this working from the readme.md, but the collapse stays open.
just tried your example code and now it works.
Sorry for creating an issue which isn't one. Can't delete it.

Active classes not added dynamically to text or icons

Lastest version
config
NavTree.createBySelector("#nav-tree", {
searchable: false,
showEmptyGroups: false,

groupOpenIconClass: "bi",
groupOpenIcon: "bi-chevron-down",

groupCloseIconClass: "bi",
groupCloseIcon: "bi-chevron-right",

linkIconClass: "",
linkIcon: "",

searchPlaceholderText: "Search",
iconPlace: "end"

});

line 134
a.addEventListener("click", () => {
this.element
.querySelectorAll("li")
.forEach((li) => li.classList.remove("active"));
a.closest("li").classList.add("active");
});

It appears no active links are added to the node.
It would be good to be able to target styles for parent links to highlight the parent and icon color

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.