Skip to content

Commit

Permalink
Merge branch '4.x' of https://github.com/filamentphp/filament into 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Feb 2, 2025
2 parents dd8c5ea + bb65db6 commit c093b26
Show file tree
Hide file tree
Showing 16 changed files with 407 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div
class="fi-fo-markdown-editor fi-disabled prose dark:prose-invert block w-full max-w-none rounded-lg bg-gray-50 px-3 py-3 text-gray-500 ring-1 shadow-xs ring-gray-950/10 sm:text-sm dark:bg-transparent dark:text-gray-400 dark:ring-white/10"
>
{!! str($getState())->markdown()->sanitizeHtml() !!}
{!! str($getState())->sanitizeHtml()->markdown($getCommonMarkOptions(), $getCommonMarkExtensions()) !!}
</div>
@else
<x-filament::input.wrapper
Expand Down
2 changes: 2 additions & 0 deletions packages/forms/src/Components/MarkdownEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace Filament\Forms\Components;

use Closure;
use Filament\Support\Concerns\CanConfigureCommonMark;
use Filament\Support\Concerns\HasExtraAlpineAttributes;

class MarkdownEditor extends Field implements Contracts\CanBeLengthConstrained, Contracts\HasFileAttachments
{
use CanConfigureCommonMark;
use Concerns\CanBeLengthConstrained;
use Concerns\HasFileAttachments;
use Concerns\HasMaxHeight;
Expand Down
11 changes: 10 additions & 1 deletion packages/infolists/docs/02-entries/02-text.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ TextEntry::make('created_at')
->dateTime()
```

You may use also the `isoDate()` and `isoDateTime()` methods to format the entry's state using [PHP date formatting macro-formats](https://carbon.nesbot.com/docs/#available-macro-formats):

```php
use Filament\Infolists\Components\TextEntry;

TextEntry::make('created_at')
->isoDateTime()
```

You may use the `since()` method to format the entry's state using [Carbon's `diffForHumans()`](https://carbon.nesbot.com/docs/#api-humandiff):

```php
Expand All @@ -56,7 +65,7 @@ TextEntry::make('created_at')
->since()
```

Additionally, you can use the `dateTooltip()`, `dateTimeTooltip()` or `timeTooltip()` method to display a formatted date in a tooltip, often to provide extra information:
Additionally, you can use the `dateTooltip()`, `dateTimeTooltip()`, `timeTooltip()`, `isoDateTooltip()`, `isoDateTimeTooltip()`, `isoTime()` or `isoTimeTooltip()` method to display a formatted date in a tooltip, often to provide extra information:

```php
use Filament\Infolists\Components\TextEntry;
Expand Down
79 changes: 78 additions & 1 deletion packages/infolists/src/Components/Concerns/CanFormatState.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Closure;
use Filament\Infolists\Components\TextEntry;
use Filament\Schemas\Schema;
use Filament\Support\Concerns\CanConfigureCommonMark;
use Filament\Support\Contracts\HasLabel as LabelInterface;
use Filament\Support\Enums\ArgumentValue;
use Illuminate\Contracts\Support\Htmlable;
Expand All @@ -15,6 +16,8 @@

trait CanFormatState
{
use CanConfigureCommonMark;

protected ?Closure $formatStateUsing = null;

protected int | Closure | null $characterLimit = null;
Expand Down Expand Up @@ -82,6 +85,35 @@ public function dateTime(string | Closure | null $format = null, ?string $timezo
return $this;
}

public function isoDate(?string $format = null): static
{
$this->isDate = true;

$format ??= Schema::$defaultIsoDateDisplayFormat;

$this->formatStateUsing(static function (TextEntry $component, $state) use ($format): ?string {
if (blank($state)) {
return null;
}

return Carbon::parse($state)
->isoFormat($format);
});

return $this;
}

public function isoDateTime(?string $format = null): static
{
$this->isDateTime = true;

$format ??= Schema::$defaultIsoDateTimeDisplayFormat;

$this->isoDate($format);

return $this;
}

public function since(?string $timezone = null): static
{
$this->isDateTime = true;
Expand Down Expand Up @@ -149,6 +181,40 @@ public function sinceTooltip(?string $timezone = null): static
return $this;
}

public function isoDateTooltip(?string $format = null): static
{
$format ??= Schema::$defaultIsoDateDisplayFormat;

$this->tooltip(static function (TextEntry $component, mixed $state) use ($format): ?string {
if (blank($state)) {
return null;
}

return Carbon::parse($state)
->isoFormat($format);
});

return $this;
}

public function isoDateTimeTooltip(?string $format = null): static
{
$format ??= Schema::$defaultIsoDateTimeDisplayFormat;

$this->isoDateTooltip($format);

return $this;
}

public function isoTimeTooltip(?string $format = null): static
{
$format ??= Schema::$defaultIsoTimeDisplayFormat;

$this->isoDateTooltip($format);

return $this;
}

public function money(string | Closure | null $currency = null, int $divideBy = 0, string | Closure | null $locale = null): static
{
$this->isMoney = true;
Expand Down Expand Up @@ -223,6 +289,17 @@ public function time(string | Closure | null $format = null, ?string $timezone =
return $this;
}

public function isoTime(?string $format = null): static
{
$this->isTime = true;

$format ??= Schema::$defaultIsoTimeDisplayFormat;

$this->isoDate($format);

return $this;
}

public function timezone(string | Closure | null $timezone): static
{
$this->timezone = $timezone;
Expand Down Expand Up @@ -304,7 +381,7 @@ public function formatState(mixed $state): mixed
}

if ($isHtml && $this->isMarkdown()) {
$state = Str::markdown($state);
$state = Str::markdown($state, $this->getCommonMarkOptions(), $this->getCommonMarkExtensions());
}

$prefix = $this->getPrefix();
Expand Down
6 changes: 6 additions & 0 deletions packages/schemas/src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,18 @@ class Schema extends ViewComponent

public static string $defaultDateDisplayFormat = 'M j, Y';

public static string $defaultIsoDateDisplayFormat = 'L';

public static string $defaultDateTimeDisplayFormat = 'M j, Y H:i:s';

public static string $defaultIsoDateTimeDisplayFormat = 'LLL';

public static ?string $defaultNumberLocale = null;

public static string $defaultTimeDisplayFormat = 'H:i:s';

public static string $defaultIsoTimeDisplayFormat = 'LT';

final public function __construct((Component & HasSchemas) | null $livewire = null)
{
$this->livewire($livewire);
Expand Down
55 changes: 55 additions & 0 deletions packages/support/src/Concerns/CanConfigureCommonMark.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Filament\Support\Concerns;

use Closure;
use League\CommonMark\Extension\ExtensionInterface;

trait CanConfigureCommonMark
{
/**
* @var array<string, mixed> | Closure | null
*/
protected array | Closure | null $commonMarkOptions = null;

/**
* @var array<array-key, ExtensionInterface> | Closure | null
*/
protected array | Closure | null $commonMarkExtensions = null;

/**
* @param array<string, mixed> | Closure | null $commonMarkOptions
*/
public function commonMarkOptions(array | Closure | null $commonMarkOptions): static
{
$this->commonMarkOptions = $commonMarkOptions;

return $this;
}

/**
* @return array<string, mixed>
*/
public function getCommonMarkOptions(): array
{
return $this->evaluate($this->commonMarkOptions) ?? [];
}

/**
* @param array<array-key, ExtensionInterface> | Closure | null $commonMarkExtensions
*/
public function commonMarkExtensions(array | Closure | null $commonMarkExtensions): static
{
$this->commonMarkExtensions = $commonMarkExtensions;

return $this;
}

/**
* @return array<array-key, ExtensionInterface>
*/
public function getCommonMarkExtensions(): array
{
return $this->evaluate($this->commonMarkExtensions) ?? [];
}
}
6 changes: 5 additions & 1 deletion packages/support/src/Concerns/EvaluatesClosures.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Database\Eloquent\Model;
use ReflectionFunction;
use ReflectionNamedType;
use ReflectionParameter;
Expand Down Expand Up @@ -81,7 +82,10 @@ protected function resolveClosureDependencyForEvaluation(ReflectionParameter $pa
return $this;
}

if (filled($typedParameterClassName)) {
if (
filled($typedParameterClassName)
&& (! is_subclass_of($typedParameterClassName, Model::class) || app()->bound($typedParameterClassName))
) {
return app()->make($typedParameterClassName);
}

Expand Down
11 changes: 10 additions & 1 deletion packages/tables/docs/02-columns/02-text.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ TextColumn::make('created_at')
->dateTime()
```

You may use also the `isoDate()` and `isoDateTime()` methods to format the column's state using [PHP date formatting macro-formats](https://carbon.nesbot.com/docs/#available-macro-formats):

```php
use Filament\Tables\Columns\TextColumn;

TextColumn::make('created_at')
->isoDateTime()
```

You may use the `since()` method to format the column's state using [Carbon's `diffForHumans()`](https://carbon.nesbot.com/docs/#api-humandiff):

```php
Expand All @@ -82,7 +91,7 @@ TextColumn::make('created_at')
->since()
```

Additionally, you can use the `dateTooltip()`, `dateTimeTooltip()` or `timeTooltip()` method to display a formatted date in a tooltip, often to provide extra information:
Additionally, you can use the `dateTooltip()`, `dateTimeTooltip()`, `timeTooltip()`, `isoDateTooltip()`, `isoDateTimeTooltip()`, `isoTime()` or `isoTimeTooltip()` method to display a formatted date in a tooltip, often to provide extra information:

```php
use Filament\Tables\Columns\TextColumn;
Expand Down
Loading

0 comments on commit c093b26

Please sign in to comment.