generated from filamentphp/plugin-skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
145 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"version":"pest_2.34.5","defects":[],"times":{"P\\Tests\\ArchTest::__pest_evaluable_it_will_not_use_debugging_functions":0.154,"P\\Tests\\ExampleTest::__pest_evaluable_it_can_test":0.008}} | ||
{"version":"pest_2.34.5","defects":[],"times":{"P\\Tests\\ArchTest::__pest_evaluable_it_will_not_use_debugging_functions":0.161,"P\\Tests\\ExampleTest::__pest_evaluable_it_can_test":0.001}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
@php | ||
$extraAlpineAttributes = $getExtraAlpineAttributes(); | ||
$id = $getId(); | ||
$isConcealed = $isConcealed(); | ||
$isDisabled = $isDisabled(); | ||
$statePath = $getStatePath(); | ||
$hintActions = $getHintActions(); | ||
$numberLength = $getNumberLength(); | ||
$isAutofocused = $isAutofocused(); | ||
@endphp | ||
|
||
<x-dynamic-component | ||
:component="$getFieldWrapperView()" | ||
:id="$getId()" | ||
:label="$getLabel()" | ||
:label-sr-only="$isLabelHidden()" | ||
:helper-text="$getHelperText()" | ||
:hint="$getHint()" | ||
:hint-icon="$getHintIcon()" | ||
:required="$isRequired()" | ||
:state-path="$getStatePath()" | ||
> | ||
<div x-data="{ | ||
state: '{{ $getStatePath() }}', | ||
length: {{$numberLength}}, | ||
autoFocus: '{{$isAutofocused}}', | ||
type: 'text', | ||
init: function(){ | ||
if (this.autoFocus){ | ||
this.$refs[1].focus(); | ||
} | ||
}, | ||
handleInput(e, i) { | ||
const input = e.target; | ||
if(input.value.length > 1){ | ||
input.value = input.value.substring(0, 1); | ||
} | ||
this.state = Array.from(Array(this.length), (element, i) => { | ||
const el = this.$refs[(i + 1)]; | ||
return el.value ? el.value : ''; | ||
}).join(''); | ||
if (i < this.length) { | ||
this.$refs[i+1].focus(); | ||
this.$refs[i+1].select(); | ||
} | ||
if(i == this.length){ | ||
@this.set('{{ $getStatePath() }}', this.state) | ||
} | ||
}, | ||
handlePaste(e) { | ||
const paste = e.clipboardData.getData('text'); | ||
this.value = paste; | ||
const inputs = Array.from(Array(this.length)); | ||
inputs.forEach((element, i) => { | ||
this.$refs[(i+1)].focus(); | ||
this.$refs[(i+1)].value = paste[i] || ''; | ||
}); | ||
}, | ||
handleBackspace(e) { | ||
const ref = e.target.getAttribute('x-ref'); | ||
e.target.value = ''; | ||
const previous = ref - 1; | ||
this.$refs[previous] && this.$refs[previous].focus(); | ||
this.$refs[previous] && this.$refs[previous].select(); | ||
e.preventDefault(); | ||
}, | ||
}"> | ||
<div class="flex justify-between gap-6 pt-3 pb-2 h-16"> | ||
|
||
@foreach(range(1, $numberLength) as $column) | ||
<x-filament::input.wrapper | ||
:disabled="$isDisabled" | ||
:valid="! $errors->has($statePath)" | ||
:attributes=" | ||
\Filament\Support\prepare_inherited_attributes($getExtraAttributeBag()) | ||
->class(['fi-fo-text-input overflow-hidden']) | ||
" | ||
> | ||
<input | ||
{{$isDisabled ? 'disabled' : ''}} | ||
type="text" | ||
maxlength="1" | ||
x-ref="{{$column}}" | ||
required | ||
class="fi-input block w-full border-none text-base text-gray-950 transition duration-75 placeholder:text-gray-400 focus:ring-0 dark:text-white dark:placeholder:text-gray-500 sm:leading-6 bg-white/0 text-center" | ||
x-on:input="handleInput($event, {{$column}})" | ||
x-on:paste="handlePaste($event)" | ||
x-on:keydown.backspace="handleBackspace($event)" | ||
/> | ||
|
||
</x-filament::input.wrapper> | ||
@endforeach | ||
|
||
</div> | ||
</div> | ||
</x-dynamic-component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Afsakar\FilamentOtpLogin\Filament\Forms; | ||
|
||
use Filament\Forms; | ||
|
||
class OtpInput extends Forms\Components\TextInput | ||
{ | ||
protected string $view = 'filament-otp-login::forms.otp-input'; | ||
|
||
protected int $numberLength = 6; | ||
|
||
public static function make(string $name): static | ||
{ | ||
$static = app(static::class, ['name' => $name]); | ||
$static->configure(); | ||
|
||
$static->numberLength = config('filament-otp-login.otp_code.length'); | ||
|
||
return $static; | ||
} | ||
|
||
public function getNumberLength(): int | ||
{ | ||
return $this->evaluate($this->numberLength); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters