@amro93/ngb-select 0.1.3 → 0.1.6

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,64 +1,235 @@
1
- # NgbSelect
1
+ # Ngb-Select (Angular Bootstrap Select Component)
2
2
 
3
- This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 21.2.0.
3
+ [![NPM Version](https://img.shields.io/npm/v/@amro93/ngb-select.svg)](https://www.npmjs.com/package/@amro93/ngb-select)
4
+ [![CI/CD Pipeline](https://github.com/amro93/ngb-select/actions/workflows/deploy.yml/badge.svg)](https://github.com/amro93/ngb-select/actions)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
6
 
5
- ## Code scaffolding
7
+ A comprehensive, lightweight Angular Standalone select component that utilizes **pure Bootstrap 5 classes** (no external UI libraries required). It covers all advanced features found in modern select components, optimized for standard Bootstrap environments.
6
8
 
7
- Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
9
+ ---
8
10
 
9
- ```bash
10
- ng generate component component-name
11
- ```
11
+ ## 🚀 Features at a Glance
12
12
 
13
- For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
13
+ - 📦 **Standalone Architecture** - Modern Angular 15+ design, easy to import without NgModules.
14
+ - 🎨 **Pure Bootstrap 5** - Uses `.form-select`, `.dropdown-menu`, and `.list-group` internally. No extra CSS payload.
15
+ - 🔍 **Filtering & Match Modes** - Fast, client-side search supporting `contains`, `startsWith`, `endsWith`, `equals`.
16
+ - 🗂️ **Grouping** - Categorize options with nested headers.
17
+ - 🛠️ **Advanced Templating** - Replace default text with fully custom DOM for items, headers, footers, and selected states.
18
+ - ⌨️ **Forms Native & Signals** - Implements `ControlValueAccessor` for seamless `ngModel`, `FormControl` (Reactive Forms), and modern Angular `model()` Signal support.
19
+ - 🛡️ **Robust Fallbacks** - Defensively programmed to gracefully handle `null`, `undefined`, and empty strings across inputs.
20
+ - ♿ **Accessible** - ARIA roles implemented (`combobox`, `listbox`, `option`) alongside keyboard navigation.
21
+ - ⚡ **Editable Combobox** - Allows custom user typing directly into the select input.
22
+ - 🎯 **Focus on Open** - Programmatically scroll and focus a specific option index when the popup opens.
14
23
 
15
- ```bash
16
- ng generate --help
17
- ```
24
+ ---
18
25
 
19
- ## Building
26
+ ## 📦 Installation
20
27
 
21
- To build the library, run:
28
+ Install `@amro93/ngb-select` along with peer dependencies:
22
29
 
23
30
  ```bash
24
- ng build ngb-select
31
+ npm install @amro93/ngb-select bootstrap bootstrap-icons
25
32
  ```
26
33
 
27
- This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
34
+ Ensure Bootstrap 5 CSS is included in your `angular.json` or `src/styles.scss`:
28
35
 
29
- ### Publishing the Library
36
+ ```scss
37
+ @import 'bootstrap/scss/bootstrap';
38
+ @import 'bootstrap-icons/font/bootstrap-icons.css';
39
+ ```
30
40
 
31
- Once the project is built, you can publish your library by following these steps:
41
+ ---
42
+
43
+ ## 💻 Usage Examples
44
+
45
+ ### 1. Basic Setup (Template Driven)
46
+
47
+ ```typescript
48
+ import { Component } from '@angular/core';
49
+ import { FormsModule } from '@angular/forms';
50
+ import { NgbSelectComponent } from '@amro93/ngb-select';
51
+
52
+ @Component({
53
+ standalone: true,
54
+ imports: [NgbSelectComponent, FormsModule],
55
+ template: `
56
+ <ngb-select
57
+ [options]="cities"
58
+ [(ngModel)]="selectedCity"
59
+ optionLabel="name"
60
+ optionValue="code"
61
+ placeholder="Select a City"
62
+ >
63
+ </ngb-select>
64
+ `,
65
+ })
66
+ export class AppComponent {
67
+ cities = [
68
+ { name: 'New York', code: 'NY' },
69
+ { name: 'Rome', code: 'RM' },
70
+ { name: 'London', code: 'LDN' },
71
+ ];
72
+ selectedCity: string = 'NY';
73
+ }
74
+ ```
32
75
 
33
- 1. Navigate to the `dist` directory:
76
+ ---
77
+
78
+ ### 2. Reactive Forms with Validation
79
+
80
+ ```typescript
81
+ import { Component } from '@angular/core';
82
+ import { ReactiveFormsModule, FormGroup, FormControl, Validators } from '@angular/forms';
83
+ import { NgbSelectComponent } from '@amro93/ngb-select';
84
+
85
+ @Component({
86
+ standalone: true,
87
+ imports: [NgbSelectComponent, ReactiveFormsModule],
88
+ template: `
89
+ <form [formGroup]="form">
90
+ <ngb-select
91
+ [options]="countries"
92
+ formControlName="selectedCountry"
93
+ optionLabel="name"
94
+ optionValue="code"
95
+ [invalid]="form.get('selectedCountry')?.invalid && form.get('selectedCountry')?.touched"
96
+ [showClear]="true"
97
+ placeholder="Select Country"
98
+ >
99
+ </ngb-select>
100
+ </form>
101
+ `,
102
+ })
103
+ export class AppComponent {
104
+ form = new FormGroup({
105
+ selectedCountry: new FormControl(null, [Validators.required]),
106
+ });
107
+ }
108
+ ```
34
109
 
35
- ```bash
36
- cd dist/ngb-select
37
- ```
110
+ ---
111
+
112
+ ### 3. Filtering and Custom Search Modes
113
+
114
+ ```html
115
+ <ngb-select
116
+ [options]="countries"
117
+ [(ngModel)]="selectedCountry"
118
+ optionLabel="name"
119
+ [filter]="true"
120
+ filterBy="name,code"
121
+ filterMatchMode="startsWith"
122
+ filterPlaceholder="Search countries..."
123
+ [showClear]="true"
124
+ placeholder="Select a Country"
125
+ >
126
+ </ngb-select>
127
+ ```
38
128
 
39
- 2. Run the `npm publish` command to publish your library to the npm registry:
40
- ```bash
41
- npm publish
42
- ```
129
+ ---
130
+
131
+ ### 4. Custom Templating
132
+
133
+ Override default rendering for options and the selected value using `<ng-template>`:
134
+
135
+ ```html
136
+ <ngb-select [options]="users" [(ngModel)]="selectedUser" optionLabel="name">
137
+ <!-- Custom Selected Item -->
138
+ <ng-template #selectedItem let-user>
139
+ <div class="d-flex align-items-center gap-2">
140
+ <img [src]="user.avatar" class="rounded-circle" width="22" height="22" />
141
+ <strong>{{ user.name }}</strong>
142
+ </div>
143
+ </ng-template>
144
+
145
+ <!-- Custom Dropdown Item -->
146
+ <ng-template #item let-user>
147
+ <div class="d-flex align-items-center justify-content-between w-100 py-1">
148
+ <div class="d-flex align-items-center gap-2">
149
+ <img [src]="user.avatar" class="rounded-circle" width="28" height="28" />
150
+ <div>
151
+ <div class="fw-semibold">{{ user.name }}</div>
152
+ <small class="text-muted">{{ user.email }}</small>
153
+ </div>
154
+ </div>
155
+ <span class="badge bg-primary-subtle text-primary-emphasis">{{ user.role }}</span>
156
+ </div>
157
+ </ng-template>
158
+ </ngb-select>
159
+ ```
43
160
 
44
- ## Running unit tests
161
+ ---
162
+
163
+ ### 5. Searchable Multi-Select with Checkboxes & Chips
164
+
165
+ ```html
166
+ <ngb-select
167
+ [options]="countries"
168
+ [(ngModel)]="selectedCountries"
169
+ optionLabel="name"
170
+ optionValue="code"
171
+ [multiple]="true"
172
+ display="chip"
173
+ [filter]="true"
174
+ filterBy="name,code"
175
+ searchPlaceholder="Search countries by name or code..."
176
+ [showSelectAll]="true"
177
+ [showClear]="true"
178
+ placeholder="Select Countries"
179
+ >
180
+ </ngb-select>
181
+ ```
45
182
 
46
- To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
183
+ ---
184
+
185
+ ### 6. Grouped Options
186
+
187
+ ```html
188
+ <ngb-select
189
+ [options]="groupedCars"
190
+ [(ngModel)]="selectedCar"
191
+ [group]="true"
192
+ optionGroupLabel="brand"
193
+ optionGroupChildren="cars"
194
+ optionLabel="name"
195
+ optionValue="value"
196
+ placeholder="Choose vehicle brand"
197
+ >
198
+ </ngb-select>
199
+ ```
47
200
 
48
- ```bash
49
- ng test
201
+ ---
202
+
203
+ ### 7. RTL (Right-to-Left) & Arabic Support
204
+
205
+ ```html
206
+ <div dir="rtl" lang="ar">
207
+ <ngb-select
208
+ [options]="arabicCountries"
209
+ [(ngModel)]="selectedCountry"
210
+ optionLabel="name"
211
+ optionValue="code"
212
+ [filter]="true"
213
+ filterPlaceholder="ابحث عن دولة..."
214
+ placeholder="اختر الدولة"
215
+ emptyMessage="لا توجد نتائج"
216
+ >
217
+ </ngb-select>
218
+ </div>
50
219
  ```
51
220
 
52
- ## Running end-to-end tests
221
+ ---
53
222
 
54
- For end-to-end (e2e) testing, run:
223
+ ## 📖 Documentation & Links
55
224
 
56
- ```bash
57
- ng e2e
58
- ```
225
+ - 🌐 **[Live Demo & Showcase](https://amro93.github.io/ngb-select/)**
226
+ - ⚡ **[StackBlitz Sandbox](https://stackblitz.com/github/amro93/ngb-select)**
227
+ - 📘 **[Architecture & Features Guide](https://github.com/amro93/ngb-select/blob/main/docs/01-architecture-and-features.md)**
228
+ - 📘 **[API & Interfaces Reference](https://github.com/amro93/ngb-select/blob/main/docs/02-api-and-interfaces.md)**
229
+ - 📘 **[Installation & Setup Guide](https://github.com/amro93/ngb-select/blob/main/docs/08-installation-guide.md)**
59
230
 
60
- Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
231
+ ---
61
232
 
62
- ## Additional Resources
233
+ ## 📄 License
63
234
 
64
- For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
235
+ Distributed under the MIT License. See [LICENSE](https://github.com/amro93/ngb-select/blob/main/LICENSE) for more information.