Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/filament-flexible-content-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@
],
],
'default' => 'primary',
'icon_positions'=> [
'flex-row-reverse' =>'left',
'flex-row' => 'right',
],
'icon_position_default' => 'left',
],

/*
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en/filament-flexible-content-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@
'form_component.content_blocks.call_to_action_cta_model' => 'Type',
'form_component.content_blocks.call_to_action_entry_id' => 'Page',
'form_component.content_blocks.call_to_action_button_style' => 'Button style',
'form_component.content_blocks.call_to_action_button_icon' => 'Button Icon',
'form_component.content_blocks.call_to_action_button_icon_position' => 'Button Icon Position',
'form_component.content_blocks.call_to_action_button_label' => 'Button label',
'form_component.content_blocks.call_to_action_button_open_in_new_window' => 'Open in new window?',
'form_component.content_blocks.call_to_action_route' => 'Route',
Expand Down
25 changes: 17 additions & 8 deletions resources/views/components/tailwind/call-to-action.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@
@if($callToAction->url)
<div {{$attributes}}>
<a href="{{$callToAction->url}}"
@if($callToAction->label) title="{{Statikbe\FilamentFlexibleContentBlocks\FilamentFlexibleContentBlocks::replaceParameters($callToAction->label)}}" @endif
class="@if($callToAction->buttonStyle) {{$callToAction->buttonStyle}} @endif @if($isFullyClickable) before:absolute before:inset-0 @endif"
@if($callToAction->openNewWindow) target="_blank" rel="noopener noreferrer" @endif>
@if($callToAction->label)
{{Statikbe\FilamentFlexibleContentBlocks\FilamentFlexibleContentBlocks::replaceParameters($callToAction->label)}}
@else
&xrarr;
@endif
@if($callToAction->label) title="{{Statikbe\FilamentFlexibleContentBlocks\FilamentFlexibleContentBlocks::replaceParameters($callToAction->label)}}" @endif
class="
@if($callToAction->buttonStyle) {{$callToAction->buttonStyle}} @endif
@if($isFullyClickable) before:absolute before:inset-0 @endif
@if($callToAction->icon) flex {{$callToAction->icon_position}} @endif
"
@if($callToAction->openNewWindow) target="_blank" rel="noopener noreferrer" @endif
>
@if($callToAction->label)
{{Statikbe\FilamentFlexibleContentBlocks\FilamentFlexibleContentBlocks::replaceParameters($callToAction->label)}}
@else
&xrarr;
@endif

@if($callToAction->icon)
<i class="{{$callToAction->icon}}" aria-hidden="true"></i>
@endif
</a>
</div>
@endif
14 changes: 14 additions & 0 deletions src/Filament/Form/Fields/Blocks/CallToActionField.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class CallToActionField extends Component

const FIELD_BUTTON_OPEN_NEW_WINDOW = 'button_open_new_window';

const FIELD_ICON = 'icon';

const FIELD_ICON_POSITION = 'icon_position';

protected string $view = 'filament-forms::components.fieldset';

public bool|Closure $isRequired = false;
Expand Down Expand Up @@ -160,6 +164,16 @@ public function getChildComponents(): array
->label(trans('filament-flexible-content-blocks::filament-flexible-content-blocks.form_component.content_blocks.call_to_action_button_open_in_new_window'))
->columnSpan(1)
->inline(false),
TextInput::make(static::FIELD_ICON)
->label(trans('filament-flexible-content-blocks::filament-flexible-content-blocks.form_component.content_blocks.call_to_action_button_icon'))
->reactive()
->columnSpan(3),
Select::make(static::FIELD_ICON_POSITION)
->label(trans('filament-flexible-content-blocks::filament-flexible-content-blocks.form_component.content_blocks.call_to_action_button_icon_position'))
->options(FilamentFlexibleBlocksConfig::getCallToActionButtonsIconPositionOptions(static::class))
->default(FilamentFlexibleBlocksConfig::getCallToActionButtonIconPositionDefault(static::class))
->visible(static::FIELD_ICON != '')
->columnSpan(2),
]),
];
}
Expand Down
8 changes: 8 additions & 0 deletions src/Filament/Form/Fields/Blocks/Data/CallToActionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public function __construct(
public ?string $label = null,
public ?string $buttonStyle = null,
public bool $openNewWindow = false,
public ?string $icon,
public ?string $icon_position,
) {}

/**
Expand Down Expand Up @@ -64,11 +66,17 @@ public static function create(array $callToActionBlockData, array $buttonStyleCl
$buttonStyle = $buttonStyleClasses[$buttonStyle];
}

$icon = $callToActionBlockData[CallToActionField::FIELD_ICON] ?? null;

$icon_position = $callToActionBlockData[CallToActionField::FIELD_ICON_POSITION] ?? null;

return new self(
$url,
$callToActionBlockData[CallToActionField::FIELD_BUTTON_LABEL] ?? null,
$buttonStyle,
$callToActionBlockData[CallToActionField::FIELD_BUTTON_OPEN_NEW_WINDOW] ?? false,
$icon ?? '',
$icon_position ?? 'left',
);
}
}
15 changes: 15 additions & 0 deletions src/FilamentFlexibleBlocksConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,14 @@ public static function getCallToActionButtonsConfig(string $blockClass): array
return self::getConfig($blockClass, 'call_to_action_buttons');
}

/**
* @return array<string, string>
*/
public static function getCallToActionButtonsIconPositionOptions(string $blockClass): array
{
return self::getCallToActionButtonsConfig($blockClass)['icon_positions'];
}

/**
* @return array<string, string>
*/
Expand All @@ -532,6 +540,13 @@ public static function getCallToActionButtonDefault(string $blockClass): ?string
{
return self::getDefault(self::getCallToActionButtonsConfig($blockClass));
}
/**
* @param class-string<AbstractContentBlock> $blockClass
*/
public static function getCallToActionButtonIconPositionDefault(string $blockClass): ?string
{
return self::getCallToActionButtonsConfig($blockClass)['icon_position_default'];
}

/**
* @param class-string<AbstractContentBlock> $blockClass
Expand Down