npm package: @luisli/menu-topbar-sidebar-test-lib
Description: Reusable Angular menu library (sidebar + topbar)
Author: Luis Li, Diego de la FLor
Latest version: 1.0.0

# Menu Library

A reusable Angular library for creating configurable sidebars and topbars following Domain-Driven Design (DDD) principles.

## Features

- **DDD Architecture**: Organized into Domain, Application, Infrastructure, and Presentation layers.
- **Design Patterns**: Implements Factory Method, Strategy, and Adapter patterns.
- **Configurable**: Easily customize themes, layouts, and permissions.
- **Extensible**: Add new menu items, roles, and permissions dynamically.
- **Standalone Components**: Built with Angular standalone components for easy integration.

## Installation

```bash
npm install menu-lib
```

## Usage

### Basic Setup

1. Import the library in your `app.config.ts`:

```typescript
import { provideMenuLib } from 'menu-lib';

export const appConfig: ApplicationConfig = {
  providers: [
    provideMenuLib()
  ]
};
```

2. Use the components in your template:

```html
<lib-sidebar [userPermissions]="userPermissions" [userRoles]="userRoles" theme="default"></lib-sidebar>
<lib-topbar [userPermissions]="userPermissions" [userRoles]="userRoles" theme="default"></lib-topbar>
```

3. Configure the menu in your component:

```typescript
import { MenuService, MenuFactory, MenuItem } from 'menu-lib';

export class AppComponent implements OnInit {
  userPermissions = ['read', 'write'];
  userRoles = ['admin'];

  constructor(private menuService: MenuService) {}

  ngOnInit(): void {
    const items = [
      MenuItem.simple('home', 'Home', '/home', '🏠'),
      MenuItem.simple('profile', 'Profile', '/profile', '👤', ['read'], ['admin'])
    ];

    const menu = MenuFactory.createStaticMenu('main-menu', 'Main Menu', items);
    this.menuService.setMenu(menu);
  }
}
```

### Advanced Configuration

#### Using Adapters for Dynamic Configuration

```typescript
import { MenuConfigService, JsonMenuAdapter } from 'menu-lib';

const jsonData = [
  { id: 'home', name: 'Home', url: '/home' },
  { id: 'settings', name: 'Settings', url: '/settings' }
];

const adapter = new JsonMenuAdapter(jsonData);
menuConfigService.setAdapter(adapter);
```

#### Custom Themes

```html
<lib-sidebar theme="dark"></lib-sidebar>
```

#### Permission-Based Visibility

The library automatically filters menu items based on user permissions and roles.

## API Reference

### Components

- `SidebarComponent`: Displays a vertical sidebar menu.
- `TopbarComponent`: Displays a horizontal topbar menu.

### Services

- `MenuService`: Manages the current menu state.
- `PermissionService`: Handles permission and role validation.
- `MenuConfigService`: Manages configuration adapters.

### Factories

- `MenuFactory`: Creates menu instances with different configurations.

### Domain Objects

- `MenuItem`: Represents a single menu item.
- `Menu`: Represents a collection of menu items.
- `MenuConfig`: Configuration for menu appearance and behavior.

## Contributing

1. Fork the repository.
2. Create a feature branch.
3. Make your changes.
4. Run tests: `ng test menu-lib`.
5. Build: `ng build menu-lib`.
6. Submit a pull request.

## License

MIT