This commit is contained in:
Dan Harrin
2023-09-09 23:23:16 +01:00
parent 156d2f26b3
commit fcbfce548a
12 changed files with 69 additions and 26 deletions
@@ -38,6 +38,15 @@ class EntriesDemo extends Component implements HasInfolists
TextEntry::make('author.name')
->state('Dan Harrin'),
]),
Group::make()
->id('placeholder')
->extraAttributes([
'class' => 'p-16 max-w-xl',
])
->schema([
TextEntry::make('title')
->placeholder('Dan Harrin'),
]),
Group::make()
->id('helperText')
->extraAttributes([
@@ -46,6 +46,7 @@ use Filament\Tables\Grouping\Group;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Livewire\Component;
use stdClass;
class TablesDemo extends Component implements HasForms, HasTable
{
@@ -232,6 +233,17 @@ class TablesDemo extends Component implements HasForms, HasTable
]);
}
public function placeholderColumns(Table $table): Table
{
return $this->postsTable($table)
->columns([
TextColumn::make('title'),
TextColumn::make('description')
->getStateUsing(fn (Post $record, stdClass $rowLoop): ?string => $rowLoop->odd ? $record->description : null)
->placeholder('No description.'),
]);
}
public function toggleableColumns(Table $table): Table
{
return $this->usersTable($table)
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 KiB

+18
View File
@@ -1184,6 +1184,15 @@ export default {
deviceScaleFactor: 3,
},
},
'infolists/entries/placeholder': {
url: 'infolists/entries',
selector: '#placeholder',
viewport: {
width: 1920,
height: 640,
deviceScaleFactor: 3,
},
},
'infolists/entries/helper-text': {
url: 'infolists/entries',
selector: '#helperText',
@@ -1832,6 +1841,15 @@ export default {
deviceScaleFactor: 3,
},
},
'tables/columns/placeholder': {
url: 'tables?table=placeholderColumns',
selector: 'body',
viewport: {
width: 1080,
height: 640,
deviceScaleFactor: 3,
},
},
'tables/columns/toggleable': {
url: 'tables?table=toggleableColumns',
selector: 'body',
@@ -87,7 +87,7 @@ TextEntry::make('title')
## Setting a default value
To set a default value for fields with a `null` state, you may use the `default()` method:
To set a default value for entries with an empty state, you may use the `default()` method. This method will treat the default state as if it were real, so entries like [image](image) or [color](color) will display the default image or color.
```php
use Filament\Infolists\Components\TextEntry;
@@ -96,6 +96,19 @@ TextEntry::make('title')
->default('Untitled')
```
## Adding placeholder text if an entry is empty
Sometimes you may want to display placeholder text for entries with an empty state, which is styled as a lighter gray text. This differs from the [default value](#setting-a-default-value), as the placeholder is always text and not treated as if it were real state.
```php
use Filament\Infolists\Components\TextEntry;
TextEntry::make('title')
->placeholder('Untitled')
```
<AutoScreenshot name="infolists/entries/placeholder" alt="Entry with a placeholder for empty state"" version="3.x" />
## Adding helper text below the entry
Sometimes, you may wish to provide extra information for the user of the infolist. For this purpose, you may add helper text below the entry.
@@ -207,17 +207,6 @@ TextEntry::make('status')
->formatStateUsing(fn (string $state): string => __("statuses.{$state}"))
```
## Adding a placeholder if the entry is empty
Sometimes you may want to display a placeholder if the entry's value is empty:
```php
use Filament\Infolists\Components\TextEntry;
TextEntry::make('updated_at')
->placeholder('Never')
```
## Customizing the color
You may set a color for the text, either `danger`, `gray`, `info`, `primary`, `success` or `warning`:
@@ -289,15 +289,28 @@ TextColumn::make('title')
## Setting a default value
To set a default value for fields with a `null` state, you may use the `default()` method:
To set a default value for columns with an empty state, you may use the `default()` method. This method will treat the default state as if it were real, so columns like [image](image) or [color](color) will display the default image or color.
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('title')
->default('Untitled')
TextColumn::make('description')
->default('No description.')
```
## Adding placeholder text if a column is empty
Sometimes you may want to display placeholder text for columns with an empty state, which is styled as a lighter gray text. This differs from the [default value](#setting-a-default-value), as the placeholder is always text and not treated as if it were real state.
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('description')
->placeholder('No description.')
```
<AutoScreenshot name="tables/columns/placeholder" alt="Column with a placeholder for empty state" version="3.x" />
## Hiding columns
To hide a column conditionally, you may use the `hidden()` and `visible()` methods, whichever you prefer:
@@ -240,17 +240,6 @@ TextColumn::make('status')
->formatStateUsing(fn (string $state): string => __("statuses.{$state}"))
```
## Adding a placeholder if the cell is empty
Sometimes you may want to display a placeholder if the cell's value is empty:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('updated_at')
->placeholder('Never')
```
## Customizing the color
You may set a color for the text, either `danger`, `gray`, `info`, `primary`, `success` or `warning`: