one-time-code.blade.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. @props([
  2. 'length' => 6,
  3. ])
  4. <div
  5. x-data="{ currentNumberOfDigits: null }"
  6. {{
  7. $attributes
  8. ->class([
  9. 'fi-one-time-code-input-ctn',
  10. ])
  11. }}
  12. >
  13. @foreach (range(1, $length) as $digit)
  14. <div
  15. x-bind:class="{
  16. 'fi-active':
  17. currentNumberOfDigits !== null &&
  18. currentNumberOfDigits >= {{ $digit }},
  19. }"
  20. class="fi-one-time-code-input-digit-field"
  21. ></div>
  22. @endforeach
  23. <input
  24. autocomplete="one-time-code"
  25. inputmode="numeric"
  26. minlength="{{ $length }}"
  27. maxlength="{{ $length }}"
  28. pattern="\d{{ '{' . $length . '}' }}"
  29. type="text"
  30. x-data="{}"
  31. x-on:focus="currentNumberOfDigits = $el.value.length"
  32. x-on:blur="currentNumberOfDigits = null"
  33. x-on:input="
  34. $el.value = $el.value.replace(/\D/g, '')
  35. currentNumberOfDigits = $el.value.length
  36. "
  37. x-bind:class="{ 'fi-valid': currentNumberOfDigits >= {{ $length }} }"
  38. class="fi-one-time-code-input"
  39. />
  40. </div>