Skip to content

Commit

Permalink
feat: ability to set max and min input height
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardcreagia committed Mar 7, 2023
1 parent e295842 commit 3cccad0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
8 changes: 8 additions & 0 deletions resources/css/plugin.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@
.cm-content {
padding: 0.5rem !important;
}

.cm-scroller {
max-height: var(--maxInputHeight) !important;
}

.cm-scroller, .cm-gutter {
min-height: var(--minInputHeight) !important;
}
6 changes: 6 additions & 0 deletions resources/views/code-field.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
:state-path="$getStatePath()"
:disabled="$isDisabled()"
>
<style>
:root {
--minInputHeight: {{ $getMinHeight() }};
--maxInputHeight: {{ $getMaxHeight() }};
}
</style>
<div x-data="filamentCodeField({
state: $wire.{{ $applyStateBindingModifiers('entangle(\''.$getStatePath().'\')') }},
language: '{{ $language }}',
Expand Down
2 changes: 2 additions & 0 deletions src/CodeField.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Creagia\FilamentCodeField;

use Creagia\FilamentCodeField\Concerns\Autocompletion;
use Creagia\FilamentCodeField\Concerns\ControlsHeight;
use Creagia\FilamentCodeField\Concerns\LineNumbers;
use Creagia\FilamentCodeField\Concerns\ProgrammingLanguages;
use Filament\Forms\Components\Field;
Expand All @@ -11,6 +12,7 @@ class CodeField extends Field
{
use ProgrammingLanguages;
use Autocompletion;
use ControlsHeight;
use LineNumbers;

const PHP = 'php';
Expand Down
44 changes: 44 additions & 0 deletions src/Concerns/ControlsHeight.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Creagia\FilamentCodeField\Concerns;

use Closure;

trait ControlsHeight
{
protected string | Closure | null $maxHeight = null;

protected string | Closure | null $minHeight = null;

public function maxHeight(string | int $height): static
{
if (! is_string($height)) {
$height .= 'px';
}

$this->maxHeight = $height;

return $this;
}

public function getMaxHeight(): ?string
{
return $this->evaluate($this->maxHeight);
}

public function minHeight(string | int $height): static
{
if (! is_string($height)) {
$height .= 'px';
}

$this->minHeight = $height;

return $this;
}

public function getMinHeight(): ?string
{
return $this->evaluate($this->minHeight);
}
}

0 comments on commit 3cccad0

Please sign in to comment.