|
1 | | -# @ngbootstrap (standalone library) |
| 1 | +# @ngbootstrap |
2 | 2 |
|
3 | | -This folder now contains everything needed to build and publish the `@ngbootstrap` |
4 | | -Angular library outside of the Nx workspace. It uses `ng-packagr` directly, so you |
5 | | -can copy the folder into its own repository and continue working without Nx. |
| 3 | +Angular UI library providing datagrid, drag‑and‑drop, pagination, and stepper components with Bootstrap‑friendly styling. |
6 | 4 |
|
7 | | -## Local development |
| 5 | +## Features |
| 6 | + |
| 7 | +- Datagrid – sortable, filterable, paginated, editable table with export (PDF/Excel) support and accessible templates. |
| 8 | +- Drag & drop – lightweight list and item directives with keyboard‑friendly a11y helpers. |
| 9 | +- Pagination – standalone Bootstrap‑styled pagination component. |
| 10 | +- Stepper – horizontal/vertical stepper with custom labels, error states, theming hooks, and keyboard support. |
| 11 | +- Angular + Bootstrap first – built for modern Angular (v17–20) and works with plain Bootstrap CSS; Material/Tailwind can be layered via custom styles. |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +```bash |
| 16 | +npm install @ngbootstrap |
| 17 | +``` |
| 18 | + |
| 19 | +Make sure your app: |
| 20 | + |
| 21 | +- Uses Angular 17–20. |
| 22 | +- Includes Bootstrap CSS (for example in `angular.json` or global styles): |
| 23 | + |
| 24 | +```css |
| 25 | +@import 'bootstrap/dist/css/bootstrap.min.css'; |
| 26 | +``` |
| 27 | + |
| 28 | +## Usage overview |
| 29 | + |
| 30 | +All components are standalone, so you import them directly into your feature components. |
| 31 | + |
| 32 | +### Datagrid |
| 33 | + |
| 34 | +```ts |
| 35 | +import { Component } from '@angular/core'; |
| 36 | +import { Datagrid } from '@ngbootstrap/datagrid'; |
| 37 | + |
| 38 | +interface User { |
| 39 | + id: number; |
| 40 | + name: string; |
| 41 | + email: string; |
| 42 | +} |
| 43 | + |
| 44 | +@Component({ |
| 45 | + standalone: true, |
| 46 | + selector: 'app-users', |
| 47 | + imports: [Datagrid], |
| 48 | + template: ` |
| 49 | + <ngb-datagrid |
| 50 | + [columns]="columns" |
| 51 | + [data]="rows" |
| 52 | + [enableSorting]="true" |
| 53 | + [enableFiltering]="true" |
| 54 | + [enablePagination]="true" |
| 55 | + [pageSize]="10" |
| 56 | + (rowSave)="onRowSave($event)" |
| 57 | + ></ngb-datagrid> |
| 58 | + `, |
| 59 | +}) |
| 60 | +export class UsersComponent { |
| 61 | + columns = [ |
| 62 | + { field: 'id', header: 'ID', sortable: true }, |
| 63 | + { field: 'name', header: 'Name', sortable: true, filterable: true }, |
| 64 | + { field: 'email', header: 'Email', sortable: true, filterable: true, type: 'email' }, |
| 65 | + ]; |
| 66 | + |
| 67 | + rows: User[] = [ |
| 68 | + { id: 1, name: 'Alice', email: 'alice@example.com' }, |
| 69 | + { id: 2, name: 'Bob', email: 'bob@example.com' }, |
| 70 | + ]; |
| 71 | + |
| 72 | + onRowSave(evt: { original: User; updated: User }) { |
| 73 | + // persist the update |
| 74 | + } |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +Key datagrid capabilities: |
| 79 | + |
| 80 | +- Sorting (`enableSorting`, `sortChange`). |
| 81 | +- Column/global filtering (`enableFiltering`, `enableGlobalFilter`, `filtersChange`). |
| 82 | +- Pagination (`enablePagination`, `pageSize`, `pageChange`). |
| 83 | +- Inline add/edit/delete (`enableAdd`, `enableEdit`, `enableDelete`, `rowAdd`, `rowSave`, `rowDelete`). |
| 84 | +- Export to PDF/Excel via `exportOptions`. |
| 85 | + |
| 86 | +### Pagination |
| 87 | + |
| 88 | +```ts |
| 89 | +import { Component } from '@angular/core'; |
| 90 | +import { NgbPaginationComponent } from '@ngbootstrap/pagination'; |
| 91 | + |
| 92 | +@Component({ |
| 93 | + standalone: true, |
| 94 | + selector: 'app-pager', |
| 95 | + imports: [NgbPaginationComponent], |
| 96 | + template: ` |
| 97 | + <ngb-pagination |
| 98 | + [(page)]="page" |
| 99 | + [pageSize]="pageSize" |
| 100 | + [collectionSize]="total" |
| 101 | + (pageChange)="loadPage($event)" |
| 102 | + ></ngb-pagination> |
| 103 | + `, |
| 104 | +}) |
| 105 | +export class PagerComponent { |
| 106 | + page = 1; |
| 107 | + pageSize = 10; |
| 108 | + total = 250; |
| 109 | + |
| 110 | + loadPage(p: number) { |
| 111 | + this.page = p; |
| 112 | + // fetch data for the page |
| 113 | + } |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +### Stepper |
| 118 | + |
| 119 | +```ts |
| 120 | +import { Component } from '@angular/core'; |
| 121 | +import { NgbStepperComponent } from '@ngbootstrap/stepper'; |
| 122 | +import { NgbStepperStep } from '@ngbootstrap/stepper'; |
| 123 | + |
| 124 | +@Component({ |
| 125 | + standalone: true, |
| 126 | + selector: 'app-wizard', |
| 127 | + imports: [NgbStepperComponent], |
| 128 | + template: ` |
| 129 | + <ngb-stepper |
| 130 | + [steps]="steps" |
| 131 | + [(selectedIndex)]="index" |
| 132 | + orientation="horizontal" |
| 133 | + [allowRevisit]="false" |
| 134 | + theme="bootstrap" |
| 135 | + (selectionChange)="onSelectionChange($event)" |
| 136 | + > |
| 137 | + <ng-template #stepContent let-index="index"> |
| 138 | + <ng-container [ngSwitch]="index"> |
| 139 | + <div *ngSwitchCase="0">Account step</div> |
| 140 | + <div *ngSwitchCase="1">Profile step</div> |
| 141 | + <div *ngSwitchCase="2">Confirm step</div> |
| 142 | + </ng-container> |
| 143 | + </ng-template> |
| 144 | + </ngb-stepper> |
| 145 | + `, |
| 146 | +}) |
| 147 | +export class WizardComponent { |
| 148 | + index = 0; |
| 149 | + |
| 150 | + steps: NgbStepperStep[] = [ |
| 151 | + { id: 'account', label: 'Account' }, |
| 152 | + { id: 'profile', label: 'Profile' }, |
| 153 | + { id: 'confirm', label: 'Confirm', optional: true }, |
| 154 | + ]; |
| 155 | + |
| 156 | + onSelectionChange(e: { previousIndex: number; currentIndex: number }) { |
| 157 | + // analytics, autosave, etc. |
| 158 | + } |
| 159 | +} |
| 160 | +``` |
| 161 | + |
| 162 | +Stepper highlights: |
| 163 | + |
| 164 | +- Horizontal/vertical variants via `orientation`. |
| 165 | +- Custom labels with the `ngbStepLabel` directive. |
| 166 | +- Label and content positioning (`labelPosition`, `contentPosition`). |
| 167 | +- Error states and messages (`errorMessage` on steps). |
| 168 | +- Controlled navigation (`allowRevisit`, `next()`, `prev()`, `reset()` and events). |
| 169 | +- Theming hooks via `theme` and CSS classes (`bootstrap`, `material`, `tailwind`). |
| 170 | + |
| 171 | +### Drag & drop |
| 172 | + |
| 173 | +```ts |
| 174 | +import { Component } from '@angular/core'; |
| 175 | +import { DndListDirective, DndItemDirective } from '@ngbootstrap/drag-drop'; |
| 176 | + |
| 177 | +@Component({ |
| 178 | + standalone: true, |
| 179 | + selector: 'app-drag-list', |
| 180 | + imports: [DndListDirective, DndItemDirective], |
| 181 | + template: ` |
| 182 | + <ul dndList [dndListData]="items"> |
| 183 | + <li *ngFor="let item of items" dndItem [dndItemData]="item"> |
| 184 | + {{ item }} |
| 185 | + </li> |
| 186 | + </ul> |
| 187 | + `, |
| 188 | +}) |
| 189 | +export class DragListComponent { |
| 190 | + items = ['One', 'Two', 'Three']; |
| 191 | +} |
| 192 | +``` |
| 193 | + |
| 194 | +Refer to the source under `src/drag-drop` and `src/datagrid`/`src/stepper` for full API details until a dedicated docs site is added. |
| 195 | + |
| 196 | +## Development |
| 197 | + |
| 198 | +Local setup: |
8 | 199 |
|
9 | 200 | ```bash |
10 | | -cd ngbootstrap |
11 | 201 | npm install |
12 | 202 | npm run lint |
| 203 | +npm test |
13 | 204 | npm run build |
14 | 205 | ``` |
15 | 206 |
|
16 | | -- The build artefacts end up in `ngbootstrap/dist/ngbootstrap`. |
17 | | -- `npm run test` executes the Jest setup provided by `jest-preset-angular`. |
| 207 | +- Build artefacts go to `dist/`. |
| 208 | +- Tests are powered by Jest + `jest-preset-angular`. |
18 | 209 |
|
19 | | -## Publishing |
| 210 | +## Releasing |
20 | 211 |
|
21 | | -After running `npm run build`, publish the generated package: |
| 212 | +Releases are automated via GitHub Actions: |
| 213 | + |
| 214 | +- Non‑`main` branches: |
| 215 | + - `.github/workflows/ci.yml` runs install, tests, build only. |
| 216 | +- `main` branch: |
| 217 | + - `.github/workflows/release.yml` bumps the patch version (`npm run build:release`), tags the commit as `vX.Y.Z`, and publishes to npm using `NPM_TOKEN` from repository secrets. |
22 | 218 |
|
23 | | -```bash |
24 | | -cd dist/ngbootstrap |
25 | | -npm publish --access public |
26 | | -``` |
27 | 219 |
|
28 | | -Feel free to rename the package in `package.json` if you plan to publish under |
29 | | -a different scope. |
|
0 commit comments