-
-
Notifications
You must be signed in to change notification settings - Fork 44
Reimagine Navigation rendering features #199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 3.x
Are you sure you want to change the base?
Changes from all commits
8ba78d8
bbeda2e
cd0526f
af8a186
42c3cb3
6b514b4
809143d
73b6cdc
b6c00b4
7bfddb3
6b0df43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <a {{ $attributes->except(['label', 'hasLabelWrap']) }}> | ||
| {{ $label }} | ||
| </a> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php | ||
|
|
||
| namespace LaraZeus\Sky\Classes\LinkRenderers; | ||
|
|
||
| use Illuminate\Database\Eloquent\Model; | ||
|
|
||
| class GenericLinkRenderer extends NavLinkRenderer | ||
| { | ||
| public function getModel(): ?Model | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| public function getLink(): ?string | ||
| { | ||
| return $this->item['data']['url']; | ||
| } | ||
|
|
||
| public function isActiveRoute(): bool | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?php | ||
|
|
||
| namespace LaraZeus\Sky\Classes\LinkRenderers; | ||
|
|
||
| use Illuminate\Database\Eloquent\Model; | ||
| use LaraZeus\Sky\Models\Library; | ||
| use LaraZeus\Sky\SkyPlugin; | ||
|
|
||
| class LibraryLinkRenderer extends NavLinkRenderer | ||
| { | ||
| public static string $rendersKey = 'library-link'; | ||
|
|
||
| public function getModel(): ?Model | ||
atmonshi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| return SkyPlugin::get()->getModel('Tag')::find($this->item['data']['library_id']); | ||
| } | ||
|
|
||
| public function getLink(): ?string | ||
| { | ||
| /** | ||
| * @var Library $tag | ||
| */ | ||
| $tag = $this->getModel(); | ||
|
|
||
| return route('library.tag', $tag->slug); | ||
| } | ||
|
|
||
| public function isActiveRoute(): bool | ||
| { | ||
| /** | ||
| * @var Library $tag | ||
| */ | ||
| $tag = $this->getModel(); | ||
|
|
||
| return str(request()->url())->contains($tag->library->first()->slug); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| <?php | ||
|
|
||
| namespace LaraZeus\Sky\Classes\LinkRenderers; | ||
|
|
||
| use Illuminate\Database\Eloquent\Model; | ||
|
|
||
| abstract class NavLinkRenderer | ||
| { | ||
| public static string $rendersKey; | ||
|
|
||
| public function __construct( | ||
| protected array $item | ||
| ) { | ||
| } | ||
|
|
||
| public static string $activeClasses = 'border-b border-b-secondary-500 text-secondary-500'; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned - having something to control this could be nice, tho not necessary immediately. |
||
|
|
||
| public static string $nonActiveClasses = 'border-transparent'; | ||
|
|
||
| abstract public function getModel(): ?Model; | ||
|
|
||
| abstract public function getLink(): ?string; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think this one was made nullable on accident 🤔 - technically the most "empty" thing we need out of this is an empty string. Don't think it actually needs to be able to be null?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a use case come to mind, I did use it in on project but for the love of god cant find which one was... the menu can have nested items, for a dropdown menu with sub nav, so maybe in this case the link can be null! |
||
|
|
||
| abstract public function isActiveRoute(): bool; | ||
|
|
||
| public function getActiveClass(): string | ||
| { | ||
| return $this->isActiveRoute() ? | ||
| self::$activeClasses : | ||
| self::$nonActiveClasses; | ||
| } | ||
|
|
||
| /** | ||
| * @return array{} | ||
| */ | ||
| public function getPreparedLink(string $classes = ''): array | ||
| { | ||
| return [ | ||
| 'class' => $classes . ' ' . $this->getActiveClass(), | ||
| 'target' => $this->item['data']['target'] ?? '_self', | ||
| 'href' => $this->getLink(), | ||
| 'label' => $this->item['label'], | ||
| ]; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <?php | ||
|
|
||
| namespace LaraZeus\Sky\Classes\LinkRenderers; | ||
|
|
||
| use Illuminate\Database\Eloquent\Model; | ||
| use LaraZeus\Sky\Models\Post; | ||
| use LaraZeus\Sky\SkyPlugin; | ||
|
|
||
| class PageLinkRenderer extends NavLinkRenderer | ||
| { | ||
| public static string $rendersKey = 'page-link'; | ||
|
|
||
| public function getModel(): ?Model | ||
| { | ||
| return SkyPlugin::get()->getModel('Post')::page() | ||
| ->whereDate('published_at', '<=', now()) | ||
| ->find($this->item['data']['page_id']); | ||
| } | ||
|
|
||
| public function getLink(): ?string | ||
| { | ||
| /** | ||
| * @var Post $page | ||
| */ | ||
| $page = $this->getModel(); | ||
|
|
||
| return route('page', $page); | ||
| } | ||
|
|
||
| public function isActiveRoute(): bool | ||
| { | ||
| /** | ||
| * @var Post $page | ||
| */ | ||
| $page = $this->getModel(); | ||
|
|
||
| return request()->routeIs('page', $page); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?php | ||
|
|
||
| namespace LaraZeus\Sky\Classes\LinkRenderers; | ||
|
|
||
| use Illuminate\Database\Eloquent\Model; | ||
| use LaraZeus\Sky\Models\Post; | ||
| use LaraZeus\Sky\SkyPlugin; | ||
|
|
||
| class PostLinkRenderer extends NavLinkRenderer | ||
| { | ||
| public static string $rendersKey = 'post-link'; | ||
|
|
||
| public function getModel(): ?Model | ||
| { | ||
| return SkyPlugin::get()->getModel('Post')::whereDate('published_at', '<=', now()) | ||
| ->find($this->item['data']['post_id']); | ||
| } | ||
|
|
||
| public function getLink(): ?string | ||
| { | ||
| /** | ||
| * @var Post $post | ||
| */ | ||
| $post = $this->getModel(); | ||
|
|
||
| return route('post', $post); | ||
| } | ||
|
|
||
| public function isActiveRoute(): bool | ||
| { | ||
| /** | ||
| * @var Post $post | ||
| */ | ||
| $post = $this->getModel(); | ||
|
|
||
| return request()->routeIs('post', $post); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <?php | ||
|
|
||
| namespace LaraZeus\Sky\Components; | ||
|
|
||
| use Illuminate\View\Component; | ||
|
|
||
| class SkyLink extends Component | ||
| { | ||
| public function __construct( | ||
| public string $label, | ||
| public ?bool $hasLabelWrap = false, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| public function render() | ||
| { | ||
| return view('zeus.sky-link', $this->data()); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.