Advertisement
ikrav4ic

Untitled

Apr 10th, 2020
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let slideUp = (target) => {
  2.     target.style.height = target.offsetHeight + 'px';
  3.     target.style.overflow = 'hidden';
  4.     target.style.transition = "all 0.3s ease";
  5.     target.style.height = 0;
  6.     window.setTimeout( () => {
  7.         target.style.display = 'none';
  8.         target.style.removeProperty('overflow');
  9.         target.style.removeProperty('transition');
  10.     }, 300);
  11. }
  12.  
  13. let slideDown = (target) => {
  14.     target.style.removeProperty('display');
  15.     let display = window.getComputedStyle(target).display;
  16.  
  17.     if (display === 'none')
  18.         display = 'block';
  19.  
  20.     target.style.display = display;
  21.     let height = 0;
  22.  
  23.     let children = target.childNodes;
  24.     children.forEach(function(item){
  25.         height = height + item.offsetHeight;
  26.     });
  27.  
  28.     target.style.overflow = 'hidden';
  29.     target.style.height = 0 + 'px';
  30.     target.style.transition = "all 0.3s ease";
  31.     target.style.height = height + 'px';
  32.     window.setTimeout( () => {
  33.         target.style.removeProperty('overflow');
  34.         target.style.removeProperty('transition');
  35.     }, 300);
  36. }
  37.  
  38. let slideToggle = (target) => {
  39.     if (window.getComputedStyle(target).display === 'none') {
  40.         return slideDown(target);
  41.     } else {
  42.         return slideUp(target);
  43.     }
  44. }
  45.  
  46.  
  47.  
  48. const renderMenu = (items, nav_class, depth) => {
  49.     return <ul className={nav_class ? nav_class : "collapse"} style={{height: nav_class ? '' : 0}}>
  50.         {items.map((i, key) => {
  51.             return <li key={key}>
  52.               <a href={i.link} className={i.menu && "has-arrow"} onClick={(e)=>{
  53.                 if(i.menu){
  54.                     slideToggle(e.target.nextElementSibling);
  55.                 }
  56.               }}>
  57.                   {!depth && <i className={i.icon ? i.icon : "icon-docs"}></i>}
  58.                   {i.title}
  59.                   {i.badge && <span className={'badge float-right ' + (i.badge.color)}>{i.badge.text}</span>}
  60.               </a>
  61.                 {i.menu && renderMenu(i.menu)}
  62.             </li>
  63.         })}
  64.     </ul>
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement