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
40 changes: 40 additions & 0 deletions components/blockquote/Component.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\View\Components;

use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
use Whitecube\BemComponents\HasBemClasses;

class Blockquote extends Component
{
use HasBemClasses;

/**
* The blockquote's text.
*/
public string $text;

/**
* The blockquote's author.
*/
public ?string $author = null;

/**
* Create a new component instance.
*/
public function __construct(string $text, string $author = null)
{
$this->text = $text;
$this->author = $author;
}

/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.blockquote');
}
}
64 changes: 64 additions & 0 deletions components/blockquote/Layout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace App\Layouts\CMS;

use Hiker\Cms\Layouts\BaseLayout;
use Hiker\Components\DataList\DataList;
use Hiker\Components\Editor\Step;
use Hiker\Components\Fields\Text\Text;
use Hiker\Components\Fields\Textarea\Textarea;
use Hiker\Components\Text\Text as TextComponent;
use Hiker\Tracks\Baggage;

class Blockquote extends BaseLayout
{
/**
* The label of the layout
*/
public function label(): string
{
return 'Blockquote';
}

public function view(): string
{
return 'blockquote';
}

/**
* The list of steps to display in the form
*/
public function form(Baggage $bag): array
{
return [
Step::make(static::label(), 'edit_blockquote_layout')
->fields([
Textarea::make('Text', 'text')
->rules('required'),

Text::make('Author', 'author')
->help('Optionnal.'),
]),
];
}

/**
* The layout's display components
*/
public function display(): array
{
return [
DataList::make()
->row('Text', TextComponent::make($this->text))
->row('Author', TextComponent::make($this->author)),
];
}

/**
* Extract the values from the bag to store them in the database.
*/
public function fillAttributes(Baggage $bag): array
{
return $bag->only(['text', 'author']);
}
}
32 changes: 32 additions & 0 deletions components/blockquote/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
.blockquote {
margin: rem(28) auto;
position: relative;
padding-left: rem(20);
width: col(6, 12);
display: flex;
flex-direction: column-reverse;

&:after {
content: "";
position: absolute;
height: 100%;
width: 1px;
background-color: color(text-primary);
left: 0;
top: 0;
bottom: 0
}

&__quote {
font-size: rem(18);
line-height: 160%;
}

&__author {
display: block;
font-size: rem(12);
line-height: 100%;
text-transform: uppercase;
margin-top: rem(12);
}
}
8 changes: 8 additions & 0 deletions components/blockquote/view.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<figure class="blockquote">
@if($author)
<figcaption class="blockquote__author">{{ $author }}</figcaption>
@endif
<blockquote class="blockquote__quote">
<p>{{ $text }}</p>
</blockquote>
</figure>
60 changes: 60 additions & 0 deletions src/Components/Publishers/Blockquote.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Whitecube\LaravelPreset\Components\Publishers;

use Whitecube\LaravelPreset\Components\File;
use Whitecube\LaravelPreset\Components\FilesCollection;
use Whitecube\LaravelPreset\Components\PublisherInterface;

class Blockquote implements PublisherInterface
{
/**
* Get the component's displayable name.
*/
public function label(): string
{
return 'Blockquote';
}

/**
* Let the publisher prompt for eventual extra input
* and return a collection of publishable files.
*/
public function handle(): FilesCollection
{
$style = File::makeFromStub(
stub: 'components/blockquote/style.scss',
destination: resource_path('sass/parts/_blockquote.scss'),
);

$view = File::makeFromStub(
stub: 'components/blockquote/view.blade.php',
destination: resource_path('views/components/blockquote.blade.php'),
);

$component = File::makeFromStub(
stub: 'components/blockquote/Component.php',
destination: base_path('app/View/Components/Blockquote.php'),
);

$layout = File::makeFromStub(
stub: 'components/blockquote/Layout.php',
destination: base_path('app/Layouts/Blockquote.php'),
);

return FilesCollection::make([
$style,
$view,
$component,
$layout
]);
}

/**
* Get the component's usage instructions
*/
public function instructions(): ?string
{
return "1. Add `@import 'parts/blockquote';` to `resources/sass/app.scss`\r\n2. Use the blade component: `<x-blockquote text=\"By 2018, Partch had won awards and assembled a formidable portfolio of grants. She sat on the boards of learned societies. She’d had a second son and recruited a group of students and postdocs inspired by her vision. Priya Crosby, a recent postdoc in her lab, remembers meeting Partch at a party and feeling awed. Partch’s passion for understanding the clock was palpable, and she seemed to have every piece of data about it at her fingertips.\" author=\"Mauris pharetra turpis eget placerat fringilla\" />`";
}
}