|
1 | | -# MyWorkspace |
| 1 | +# Code/pincode input component for angular |
2 | 2 |
|
3 | | -This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 7.3.9. |
| 3 | +Code (number/chars) input component for angular 7+ projects.<br /> |
| 4 | +Ionic 4+ is supported, can be used in iOS and Android. |
4 | 5 |
|
5 | | -## Development server |
| 6 | +Preview |
6 | 7 |
|
7 | | -Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. |
| 8 | +## Installation |
8 | 9 |
|
9 | | -## Code scaffolding |
| 10 | + $ npm install --save angular-code-input |
10 | 11 |
|
11 | | -Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. |
| 12 | +## Usage |
12 | 13 |
|
13 | | -## Build |
| 14 | +Import `CodeInputModule` in your app module or page module: |
14 | 15 |
|
15 | | -Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. |
| 16 | +```ts |
| 17 | +import { CodeInputModule } from 'angular-code-input'; |
16 | 18 |
|
17 | | -## Running unit tests |
| 19 | +@NgModule({ |
| 20 | + imports: [ |
| 21 | + // ... |
| 22 | + CodeInputModule |
| 23 | + ] |
| 24 | +}) |
| 25 | +``` |
18 | 26 |
|
19 | | -Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). |
| 27 | +Include the component on page template HTML: |
20 | 28 |
|
21 | | -## Running end-to-end tests |
| 29 | +```html |
| 30 | + <code-input [isCodeHidden]="false" |
| 31 | + [isNonDigitsCode]="false" |
| 32 | + [codeLength]="4" |
| 33 | + (codeChanged)="onCodeChanged($event)" |
| 34 | + (codeCompleted)="onCodeCompleted($event)"> |
| 35 | + </code-input> |
| 36 | +``` |
22 | 37 |
|
23 | | -Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). |
| 38 | +Inside a page script: |
24 | 39 |
|
25 | | -## Further help |
| 40 | +```ts |
| 41 | + // this called every time when user changed the code |
| 42 | + onCodeChanged(code: string) { |
| 43 | + } |
| 44 | + |
| 45 | + // this called only if user entered full code |
| 46 | + onCodeCompleted(code: string) { |
| 47 | + } |
| 48 | +``` |
| 49 | + |
| 50 | +## Configuration |
| 51 | + |
| 52 | +#### View |
| 53 | + |
| 54 | +It is possible to configure the component via CSS vars |
| 55 | +<br />or using `::ng-deep` (deprecated) angular CSS selector |
| 56 | +[::ng-deep](https://angular.io/guide/component-styles#deprecated-deep--and-ng-deep) |
| 57 | + |
| 58 | +CSS vars: |
| 59 | + |
| 60 | +`--text-security-type: disc;` - text presentation type when the isCodeHidden is enabled<br /> |
| 61 | +`--item-spacing: 4px;` - horizontal space between input items <br /> |
| 62 | +`--item-height: 4.375em;` - height of input items <br /> |
| 63 | +`--item-border: 1px solid #dddddd;` - border of input item for an empty value <br /> |
| 64 | +`--item-border-bottom: 1px solid #dddddd;` - bottom border of input item for an empty value <br /> |
| 65 | +`--item-border-has-value: 1px solid #dddddd;` - border of input item with a value <br /> |
| 66 | +`--item-border-bottom-has-value: 1px solid #dddddd;` - bottom border of input item with a value <br /> |
| 67 | +`--item-border-focused: 1px solid #dddddd;` - border of input item when focused <br /> |
| 68 | +`--item-border-bottom-focused: 1px solid #dddddd;` - bottom border of input item when focused <br /> |
| 69 | +`--item-shadow-focused: 0px 1px 5px rgba(221, 221, 221, 1);` - shadow of input item when focused <br /> |
| 70 | +`--item-border-radius: 5px;` - border radius of input item <br /> |
| 71 | +`--item-background: transparent;` - input item background <br /> |
| 72 | +`--color: #171516;` - text color of input items <br /> |
| 73 | + |
| 74 | +Example with only bottom borders: |
| 75 | + |
| 76 | +```` |
| 77 | +/* inside page styles*/ |
| 78 | +... |
| 79 | + code-input { |
| 80 | + --item-spacing: 10px; |
| 81 | + --item-height: 3em; |
| 82 | + --item-border: none; |
| 83 | + --item-border-bottom: 2px solid #dddddd; |
| 84 | + --item-border-has-value: none; |
| 85 | + --item-border-bottom-has-value: 2px solid #888888; |
| 86 | + --item-border-focused: none; |
| 87 | + --item-border-bottom-focused: 2px solid #809070; |
| 88 | + --item-shadow-focused: none; |
| 89 | + --item-border-radius: 0px; |
| 90 | + } |
| 91 | +... |
| 92 | +```` |
| 93 | + |
| 94 | +#### Component options |
| 95 | + |
| 96 | +`codeLength: number` - length of input code <br /> |
| 97 | +`isCodeHidden: boolean` - when `true` inputted code chars will be shown as asterisks (points)<br /> |
| 98 | +`isNonDigitsCode: boolean` - when `true` inputted code can contain any char and not only digits from 0 to 9 <br /> |
| 99 | + |
| 100 | +#### Events |
| 101 | + |
| 102 | +`codeChanged` - will be called every time when a user changed the code <br /> |
| 103 | +`codeCompleted` - will be called only if a user entered full code |
26 | 104 |
|
27 | | -To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). |
|
0 commit comments