Skip to content

Commit

Permalink
Fix toggle functionality and improve keyboard control
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeWithDennis committed Oct 20, 2024
1 parent a7d93a3 commit 210b49e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
4 changes: 2 additions & 2 deletions resources/dist/filament-theme-inspector.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 16 additions & 11 deletions resources/js/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

function createPopup() {
const popup = document.createElement('div');
popup.classList.add('theme-inspector-container');
Expand Down Expand Up @@ -94,19 +93,25 @@ document.body.addEventListener('mouseenter', (e) => {
}, true);

document.body.addEventListener('mouseleave', (e) => {
// Hide the popup when the mouse leaves the target
if (e.target.matches('[class*="fi-"]') && !isFrozen) {
hidePopup(popup);
}
}, true);

document.addEventListener('keydown', (e) => {
if (e.altKey) {
isFrozen = true;
popup.style.pointerEvents = 'auto';
}
});
if (window.filamentData.toggle === true) {
document.addEventListener('keydown', (e) => {
if (e.key === 'Alt') {
isFrozen = !isFrozen;
}
});
} else {
document.addEventListener('keydown', (e) => {
if (e.altKey) {
isFrozen = true;
}
});

document.addEventListener('keyup', (e) => {
if (e.key === 'Alt' || e.key === 'Meta') isFrozen = false;
});
document.addEventListener('keyup', (e) => {
if (e.key === 'Alt' || e.key === 'Meta') isFrozen = false;
});
}
18 changes: 18 additions & 0 deletions src/FilamentThemeInspectorPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@ class FilamentThemeInspectorPlugin implements Plugin

protected Closure | bool $disabled = false;

protected bool $toggle = false;

public function getId(): string
{
return 'filament-theme-inspector';
}

public function toggle(bool $toggle = true): self
{
$this->toggle = $toggle;

return $this;
}

public function disabled(Closure | bool $disabled = true): self
{
$this->disabled = $disabled;
Expand All @@ -33,13 +42,22 @@ public function isDisabled(): bool
return $this->evaluate($this->disabled);
}

public function isToggle(): bool
{
return $this->toggle;
}

public function register(Panel $panel): void
{
if (! $this->isDisabled()) {
FilamentAsset::register([
Js::make('filament-theme-inspector-scripts', __DIR__ . '/../resources/dist/filament-theme-inspector.js'),
Css::make('filament-theme-inspector-styles', __DIR__ . '/../resources/dist/filament-theme-inspector.css'),
]);

FilamentAsset::registerScriptData([
'toggle' => $this->isToggle(),
]);
}
}

Expand Down

0 comments on commit 210b49e

Please sign in to comment.