Skip to content

Commit f5206dc

Browse files
committed
chore: add packaged module
1 parent f4ca30d commit f5206dc

16 files changed

+1231
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# See http://help.github.com/ignore-files/ for more about ignoring files.
22

33
# compiled output
4-
/dist
54
/tmp
65
/out-tsc
76
# Only exists if Bazel was run

dist/angular-code-input/LICENSE

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Copyright (c) 2019 Alexander Dmitrenko
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall
11+
be included in all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

dist/angular-code-input/README.md

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# Code/pincode input component for angular
2+
3+
![](https://img.shields.io/npm/dm/angular-code-input?color=55aa33)
4+
![](https://img.shields.io/github/stars/AlexMiniApps/angular-code-input)
5+
![](https://badgen.net/badge/icon/typescript?icon=typescript&label&color=99aabb)
6+
![](https://img.shields.io/github/license/AlexMiniApps/angular-code-input?color=00ccbb)
7+
8+
Robust and <b>tested</b> code (number/chars) input component for Angular 7 - 16+ projects.<br />
9+
Ionic 4 - 7+ is supported, can be used in iOS and Android.<br />
10+
<b>Clipboard</b> events are supported.
11+
12+
Star it to inspire us to build the best component! <img src="https://github.com/AlexMiniApps/angular-code-input/blob/master/star.jpg" alt="Star"/>
13+
14+
Preview
15+
16+
![](https://github.com/AlexMiniApps/angular-code-input/blob/master/preview1.gif)
17+
18+
![](https://github.com/AlexMiniApps/angular-code-input/blob/master/preview2.gif)
19+
20+
## Supported platforms
21+
22+
<b>Angular</b> 7 - 16+<br />
23+
<b>Ionic</b> 4 - 7+<br />
24+
Mobile browsers and WebViews on: <b>Android</b> and <b>iOS</b><br />
25+
Desktop browsers: <b>Chrome, Firefox, Safari, Edge v.79 +</b><br />
26+
Other browsers: <b>Edge v.41 - 44</b> (without code hidden feature)
27+
28+
## Installation
29+
30+
$ npm install --save angular-code-input
31+
32+
Choose the version corresponding to your Angular version:
33+
34+
| Angular | angular-code-input |
35+
|------------|--------------------|
36+
| 16+ | 2.x+ |
37+
| 7-15 | 1.x+ |
38+
39+
## Usage
40+
41+
Import `CodeInputModule` in your app module or page module:
42+
43+
```ts
44+
import { CodeInputModule } from 'angular-code-input';
45+
46+
@NgModule({
47+
imports: [
48+
// ...
49+
CodeInputModule
50+
]
51+
})
52+
```
53+
54+
It is possible to configure the component across the app using the root config. In such case the import will look as follows:
55+
```ts
56+
import { CodeInputModule } from 'angular-code-input';
57+
58+
@NgModule({
59+
imports: [
60+
// ...
61+
CodeInputModule.forRoot({
62+
codeLength: 6,
63+
isCharsCode: true,
64+
code: 'abcdef'
65+
}),
66+
]
67+
})
68+
```
69+
70+
Include the component on page template HTML:
71+
72+
```html
73+
<code-input [isCodeHidden]="true"
74+
[codeLength]="5"
75+
(codeChanged)="onCodeChanged($event)"
76+
(codeCompleted)="onCodeCompleted($event)">
77+
</code-input>
78+
```
79+
80+
Inside a page script:
81+
82+
```ts
83+
// this called every time when user changed the code
84+
onCodeChanged(code: string) {
85+
}
86+
87+
// this called only if user entered full code
88+
onCodeCompleted(code: string) {
89+
}
90+
```
91+
92+
## Configuration
93+
94+
#### View
95+
96+
It is possible to configure the component via CSS vars
97+
<br />or using `::ng-deep` (deprecated) angular CSS selector
98+
[::ng-deep](https://angular.io/guide/component-styles#deprecated-deep--and-ng-deep)
99+
100+
CSS vars:
101+
102+
| CSS Var | Description |
103+
|--------------------------------------------------------------|--------------------------------------------------------|
104+
| `--text-security-type: disc;` | Text presentation type when the isCodeHidden is enabled |
105+
| `--item-spacing: 4px;` | Horizontal space between input items |
106+
| `--item-height: 4.375em;` | Height of input items |
107+
| `--item-border: 1px solid #dddddd;` | Border of input item for an empty value |
108+
| `--item-border-bottom: 1px solid #dddddd;` | Bottom border of input item for an empty value |
109+
| `--item-border-has-value: 1px solid #dddddd;` | Border of input item with a value |
110+
| `--item-border-bottom-has-value: 1px solid #dddddd;` | Bottom border of input item with a value |
111+
| `--item-border-focused: 1px solid #dddddd;` | Border of input item when focused |
112+
| `--item-border-bottom-focused: 1px solid #dddddd;` | Bottom border of input item when focused |
113+
| `--item-shadow-focused: 0px 1px 5px rgba(221, 221, 221, 1);` | Shadow of input item when focused |
114+
| `--item-border-radius: 5px;` | Border radius of input item |
115+
| `--item-background: transparent;` | Input item background |
116+
| `--item-font-weight: 300;` | Font weight of input item |
117+
| `--color: #171516;` | Text color of input items |
118+
119+
Example with only bottom borders:
120+
121+
````
122+
/* inside page styles*/
123+
...
124+
code-input {
125+
--item-spacing: 10px;
126+
--item-height: 3em;
127+
--item-border: none;
128+
--item-border-bottom: 2px solid #dddddd;
129+
--item-border-has-value: none;
130+
--item-border-bottom-has-value: 2px solid #888888;
131+
--item-border-focused: none;
132+
--item-border-bottom-focused: 2px solid #809070;
133+
--item-shadow-focused: none;
134+
--item-border-radius: 0px;
135+
}
136+
...
137+
````
138+
139+
#### Component options
140+
141+
| Property | Type | Default | Description |
142+
|----------|:-------:|:-----:|----------|
143+
| <b>`codeLength`</b> | number | 4 | Length of input code |
144+
| <b>`inputType`</b> | string | tel | Type of the input DOM elements like `<input [type]="inputType"/>` default '`tel'` |
145+
| <b>`isCodeHidden`</b> | boolean | false | When `true` inputted code chars will be shown as asterisks (points) |
146+
| <b>`isCharsCode`</b> | boolean | false | When `true` inputted code can contain any char and not only digits from 0 to 9. If the input parameter <b>`code`</b> contains non digits chars and `isCharsCode` is `false` the value will be ignored |
147+
| <b>`isPrevFocusableAfterClearing`</b> | boolean | true | When `true` after the input value deletion the caret will be moved to the previous input immediately. If `false` then after the input value deletion the caret will stay on the current input and be moved to the previous input only if the current input is empty |
148+
| <b>`isFocusingOnLastByClickIfFilled`</b> | boolean | false | When `true` and the code is filled then the focus will be moved to the last input element when clicked |
149+
| <b>`initialFocusField`</b> | number | - | The index of the input box for initial focusing. When the component will appear the focus will be placed on the input with this index. <br/> Note: If you need to dynamically hide the component it is needed to use <b>*ngIf</b> directive instead of the `[hidden]` attribute |
150+
| <b>`code`</b> | string / number | - | The input code value for the component. If the parameter contains non digits chars and `isCharsCode` is `false` the value will be <b>ignored</b> |
151+
| <b>`disabled`</b> | boolean | false | When `true` then the component will not handle user actions, like in regular html input element with the `disabled` attribute |
152+
| <b>`autocapitalize`</b> | string | - | The autocapitalize attribute is an enumerated attribute that controls whether and how text input is automatically capitalized as it is entered/edited by the user |
153+
154+
#### Events
155+
156+
| Event | Description |
157+
|----------|--------------------|
158+
| `codeChanged` | Will be called every time when a user changed the code |
159+
| `codeCompleted` | Will be called only if a user entered full code |
160+
161+
## Methods
162+
163+
For calling the component's methods it is required to access the component inside the template or page script.
164+
It can be reached as follows.
165+
166+
Inside the page template HTML add a template ref:
167+
168+
```html
169+
<code-input
170+
...
171+
#codeInput
172+
...
173+
>
174+
</code-input>
175+
```
176+
177+
Inside a page script attach the component:
178+
179+
```ts
180+
...
181+
// adding to the imports
182+
import {CodeInputComponent} from 'angular-code-input';
183+
...
184+
// adding to the page props
185+
@ViewChild('codeInput') codeInput !: CodeInputComponent;
186+
...
187+
// calling the component's methods somewhere in the page.
188+
// IMPORTANT: it will be accessible only after the view initialization!
189+
this.codeInput.reset();
190+
```
191+
192+
| Method | Description |
193+
|----------------|--------------------|
194+
| <b>`focusOnField(index: number): void`</b> | Focuses the input caret on the input box with the passed index |
195+
| <b>`reset(isChangesEmitting = false): void`</b> | <p>Resets the component values in the following way:</p><p>if the `code` option is supplied then the value will be reset to the `code` option value. If the `code` option is not supplied then the component will be reset to empty values.</p><p>if the `initialFocusField` option is supplied then the caret will be focused in that filed after reset.</p><p>if the `isChangesEmitting` param is passed then changes will be emitted</p>|
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* Generated bundle index. Do not edit.
3+
*/
4+
export * from './public-api';
5+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYW5ndWxhci1jb2RlLWlucHV0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vYW5ndWxhci1jb2RlLWlucHV0L3NyYy9hbmd1bGFyLWNvZGUtaW5wdXQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7O0dBRUc7QUFFSCxjQUFjLGNBQWMsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogR2VuZXJhdGVkIGJ1bmRsZSBpbmRleC4gRG8gbm90IGVkaXQuXG4gKi9cblxuZXhwb3J0ICogZnJvbSAnLi9wdWJsaWMtYXBpJztcbiJdfQ==
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { InjectionToken } from '@angular/core';
2+
export const CodeInputComponentConfigToken = new InjectionToken('CodeInputComponentConfig');
3+
export const defaultComponentConfig = {
4+
codeLength: 4,
5+
inputType: 'tel',
6+
inputMode: 'numeric',
7+
initialFocusField: undefined,
8+
isCharsCode: false,
9+
isCodeHidden: false,
10+
isPrevFocusableAfterClearing: true,
11+
isFocusingOnLastByClickIfFilled: false,
12+
code: undefined,
13+
disabled: false,
14+
autocapitalize: undefined
15+
};
16+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29kZS1pbnB1dC5jb21wb25lbnQuY29uZmlnLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vYW5ndWxhci1jb2RlLWlucHV0L3NyYy9saWIvY29kZS1pbnB1dC5jb21wb25lbnQuY29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBQyxjQUFjLEVBQUMsTUFBTSxlQUFlLENBQUM7QUFFN0MsTUFBTSxDQUFDLE1BQU0sNkJBQTZCLEdBQUcsSUFBSSxjQUFjLENBQTJCLDBCQUEwQixDQUFDLENBQUM7QUFnQnRILE1BQU0sQ0FBQyxNQUFNLHNCQUFzQixHQUE2QjtJQUM5RCxVQUFVLEVBQUUsQ0FBQztJQUNiLFNBQVMsRUFBRSxLQUFLO0lBQ2hCLFNBQVMsRUFBRSxTQUFTO0lBQ3BCLGlCQUFpQixFQUFFLFNBQVM7SUFDNUIsV0FBVyxFQUFFLEtBQUs7SUFDbEIsWUFBWSxFQUFFLEtBQUs7SUFDbkIsNEJBQTRCLEVBQUUsSUFBSTtJQUNsQywrQkFBK0IsRUFBRSxLQUFLO0lBQ3RDLElBQUksRUFBRSxTQUFTO0lBQ2YsUUFBUSxFQUFFLEtBQUs7SUFDZixjQUFjLEVBQUUsU0FBUztDQUMxQixDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHtJbmplY3Rpb25Ub2tlbn0gZnJvbSAnQGFuZ3VsYXIvY29yZSc7XHJcblxyXG5leHBvcnQgY29uc3QgQ29kZUlucHV0Q29tcG9uZW50Q29uZmlnVG9rZW4gPSBuZ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