Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions docs/app/_components/CommandItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { iterateTokens } from '@/lib/utils';
import { ruiTheme } from '@/theme';
import { Icons, cn } from '@/ui';
import { Command, CommandGroup, useCommandState } from 'cmdk';
import type { Route } from 'next';
import {
Dispatch,
ReactNode,
Expand All @@ -19,6 +20,10 @@ import { ExternalLink } from '@marigold/icons';
import { NestedStringObject } from '@marigold/system';
import { Hotkey } from './SiteMenu';

type RouteWithoutSlash<T extends string = Route> = T extends `/${infer Rest}`
? Rest
: T;

interface CopyItemProps {
children: ReactNode;
className?: string;
Expand Down Expand Up @@ -60,8 +65,17 @@ const useGoto = (
) => {
const router = useRouter();

const goto = ({ slug, hash = '' }: { slug: string; hash?: string }) => {
const url = `/${slug}${hash}`;
const goto = ({
slug,
hash,
}: {
slug: RouteWithoutSlash;
hash?: `#${string}`;
}) => {
let url: Route = `/${slug}`;
if (hash && hash.startsWith('#')) {
url = `/${slug}${hash}`;
}

router.push(url);
setOpen(false);
Expand Down Expand Up @@ -195,7 +209,7 @@ export const PagesItem = ({
key={page.slug}
value={page.slug}
keywords={[page.title]}
onSelect={() => goto({ slug: page.slug })}
onSelect={() => goto({ slug: page.slug as RouteWithoutSlash })}
>
<Inline space={4} alignY="center">
{page.title}
Expand All @@ -215,7 +229,10 @@ export const PagesItem = ({
classNames.item
)}
onSelect={() =>
goto({ slug: page.slug, hash: `#${sub.slug}` })
goto({
slug: page.slug as RouteWithoutSlash,
hash: `#${sub.slug}`,
})
}
>
{sub.text}
Expand All @@ -241,7 +258,7 @@ export const InternalPage = ({ classNames, setOpen }: ChangeOpenItemProps) => {
className={classNames.item}
key={name}
value={slug}
onSelect={() => goto({ slug })}
onSelect={() => goto({ slug: slug as RouteWithoutSlash })}
>
{name}
</Command.Item>
Expand Down
3 changes: 2 additions & 1 deletion docs/app/_components/SiteNavigation.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';

import type { Route } from 'next';
import { usePathname } from 'next/navigation';
import { NavLink } from '@/ui/navigation/NavLink';
import { useNavigation } from '@/ui/navigation/Navigation';
Expand All @@ -21,7 +22,7 @@ export const SiteNavigation = () => {
className="text-sm font-medium lg:px-1"
key={index}
current={pathname.startsWith(`/${slug}`)}
href={link?.href ?? `/${slug}`}
href={(link?.href ?? `/${slug}`) as Route}
>
{name}
</NavLink>
Expand Down
2 changes: 1 addition & 1 deletion docs/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ export const internal = [
},
],
},
];
] as const;
1 change: 1 addition & 0 deletions docs/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const pkg = require('./package.json');
const nextConfig = {
reactStrictMode: false,
distDir: '.next',
typedRoutes: true,
transpilePackages: ['@marigold/components', '@marigold/system'],
env: {
version: pkg.version,
Expand Down
3 changes: 2 additions & 1 deletion docs/ui/TeaserCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Card, Stack, Tiles } from '@/ui';
import type { Route } from 'next';
import type { ReactElement } from 'react';
import Link from 'next/link';

Expand All @@ -10,7 +11,7 @@ export interface TeaserCardProps {
}

export const TeaserCard = ({ href, icon, title, caption }: TeaserCardProps) => (
<Link className="flex no-underline" href={href}>
<Link className="flex no-underline" href={href as Route}>
<Card variant="hovering">
<Stack space={4}>
<div className="bg-bg-muted grid size-12 place-items-center rounded-full p-2">
Expand Down
5 changes: 3 additions & 2 deletions docs/ui/layout/SectionNavigation.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';

import type { Route } from 'next';
import { usePathname } from 'next/navigation';
import { Badge } from '@marigold/components';
import { NavLink } from '@/ui/navigation/NavLink';
Expand All @@ -25,7 +26,7 @@ export const SectionNavigation = () => {
className="flex items-center gap-4"
key={href}
current={pathname === href}
href={href}
href={href as Route}
>
{name}
{badge && <Badge variant="dark">{badge}</Badge>}
Expand All @@ -42,7 +43,7 @@ export const SectionNavigation = () => {
<NavLink
className="flex items-center gap-4"
current={pathname === href}
href={href}
href={href as Route}
>
{name}
{badge && <Badge variant="dark">{badge}</Badge>}
Expand Down
5 changes: 4 additions & 1 deletion docs/ui/navigation/NavLink.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Route } from 'next';
import type { ReactNode } from 'react';
import Link, { LinkProps } from 'next/link';
import { type VariantProps, cn, cva } from '@marigold/system';
Expand Down Expand Up @@ -42,7 +43,9 @@ const styles = cva([], {
},
});

export interface NavLinkProps extends VariantProps<typeof styles>, LinkProps {
export interface NavLinkProps
extends VariantProps<typeof styles>,
LinkProps<Route> {
className: string;
children: ReactNode;
}
Expand Down
5 changes: 3 additions & 2 deletions docs/ui/navigation/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { siteConfig } from '@/lib/config';
import { Badge } from '@/ui';
import { ContentPage, allContentPages } from 'contentlayer/generated';
import type { Route } from 'next';
import { usePathname } from 'next/navigation';
import { NavLink } from './NavLink';

Expand Down Expand Up @@ -87,7 +88,7 @@ export const Navigation = ({ onClick }: NavigationProps) => {
className="flex items-center gap-4"
key={href}
current={pathname === href}
href={href}
href={href as Route}
onClick={onClick}
>
{name}
Expand All @@ -107,7 +108,7 @@ export const Navigation = ({ onClick }: NavigationProps) => {
<NavLink
className="flex items-center gap-4"
current={pathname === href}
href={href}
href={href as Route}
onClick={onClick}
>
{name}
Expand Down