Skip to content

Commit f8cf905

Browse files
author
Matt Lewis
committed
feat: initial implementation
1 parent d1f5f75 commit f8cf905

16 files changed

+808
-50
lines changed

README.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,23 @@ Install through npm:
2929
npm install --save angular-text-input-autocomplete
3030
```
3131

32+
For older browsers you will need the `keyboardevent-key-polyfill` polyfill:
33+
```
34+
npm install --save keyboardevent-key-polyfill
35+
```
36+
3237
Then include in your apps module:
3338

3439
```typescript
40+
import { polyfill as keyboardEventKeyPolyfill } from 'keyboardevent-key-polyfill';
3541
import { NgModule } from '@angular/core';
3642
import { TextInputAutocompleteModule } from 'angular-text-input-autocomplete';
3743

44+
keyboardEventKeyPolyfill();
45+
3846
@NgModule({
3947
imports: [
40-
TextInputAutocompleteModule.forRoot()
48+
TextInputAutocompleteModule
4149
]
4250
})
4351
export class MyModule {}
@@ -48,9 +56,32 @@ Finally use in one of your apps components:
4856
import { Component } from '@angular/core';
4957

5058
@Component({
51-
template: '<hello-world></hello-world>'
59+
selector: 'mwl-demo-app',
60+
template: `
61+
<mwl-text-input-autocomplete-container>
62+
<textarea
63+
placeholder="Type @ to search..."
64+
class="form-control"
65+
rows="5"
66+
[(ngModel)]="formControlValue"
67+
mwlTextInputAutocomplete
68+
[findChoices]="findChoices"
69+
[getChoiceLabel]="getChoiceLabel">
70+
</textarea>
71+
</mwl-text-input-autocomplete-container>
72+
`
5273
})
53-
export class MyComponent {}
74+
export class DemoComponent {
75+
formControlValue = '';
76+
77+
findChoices(searchText: string) {
78+
return ['John', 'Jane', 'Jonny'].filter(item => item.toLowerCase().includes(searchText.toLowerCase()));
79+
}
80+
81+
getChoiceLabel(choice: string) {
82+
return `@${choice} `;
83+
}
84+
}
5485
```
5586

5687
You may also find it useful to view the [demo source](https://github.com/mattlewis92/angular-text-input-autocomplete/blob/master/demo/demo.component.ts).
@@ -67,6 +98,9 @@ You may also find it useful to view the [demo source](https://github.com/mattlew
6798
All documentation is auto-generated from the source via [compodoc](https://compodoc.github.io/compodoc/) and can be viewed here:
6899
https://mattlewis92.github.io/angular-text-input-autocomplete/docs/
69100

101+
## Related
102+
[angular-text-input-highlight](https://github.com/mattlewis92/angular-text-input-highlight) - a component for highlighting parts of a textarea
103+
70104
## Development
71105

72106
### Prepare your environment

custom-typings.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ declare module 'webpack-angular-externals';
33
declare module 'webpack-rxjs-externals';
44
declare module 'webpack-config-utils';
55
declare module 'offline-plugin';
6-
declare module '@mattlewis92/webpack-karma-die-hard';
6+
declare module '@mattlewis92/webpack-karma-die-hard';
7+
declare module 'textarea-caret';
8+
declare module 'keyboardevent-key-polyfill';

demo/demo.component.ts

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,55 @@
11
import { Component } from '@angular/core';
22

3+
// generated from http://listofrandomnames.com/index.cfm?textarea
4+
const names = [
5+
'Reda Marriott',
6+
'Cleta Cheatwood',
7+
'Penney Fortman',
8+
'Andy Mary',
9+
'Lilia Ricci',
10+
'Simonne Horne',
11+
'Marquis Macgillivray',
12+
'Ettie Koester',
13+
'Lovie Mero',
14+
'Gretta Ripley',
15+
'Jutta Casteel',
16+
'Donita Looby',
17+
'Patrice Guillotte',
18+
'Kirstin Sever',
19+
'Ezra Tremper',
20+
'Darell Monnier',
21+
'Elvira Balser',
22+
'Noriko Kluge',
23+
'Zulema Shake',
24+
'Kary Schreck'
25+
];
26+
327
@Component({
428
selector: 'mwl-demo-app',
5-
template: '<mwl-hello-world></mwl-hello-world>'
29+
template: `
30+
<mwl-text-input-autocomplete-container>
31+
<textarea
32+
placeholder="Type @ to search..."
33+
class="form-control"
34+
rows="5"
35+
[(ngModel)]="formControlValue"
36+
mwlTextInputAutocomplete
37+
[findChoices]="findChoices"
38+
[getChoiceLabel]="getChoiceLabel">
39+
</textarea>
40+
</mwl-text-input-autocomplete-container>
41+
`
642
})
7-
export class DemoComponent {}
43+
export class DemoComponent {
44+
formControlValue = '';
45+
46+
findChoices(searchText: string) {
47+
return names
48+
.filter(item => item.toLowerCase().includes(searchText.toLowerCase()))
49+
.slice(0, 5);
50+
}
51+
52+
getChoiceLabel(choice: string) {
53+
return `@${choice} `;
54+
}
55+
}

demo/demo.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { NgModule } from '@angular/core';
2+
import { FormsModule } from '@angular/forms';
23
import { BrowserModule } from '@angular/platform-browser';
34
import { TextInputAutocompleteModule } from '../src';
45
import { DemoComponent } from './demo.component';
56

67
@NgModule({
78
declarations: [DemoComponent],
8-
imports: [BrowserModule, TextInputAutocompleteModule.forRoot()],
9+
imports: [BrowserModule, TextInputAutocompleteModule, FormsModule],
910
bootstrap: [DemoComponent]
1011
})
1112
export class DemoModule {}

demo/entry.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ import 'core-js/es6/set';
1515
import 'core-js/es6/reflect';
1616
import 'core-js/es7/reflect';
1717
import 'zone.js/dist/zone';
18+
import { polyfill as keyboardEventKeyPolyfill } from 'keyboardevent-key-polyfill';
1819
import { enableProdMode } from '@angular/core';
1920
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
2021
import { DemoModule } from './demo.module';
2122

23+
// required for older browsers
24+
keyboardEventKeyPolyfill();
25+
2226
declare const ENV: string;
2327
if (ENV === 'production') {
2428
const { install } = require('offline-plugin/runtime'); // tslint:disable-line

package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"@angular/compiler": "^4.0.0",
6565
"@angular/compiler-cli": "^4.0.0",
6666
"@angular/core": "^4.0.0",
67+
"@angular/forms": "^4.4.4",
6768
"@angular/language-service": "^4.0.0",
6869
"@angular/platform-browser": "^4.0.0",
6970
"@angular/platform-browser-dynamic": "^4.0.0",
@@ -99,6 +100,7 @@
99100
"karma-mocha-reporter": "^2.2.3",
100101
"karma-sourcemap-loader": "^0.3.7",
101102
"karma-webpack": "^2.0.1",
103+
"keyboardevent-key-polyfill": "^1.1.0",
102104
"lint-staged": "^4.0.2",
103105
"mocha": "^4.0.1",
104106
"offline-plugin": "^4.8.3",
@@ -122,5 +124,8 @@
122124
},
123125
"peerDependencies": {
124126
"@angular/core": ">=4.0.0 <6.0.0"
127+
},
128+
"dependencies": {
129+
"textarea-caret": "^3.0.2"
125130
}
126131
}

src/hello-world.component.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
export * from './text-input-autocomplete.module';
2+
export {
3+
TextInputAutocompleteMenuComponent
4+
} from './text-input-autocomplete-menu.component';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'mwl-text-input-autocomplete-container',
5+
styles: [
6+
`
7+
:host {
8+
position: relative;
9+
display: block;
10+
}
11+
`
12+
],
13+
template: '<ng-content></ng-content>'
14+
})
15+
export class TextInputAutocompleteContainerComponent {}

0 commit comments

Comments
 (0)