coreui / coreui-free-react-admin-template

Open source admin template based on Bootstrap 5 and React.js
https://coreui.io/product/free-react-admin-template/
MIT License
4.6k stars 2.33k forks source link

How do I create a Logout link (with icon) at the footer of the sidebar ? (in React) #419

Closed axilaris closed 4 months ago

axilaris commented 7 months ago

How do I create a Logout link (with icon) properly at the footer of the sidebar ? (in React). I would like it to be able to disappear the text when sidebar collapse while the icon remains.

I tried the following:

      <CSidebarFooter className="border-top d-none d-lg-flex">

      <CNavItem customClassName="nav-icon">
        <CNavLink to='/logout'>
          <CIcon icon={cilAccountLogout} className="me-2" />
          Logout
        </CNavLink>
      </CNavItem>

        <CSidebarToggler
          onClick={() => dispatch({ type: 'set', sidebarUnfoldable: !unfoldable })}
        />
      </CSidebarFooter>

But if you check out the screenshots. There is a dot and when the sidebar is contracted, the word "Logout" doesnt disappear.

Screenshot 2024-04-06 at 8 28 32 AM

WhatsApp Image 2024-04-06 at 8 28 14 AM

mrholek commented 7 months ago

@axilaris <CNavItem> should be wrapped in <CSidebarNav>

axilaris commented 7 months ago

@mrholek Thanks a lot. it manage to disappear the icon and text altogether when collapse.

but i actually want the icon to appear when collapse. what can be done ?

      <CSidebarNav>
        <CNavItem customClassName="nav-icon">
          <CNavLink to='/logout'>
            <CIcon icon={cilAccountLogout} className="me-2" />
            Logout
          </CNavLink>
        </CNavItem>
      </CSidebarNav>

another way i thought is this, but this disappear the icon but not the text. its the other way round that i want. icon should be maintain when collapse.


      <CSidebarFooter style={{ cursor: 'pointer' }}>               

            <CIcon icon={cilAccountLogout} height={20} onClick={handleLogout}/>      
            <div onClick={handleLogout} style={{fontSize: 15 }}> Logout</div>  

        <CSidebarToggler
          onClick={() => dispatch({ type: 'set', sidebarUnfoldable: !unfoldable })}
        />        
      </CSidebarFooter>
axilaris commented 7 months ago

@mrholek I'ved posted this issue also on stackoverflow. https://stackoverflow.com/questions/78282849/coreui-how-do-i-create-a-logout-link-with-icon-at-the-footer-csidebarfooter

Thanks.

github-actions[bot] commented 5 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions