Skip to content

Commit

Permalink
Merge pull request #23 from vincent-tarrit/main
Browse files Browse the repository at this point in the history
Display template or not, settable
  • Loading branch information
coolsam726 authored Oct 2, 2024
2 parents f3d7e67 + 704c05a commit bd47734
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$suffixIcon = $getSuffixIcon();
$suffixLabel = $getSuffixLabel();
$statePath = $getStatePath();
$displayTemplate = $getDisplayTemplate();
@endphp
<x-dynamic-component
:component="$getFieldWrapperView()"
Expand All @@ -36,9 +37,11 @@
id: '{{ $id }}',
})"
class="p-2 md:p-4 bg-white dark:bg-gray-500 sm:rounded-md">
<template x-if="state">
<img class="border mx-auto dark:border-gray-700 rounded-lg w-full max-w-[800px]" alt="current_signature" :src="state">
</template>
@if($displayTemplate)
<template x-if="state">
<img class="border mx-auto dark:border-gray-700 rounded-lg w-full max-w-[800px]" alt="current_signature" :src="state">
</template>
@endif
@if(!($isReadOnly() || $isDisabled))
<canvas
before="Hello World"
Expand Down
2 changes: 2 additions & 0 deletions src/Forms/Components/Fields/SignaturePad.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Coolsam\SignaturePad\Forms\Components\Fields;

use Coolsam\SignaturePad\Forms\Concerns\CanDisplayTemplate;
use Coolsam\SignaturePad\Forms\Concerns\HasSignaturePadAttributes;
use Filament\Forms\Components\Concerns;
use Filament\Forms\Components\Contracts;
Expand All @@ -19,6 +20,7 @@ class SignaturePad extends Field implements Contracts\CanBeLengthConstrained, Co
use Concerns\HasInputMode;
use Concerns\HasPlaceholder;
use HasExtraAlpineAttributes;
use CanDisplayTemplate;
use HasSignaturePadAttributes;

const PACKAGE_NAME = 'coolsam/signature-pad';
Expand Down
26 changes: 26 additions & 0 deletions src/Forms/Concerns/CanDisplayTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Coolsam\SignaturePad\Forms\Concerns;

use Closure;

trait CanDisplayTemplate
{
protected bool | Closure | null $displayTemplate = true;

/**
* @param bool $displayTemplate
* @return CanDisplayTemplate
*/
public function displayTemplate(bool $displayTemplate = true): static
{
$this->displayTemplate = $displayTemplate;

return $this;
}

public function getDisplayTemplate(): ?float
{
return $this->evaluate($this->displayTemplate);
}
}

0 comments on commit bd47734

Please sign in to comment.