Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Il faut une majuscule ici, non ?

{
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 ?? '--')),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le -- est la valeur par défaut si $this->author vaut null, donc pas besoin de le mettre.

];
}

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

&: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(20);
}
}
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 @@
<div class="blockquote">
<blockquote class="blockquote__quote">
{{ $text }}
</blockquote>
@if($author)
<cite class="blockquote__author">{{ $author }}</cite>
@endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D'après https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/blockquote ce sont des paragraphes qu'il faut mettre dans le contenu du blocquote. Du coup je te suggère simplement de passer le type de field à WYSIWYG, ça nous emmerdera moins par la suite.

Attention que <cite> ne sert pas à baliser l'auteur. C'est pour la source uniquement :

The cite element represents the title of a work (e.g. a book, a paper, [...])

A person's name is not the title of a work [...] and the element must therefore not be used to mark up people's names.

Il semblerait plus adéquat d'utiliser figure + blockquote + figcaption :)
https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/figure#quotations

</div>
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\" />`";
}
}