- Added `Choices` component for dropdowns with search and multi-selection functionality. - Implemented foundational classes for service connection: - `ConnectServiceData` - `ConnectedServiceFactory` - `ConnectedServicesService` - Added `ConnectServiceForm` Livewire component for managing service connections. - Introduced shared utility traits (`HasAttributeHelpers`) and error components. - Added components for generic use: `Input` and `ListItem`.
76 lines
1.9 KiB
PHP
76 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Concerns\UI;
|
|
|
|
use Illuminate\View\ComponentAttributeBag;
|
|
|
|
/**
|
|
* This trait is used to add some helpers methods to components.
|
|
*
|
|
* @property ComponentAttributeBag $attributes
|
|
*/
|
|
trait HasAttributeHelpers
|
|
{
|
|
/**
|
|
* Check if the element has the given attribute.
|
|
*/
|
|
public function hasAttribute(string $attribute): bool
|
|
{
|
|
return $this->attributes->has($attribute);
|
|
}
|
|
|
|
/**
|
|
* Get the error field name.
|
|
* If the parent class has an error field name (passed via props or defined), it will be returned.
|
|
* Otherwise, the model name will be returned.
|
|
*/
|
|
public function errorFieldName(): ?string
|
|
{
|
|
return $this->errorField ?? $this->modelName();
|
|
}
|
|
|
|
/**
|
|
* This function will return the model name from the wire:model attribute.
|
|
* This is useful as we use this to bind wire:model props passed from high level
|
|
* components (ex: input) to the internal html components (ex: input tag).
|
|
*/
|
|
public function modelName(): ?string
|
|
{
|
|
return $this->attributes->whereStartsWith('wire:model')->first();
|
|
}
|
|
|
|
/**
|
|
* Check if the input is required.
|
|
*/
|
|
public function isRequired(): bool
|
|
{
|
|
return $this->attributes->has('required') && true === $this->attributes->get('required');
|
|
}
|
|
|
|
/**
|
|
* Check if the input is disabled.
|
|
*/
|
|
public function isDisabled(): bool
|
|
{
|
|
return $this->attributes->has('disabled') && true === $this->attributes->get('disabled');
|
|
}
|
|
|
|
/**
|
|
* Check if the input is readonly.
|
|
*/
|
|
public function isReadonly(): bool
|
|
{
|
|
return $this->attributes->has('readonly') && true === $this->attributes->get('readonly');
|
|
}
|
|
|
|
/**
|
|
* Check if the input is autofocus.
|
|
*/
|
|
public function isAutofocus(): bool
|
|
{
|
|
return $this->attributes->has('autofocus') && true === $this->attributes->get('autofocus');
|
|
}
|
|
}
|