1.0.1 • Published 10 months ago

@angulogic/ng-sidebar v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

@angulogic/ng-sidebar

npm version License Angular Version

@angulogic/ng-sidebar is a dynamic, interactive, and highly configurable Angular sidebar component designed to provide a rich navigation experience in your Angular applications. It supports nested menus, search functionality, favorites management, theme toggling, responsive view modes, and resizable/auto-position capabilities.


Light Theme Dark Theme


Table of Contents


Features

  • Dynamic Menu Navigation:
    Create multiple sidebar sections with nested menu items and submenus.

  • Search & Favorites:
    Integrated search functionality with configurable matching strategies (contains, startsWith, endsWith, equal) and a favorites management system.

  • Custom Banner & User Profile:
    Display a customizable banner (logo and title) and user profile section with click callbacks.

  • Responsive & Flexible:
    Supports various view modes such as toggle, hover, mobile, and fix. Auto-positioning adapts the layout dynamically.

  • Resizable Sidebar:
    End users can resize the sidebar while respecting minimum and maximum width constraints.

  • Theme Switching:
    Built-in light/dark theme support along with an optional theme picker.

  • Extensible Callbacks:
    Provides hooks for events like menu item clicks, toggles, search start/end, resizing events, and theme changes.


Installation

Install @angulogic/ng-sidebar via npm:

npm install @angulogic/ng-sidebar

Setup

You can add it to your angular.json for icons and fonts

"assets": [
    {
    "glob": "*/",
    "input": "./node_modules/@angulogic/ng-sidebar/assets",
    "output": "/assets/"
  }
],

Usage

Basic Usage

import { NgSidebarModule } from '@angulogic/ng-sidebar';
import { SidebarModel } from '@angulogic/ng-sidebar';

@NgModule({
  imports: [NgSidebarModule],
})
export class AppModule {}

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
})
export class AppComponent {
  sidebarModel: SidebarModel = {
    bannerOptions: {
      title: 'My App',
      logo: 'assets/logo.png',
    },
    userOptions: {
      name: 'John Doe',
      avatar: 'assets/avatar.png',
    },
    sidebarData: [
      {
        title: 'Main Menu',
        data: [
          { name: 'Dashboard', route: '/dashboard' },
          { name: 'Settings', route: '/settings' },
        ],
      },
    ],
    options: {
      expand: true,
      theme: 'light',
    },
  };
}
<ng-sidebar [options]="sidebarModel"></ng-sidebar>

Advanced Configuration

You can customize the sidebar with content projection using directives like:

<ng-sidebar [options]="sidebarModel">
  <div al-sidebar-banner>Custom Banner Content</div>
  <div al-sidebar-top-user>Custom User Content</div>
  <div al-sidebar-menu>Custom Menu Content</div>
</ng-sidebar>

CSS Customization

You can customize the appearance of the sidebar by overriding CSS variables:

ng-sidebar {
  --primary: red !important;
  --bg-color: #f0f0f0 !important;
}

Available CSS Variables

VariableDescriptionDefault Value
--radiusBorder radius for UI elements6px
--collapse-widthWidth when the sidebar is collapsed100px
--sidebar-widthDefault width of the sidebar250px
--bg-colorBackground color of the sidebarwhite
--text-colorDefault text color#000000de
--primaryPrimary color used for highlights#1b84ff
--primary-2Secondary shade of primary color#4394f1
--primary-3Tertiary shade of primary color#5c9be4
--secondarySecondary color#d6d6d6
--secondary-2Lighter shade of secondary color#e9e9e9
--secondary-3Lightest shade of secondary color#f3f3f3
--default-font-familyDefault font family'Inter', sans-serif
--collapsed-banner-padding-rightPadding right for the collapsed banner1rem
--resizer-colorColor of the resizer#1b84ff
--resizer-widthWidth of the resizer5px
--resizer-heightHeight of the resizer100%
--resizer-rightPositioning from the right-3px
--resiver-topPositioning from the top0
--toggle-border-radiusBorder radius of toggle button6px
--toggle-border-colorBorder color of toggle button#d6d6d6
--toggle-bg-colorBackground color of toggle buttonwhite
--toggle-border-widthBorder width of toggle button1px
--search-widthWidth of the search bar100%
--search-icon-leftLeft position for search icon0.75rem
--search-icon-topTop position for search icon50%
--search-input-border-radiusBorder radius of the search input6px
--search-input-border-colorBorder color of the search input#d6d6d6
--search-input-border-widthBorder width of the search input1px
--search-input-bg-colorBackground color of the search input#f6f8fa
--search-input-colorText color of the search input#333333
--search-input-widthWidth of the search input100%
--search-input-heightHeight of the search input2rem
--search-input-paddingPadding for the search input0px 1.5rem
--search-input-marginMargin for the search input0px 0.5rem
--search-cancel-icon-rightRight position for search cancel icon0.75rem
--search-cancel-icon-topTop position for search cancel icon50%
--menu-paddingPadding for the menu0px 1rem
--menu-marginMargin for the menu1rem 0px
--menu-heightHeight of the menu100%
--menu-wrapper-margin-bottomBottom margin for the menu wrapper1rem
--menu-wrapper-collapsed-margin-bottomBottom margin when the menu is collapsed0px
--menu-wrapper-collapsed-colorText color for collapsed menu#d6d6d6
--menu-wrapper-title-font-sizeFont size for menu section titles20px
--menu-wrapper-title-padding-bottomBottom padding for menu section titles0.5rem
--user-name-font-weightFont weight for the user namebold
--user-name-font-sizeFont size for the user namelarge
--scrollbar-heightHeight of the scrollbar0.4rem
--scrollbar-widthWidth of the scrollbar0.4rem
--banner-heightHeight of the banner10%
--banner-paddingPadding for the banner1rem
--banner-logo-heightHeight of the banner logo5rem
--banner-title-font-sizeFont size of the banner titlexx-large

API Documentation

Models

ModelPropertyTypeDescriptionDefault
SidebarModelbannerOptionsBannerConfiguration for sidebar bannerundefined
userOptionsUserUser profile section configurationundefined
sidebarDataSidebarData[]Array of sidebar sections and menus[]
optionsSidebarOptionsGeneral sidebar settingsundefined
searchOptionsSearchConfiguration for search functionalityundefined
favoritesMenuData[]List of favorite menu items[]
theme'light' , 'dark'Current sidebar theme'light'
viewMode'toggle' , 'hover'Sidebar display mode'toggle'
BannerlogostringSidebar logo URLundefined
titlestringSidebar banner titleundefined
onClick(element) => voidCallback when banner elements are clickedundefined
UseravatarstringUser avatar URLundefined
namestringDisplay name for the userundefined
position'top' , 'bottom'Position of the user profile'bottom'
onClick(element) => voidCallback when user elements are clickedundefined
SidebarDatatitlestringTitle of the sidebar sectionundefined
cssClassstringCustom CSS classundefined
visiblebooleanVisibility of the sectiontrue
dataMenuData[]Array of menu items[]
MenuDatanamestringName of the menu itemundefined
iconstringIcon URL for the menu itemundefined
routestringNavigation routeundefined
visiblebooleanVisibility of the menu itemtrue
isExpandedbooleanExpansion state for submenusfalse
isFavoritedbooleanFavorite status of the menu itemfalse
childrenMenuData[]Nested submenu items[]
onClick(event) => voidCallback for menu item clickundefined
SidebarOptionsresizebooleanEnables resizing of the sidebartrue
expandbooleanEnables sidebar expansiontrue
theme'light' , 'dark'Sidebar theme'light'
autoPositionbooleanEnables automatic positioningtrue
minWidthnumberMinimum width of the sidebar300
maxWidthnumberMaximum width of the sidebar500
SearchplaceholderstringPlaceholder text for the search barundefined
caseSensitivebooleanEnables case sensitivity in searchesfalse
strategy'contains' , 'startsWith', 'endsWith' , 'equal'Defines search strategy'contains'
onSearchStart(event) => voidCallback for search start eventundefined
onSearchEnd(event) => voidCallback for search end eventundefined

For more details on the available models, refer to the source code documentation.


Methods

MethodDescriptionParameters
changeTheme()Switches between light and dark themesNone

Development

Run Locally

git clone https://github.com/skarahan35/angulogic.git
npm install
npm run start

Build for Production

cd projects/ng-sidebar
npm run build

Contributing

We welcome contributions to @angulogic/ng-sidebar!

  1. Fork the repository.
  2. Create a new branch: git checkout -b feature/your-feature-name
  3. Make your changes and commit: git commit -m 'Add new feature'
  4. Push to your branch: git push origin feature/your-feature-name
  5. Open a pull request.

License

@angulogic/ng-sidebar is licensed under the MIT License.


Maintainers

Enjoy building with @angulogic/ng-sidebar! 🚀

1.0.1

10 months ago

1.0.0

10 months ago

0.0.1

11 months ago