Führe einen gemeinsamen Layoutvertrag ein und integriere die Premium-Widgets.
Layoutvertrag (ADR-38) in der bestehenden Registry: Jede Widget-Art erklärt zulässige Rasterbreiten (supportedUnits), Höhen aus einem gemeinsamen Vokabular (heights, gespeichert als settings.height), Darstellungsmodi und Verhalten bei wenig Platz. Unzulässige Breiten werden beim Speichern verständlich abgewiesen; Höhe „fill“ streckt den Handlungsaufruf auf die Abschnittszeile. Premium-Widgets nach Brand-UI-Kit v1.6: - hero Version 2: photo_split/editorial_solid, Höhen compact/normal/ large, Label, Überschriftenebene, Akzent, Bildfokus in Prozent, zwei Schaltflächen; nur 3 oder 4 Einheiten. Upgrade aus Version 1. - image_text Version 3: Fläche cream/clear/navy, Höhen compact/normal/ spacious, Label, zwei Schaltflächen, Bildfokus; 1 bis 4 Einheiten. Upgrade aus Version 2 (format entfällt, Fokus in Prozent). - Kit-CSS ersetzt das bisherige Hero- und Bild-und-Text-CSS; der Randlos-Mechanismus der Designiteration 1 entfällt. Editor: Reiter Inhalt/Medien/Darstellung aus der Registry, Auswahl- knöpfe mit Symbolen, Schieberegler für den Bildfokus und eine Live- Vorschau im Dialog mit demselben Renderer in wählbarer Platzbreite. Tests bewusst angepasst: Einstieg braucht jetzt 3 oder 4 Einheiten (vorher Mindestbreite 2), image_text ist Version 3, Klassen der neuen Ansichten; die Hero-/Bild-Tests der Designiteration 1 sind durch CmsPremiumWidgetsTest ersetzt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3cdb36e7a3
commit
0bfb53463a
38 files changed
+1755
-856
No files matched your search
@@ -14,6 +14,12 @@
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Tabs;
|
||||
use Filament\Schemas\Components\Tabs\Tab;
|
||||
use Filament\Schemas\Components\Text;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
use Filament\Schemas\Components\View;
|
||||
use Illuminate\Foundation\Vite;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -83,34 +89,69 @@ public static function slotBuilder(string $name = 'widget'): Builder
|
||||
|
||||
public static function block(WidgetType $type): Block
|
||||
{
|
||||
$variants = $type->variants();
|
||||
$icons = $type->optionIcons();
|
||||
$display = [];
|
||||
|
||||
$schema = [Hidden::make('id')];
|
||||
|
||||
$schema[] = count($variants) > 1
|
||||
? ToggleButtons::make('variant')
|
||||
if (count($type->variants()) > 1) {
|
||||
$display[] = ToggleButtons::make('variant')
|
||||
->label('Darstellung')
|
||||
->options($variants)
|
||||
->options($type->variants())
|
||||
->icons($icons['variant'] ?? [])
|
||||
->default($type->defaultVariant())
|
||||
->inline()
|
||||
->required()
|
||||
: Hidden::make('variant')->default($type->defaultVariant());
|
||||
->live();
|
||||
}
|
||||
|
||||
if ($type->settings() !== []) {
|
||||
$settings = [];
|
||||
$labels = $type->settingLabels();
|
||||
foreach ($type->settings() as $key => $options) {
|
||||
$settings[] = Select::make($key)
|
||||
$settings = [];
|
||||
$labels = $type->settingLabels();
|
||||
foreach ($type->settingOptions() as $key => $options) {
|
||||
// Gemeinsame Höhe (ADR-38): immer als sichtbare Auswahl mit Vorgabe, nie als freie Eingabe.
|
||||
$settings[] = $key === 'height'
|
||||
? ToggleButtons::make('height')
|
||||
->label('Höhe')
|
||||
->helperText('Gestaltungsparameter, keine Begrenzung: Längere Inhalte erhalten immer den nötigen Platz.')
|
||||
->options($options)
|
||||
->icons($icons['height'] ?? [])
|
||||
->default($type->defaultHeight())
|
||||
->inline()
|
||||
->live()
|
||||
: Select::make($key)
|
||||
->label($labels[$key][0] ?? Str::headline($key))
|
||||
->helperText($labels[$key][1] ?? null)
|
||||
->placeholder('Vorgabe der Darstellung')
|
||||
->options($options);
|
||||
}
|
||||
$schema[] = Grid::make(['default' => 1, 'md' => min(3, count($settings))])->schema($settings)->statePath('settings');
|
||||
->options($options)
|
||||
->live();
|
||||
}
|
||||
|
||||
foreach ($type->editorSchema() as $component) {
|
||||
$schema[] = $component;
|
||||
if ($settings !== []) {
|
||||
$display[] = Grid::make(['default' => 1, 'md' => 2])->schema($settings)->statePath('settings');
|
||||
}
|
||||
|
||||
$variantField = count($type->variants()) > 1 ? [] : [Hidden::make('variant')->default($type->defaultVariant())];
|
||||
$content = $type->editorSchema();
|
||||
$media = $type->mediaSchema();
|
||||
|
||||
if ($display === [] && $media === []) {
|
||||
$schema = [Hidden::make('id'), ...$variantField, ...$content];
|
||||
} else {
|
||||
$tabs = [Tab::make('Inhalt')->icon('heroicon-o-pencil-square')->schema($content)];
|
||||
if ($media !== []) {
|
||||
$tabs[] = Tab::make('Medien')->icon('heroicon-o-photo')->schema($media);
|
||||
}
|
||||
if ($display !== []) {
|
||||
$tabs[] = Tab::make('Darstellung')->icon('heroicon-o-adjustments-horizontal')->schema([
|
||||
...$display,
|
||||
Text::make('Platzbreiten: '.$type->unitsLabel().' Rastereinheiten. '.$type->narrowBehavior()),
|
||||
]);
|
||||
}
|
||||
|
||||
$schema = [
|
||||
Hidden::make('id'),
|
||||
...$variantField,
|
||||
Tabs::make('Widget')->tabs($tabs)->contained(false),
|
||||
self::livePreview($type),
|
||||
];
|
||||
}
|
||||
|
||||
return WidgetBlock::make($type->key())
|
||||
@@ -238,6 +279,50 @@ public static function notifyErrors(array $errors, array $blocks): void
|
||||
->send();
|
||||
}
|
||||
|
||||
/** Logische Vorschaubreiten in px: tatsächliche Platzbreiten im Standardabschnitt bei 1440 px Fensterbreite. */
|
||||
public const PREVIEW_UNIT_WIDTHS = [1 => 310, 2 => 640, 3 => 960, 4 => 1300];
|
||||
|
||||
public const PREVIEW_PHONE_WIDTH = 390;
|
||||
|
||||
/**
|
||||
* Live-Vorschau im Bearbeitungsdialog: rendert den ungespeicherten Zustand mit derselben Ansicht wie die Website
|
||||
* in einer wählbaren Platzbreite. Die Breitenwahl (_preview_width) wird nicht gespeichert.
|
||||
*/
|
||||
private static function livePreview(WidgetType $type): Section
|
||||
{
|
||||
$default = (string) self::PREVIEW_UNIT_WIDTHS[$type->preferredUnits()];
|
||||
$widths = [(string) self::PREVIEW_PHONE_WIDTH => 'Smartphone'];
|
||||
foreach ($type->supportedUnits() as $units) {
|
||||
$widths[(string) self::PREVIEW_UNIT_WIDTHS[$units]] = $units.' '.($units === 1 ? 'Einheit' : 'Einheiten');
|
||||
}
|
||||
|
||||
return Section::make('Vorschau')
|
||||
->description('Änderungen erscheinen sofort. Unter 860 px zeigt der Einstieg den Sicherheitsumbruch, Bild und Text ab 900 px zwei Spalten.')
|
||||
->collapsible()
|
||||
->compact()
|
||||
->schema([
|
||||
ToggleButtons::make('_preview_width')
|
||||
->hiddenLabel()
|
||||
->options($widths)
|
||||
->default($default)
|
||||
->inline()
|
||||
->live()
|
||||
->dehydrated(false)
|
||||
->extraAttributes(['class' => 'luf-preview-width']),
|
||||
View::make('filament.cms.widget-live-preview')
|
||||
->viewData(fn (Get $get): array => [
|
||||
'html' => self::renderPreview($type->key(), [
|
||||
'variant' => $get('variant'),
|
||||
'settings' => $get('settings'),
|
||||
'data' => $get('data'),
|
||||
'refs' => $get('refs'),
|
||||
]),
|
||||
'stylesheets' => self::previewStylesheets(),
|
||||
'width' => (int) ($get('_preview_width') ?: $default),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blockvorschau: dieselbe Widget-Ansicht wie öffentlich, aus dem ungespeicherten Zustand.
|
||||
*
|
||||
@@ -292,9 +377,9 @@ private static function pickerLabel(WidgetType $type): HtmlString
|
||||
|
||||
private static function unitsHint(WidgetType $type): string
|
||||
{
|
||||
return $type->minUnits() === 1
|
||||
? 'Passt in jeden Platz'
|
||||
: 'Braucht einen Platz ab '.$type->minUnits().' Rastereinheiten';
|
||||
return $type->supportedUnits() === [1, 2, 3, 4]
|
||||
? 'Passt in jeden Platz (1 bis 4 Einheiten)'
|
||||
: 'Für Plätze mit '.$type->unitsLabel().' Rastereinheiten';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user