From dc4ba5808fd6b015631d21b8ed67a13c9e577f82 Mon Sep 17 00:00:00 2001 From: 199ocero <199ocero@gmail.com> Date: Sat, 20 Jan 2024 22:10:50 +0800 Subject: [PATCH 1/2] added heading visible and docu --- README.md | 4 ++ resources/views/components/section.blade.php | 56 +++++++++---------- .../components/activity-section.blade.php | 2 +- src/Components/ActivitySection.php | 16 +++++- src/Concerns/HasSetting.php | 10 +++- 5 files changed, 55 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 63f8834..ff5b1ea 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,8 @@ public function activityTimelineInfolist(Infolist $infolist): Infolist ->showItemsIcon('heroicon-m-chevron-down') // Show button icon ->showItemsColor('gray') // Show button color and it supports all colors ->aside(true) + ->headingVisible(true) // make heading visible or not + ->extraAttributes(['class'=>'my-new-class']) // add extra class ]); } ``` @@ -241,6 +243,8 @@ class ViewOrderActivities extends ActivityTimelinePage 'empty_state_heading' => 'No activities yet', // heading for the empty state 'empty_state_description' => 'Check back later for activities that have been recorded.', // description for the empty state 'empty_state_icon' => 'heroicon-o-bolt-slash', // icon for the empty state + 'heading_visible' => true, // show the heading + 'extra_attributes' => [], // extra attributes ], 'activity_title' => [ 'placeholder' => 'No title is set', // this will show when there is no title diff --git a/resources/views/components/section.blade.php b/resources/views/components/section.blade.php index 32c4e9a..95b7ddb 100644 --- a/resources/views/components/section.blade.php +++ b/resources/views/components/section.blade.php @@ -1,32 +1,29 @@ -@props(['heading', 'description' => null, 'aside' => true, 'extraAttributes' => []]) +@props(['heading', 'headingVisible' => true, 'description' => null, 'aside' => true, 'extraAttributes' => []])
merge($extraAttributes, escape: false) - ->class([ - 'fi-timeline-section', - match (true) { - !$aside => 'bg-white shadow-sm rounded-xl ring-1 ring-gray-950/5 dark:bg-gray-900 dark:ring-white/10', - $aside => 'grid items-start grid-cols-1 gap-x-6 gap-y-4 md:grid-cols-3', - }, - ]) - }}> -
!$aside, - 'flex flex-col gap-3 overflow-hidden sm:flex-row sm:items-center' => $aside, - ])> -
-

- {{ $heading }} -

-

- {{ $description }} -

-
-
+ {{ $attributes->merge($extraAttributes, escape: false)->class([ + 'fi-timeline-section', + 'grid items-start grid-cols-1 gap-x-6 gap-y-4 md:grid-cols-3' => $aside && $headingVisible, + 'bg-white shadow-sm rounded-xl ring-1 ring-gray-950/5 dark:bg-gray-900 dark:ring-white/10' => !$aside, + ]) }}> + + @if ($headingVisible) +
!$aside, + 'flex flex-col gap-3 overflow-hidden sm:flex-row sm:items-center' => $aside, + ])> +
+

+ {{ $heading }} +

+

+ {{ $description }} +

