mvorisek/atk4-hintable
Adds “hintable” UI helpers for Agile Toolkit v4 (atk4): attach contextual hints/tooltips to form fields and other components to improve UX. Lightweight package for Laravel/PHP projects using atk4.
Install the Package Require the package via Composer in your Laravel project (if using ATK4):
composer require mvorisek/atk4-hintable
Note: This package is designed for ATK4, not vanilla Laravel. Ensure your project integrates ATK4 (e.g., via atk4/core).
First Use Case: Adding a Hint to a Field
Extend an ATK4 field (e.g., TextField) with the Hintable trait:
use Atk4\Hintable\Hintable;
use Atk4\Ui\Form;
$form = new Form();
$field = $form->addField('email', ['TextField']);
$field->addExtension(Hintable::class)->setHint('Enter a valid email address');
Render the form to see the hint appear as a tooltip or inline text.
Where to Look First
src/Hintable.php: Core logic for hint attachment and rendering.tests/HintableTest.php for usage examples and edge cases.Basic Hint Attachment
Attach hints to any ATK4 field (e.g., TextField, DateField):
$field->addExtension(Hintable::class)
->setHint('This field is required');
Dynamic Hints via Validation Update hints based on field state (e.g., validation errors):
$field->onValidate(function($field) {
if (!$field->isFilled()) {
$field->getExtension(Hintable::class)
->setHint('Please fill this field')
->setHintType('error');
}
});
Bulk Hint Application Apply hints to multiple fields in a loop:
foreach ($form->getFields() as $field) {
$field->addExtension(Hintable::class)
->setHint('Required format: ' . $field->getName());
}
Custom Hint Templates Override the default hint rendering (if the package supports templates):
$field->getExtension(Hintable::class)
->setHintTemplate('<div class="custom-hint">{{hint}}</div>');
Form constructor).$hint = __("Hint for {field}", ['field' => $field->getName()]);
$field->getExtension(Hintable::class)->setHint($hint);
$grid->addColumn('status')
->addExtension(Hintable::class)
->setHint('Pending/Active/Completed');
aria-describedby:
$field->addExtension(Hintable::class)
->setHint('Description for screen readers')
->enableAriaSupport();
ATK4 Dependency
Hint Rendering Conflicts
.hintable-tooltip { /* Customize to avoid conflicts */ }
Dynamic Content in Hints
$field->getExtension(Hintable::class)->refreshHint();
Missing Documentation
tests/ directory for usage patterns and extend the package as needed.Hintable extension is properly added:
if (!$field->hasExtension(Hintable::class)) {
throw new \RuntimeException('Hintable extension not attached!');
}
display: none).$field->getExtension(Hintable::class)->on('hintRendered', function() {
\Log::debug('Hint rendered for field: ' . $field->getName());
});
info, warning, or error. Test all types to ensure consistent styling:
$field->getExtension(Hintable::class)->setHintType('warning');
class BaseField extends \Atk4\Ui\Field {
public function init() {
$this->addExtension(Hintable::class)
->setHint('Default hint text');
}
}
$field->getExtension(Hintable::class)
->setTrigger('click'); // Default is 'hover'
$hint = config("hints.{$field->getName()}");
$field->getExtension(Hintable::class)->setHint($hint);
$field->getExtension(Hintable::class)
->setHint(__('hints.field_name'));
How can I help you explore Laravel packages today?