ng-hub-ui-breadcrumbs 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,24 +1,589 @@
1
- # NgHubUiBreadcrumb
1
+ # Hub UI Breadcrumb
2
2
 
3
- This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 17.3.0.
3
+ A flexible and reusable breadcrumb component for Angular applications that automatically generates breadcrumbs based on your routing configuration.
4
4
 
5
- ## Code scaffolding
5
+ ## Installation
6
6
 
7
- Run `ng generate component component-name --project breadcrumbs` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project breadcrumbs`.
8
- > Note: Don't forget to add `--project breadcrumbs` or else it will be added to the default project in your `angular.json` file.
7
+ ```bash
8
+ npm install ng-hub-ui-breadcrumbs
9
+ ```
9
10
 
10
- ## Build
11
+ ## Features
11
12
 
12
- Run `ng build breadcrumbs` to build the project. The build artifacts will be stored in the `dist/` directory.
13
+ - Automatic breadcrumb generation from route configuration
14
+ - Customizable through CSS variables
15
+ - RTL support
16
+ - Templating support for custom breadcrumb items
17
+ - Bootstrap-compatible styling
13
18
 
14
- ## Publishing
19
+ ## Usage
15
20
 
16
- After building your library with `ng build breadcrumbs`, go to the dist folder `cd dist/breadcrumbs` and run `npm publish`.
21
+ ## Basic Setup
17
22
 
18
- ## Running unit tests
23
+ You can use this component in two ways:
19
24
 
20
- Run `ng test breadcrumbs` to execute the unit tests via [Karma](https://karma-runner.github.io).
25
+ ### 1. Standalone Components
21
26
 
22
- ## Further help
27
+ Import the required artifacts in your component:
28
+
29
+ ```typescript
30
+ import { HubBreadcrumbComponent } from '@hub/breadcrumb';
31
+ import { HubBreadcrumbItemDirective } from '@hub/breadcrumb';
32
+
33
+ @Component({
34
+ // ...
35
+ imports: [HubBreadcrumbComponent, HubBreadcrumbItemDirective]
36
+ })
37
+ ```
38
+
39
+ ### 2. Module Import
40
+
41
+ If you prefer using NgModules, import the HubBreadcrumbModule:
42
+
43
+ ```typescript
44
+ import { HubBreadcrumbModule } from '@hub/breadcrumb';
45
+
46
+ @NgModule({
47
+ imports: [HubBreadcrumbModule]
48
+ })
49
+ export class AppModule { }
50
+ ```
51
+
52
+ ### Route Configuration
53
+
54
+ Configure your routes with breadcrumb data:
55
+
56
+ ```typescript
57
+ // app-routing.module.ts
58
+ const routes: Routes = [
59
+ {
60
+ path: '',
61
+ data: { breadcrumb: 'Home' }
62
+ },
63
+ {
64
+ path: 'products',
65
+ data: { breadcrumb: 'Products' },
66
+ children: [
67
+ {
68
+ path: ':id',
69
+ resolve: {
70
+ resolvedData: ProductResolver
71
+ },
72
+ data: {
73
+ breadcrumb: '{name}' // Will use the product name from resolver
74
+ }
75
+ }
76
+ ]
77
+ }
78
+ ];
79
+ ```
80
+
81
+ ### Add to Template
82
+
83
+ Add the component to your template:
84
+
85
+ ```html
86
+ <hub-breadcrumbs></hub-breadcrumbs>
87
+ ```
88
+
89
+ <!-- ### Dynamic Labels
90
+
91
+ You can use resolved data in your breadcrumb labels:
92
+
93
+ ```typescript
94
+ const routes: Routes = [
95
+ {
96
+ path: 'product/:id',
97
+ resolve: {
98
+ resolvedData: ProductResolver
99
+ },
100
+ data: {
101
+ breadcrumb: '{name}' // Will be replaced with resolvedData.name
102
+ }
103
+ }
104
+ ];
105
+ ``` -->
106
+
107
+ ### Function Labels
108
+
109
+ You can also use functions to generate dynamic labels:
110
+
111
+ ```typescript
112
+ const routes: Routes = [
113
+ {
114
+ path: 'products',
115
+ resolve: { info: infoResolver },
116
+ data: { breadcrumb: (data: any) => `${data.info.title}` },
117
+ }
118
+ ];
119
+ ```
120
+
121
+ ### Component Features
122
+
123
+ The breadcrumb component automatically:
124
+ - Listens to route changes
125
+ - Extracts breadcrumb data from route configuration
126
+ - Builds the breadcrumb path
127
+ - Handles template customization
128
+ - Supports RTL languages
129
+
130
+ ### Working with Lazy Loading
131
+
132
+ For lazy-loaded modules, configure the parent route with breadcrumb data:
133
+
134
+ ```typescript
135
+ // app-routing.module.ts
136
+ const routes: Routes = [
137
+ {
138
+ path: 'admin',
139
+ data: { breadcrumb: 'Administration' },
140
+ loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule)
141
+ }
142
+ ];
143
+
144
+ // admin-routing.module.ts
145
+ const adminRoutes: Routes = [
146
+ {
147
+ path: 'users',
148
+ data: { breadcrumb: 'Users' }
149
+ }
150
+ ];
151
+ ```
152
+
153
+ This will generate breadcrumbs like: Home > Administration > Users
154
+
155
+ ## Custom Template
156
+
157
+ You can customize how each breadcrumb item is rendered using a template.
158
+
159
+ ### Basic Template
160
+
161
+ ```html
162
+ <hub-breadcrumbs>
163
+ <ng-template hubBreadcrumbItem let-item let-isLast="isLast">
164
+ @if (!isLast) {
165
+ <a [routerLink]="item.url" class="hub-breadcrumb__link">
166
+ {{ item.label }}
167
+ </a>
168
+ } @else {
169
+ <span class="hub-breadcrumb__text">{{ item.label }}</span>
170
+ }
171
+ </ng-template>
172
+ </hub-breadcrumbs>
173
+ ```
174
+
175
+ ### Template Context
176
+
177
+ The template context provides these properties:
178
+
179
+ ```typescript
180
+ interface BreadcrumbTemplateContext {
181
+ $implicit: BreadcrumbItem; // The current breadcrumb item
182
+ isLast: boolean; // Whether this is the last item
183
+ }
184
+
185
+ interface BreadcrumbItem {
186
+ label: string; // The text to display
187
+ url: string; // The route URL
188
+ data: any; // Additional data from route configuration
189
+ }
190
+ ```
191
+
192
+ ### Examples
193
+
194
+ With icons:
195
+ ```html
196
+ <hub-breadcrumbs>
197
+ <ng-template hubBreadcrumbItem let-item let-isLast="isLast">
198
+ @if (!isLast) {
199
+ <a [routerLink]="item.url" class="hub-breadcrumb__link">
200
+ <i [class]="item.data?.icon"></i>
201
+ {{ item.label }}
202
+ </a>
203
+ } @else {
204
+ <span class="hub-breadcrumb__text">
205
+ <i [class]="item.data?.icon"></i>
206
+ {{ item.label }}
207
+ </span>
208
+ }
209
+ </ng-template>
210
+ </hub-breadcrumbs>
211
+ ```
212
+
213
+ Route configuration for icons:
214
+ ```typescript
215
+ const routes: Routes = [
216
+ {
217
+ path: 'products',
218
+ data: {
219
+ breadcrumb: 'Products',
220
+ icon: 'fa fa-box' // Will be available in template
221
+ }
222
+ }
223
+ ];
224
+ ```
225
+
226
+ With custom separators:
227
+ ```html
228
+ <hub-breadcrumbs>
229
+ <ng-template hubBreadcrumbItem let-item let-isLast="isLast">
230
+ @if (!isLast) {
231
+ <a [routerLink]="item.url" class="hub-breadcrumb__link">
232
+ {{ item.label }}
233
+ </a>
234
+ <span class="hub-breadcrumb__separator">→</span>
235
+ } @else {
236
+ <span class="hub-breadcrumb__text">{{ item.label }}</span>
237
+ }
238
+ </ng-template>
239
+ </hub-breadcrumbs>
240
+ ```
241
+
242
+ Note: When using a custom template, you're responsible for:
243
+ - Handling the navigation with `routerLink`
244
+ - Managing active/inactive states
245
+ - Applying appropriate styles
246
+ - Handling RTL if needed
247
+
248
+ ## Styling
249
+
250
+ The breadcrumb component uses CSS variables for styling, making it highly customizable. It's designed to work with or without Bootstrap.
251
+
252
+ ### Default SCSS Variables
253
+
254
+ These SCSS variables set the default values:
255
+
256
+ ```scss
257
+ $border-radius-pill: 50rem !default;
258
+ $secondary-color: black !default;
259
+ $breadcrumb-font-size: null !default;
260
+ $breadcrumb-padding-y: 0.25rem !default;
261
+ $breadcrumb-padding-x: 1rem !default;
262
+ $breadcrumb-item-padding-x: 0.5rem !default;
263
+ $breadcrumb-margin-bottom: 0 !default;
264
+ $breadcrumb-bg: white !default;
265
+ $breadcrumb-divider-color: $secondary-color !default;
266
+ $breadcrumb-active-color: $secondary-color !default;
267
+ $breadcrumb-divider: quote('>') !default;
268
+ $breadcrumb-divider-flipped: $breadcrumb-divider !default;
269
+ $breadcrumb-border-radius: $border-radius-pill !default;
270
+ ```
271
+
272
+ ### CSS Variables
273
+
274
+ These variables are exposed for runtime customization:
275
+
276
+ ```css
277
+ .hub-breadcrumb__list {
278
+ --hub-breadcrumb-padding-x: 1rem;
279
+ --hub-breadcrumb-padding-y: 0.25rem;
280
+ --hub-breadcrumb-margin-bottom: 0;
281
+ --hub-breadcrumb-bg: white;
282
+ --hub-breadcrumb-border-radius: 50rem;
283
+ --hub-breadcrumb-divider-color: black;
284
+ --hub-breadcrumb-item-padding-x: 0.5rem;
285
+ --hub-breadcrumb-item-active-color: black;
286
+ }
287
+ ```
288
+
289
+ ### Customizing Styles
290
+
291
+ 1. Override SCSS variables (compile-time):
292
+ ```scss
293
+ // your-styles.scss
294
+ $breadcrumb-bg: #f8f9fa;
295
+ $breadcrumb-divider: quote('→');
296
+ $breadcrumb-active-color: #6c757d;
297
+ ```
298
+
299
+ 2. Override CSS variables (runtime):
300
+ ```css
301
+ .hub-breadcrumb__list {
302
+ --hub-breadcrumb-bg: #f8f9fa;
303
+ --hub-breadcrumb-divider-color: #6c757d;
304
+ }
305
+ ```
306
+
307
+ 3. Override classes directly:
308
+ ```scss
309
+ .hub-breadcrumb__item {
310
+ &--active {
311
+ font-weight: bold;
312
+ }
313
+ }
314
+ ```
315
+
316
+ ### RTL Support
317
+
318
+ The component automatically handles RTL languages by flipping the divider. You can customize the flipped divider using:
319
+
320
+ ```scss
321
+ $breadcrumb-divider-flipped: quote('<');
322
+ ```
323
+
324
+ ### Class Structure
325
+
326
+ The component uses BEM methodology:
327
+ - `.hub-breadcrumb` - Block (host component)
328
+ - `.hub-breadcrumb__list` - Element (container)
329
+ - `.hub-breadcrumb__item` - Element (each breadcrumb)
330
+ - `.hub-breadcrumb__item--active` - Modifier (active state)
331
+
332
+ ### Integration with Bootstrap
333
+
334
+ While the component works independently, it's designed to be compatible with Bootstrap's breadcrumb styles. If you're using Bootstrap, the styles will automatically align with your Bootstrap theme.
335
+
336
+ ### Inline Style Customization
337
+
338
+ You can customize the breadcrumb directly in your template using inline styles:
339
+
340
+ ```html
341
+ <hub-breadcrumbs style="
342
+ --hub-breadcrumb-divider: '🐸';
343
+ --hub-breadcrumb-bg: #e9ecef;
344
+ --hub-breadcrumb-item-active-color: #0d6efd;
345
+ "></hub-breadcrumbs>
346
+ ```
347
+
348
+ Common use cases:
349
+
350
+ 1. Custom divider:
351
+ ```html
352
+ <hub-breadcrumbs style="--hub-breadcrumb-divider: '→'"></hub-breadcrumbs>
353
+ <hub-breadcrumbs style="--hub-breadcrumb-divider: '>'"></hub-breadcrumbs>
354
+ <hub-breadcrumbs style="--hub-breadcrumb-divider: '/'"></hub-breadcrumbs>
355
+ <hub-breadcrumbs style="--hub-breadcrumb-divider: '🐸'"></hub-breadcrumbs>
356
+ ```
357
+
358
+ 2. Custom colors:
359
+ ```html
360
+ <hub-breadcrumbs style="
361
+ --hub-breadcrumb-bg: transparent;
362
+ --hub-breadcrumb-divider-color: #6c757d;
363
+ --hub-breadcrumb-item-active-color: #0d6efd;
364
+ "></hub-breadcrumbs>
365
+ ```
366
+
367
+ 3. Custom spacing:
368
+ ```html
369
+ <hub-breadcrumbs style="
370
+ --hub-breadcrumb-padding-x: 0;
371
+ --hub-breadcrumb-padding-y: 0;
372
+ --hub-breadcrumb-item-padding-x: 1rem;
373
+ "></hub-breadcrumbs>
374
+ ```
375
+
376
+ Note: When using emojis or special characters as dividers, make sure to wrap them in quotes.
377
+
378
+ ## API
379
+
380
+ ### Components
381
+
382
+ #### HubBreadcrumbComponent
383
+ ```typescript
384
+ @Component({
385
+ selector: 'hub-breadcrumb',
386
+ standalone: true
387
+ })
388
+ ```
389
+
390
+ A standalone component that automatically generates breadcrumbs from route configuration.
391
+
392
+ ### Directives
393
+
394
+ #### HubBreadcrumbItemDirective
395
+ ```typescript
396
+ @Directive({
397
+ selector: '[hubBreadcrumbItem]',
398
+ standalone: true
399
+ })
400
+ ```
401
+
402
+ Template directive for customizing breadcrumb item rendering.
403
+
404
+ ### Interfaces
405
+
406
+ #### BreadcrumbItem
407
+ ```typescript
408
+ interface BreadcrumbItem {
409
+ label: string; // Display text
410
+ url: string; // Navigation URL
411
+ data: any; // Additional data from route configuration
412
+ }
413
+ ```
414
+
415
+ #### BreadcrumbTemplateContext
416
+ ```typescript
417
+ interface BreadcrumbTemplateContext {
418
+ $implicit: BreadcrumbItem; // Current breadcrumb item
419
+ isLast: boolean; // Whether this is the last item
420
+ }
421
+ ```
422
+
423
+ ### Route Configuration
424
+
425
+ The component reads breadcrumb configuration from route data:
426
+
427
+ ```typescript
428
+ interface BreadcrumbRouteData {
429
+ breadcrumb: string | ((data: any) => string); // Static text or function
430
+ icon?: string; // Optional icon class
431
+ [key: string]: any; // Additional custom data
432
+ }
433
+ ```
434
+
435
+ ### CSS Custom Properties
436
+
437
+ | Property | Description | Default |
438
+ |----------|-------------|---------|
439
+ | `--hub-breadcrumb-padding-x` | Horizontal padding | `1rem` |
440
+ | `--hub-breadcrumb-padding-y` | Vertical padding | `0.25rem` |
441
+ | `--hub-breadcrumb-margin-bottom` | Bottom margin | `0` |
442
+ | `--hub-breadcrumb-bg` | Background color | `white` |
443
+ | `--hub-breadcrumb-border-radius` | Border radius | `50rem` |
444
+ | `--hub-breadcrumb-divider-color` | Divider color | `black` |
445
+ | `--hub-breadcrumb-item-padding-x` | Item spacing | `0.5rem` |
446
+ | `--hub-breadcrumb-item-active-color` | Active item color | `black` |
447
+
448
+ ### SCSS Variables
449
+
450
+ | Variable | Description | Default |
451
+ |----------|-------------|---------|
452
+ | `$breadcrumb-padding-y` | Vertical padding | `0.25rem` |
453
+ | `$breadcrumb-padding-x` | Horizontal padding | `1rem` |
454
+ | `$breadcrumb-margin-bottom` | Bottom margin | `0` |
455
+ | `$breadcrumb-bg` | Background color | `white` |
456
+ | `$breadcrumb-divider` | Divider character | `'>'` |
457
+ | `$breadcrumb-divider-flipped` | RTL divider character | Same as `$breadcrumb-divider` |
458
+ | `$breadcrumb-border-radius` | Border radius | `50rem` |
459
+ | `$breadcrumb-active-color` | Active item color | `black` |
460
+
461
+
462
+ ## Contributing
463
+
464
+ We appreciate your interest in contributing to Hub Breadcrumb! Here's how you can help:
465
+
466
+ ### Development Setup
467
+
468
+ 1. Clone the repository
469
+ ```bash
470
+ git clone https://github.com/carlos-morcillo/ng-hub-ui-breadcrumbs.git
471
+ cd ng-hub-ui-breadcrumbs
472
+ ```
473
+
474
+ 2. Install dependencies
475
+ ```bash
476
+ npm install
477
+ ```
478
+
479
+ 3. Start the development server
480
+ ```bash
481
+ npm start
482
+ ```
483
+
484
+ ### Testing
485
+
486
+ Run the test suite:
487
+ ```bash
488
+ # Unit tests
489
+ npm run test
490
+
491
+ # E2E tests
492
+ npm run e2e
493
+
494
+ # Test coverage
495
+ npm run test:coverage
496
+ ```
497
+
498
+ ### Project Structure
499
+
500
+ ```
501
+ ng-hub-ui-breadcrumbs/
502
+ ├── src/
503
+ │ ├── lib/
504
+ │ │ ├── components/
505
+ │ │ │ ├── hub-breadcrumb.component.ts
506
+ │ │ │ ├── hub-breadcrumb.component.spec.ts
507
+ │ │ │ └── hub-breadcrumb.component.scss
508
+ │ │ ├── directives/
509
+ │ │ │ └── hub-breadcrumb-item.directive.ts
510
+ │ │ ├── services/
511
+ │ │ │ └── hub-breadcrumb.service.ts
512
+ │ │ └── interfaces/
513
+ │ │ └── breadcrumb-item.ts
514
+ │ └── public-api.ts
515
+ ├── README.md
516
+ └── package.json
517
+ ```
518
+
519
+ ### Commit Guidelines
520
+
521
+ We follow [Conventional Commits](https://www.conventionalcommits.org/):
522
+
523
+ - `feat:` New features
524
+ - `fix:` Bug fixes
525
+ - `docs:` Documentation changes
526
+ - `style:` Code style changes (formatting, etc)
527
+ - `refactor:` Code refactors
528
+ - `test:` Adding or updating tests
529
+ - `chore:` Maintenance tasks
530
+
531
+ Example:
532
+ ```bash
533
+ git commit -m "feat: add custom divider support"
534
+ ```
535
+
536
+ ### Pull Request Process
537
+
538
+ 1. Fork the repository
539
+ 2. Create a new branch:
540
+ ```bash
541
+ git checkout -b feat/my-new-feature
542
+ ```
543
+ 3. Make your changes
544
+ 4. Add tests for any new functionality
545
+ 5. Update documentation if needed
546
+ 6. Submit a Pull Request
547
+
548
+ ### Development Guidelines
549
+
550
+ - Write unit tests for new features
551
+ - Follow Angular style guide
552
+ - Update documentation for API changes
553
+ - Maintain backward compatibility
554
+ - Add comments for complex logic
555
+
556
+ ### Issues
557
+
558
+ Before creating an issue, please:
559
+
560
+ - Check existing issues
561
+ - Use the issue template
562
+ - Include reproduction steps
563
+ - Specify your environment
564
+
565
+ ### Code Style
566
+
567
+ We follow the [Angular Style Guide](https://angular.io/guide/styleguide):
568
+
569
+ - Use TypeScript
570
+ - Follow BEM for CSS
571
+ - Maintain consistent naming
572
+ - Add JSDoc comments
573
+
574
+ ## Support the Project
575
+
576
+ If you find this project helpful and would like to support its development, you can buy me a coffee:
577
+
578
+ [!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/carlosmorcillo)
579
+
580
+ Your support is greatly appreciated and helps maintain and improve this project!
581
+
582
+ ## License
583
+
584
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
585
+
586
+ ---
587
+
588
+ Made with ❤️ by [Carlos Morcillo Fernández]
23
589
 
24
- To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ng-hub-ui-breadcrumbs",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "A flexible and reusable breadcrumb component for Angular applications that automatically generates breadcrumbs based on routing configuration",
5
5
  "keywords": [
6
6
  "angular",
Binary file