+
+
+ @endif @if ($aside)
+
$headingVisible, + ])> {{ $slot }}
@endif diff --git a/resources/views/infolists/components/activity-section.blade.php b/resources/views/infolists/components/activity-section.blade.php index a873ee9..5486277 100644 --- a/resources/views/infolists/components/activity-section.blade.php +++ b/resources/views/infolists/components/activity-section.blade.php @@ -1,4 +1,4 @@ - + {{ $getLabel() ?? $getHeading() }} diff --git a/src/Components/ActivitySection.php b/src/Components/ActivitySection.php index 221c453..8f68778 100644 --- a/src/Components/ActivitySection.php +++ b/src/Components/ActivitySection.php @@ -26,6 +26,8 @@ class ActivitySection extends Entry protected bool|Closure|null $isAside = null; + protected bool|Closure|null $isHeadingVisible = null; + public function description(string|Closure|null $description = null): static { $this->description = $description; @@ -68,6 +70,13 @@ public function showItemsColor(string|Closure $color): static return $this; } + public function headingVisible(bool|Closure|null $condition = true): static + { + $this->isHeadingVisible = $condition; + + return $this; + } + public function isAside(): bool { return (bool) ($this->evaluate($this->isAside) ?? false); @@ -104,12 +113,17 @@ public function getShowItemsColor(): string return $this->evaluate($this->showItemsColor) ?? 'gray'; } + public function isHeadingVisible(): bool + { + return (bool) ($this->evaluate($this->isHeadingVisible) ?? true); + } + /** * @return array */ public function getChildComponentContainers(bool $withHidden = false): array { - if ((! $withHidden) && $this->isHidden()) { + if ((!$withHidden) && $this->isHidden()) { return []; } diff --git a/src/Concerns/HasSetting.php b/src/Concerns/HasSetting.php index 12c272c..302398a 100644 --- a/src/Concerns/HasSetting.php +++ b/src/Concerns/HasSetting.php @@ -28,6 +28,8 @@ protected function configuration(): array 'empty_state_heading' => 'No activities yet', 'empty_state_description' => 'Check back later for activities that have been recorded.', 'empty_state_icon' => 'heroicon-o-bolt-slash', + 'heading_visible' => true, + 'extra_attributes' => [], ], 'activity_title' => [ 'placeholder' => 'No title is set', @@ -97,7 +99,9 @@ public function activityInfolist(Infolist $infolist): Infolist ->aside($this->configuration()['activity_section']['aside']) ->emptyStateHeading($this->configuration()['activity_section']['empty_state_heading']) ->emptyStateDescription($this->configuration()['activity_section']['empty_state_description']) - ->emptyStateIcon($this->configuration()['activity_section']['empty_state_icon']), + ->emptyStateIcon($this->configuration()['activity_section']['empty_state_icon']) + ->headingVisible($this->configuration()['activity_section']['heading_visible']) + ->extraAttributes($this->configuration()['activity_section']['extra_attributes']), ]) ->columns(1); } @@ -152,7 +156,7 @@ private function modifiedState(): array $properties = $state['properties']; - if (! empty($properties) && isset($properties['old']) && isset($properties['attributes'])) { + if (!empty($properties) && isset($properties['old']) && isset($properties['attributes'])) { $oldValues = $properties['old']; $newValues = $properties['attributes']; @@ -161,7 +165,7 @@ private function modifiedState(): array foreach ($newValues as $key => $newValue) { if (isset($oldValues[$key]) && $oldValues[$key] != $newValue) { - $changes[] = "- {$key} from ".htmlspecialchars($oldValues[$key]).' to '.htmlspecialchars($newValue).''; + $changes[] = "- {$key} from " . htmlspecialchars($oldValues[$key]) . ' to ' . htmlspecialchars($newValue) . ''; } } From 5cfa048e223764a284b1219db164f6cde5cfce39 Mon Sep 17 00:00:00 2001 From: 199ocero <199ocero@users.noreply.github.com> Date: Sat, 20 Jan 2024 14:11:30 +0000 Subject: [PATCH 2/2] Fix styling --- src/Components/ActivitySection.php | 2 +- src/Concerns/HasSetting.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Components/ActivitySection.php b/src/Components/ActivitySection.php index 8f68778..5e48ef4 100644 --- a/src/Components/ActivitySection.php +++ b/src/Components/ActivitySection.php @@ -123,7 +123,7 @@ public function isHeadingVisible(): bool */ public function getChildComponentContainers(bool $withHidden = false): array { - if ((!$withHidden) && $this->isHidden()) { + if ((! $withHidden) && $this->isHidden()) { return []; } diff --git a/src/Concerns/HasSetting.php b/src/Concerns/HasSetting.php index 302398a..b0ec58a 100644 --- a/src/Concerns/HasSetting.php +++ b/src/Concerns/HasSetting.php @@ -156,7 +156,7 @@ private function modifiedState(): array $properties = $state['properties']; - if (!empty($properties) && isset($properties['old']) && isset($properties['attributes'])) { + if (! empty($properties) && isset($properties['old']) && isset($properties['attributes'])) { $oldValues = $properties['old']; $newValues = $properties['attributes']; @@ -165,7 +165,7 @@ private function modifiedState(): array foreach ($newValues as $key => $newValue) { if (isset($oldValues[$key]) && $oldValues[$key] != $newValue) { - $changes[] = "- {$key} from " . htmlspecialchars($oldValues[$key]) . ' to ' . htmlspecialchars($newValue) . ''; + $changes[] = "- {$key} from ".htmlspecialchars($oldValues[$key]).' to '.htmlspecialchars($newValue).''; } }