Skip to content

Commit

Permalink
feat: add option to disable default classes
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Frey <[email protected]>
  • Loading branch information
lukas-frey committed May 9, 2024
1 parent c41166f commit 89a5dab
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,18 @@ KnowledgeBasePanel::configureUsing(
);
```

#### Disable default classes
To disable the default styling altogether, you can use:

```php
use Guava\FilamentKnowledgeBase\Filament\Panels\KnowledgeBasePanel;

KnowledgeBasePanel::configureUsing(
fn(KnowledgeBasePanel $panel) => $panel
->disableDefaultClasses()
);
```

### Disable the knowledge base panel button
When in a panel where the Knowledge Base plugin is enabled, we render by default in the bottom of the sidebar a button to go to the knowledge base panel. You can disable it if you like:
```php
Expand Down
20 changes: 20 additions & 0 deletions src/Concerns/CanDisableDefaultClasses.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Guava\FilamentKnowledgeBase\Concerns;

trait CanDisableDefaultClasses
{
protected bool $disableDefaultClasses = false;

public function disableDefaultClasses(bool $condition = true): static
{
$this->disableDefaultClasses = $condition;

return $this;
}

public function shouldDisableDefaultClasses(): bool
{
return $this->evaluate($this->disableDefaultClasses);
}
}
2 changes: 2 additions & 0 deletions src/Filament/Panels/KnowledgeBasePanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Filament\Widgets\AccountWidget;
use Guava\FilamentKnowledgeBase\Concerns\CanDisableBackToDefaultPanelButton;
use Guava\FilamentKnowledgeBase\Concerns\CanDisableBreadcrumbs;
use Guava\FilamentKnowledgeBase\Concerns\CanDisableDefaultClasses;
use Guava\FilamentKnowledgeBase\Concerns\HasAnchorSymbol;
use Guava\FilamentKnowledgeBase\Concerns\HasArticleClass;
use Guava\FilamentKnowledgeBase\Contracts\Documentable;
Expand All @@ -43,6 +44,7 @@ class KnowledgeBasePanel extends Panel
{
use CanDisableBackToDefaultPanelButton;
use CanDisableBreadcrumbs;
use CanDisableDefaultClasses;
use HasAnchorSymbol;
use HasArticleClass;

Expand Down
21 changes: 12 additions & 9 deletions src/Markdown/MarkdownRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,28 @@ public function isMinimal(): bool
private function getOptions(): array
{
$anchorSymbol = KnowledgeBase::panel()->getAnchorSymbol();
$shouldDisableDefaultClasses = KnowledgeBase::panel()->shouldDisableDefaultClasses();

return [
'default_attributes' => [
Heading::class => [
'class' => static fn (Heading $node) => match ($node->getLevel()) {
1 => 'text-3xl mb-2 [&:first-child]:mt-0 mt-10',
2 => 'text-xl mb-2 [&:first-child]:mt-0 mt-2',
3 => 'text-lg mb-1 [&:first-child]:mt-0 mt-2',
default => null,
} . ' relative',
'class' => $shouldDisableDefaultClasses
? 'relative'
: static fn (Heading $node) => match ($node->getLevel()) {
1 => 'text-3xl mb-2 [&:first-child]:mt-0 mt-10',
2 => 'text-xl mb-2 [&:first-child]:mt-0 mt-2',
3 => 'text-lg mb-1 [&:first-child]:mt-0 mt-2',
default => null,
} . ' relative',
],
Paragraph::class => [
'class' => 'mb-4 [&:last-child]:mb-0 leading-relaxed',
'class' => $shouldDisableDefaultClasses ? '' : 'mb-4 [&:last-child]:mb-0 leading-relaxed',
],
Marker::class => [
'class' => 'bg-primary-500/20 dark:bg-primary-400/40 text-inherit rounded-md py-0.5 px-1.5',
],
BlockQuote::class => [
'class' => 'bg-white dark:bg-gray-900 mt-2 mb-4 p-4 rounded-md ring-1 ring-gray-950/5 dark:ring-white/10',
'class' => $shouldDisableDefaultClasses ? '' : 'bg-white dark:bg-gray-900 mt-2 mb-4 p-4 rounded-md ring-1 ring-gray-950/5 dark:ring-white/10',
],
],
'heading_permalink' => [
Expand All @@ -79,7 +82,7 @@ private function getOptions(): array
'enabled' => true,
'tag' => 'div',
'attributes' => [
'class' => Arr::toCssClasses([
'class' => $shouldDisableDefaultClasses ? '' : Arr::toCssClasses([
'divide-y divide-gray-200 overflow-hidden rounded-xl bg-white shadow-sm ring-1 ring-gray-950/5 dark:divide-white/10 dark:bg-gray-900 dark:ring-white/10',
'fi-ta-content relative divide-y divide-gray-200 overflow-x-auto dark:divide-white/10 dark:border-t-white/10 !border-t-0',
'[&_table]:fi-ta-table [&_table]:w-full [&_table]:table-auto [&_table]:divide-y [&_table]:divide-gray-200 [&_table]:text-start [&_table]:dark:divide-white/5',
Expand Down

0 comments on commit 89a5dab

Please sign in to comment.