├── .editorconfig
├── .gitignore
├── LICENSE
├── README.md
├── angular-code-input
├── CHANGELOG.md
├── LICENSE
├── README.md
├── karma.conf.js
├── ng-package.json
├── package.json
├── src
│ ├── lib
│ │ ├── code-input.component.config.ts
│ │ ├── code-input.component.html
│ │ ├── code-input.component.scss
│ │ ├── code-input.component.spec.ts
│ │ ├── code-input.component.ts
│ │ └── code-input.module.ts
│ ├── public-api.ts
│ └── test.ts
├── tsconfig.lib.json
├── tsconfig.lib.prod.json
├── tsconfig.spec.json
└── tslint.json
├── angular.json
├── package-lock.json
├── package.json
├── preview1.gif
├── preview2.gif
├── star.jpg
├── tsconfig.json
└── tslint.json
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see https://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | indent_style = space
7 | indent_size = 2
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
11 | [*.md]
12 | max_line_length = off
13 | trim_trailing_whitespace = false
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See http://help.github.com/ignore-files/ for more about ignoring files.
2 |
3 | # compiled output
4 | /dist
5 | /tmp
6 | /out-tsc
7 | # Only exists if Bazel was run
8 | /bazel-out
9 |
10 | # dependencies
11 | /node_modules
12 |
13 | # profiling files
14 | chrome-profiler-events.json
15 | speed-measure-plugin.json
16 |
17 | # IDEs and editors
18 | /.idea
19 | .project
20 | .classpath
21 | .c9/
22 | *.launch
23 | .settings/
24 | *.sublime-workspace
25 |
26 | # IDE - VSCode
27 | .vscode/*
28 | !.vscode/settings.json
29 | !.vscode/tasks.json
30 | !.vscode/launch.json
31 | !.vscode/extensions.json
32 | .history/*
33 |
34 | # misc
35 | /.sass-cache
36 | /connect.lock
37 | /coverage
38 | /libpeerconnection.log
39 | npm-debug.log
40 | yarn-error.log
41 | testem.log
42 | /typings
43 | .angular
44 |
45 | # System Files
46 | .DS_Store
47 | Thumbs.db
48 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Code/pincode input component for angular
2 |
3 | 
4 | 
5 | 
6 | 
7 |
8 | Robust and tested code (number/chars) input component for Angular 7 - 16+ projects.
9 | Ionic 4 - 7+ is supported, can be used in iOS and Android.
10 | Clipboard events are supported.
11 |
12 | Star it to inspire us to build the best component!
13 |
14 | Preview
15 |
16 | 
17 |
18 | 
19 |
20 | ## Supported platforms
21 |
22 | Angular 7 - 16+
23 | Ionic 4 - 7+
24 | Mobile browsers and WebViews on: Android and iOS
25 | Desktop browsers: Chrome, Firefox, Safari, Edge v.79 +
26 | Other browsers: Edge v.41 - 44 (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 |
77 |
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 | 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 | | `codeLength` | number | 4 | Length of input code |
144 | | `inputType` | string | tel | Type of the input DOM elements like `` default '`tel'` |
145 | | `inputMode` | string | numeric | inputmode of the input DOM elements like `` default '`numeric'` |
146 | | `isCodeHidden` | boolean | false | When `true` inputted code chars will be shown as asterisks (points) |
147 | | `isCharsCode` | boolean | false | When `true` inputted code can contain any char and not only digits from 0 to 9. If the input parameter `code` contains non digits chars and `isCharsCode` is `false` the value will be ignored |
148 | | `isPrevFocusableAfterClearing` | 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 |
149 | | `isFocusingOnLastByClickIfFilled` | boolean | false | When `true` and the code is filled then the focus will be moved to the last input element when clicked |
150 | | `initialFocusField` | 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. Note: If you need to dynamically hide the component it is needed to use *ngIf directive instead of the `[hidden]` attribute |
151 | | `code` | string / number | - | The input code value for the component. If the parameter contains non digits chars and `isCharsCode` is `false` the value will be ignored |
152 | | `disabled` | boolean | false | When `true` then the component will not handle user actions, like in regular html input element with the `disabled` attribute |
153 | | `autocapitalize` | 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 |
154 |
155 | #### Events
156 |
157 | | Event | Description |
158 | |----------|--------------------|
159 | | `codeChanged` | Will be called every time when a user changed the code |
160 | | `codeCompleted` | Will be called only if a user entered full code |
161 |
162 | ## Methods
163 |
164 | For calling the component's methods it is required to access the component inside the template or page script.
165 | It can be reached as follows.
166 |
167 | Inside the page template HTML add a template ref:
168 |
169 | ```html
170 |
175 |
176 | ```
177 |
178 | Inside a page script attach the component:
179 |
180 | ```ts
181 | ...
182 | // adding to the imports
183 | import {CodeInputComponent} from 'angular-code-input';
184 | ...
185 | // adding to the page props
186 | @ViewChild('codeInput') codeInput !: CodeInputComponent;
187 | ...
188 | // calling the component's methods somewhere in the page.
189 | // IMPORTANT: it will be accessible only after the view initialization!
190 | this.codeInput.reset();
191 | ```
192 |
193 | | Method | Description |
194 | |----------------|--------------------|
195 | | `focusOnField(index: number): void` | Focuses the input caret on the input box with the passed index |
196 | | `reset(isChangesEmitting = false): void` |
Resets the component values in the following way:
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.
if the `initialFocusField` option is supplied then the caret will be focused in that filed after reset.
if the `isChangesEmitting` param is passed then changes will be emitted
|
197 |
--------------------------------------------------------------------------------
/angular-code-input/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # 2.0.0 (15.06.2023)
2 | **Breaking changes**:
3 | - Enabled Ivy in the compiled library
4 | - The minimum supported version of Angular is set to **16**
5 |
6 | **Note:** Resolved the issue:
7 | - Add support for angular 13 [#59](https://github.com/AlexMiniApps/angular-code-input/issues/59)
8 |
9 | # 1.6.0 (11.11.2021)
10 | **Note:** Fixed issues and implemented cool features:
11 | - Always uppercase keyboard [#51](https://github.com/AlexMiniApps/angular-code-input/issues/51)
12 | - Change codeLength in app [#46](https://github.com/AlexMiniApps/angular-code-input/issues/46)
13 | - Delete button is not triggering on (codechanged) [#44](https://github.com/AlexMiniApps/angular-code-input/issues/44)
14 |
15 | # 1.5.0 (27.05.2021)
16 | **Note:** The following changes have been made:
17 | - Have implemented the feature 'Disabled state' [#28](https://github.com/AlexMiniApps/angular-code-input/issues/28)
18 | - Have fixed the issue 'Insert code "from messages" doesn't appear on iOS' [#36](https://github.com/AlexMiniApps/angular-code-input/issues/36)
19 |
20 | # 1.4.0 (09.02.2021)
21 | **Note:** The following changes have been made:
22 | - Have fixed the issue 'initialFocusField not working for 0 as index bug' [#26](https://github.com/AlexMiniApps/angular-code-input/issues/26)
23 | - Have implemented the feature 'Clear the inputs?' [#27](https://github.com/AlexMiniApps/angular-code-input/issues/27)
24 | - Have added the method for an input field focusing
25 |
26 | # 1.3.3 (21.01.2021)
27 | **Note:** Have implemented the feature:
28 |
29 | Insert Code from Messages not working on IOS [#19](https://github.com/AlexMiniApps/angular-code-input/issues/19)
30 |
31 | # 1.3.2 (15.12.2020)
32 | **Note:** Have implemented the feature:
33 |
34 | Trim whitespace before paste in digit code input [#23](https://github.com/AlexMiniApps/angular-code-input/issues/23)
35 |
36 | # 1.3.1 (01.12.2020)
37 | **Note:** The following changes have been made:
38 | - The issue with inline component configuration has been resolved
39 | - Have fixed issues with readonly properties in Angular 11
40 | - Adjusting tslint issues
41 |
42 | # 1.3.0 (30.11.2020)
43 | **Note:** The following changes have been made:
44 | - Added the root config of the component
45 | - The prop `isCharsCode` has been added for using instead of the `isNonDigitsCode`
46 | - Added the ability to configure component at runtime
47 |
48 | # 1.2.2 (04.08.2020)
49 | **Note:** Have added the prop initialFocusField for focusing on the appropriate input when
50 | the component has been appeared.
51 |
52 | # 1.2.1 (20.06.2020)
53 | **Note:** Have added the prop isFocusingOnLastByClickIfFilled for focusing on the last input box
54 | if the code is full, and any input box clicked.
55 |
56 | # 1.2.0 (20.05.2020)
57 | **Note:** Have added the ability to paste code from the clipboard.
58 |
59 | # 1.1.0 (04.03.2020)
60 | **Note:** Have added to the component new input props - code, isPrevFocusableAfterClearing, inputType.
61 | Minor refactoring.
62 | Fixing Android issues.
63 |
64 | # 1.0.1 (30.12.2019)
65 | **Note:** Have added links to the repository and bugs to the package.json.
66 |
67 | # 1.0.0 (28.12.2019)
68 | **Note:** Initial build.
69 |
--------------------------------------------------------------------------------
/angular-code-input/LICENSE:
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
/angular-code-input/README.md:
--------------------------------------------------------------------------------
1 | # Code/pincode input component for angular
2 |
3 | 
4 | 
5 | 
6 | 
7 |
8 | Robust and tested code (number/chars) input component for Angular 7 - 16+ projects.
9 | Ionic 4 - 7+ is supported, can be used in iOS and Android.
10 | Clipboard events are supported.
11 |
12 | Star it to inspire us to build the best component!
13 |
14 | Preview
15 |
16 | 
17 |
18 | 
19 |
20 | ## Supported platforms
21 |
22 | Angular 7 - 16+
23 | Ionic 4 - 7+
24 | Mobile browsers and WebViews on: Android and iOS
25 | Desktop browsers: Chrome, Firefox, Safari, Edge v.79 +
26 | Other browsers: Edge v.41 - 44 (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 |
77 |
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 | 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 | | `codeLength` | number | 4 | Length of input code |
144 | | `inputType` | string | tel | Type of the input DOM elements like `` default '`tel'` |
145 | | `isCodeHidden` | boolean | false | When `true` inputted code chars will be shown as asterisks (points) |
146 | | `isCharsCode` | boolean | false | When `true` inputted code can contain any char and not only digits from 0 to 9. If the input parameter `code` contains non digits chars and `isCharsCode` is `false` the value will be ignored |
147 | | `isPrevFocusableAfterClearing` | 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 | | `isFocusingOnLastByClickIfFilled` | boolean | false | When `true` and the code is filled then the focus will be moved to the last input element when clicked |
149 | | `initialFocusField` | 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. Note: If you need to dynamically hide the component it is needed to use *ngIf directive instead of the `[hidden]` attribute |
150 | | `code` | string / number | - | The input code value for the component. If the parameter contains non digits chars and `isCharsCode` is `false` the value will be ignored |
151 | | `disabled` | boolean | false | When `true` then the component will not handle user actions, like in regular html input element with the `disabled` attribute |
152 | | `autocapitalize` | 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 |
174 |
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 | | `focusOnField(index: number): void` | Focuses the input caret on the input box with the passed index |
195 | | `reset(isChangesEmitting = false): void` |
Resets the component values in the following way:
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.
if the `initialFocusField` option is supplied then the caret will be focused in that filed after reset.
if the `isChangesEmitting` param is passed then changes will be emitted