Skip to content

Commit 100316f

Browse files
authored
feat: better design (#72)
* fix sidebar clipping and main content stretching * feat: collapsed menu + worked some colors * fix: colors and contrasts * chore: update deps * fix: TOC scrolling * fix: colors, contrasts, paddings * fix: sidebar TOC weight colors & contrasts * fix: step down headings + balances + fix mobile * fix: footer mobile * fix: social icons
1 parent 063e7a9 commit 100316f

20 files changed

+509
-448
lines changed

app/Http/Controllers/ShowDocumentationController.php

+36-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Illuminate\Support\Str;
1313
use Illuminate\View\View;
1414
use InvalidArgumentException;
15-
use Spatie\Menu\Link;
15+
use Spatie\Menu\Html;
1616
use Spatie\Menu\Menu;
1717
use Spatie\YamlFrontMatter\YamlFrontMatter;
1818
use Symfony\Component\Finder\Finder;
@@ -39,9 +39,10 @@ public function __invoke(Request $request, string $version, ?string $page = null
3939
}
4040

4141
try {
42-
$pageProperties = Cache::remember("docs_{$version}_{$page}", now()->addDay(), function () use ($version, $page) {
43-
return $this->getPageProperties($version, $page);
44-
});
42+
$pageProperties = Cache::remember("docs_{$version}_{$page}", now()->addDay(),
43+
function () use ($version, $page) {
44+
return $this->getPageProperties($version, $page);
45+
});
4546
} catch (InvalidArgumentException $e) {
4647
return $this->redirectToFirstNavigationPage($navigation, $page);
4748
}
@@ -77,11 +78,33 @@ protected function getPageProperties($version, $page = null): array
7778
if (array_key_exists('path', $nav)) {
7879
$menu->link($nav['path'], $nav['title']);
7980
} elseif (array_key_exists('children', $nav)) {
80-
$menu->submenu(Link::to($nav['children'][0]['path'], $nav['title']), function (Menu $submenu) use ($nav) {
81-
foreach ($nav['children'] as $child) {
82-
$submenu->link($child['path'], $child['title']);
83-
}
84-
});
81+
$menu->setItemParentAttribute('x-data', '{ open: $el.classList.contains(\'active\') }');
82+
83+
$header = Html::raw('
84+
<a href="'.$nav['children'][0]['path'].'" class="flex items-center gap-2 justify-between" x-on:click.prevent="open = !open">
85+
<span>'.$nav['title'].'</span>
86+
<span class="text-gray-400 dark:text-gray-600">
87+
<svg x-show="open" x-cloak class="size-3" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
88+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
89+
</svg>
90+
<svg x-show="!open" x-cloak class="size-3" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
91+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 15l7-7 7 7"></path>
92+
</svg>
93+
</span>
94+
</a>
95+
');
96+
97+
$submenu = Menu::new()
98+
->setAttributes([
99+
'x-show' => 'open',
100+
'x-collapse' => '',
101+
'x-cloak' => '',
102+
]);
103+
foreach ($nav['children'] as $child) {
104+
$submenu->link($child['path'], $child['title']);
105+
}
106+
107+
$menu->submenu($header, $submenu);
85108
}
86109
})
87110
->setActive(\request()->path())
@@ -223,6 +246,7 @@ protected function extractTableOfContents(string $document): array
223246
'anchor' => Str::slug(Str::replace('`', 'code', $title)),
224247
];
225248
})
249+
->values()
226250
->toArray();
227251
}
228252

@@ -263,7 +287,7 @@ protected function redirectToFirstNavigationPage(array $navigation, $page = null
263287
->filter(function ($nav) {
264288
return array_key_exists('path', $nav) || array_key_exists('children', $nav);
265289
})
266-
->map(function ($nav) {
290+
->flatMap(function ($nav) {
267291
if (array_key_exists('path', $nav)) {
268292
return $nav;
269293
}
@@ -273,14 +297,14 @@ protected function redirectToFirstNavigationPage(array $navigation, $page = null
273297

274298
return null;
275299
})
276-
->flatten(1)
277300
->first();
278301

279302
if (is_null($firstNavigationPath) && ! is_null($page)) {
280303
return $this->redirectToFirstNavigationPage($navigation);
281304
}
282305

283-
return is_string($firstNavigationPath) ? redirect($firstNavigationPath, 301) : redirect($firstNavigationPath['path'], 301);
306+
return is_string($firstNavigationPath) ? redirect($firstNavigationPath,
307+
301) : redirect($firstNavigationPath['path'], 301);
284308
}
285309

286310
protected function getMarkdownView($view, array $data = [], array $mergeData = []): View

app/Support/CommonMark/HeadingRenderer.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer)
2626
$element->setContents(
2727
new HtmlElement(
2828
'a',
29-
['href' => "#{$id}", 'class' => 'mr-2 no-underline', 'style' => 'border-bottom: 0 !important;'],
30-
new HtmlElement('div', ['class' => 'inline font-bold text-indigo-600'], '#'),
29+
['href' => "#{$id}", 'class' => 'mr-2 no-underline font-medium', 'style' => 'border-bottom: 0 !important;'],
30+
new HtmlElement('span', ['class' => ' text-gray-600 dark:text-gray-400 hover:text-[#00aaa6]'], '#'),
3131
).
3232
$element->getContents()
3333
);

0 commit comments

Comments
 (0)