@@ -20,9 +20,9 @@ import { InputOTPComponent } from '@ngxpert/input-otp';
2020@Component ({
2121 selector: ' app-my-component' ,
2222 template: `
23- <input-otp [maxLength]="6" [(ngModel)]="otpValue">
23+ <input-otp [maxLength]="6" [(ngModel)]="otpValue" #otpInput >
2424 <div style="display: flex;">
25- @for (slot of otp .slots(); track $index) {
25+ @for (slot of otpInput .slots(); track $index) {
2626 <div>{{ slot.char }}</div>
2727 }
2828 </div>
@@ -43,11 +43,11 @@ export class MyComponent {
4343
4444## Default example
4545
46- The example below uses ` tailwindcss ` ` tailwind-merge ` ` clsx ` :
46+ The example below uses ` tailwindcss ` ` tailwind-merge ` ` clsx ` . You can see it online [ here ] ( https://ngxpert.github.io/input-otp/examples ) , code available [ here ] ( https://github.com/ngxpert/input-otp/tree/main/src/app/pages/examples/main ) .
4747
4848### main.component
4949
50- ``` tsx
50+ ``` ts
5151import { Component } from ' @angular/core' ;
5252import { FormsModule } from ' @angular/forms' ;
5353import { InputOTPComponent } from ' @ngxpert/input-otp' ;
@@ -64,23 +64,37 @@ import { FakeDashComponent } from './fake-components';
6464 #otp="inputOtp"
6565 >
6666 <div class="flex">
67- @for (slot of otp.slots().slice(0, 3); track $index) {
67+ @for (
68+ slot of otp.slots().slice(0, 3);
69+ track $index;
70+ let first = $first;
71+ let last = $last
72+ ) {
6873 <app-slot
6974 [isActive]="slot.isActive"
7075 [char]="slot.char"
7176 [placeholderChar]="slot.placeholderChar"
7277 [hasFakeCaret]="slot.hasFakeCaret"
78+ [first]="first"
79+ [last]="last"
7380 />
7481 }
7582 </div>
7683 <app-fake-dash />
7784 <div class="flex">
78- @for (slot of otp.slots().slice(3, 6); track $index + 3) {
85+ @for (
86+ slot of otp.slots().slice(3, 6);
87+ track $index + 3;
88+ let last = $last;
89+ let first = $first
90+ ) {
7991 <app-slot
8092 [isActive]="slot.isActive"
8193 [char]="slot.char"
8294 [placeholderChar]="slot.placeholderChar"
8395 [hasFakeCaret]="slot.hasFakeCaret"
96+ [first]="first"
97+ [last]="last"
8498 />
8599 }
86100 </div>
@@ -110,10 +124,12 @@ import { cn } from './utils';
110124 'relative w-10 h-14 text-[2rem]',
111125 'flex items-center justify-center',
112126 'transition-all duration-300',
113- 'border-border border- y border-r first:border-l first:rounded-l-md last:rounded-r-md ',
127+ 'border-y border-r',
114128 'group-hover:border-accent-foreground/20 group-focus-within:border-accent-foreground/20',
115129 'outline outline-0 outline-accent-foreground/20',
116- { 'outline-4 outline-accent-foreground': isActive }
130+ { 'outline-4 outline-accent-foreground': isActive },
131+ { 'border-l rounded-l-md': first },
132+ { 'rounded-r-md': last }
117133 )
118134 "
119135 >
@@ -134,6 +150,8 @@ export class SlotComponent {
134150 @Input () char: string | null = null ;
135151 @Input () placeholderChar: string | null = null ;
136152 @Input () hasFakeCaret = false ;
153+ @Input () first = false ;
154+ @Input () last = false ;
137155 cn = cn ;
138156}
139157
@@ -148,7 +166,7 @@ import { Component } from '@angular/core';
148166 selector: ' app-fake-dash' ,
149167 template: `
150168 <div class="flex w-10 justify-center items-center">
151- <div class="w-3 h-1 rounded-full bg-border "></div>
169+ <div class="w-3 h-1 rounded-full bg-black/75 "></div>
152170 </div>
153171 ` ,
154172})
@@ -160,7 +178,7 @@ export class FakeDashComponent {}
160178 <div
161179 class="absolute pointer-events-none inset-0 flex items-center justify-center animate-caret-blink"
162180 >
163- <div class="w-px h-8 bg-white "></div>
181+ <div class="w-[2px] h-8 bg-black/75 "></div>
164182 </div>
165183 ` ,
166184})
@@ -171,7 +189,6 @@ export class FakeCaretComponent {}
171189### utils
172190
173191``` ts
174- // Small utility to merge class names.
175192import { clsx } from ' clsx' ;
176193import { twMerge } from ' tailwind-merge' ;
177194
@@ -183,6 +200,27 @@ export function cn(...inputs: ClassValue[]) {
183200
184201```
185202
203+ ### styles
204+
205+ ``` css
206+ @import " tailwindcss" ;
207+
208+ @theme {
209+ --animate-caret-blink: caret-blink 1.2s ease-out infinite;
210+ @keyframes caret-blink {
211+ 0% ,
212+ 70% ,
213+ 100% {
214+ opacity : 1 ;
215+ }
216+ 20% ,
217+ 50% {
218+ opacity : 0 ;
219+ }
220+ }
221+ }
222+ ```
223+
186224## How it works
187225
188226There's currently no native OTP/2FA/MFA input in HTML, which means people are either going with
0 commit comments