التواصل
contact-01
نموذج تواصل في المنتصف: سطر تعريفي وعنوان ومقدمة فوق حقول الاسم والبريد والرسالة، مع مربع قبول الشروط وزر إرسال.
{{--
Every piece of content is a prop, so you can drive this block from a CMS.
A field is ['name' =>, 'label' =>, 'type' =>, 'placeholder' =>, 'required' =>,
'width' =>, 'options' =>]. type is text, email, tel, textarea, select or
radio (any other value is passed to the input as its type). width is full
(default), half (half width at every size) or md:half (full on phones,
half from md up). select and radio read 'options': plain strings or
['label' => ..., 'value' => ...]. Pass :terms="false" to drop the checkbox.
method can be GET, POST, PUT, PATCH or DELETE; a @csrf field is added for
anything but GET unless you pass :csrf="false".
<x-ui.blocks.contact-01
tagline="Support"
heading="Get in touch"
description="We reply within one working day."
:action="route('contact.store')"
:fields="[
['name' => 'name', 'label' => 'Your name', 'required' => true],
['name' => 'email', 'label' => 'Email', 'type' => 'email', 'required' => true],
['name' => 'message', 'label' => 'How can we help?', 'type' => 'textarea', 'placeholder' => 'Tell us a little about it'],
]"
terms="I agree to the"
:terms-link="['label' => 'privacy policy', 'href' => '/privacy']"
submit-label="Send message"
/>
--}}
@props([
'tagline' => 'Tagline',
'heading' => 'Contact us',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'action' => '#',
'method' => 'POST',
'csrf' => true,
'fields' => [
['name' => 'name', 'label' => 'Name', 'type' => 'text', 'required' => true],
['name' => 'email', 'label' => 'Email', 'type' => 'email', 'required' => true],
[
'name' => 'message',
'label' => 'Message',
'type' => 'textarea',
'placeholder' => 'Type your message...',
'required' => true,
],
],
'terms' => 'I accept the',
'termsLink' => ['label' => 'Terms', 'href' => '#'],
'submitLabel' => 'Submit',
])
@php
// A plain form only knows GET and POST; anything else is spoofed with _method.
$verb = strtoupper($method);
$formMethod = $verb === 'GET' ? 'GET' : 'POST';
@endphp
<section {{ $attributes->merge(['class' => 'bg-background px-[5%] py-16 text-foreground md:py-24 lg:py-28']) }}>
<div class="mx-auto max-w-7xl">
<div class="mx-auto mb-8 max-w-3xl text-center md:mb-12 lg:mb-20">
@if ($tagline)
<p class="mb-3 font-semibold md:mb-4">{{ $tagline }}</p>
@endif
<h2 class="mb-5 text-4xl font-bold leading-[1.2] md:mb-6 md:text-5xl">{{ $heading }}</h2>
@if ($description)
<p class="text-muted-foreground md:text-lg">{{ $description }}</p>
@endif
</div>
<form action="{{ $action }}" method="{{ $formMethod }}" class="flex flex-col gap-6 mx-auto max-w-140">
@if ($formMethod === 'POST')
@if ($csrf)
@csrf
@endif
@if ($verb !== 'POST')
@method($verb)
@endif
@endif
<div class="grid grid-cols-2 gap-6">
@foreach ($fields as $field)
@php
$type = $field['type'] ?? 'text';
$fieldName = $field['name'] ?? 'field_' . $loop->index;
$fieldId = 'contact-01-' . $fieldName;
$span = match ($field['width'] ?? 'full') {
'half' => 'col-span-1',
'md:half' => 'col-span-2 md:col-span-1',
default => 'col-span-2',
};
$options = array_map(
static fn($option): array => is_array($option)
? $option + ['value' => $option['label'] ?? '']
: ['label' => $option, 'value' => $option],
$field['options'] ?? [],
);
@endphp
@if ($type === 'radio')
<div class="{{ $span }} py-4">
<fieldset>
<legend class="mb-4 text-sm font-medium">{{ $field['label'] ?? '' }}</legend>
<div class="grid grid-cols-2 gap-x-6 gap-y-3.5">
@foreach ($options as $option)
<x-ui.label class="font-normal">
<x-ui.radio name="{{ $fieldName }}" value="{{ $option['value'] }}"
:required="$field['required'] ?? false" />
{{ $option['label'] }}
</x-ui.label>
@endforeach
</div>
</fieldset>
</div>
@else
<div class="{{ $span }} flex flex-col gap-2">
<x-ui.label for="{{ $fieldId }}">{{ $field['label'] ?? '' }}</x-ui.label>
@if ($type === 'textarea')
<x-ui.textarea id="{{ $fieldId }}" name="{{ $fieldName }}"
placeholder="{{ $field['placeholder'] ?? '' }}"
:required="$field['required'] ?? false" class="min-h-45" />
@elseif ($type === 'select')
<x-ui.select id="{{ $fieldId }}" name="{{ $fieldName }}"
:required="$field['required'] ?? false">
<option value="" disabled selected>{{ $field['placeholder'] ?? '' }}</option>
@foreach ($options as $option)
<option value="{{ $option['value'] }}">{{ $option['label'] }}</option>
@endforeach
</x-ui.select>
@else
<x-ui.input type="{{ $type }}" id="{{ $fieldId }}" name="{{ $fieldName }}"
placeholder="{{ $field['placeholder'] ?? '' }}"
:required="$field['required'] ?? false" />
@endif
</div>
@endif
@endforeach
</div>
@if ($terms)
<div class="flex items-center gap-2 pb-4">
<x-ui.checkbox id="contact-01-terms" name="terms" value="1" required />
<x-ui.label for="contact-01-terms" class="font-normal">
<span>
{{ $terms }}
@if ($termsLink)
<a href="{{ is_array($termsLink) ? $termsLink['href'] ?? '#' : '#' }}"
class="underline underline-offset-4">{{ is_array($termsLink) ? $termsLink['label'] ?? '' : $termsLink }}</a>
@endif
</span>
</x-ui.label>
</div>
@endif
<x-ui.button type="submit" size="lg" class="self-center">{{ $submitLabel }}</x-ui.button>
</form>
</div>
</section>
التثبيت
php artisan ui:add-block contact-01
أمر واحد يثبّت ملف Blade الخاص بالقالب وكل مكوّن يعتمد عليه. اعرضه في تخطيطك كالتالي
<x-ui.blocks.contact-01
/>.
1. ثبّت المكونات المطلوبة
php artisan ui:add button checkbox input label textarea
2. حزم خارجية
- composer:
gehrisandro/tailwind-merge-laravel
3.
انسخ كود القالب إلى
resources/views/components/ui/
resources/views/components/ui/blocks/contact-01.blade.php
{{--
Every piece of content is a prop, so you can drive this block from a CMS.
A field is ['name' =>, 'label' =>, 'type' =>, 'placeholder' =>, 'required' =>,
'width' =>, 'options' =>]. type is text, email, tel, textarea, select or
radio (any other value is passed to the input as its type). width is full
(default), half (half width at every size) or md:half (full on phones,
half from md up). select and radio read 'options': plain strings or
['label' => ..., 'value' => ...]. Pass :terms="false" to drop the checkbox.
method can be GET, POST, PUT, PATCH or DELETE; a @csrf field is added for
anything but GET unless you pass :csrf="false".
<x-ui.blocks.contact-01
tagline="Support"
heading="Get in touch"
description="We reply within one working day."
:action="route('contact.store')"
:fields="[
['name' => 'name', 'label' => 'Your name', 'required' => true],
['name' => 'email', 'label' => 'Email', 'type' => 'email', 'required' => true],
['name' => 'message', 'label' => 'How can we help?', 'type' => 'textarea', 'placeholder' => 'Tell us a little about it'],
]"
terms="I agree to the"
:terms-link="['label' => 'privacy policy', 'href' => '/privacy']"
submit-label="Send message"
/>
--}}
@props([
'tagline' => 'Tagline',
'heading' => 'Contact us',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'action' => '#',
'method' => 'POST',
'csrf' => true,
'fields' => [
['name' => 'name', 'label' => 'Name', 'type' => 'text', 'required' => true],
['name' => 'email', 'label' => 'Email', 'type' => 'email', 'required' => true],
[
'name' => 'message',
'label' => 'Message',
'type' => 'textarea',
'placeholder' => 'Type your message...',
'required' => true,
],
],
'terms' => 'I accept the',
'termsLink' => ['label' => 'Terms', 'href' => '#'],
'submitLabel' => 'Submit',
])
@php
// A plain form only knows GET and POST; anything else is spoofed with _method.
$verb = strtoupper($method);
$formMethod = $verb === 'GET' ? 'GET' : 'POST';
@endphp
<section {{ $attributes->merge(['class' => 'bg-background px-[5%] py-16 text-foreground md:py-24 lg:py-28']) }}>
<div class="mx-auto max-w-7xl">
<div class="mx-auto mb-8 max-w-3xl text-center md:mb-12 lg:mb-20">
@if ($tagline)
<p class="mb-3 font-semibold md:mb-4">{{ $tagline }}</p>
@endif
<h2 class="mb-5 text-4xl font-bold leading-[1.2] md:mb-6 md:text-5xl">{{ $heading }}</h2>
@if ($description)
<p class="text-muted-foreground md:text-lg">{{ $description }}</p>
@endif
</div>
<form action="{{ $action }}" method="{{ $formMethod }}" class="flex flex-col gap-6 mx-auto max-w-140">
@if ($formMethod === 'POST')
@if ($csrf)
@csrf
@endif
@if ($verb !== 'POST')
@method($verb)
@endif
@endif
<div class="grid grid-cols-2 gap-6">
@foreach ($fields as $field)
@php
$type = $field['type'] ?? 'text';
$fieldName = $field['name'] ?? 'field_' . $loop->index;
$fieldId = 'contact-01-' . $fieldName;
$span = match ($field['width'] ?? 'full') {
'half' => 'col-span-1',
'md:half' => 'col-span-2 md:col-span-1',
default => 'col-span-2',
};
$options = array_map(
static fn($option): array => is_array($option)
? $option + ['value' => $option['label'] ?? '']
: ['label' => $option, 'value' => $option],
$field['options'] ?? [],
);
@endphp
@if ($type === 'radio')
<div class="{{ $span }} py-4">
<fieldset>
<legend class="mb-4 text-sm font-medium">{{ $field['label'] ?? '' }}</legend>
<div class="grid grid-cols-2 gap-x-6 gap-y-3.5">
@foreach ($options as $option)
<x-ui.label class="font-normal">
<x-ui.radio name="{{ $fieldName }}" value="{{ $option['value'] }}"
:required="$field['required'] ?? false" />
{{ $option['label'] }}
</x-ui.label>
@endforeach
</div>
</fieldset>
</div>
@else
<div class="{{ $span }} flex flex-col gap-2">
<x-ui.label for="{{ $fieldId }}">{{ $field['label'] ?? '' }}</x-ui.label>
@if ($type === 'textarea')
<x-ui.textarea id="{{ $fieldId }}" name="{{ $fieldName }}"
placeholder="{{ $field['placeholder'] ?? '' }}"
:required="$field['required'] ?? false" class="min-h-45" />
@elseif ($type === 'select')
<x-ui.select id="{{ $fieldId }}" name="{{ $fieldName }}"
:required="$field['required'] ?? false">
<option value="" disabled selected>{{ $field['placeholder'] ?? '' }}</option>
@foreach ($options as $option)
<option value="{{ $option['value'] }}">{{ $option['label'] }}</option>
@endforeach
</x-ui.select>
@else
<x-ui.input type="{{ $type }}" id="{{ $fieldId }}" name="{{ $fieldName }}"
placeholder="{{ $field['placeholder'] ?? '' }}"
:required="$field['required'] ?? false" />
@endif
</div>
@endif
@endforeach
</div>
@if ($terms)
<div class="flex items-center gap-2 pb-4">
<x-ui.checkbox id="contact-01-terms" name="terms" value="1" required />
<x-ui.label for="contact-01-terms" class="font-normal">
<span>
{{ $terms }}
@if ($termsLink)
<a href="{{ is_array($termsLink) ? $termsLink['href'] ?? '#' : '#' }}"
class="underline underline-offset-4">{{ is_array($termsLink) ? $termsLink['label'] ?? '' : $termsLink }}</a>
@endif
</span>
</x-ui.label>
</div>
@endif
<x-ui.button type="submit" size="lg" class="self-center">{{ $submitLabel }}</x-ui.button>
</form>
</div>
</section>
الاستخدام
Every piece of content is a prop, so you can drive this block from a CMS. A field is ['name' =>, 'label' =>, 'type' =>, 'placeholder' =>, 'required' =>, 'width' =>, 'options' =>]. type is text, email, tel, textarea, select or radio (any other value is passed to the input as its type). width is full (default), half (half width at every size) or md:half (full on phones, half from md up). select and radio read 'options': plain strings or ['label' => ..., 'value' => ...]. Pass :terms="false" to drop the checkbox. method can be GET, POST, PUT, PATCH or DELETE; a @csrf field is added for anything but GET unless you pass :csrf="false".
<x-ui.blocks.contact-01
tagline="Support"
heading="Get in touch"
description="We reply within one working day."
:action="route('contact.store')"
:fields="[
['name' => 'name', 'label' => 'Your name', 'required' => true],
['name' => 'email', 'label' => 'Email', 'type' => 'email', 'required' => true],
['name' => 'message', 'label' => 'How can we help?', 'type' => 'textarea', 'placeholder' => 'Tell us a little about it'],
]"
terms="I agree to the"
:terms-link="['label' => 'privacy policy', 'href' => '/privacy']"
submit-label="Send message"
/>
الخصائص
كل خاصية مع قيمتها الافتراضية. مرّر أيًّا منها كسمة، واستخدم : لربط قيمة PHP.
@props([
'tagline' => 'Tagline',
'heading' => 'Contact us',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'action' => '#',
'method' => 'POST',
'csrf' => true,
'fields' => [
['name' => 'name', 'label' => 'Name', 'type' => 'text', 'required' => true],
['name' => 'email', 'label' => 'Email', 'type' => 'email', 'required' => true],
[
'name' => 'message',
'label' => 'Message',
'type' => 'textarea',
'placeholder' => 'Type your message...',
'required' => true,
],
],
'terms' => 'I accept the',
'termsLink' => ['label' => 'Terms', 'href' => '#'],
'submitLabel' => 'Submit',
])