Skip to content
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,40 @@ Usage:
<x-brave-read-speaker />
```

### Tolkie

Enqueues the Tolkie script and adds the button placeholder.
It [automatically](./src/Hooks/Tolkie.php) adds a placeholder bellow every `H1` heading.

Usage:

1. Add the Tolkie token to the config
```
return [
...

'tolkie' => [
'token' => 'yourtokenhere',
],
];
```
2. If needed add the button placeholder component to the templates
```blade
<x-brave-tolkie />
```

If needed you can configure the Tolkie script in the config. Every attribute you would normally add in `wp_print_script_tag()` can be added here.

Lets say you want to add a new `data` attribute:
```
'tolkie' => [
'html_attributes' => [
'data-tolkie-new-option' => 'new-value',
'data-tolkie-state' => 'separateButtons',
]
],
```

### Nav

Navigation component with optional dropdowns. Provides the right ARIA attributes and keyboard navigation for accessibility.
Expand Down
7 changes: 7 additions & 0 deletions config/components.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@
'disable' => '',
'automaticallyAddToH1' => true,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

automaticallyAddToH1 => automatically_add_to_h1 👀

Kunnen we dit nog aanpassen met backwards compatibility

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Da was nie mijn aanpassing! Maar wel cool om dat voor Tolkie toe te voegen ja :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Die van readSpeaker pak ik op in een tweede pr

],
'tolkie' => [
'token' => null,
'automatically_add_to_h1' => true,
'html_attributes' => [
'data-tolkie-state' => 'separateButtons',
],
],
];
1 change: 1 addition & 0 deletions resources/views/components/tolkie.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="tolkie-buttons-afterbegin"></div>
17 changes: 17 additions & 0 deletions src/Components/Tolkie.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Yard\Brave\Components;

use Illuminate\Contracts\View\Factory;
use Illuminate\View\Component;
use Illuminate\View\View;

class Tolkie extends Component
{
public function render(): Factory|View
{
return view('brave::components.tolkie');
}
}
11 changes: 10 additions & 1 deletion src/ComponentsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Yard\Brave\Components\PatternContent;
use Yard\Brave\Components\ReadSpeaker;
use Yard\Brave\Components\SocialIcon;
use Yard\Brave\Components\Tolkie;
use Yard\Brave\Components\Tooltip;
use Yard\Hook\Registrar;

Expand All @@ -39,7 +40,8 @@ public function configurePackage(Package $package): void
PatternContent::class,
ReadSpeaker::class,
SocialIcon::class,
Tooltip::class
Tooltip::class,
Tolkie::class
);
}

Expand All @@ -55,6 +57,13 @@ public function packageBooted(): void
$hooks[] = Hooks\ReadSpeaker::class;
}

if ('' !== config('components.tolkie.token', '')) {
// dd(config('components.tolkie.token'), config('components.tolkie.automatically_add_to_h1'), [...config('components.tolkie.html_attributes', [
Comment thread
FreakyWizard marked this conversation as resolved.
// 'data-tolkie-state' => 'separateButtons',
// ]),]);
$hooks[] = Hooks\Tolkie::class;
}

(new Registrar($hooks))->registerHooks();
}
}
39 changes: 39 additions & 0 deletions src/Hooks/Tolkie.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace Yard\Brave\Hooks;

use Yard\Hook\Action;
use Yard\Hook\Filter;

class Tolkie
{
#[Action('wp_footer')]
public function addTolkieScript(): void
{
wp_print_script_tag([
...config('components.tolkie.html_attributes', [
'data-tolkie-state' => 'separateButtons',
]),
'class' => 'tolkieIntegrationScript',
'id' => 'tolkie-script',
'type' => 'module',
'src' => 'https://app.tolkie.nl/',
'crossorigin' => 'anonymous',
'defer' => '',
'data-tolkie-token' => config('components.tolkie.token'),
]);
}

#[Filter('render_block_core/heading')]
#[Filter('render_block_core/post-title')]
public function addTolkieTag(string $content, array $block): string
{
if (config('components.tolkie.automatically_add_to_h1', true) && 1 === ($block['attrs']['level'] ?? 0)) {
$content .= '<div class="tolkie-buttons-afterbegin"></div>';
}

return $content;
}
}