Skip to content

Commit

Permalink
feat: support react node as title
Browse files Browse the repository at this point in the history
  • Loading branch information
foyarash committed Jan 21, 2025
1 parent 522c5b2 commit f8db9dc
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-kings-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@premieroctet/next-admin": minor
---

feat: support react node as title (#512)
14 changes: 9 additions & 5 deletions packages/next-admin/src/components/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { clsx } from "clsx";
import dynamic from "next/dynamic";
import Link from "next/link";
import { Fragment, useState } from "react";
import { Fragment, useState, ReactNode } from "react";

import { useTheme } from "next-themes";
import { useConfig } from "../context/ConfigContext";
Expand Down Expand Up @@ -44,7 +44,7 @@ export type MenuProps = {
resourcesIcons: AdminComponentProps["resourcesIcons"];
user?: AdminComponentProps["user"];
externalLinks?: AdminComponentProps["externalLinks"];
title?: string;
title?: ReactNode;
};

export default function Menu({
Expand Down Expand Up @@ -223,9 +223,13 @@ export default function Menu({
href={basePath}
className="flex h-[40px] items-center gap-2 overflow-hidden"
>
<div className="text-md dark:text-dark-nextadmin-brand-inverted overflow-hidden text-ellipsis whitespace-nowrap font-semibold">
{title}
</div>
{typeof title === "string" ? (
<div className="text-md dark:text-dark-nextadmin-brand-inverted overflow-hidden text-ellipsis whitespace-nowrap font-semibold">
{title}
</div>
) : (
title
)}
</Link>
</div>
<Divider />
Expand Down
5 changes: 3 additions & 2 deletions packages/next-admin/src/components/NextAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ export function NextAdmin({
}
};

const titleElement = isAppDir ? title : options?.title;

return (
<>
<PageLoader />
{!isAppDir && (
<Head>
<title>{title}</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/favicon.ico" />
</Head>
Expand All @@ -119,7 +120,7 @@ export function NextAdmin({
isAppDir={isAppDir}
translations={translations}
locale={locale}
title={title}
title={titleElement}
sidebar={sidebar}
resourcesIcons={resourcesIcons}
user={user}
Expand Down
7 changes: 4 additions & 3 deletions packages/next-admin/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ export type NextAdminOptions = {
*
* @default "Admin"
*/
title?: string;
title?: ReactNode;
/**
* `model` is an object that represents the customization options for each model in your schema.
*/
Expand Down Expand Up @@ -872,7 +872,7 @@ export type AdminComponentProps = {
*
* @default "Admin"
*/
title?: string;
title?: ReactNode;
sidebar?: SidebarConfiguration;
user?: AdminUser;
externalLinks?: ExternalLink[];
Expand Down Expand Up @@ -937,7 +937,8 @@ export type CustomInputProps = Partial<{
disabled: boolean;
required?: boolean;
mode: "create" | "edit";
}> & ComponentProps<"input">;
}> &
ComponentProps<"input">;

export type TranslationKeys =
| "actions.delete.label"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-admin/src/utils/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export const getMainLayoutProps = ({
customPages,
resourcesTitles,
isAppDir,
title: options?.title ?? "Admin",
title: isAppDir ? (options?.title ?? "Admin") : null,
sidebar: options?.sidebar,
resourcesIcons,
externalLinks: options?.externalLinks,
Expand Down

0 comments on commit f8db9dc

Please sign in to comment.