Skip to content

Commit

Permalink
Re-use notification partial for form error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
robdekort committed Feb 10, 2025
1 parent 7780cc8 commit 9b2eee6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
33 changes: 19 additions & 14 deletions export/resources/views/components/_notification.antlers.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{#
@name Notification
@desc The notification component. Currently used in `resources/views/page_builder/_form.antlers.html`.
@param* content The notification content.
@param* type The type of notification: `success`, `notice`, or `error`.
@param content The notification content.
@param class Add custom CSS classes.
#}}

Expand All @@ -18,6 +18,7 @@
)}}
{{ class }}
"
{{ slot:attributes }}
>
<div class="flex">
<div class="shrink-0">
Expand All @@ -37,19 +38,23 @@
}}
</div>
<div class="ml-3">
<h3
class="
text-sm leading-5 font-bold
{{ switch(
(type == 'success') => 'text-green-800',
(type == 'notice') => 'text-yellow-800',
(type == 'error') => 'text-red-800',
() => 'text-gray-800'
)}}
"
>
{{ content }}
</h3>
{{ if content }}
<h3
class="
text-sm leading-5 font-bold
{{ switch(
(type == 'success') => 'text-green-800',
(type == 'notice') => 'text-yellow-800',
(type == 'error') => 'text-red-800',
() => 'text-gray-800'
)}}
"
>
{{ content }}
</h3>
{{ /if }}

{{ slot }}
</div>
</div>
</div>
Expand Down
5 changes: 3 additions & 2 deletions export/resources/views/page_builder/_form.antlers.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
<div x-data="formHandler()" class="flex flex-col gap-8" x-cloak>
{{# Error notifications. #}}
<template x-if="form.hasErrors && submitted">
<div id="summary" role="group" class="rounded-sm border p-4 bg-red-50 border-red-700">
{{ partial:components/notification type="error" }}
{{ slot:attributes }}id="summary" role="group"{{ /slot:attributes }}
<h3 class="mb-2 leading-5 font-bold text-red-700">{{ trans:strings.form_error }}</h3>
<ul class="list-disc list-inside marker:text-red-700">
<template x-for="(error, index) in form.errors">
Expand All @@ -26,7 +27,7 @@ <h3 class="mb-2 leading-5 font-bold text-red-700">{{ trans:strings.form_error }}
</li>
</template>
</ul>
</div>
{{ /partial:components/notification }}
</template>

{{# Success notifications. #}}
Expand Down

0 comments on commit 9b2eee6

Please # to comment.