<?php
namespace PHPFUI\Input;
class PasswordEye extends \PHPFUI\Input\Password
{
public function __construct(string $name, string $label = '', ?string $value = '')
{
parent::__construct($name, $label, $value);
}
public function getBody() : string
{
$inputGroup = new \PHPFUI\InputGroup();
$password = $this->upCastCopy(new \PHPFUI\Input\Password('p'), $this);
$icon = new \PHPFUI\IconBase('fa-eye');
$icon->addClass('far');
$iconId = $icon->getId();
$passwordId = $password->getId();
$js = "var iconId=$('#{$iconId}'),passwordId=$('#{$passwordId}'),remove='',add='-slash',type='text';" .
"if(iconId.hasClass('fa-eye'+add)){remove=add;add='';type='password'};iconId.removeClass('fa-eye'+remove);" .
"iconId.addClass('fa-eye'+add);passwordId.prop('type',type);";
$inputGroup->addInput($password);
$inputGroup->addLabel($icon)->setAttribute('onclick', \str_replace("'", '"', $js));
return $inputGroup;
}
public function getEnd() : string
{
return '';
}
public function getStart() : string
{
return '';
}
}