52 lines
2.1 KiB
PHTML
52 lines
2.1 KiB
PHTML
|
|
<?php
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Copyable text input — standard <label> + <span> above, input with a
|
||
|
|
* compact copy button overlaid on the right edge. A <div> wrapper around
|
||
|
|
* the input+button provides a dedicated positioning context so nothing
|
||
|
|
* leaks from the label's layout rules.
|
||
|
|
*
|
||
|
|
* The copy button reads the input's CURRENT value (live) via
|
||
|
|
* data-copy-target so users can edit the field and still copy the new value.
|
||
|
|
*
|
||
|
|
* Required view vars:
|
||
|
|
* $name — input name attribute
|
||
|
|
* $label — already-translated label text
|
||
|
|
*
|
||
|
|
* Optional:
|
||
|
|
* $id, $value, $type (default 'text'), $placeholder,
|
||
|
|
* $readonly, $required, $disabled
|
||
|
|
*/
|
||
|
|
|
||
|
|
$inputName = (string) ($name ?? '');
|
||
|
|
if ($inputName === '') {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
$inputId = (string) ($id ?? $inputName);
|
||
|
|
$inputType = (string) ($type ?? 'text');
|
||
|
|
$inputValue = (string) ($value ?? '');
|
||
|
|
$inputLabel = (string) ($label ?? '');
|
||
|
|
$inputPlaceholder = (string) ($placeholder ?? '');
|
||
|
|
$inputReadonly = (bool) ($readonly ?? false);
|
||
|
|
$inputRequired = (bool) ($required ?? false);
|
||
|
|
$inputDisabled = (bool) ($disabled ?? false);
|
||
|
|
?>
|
||
|
|
<label for="<?php e($inputId); ?>">
|
||
|
|
<span><?php e($inputLabel); ?></span>
|
||
|
|
<div class="app-input-copy">
|
||
|
|
<input type="<?php e($inputType); ?>" name="<?php e($inputName); ?>" id="<?php e($inputId); ?>"
|
||
|
|
value="<?php e($inputValue); ?>"
|
||
|
|
<?php if ($inputPlaceholder !== ''): ?>placeholder="<?php e($inputPlaceholder); ?>"<?php endif; ?>
|
||
|
|
<?php if ($inputReadonly): ?>readonly<?php endif; ?>
|
||
|
|
<?php if ($inputRequired): ?>required<?php endif; ?>
|
||
|
|
<?php if ($inputDisabled): ?>disabled<?php endif; ?> />
|
||
|
|
<button type="button" class="app-input-copy-button"
|
||
|
|
data-copy-button data-copy-target="<?php e($inputId); ?>"
|
||
|
|
data-tooltip="<?php e(t('Copy to clipboard')); ?>" data-tooltip-pos="top"
|
||
|
|
aria-label="<?php e(t('Copy to clipboard')); ?>">
|
||
|
|
<i class="bi bi-clipboard" data-copy-icon-idle aria-hidden="true"></i>
|
||
|
|
<i class="bi bi-check-lg" data-copy-icon-done aria-hidden="true"></i>
|
||
|
|
</button>
|
||
|
|
</div>
|
||
|
|
</label>
|