Skip to content

An implementation of Kahn's algorithm for topological sorting

License

Notifications You must be signed in to change notification settings

jdan/topological-sort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

topological-sort

An implementation of Kahn's Algorithm, written for my post on using topological sort to generate z-index values.

example

const resolver = new ZIndexResolver();

// A nav with dropdowns
resolver.above(".nav", "main");
resolver.above(".dropdown", ".nav");
resolver.above(".submenu", ".dropdown");

// Tooltips in the document
resolver.above(".tooltip", "main");

// Modals should go above everything
resolver.above(".modal", ".nav");
resolver.above(".modal", ".submenu");
resolver.above(".modal", ".tooltip");

// Dropdowns must appear above tooltips
resolver.above(".dropdown", ".tooltip");

console.log(resolver.generateCSS());

Producing the following output:

main { z-index: 0; }
.nav { z-index: 1; }
.tooltip { z-index: 2; }
.dropdown { z-index: 3; }
.submenu { z-index: 4; }
.modal { z-index: 5; }

license

MIT

About

An implementation of Kahn's algorithm for topological sorting

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published