diff --git a/app/components/DocsLayout.tsx b/app/components/DocsLayout.tsx index 74844b7e..c181ae0f 100644 --- a/app/components/DocsLayout.tsx +++ b/app/components/DocsLayout.tsx @@ -2,54 +2,37 @@ import { DocSearch } from '@docsearch/react' import * as React from 'react' import { CgClose, CgMenuLeft } from 'react-icons/cg' import { FaArrowLeft, FaArrowRight, FaTimes } from 'react-icons/fa' -import { NavLink, Outlet, useMatches } from '@remix-run/react' +import { NavLink, useMatches } from '@remix-run/react' import { last } from '~/utils/utils' import { Carbon } from '~/components/Carbon' import { LinkOrA } from '~/components/LinkOrA' import { Search } from '~/components/Search' -import type { SelectProps } from '~/components/Select' import { Select } from '~/components/Select' import { useLocalStorage } from '~/utils/useLocalStorage' import { DocsCalloutQueryGG } from '~/components/DocsCalloutQueryGG' import { DocsCalloutBytes } from '~/components/DocsCalloutBytes' - -export type DocsConfig = { - docSearch: { - appId: string - indexName: string - apiKey: string - } - menu: { - label: string | React.ReactNode - children: { - label: string | React.ReactNode - to: string - badge?: string - }[] - }[] -} +import { DocsLogo } from '~/components/DocsLogo' +import type { DocsConfig } from '~/utils/config' export function DocsLayout({ + name, + version, colorFrom, colorTo, textColor, - logo, config, - framework, - version, children, - v2, }: { + name: string + version: string colorFrom: string colorTo: string textColor: string - logo: React.ReactNode config: DocsConfig - framework?: SelectProps - version?: SelectProps - children?: any - v2?: boolean + children: React.ReactNode }) { + const frameworkConfig = config.frameworkConfig + const versionConfig = config.versionConfig const matches = useMatches() const lastMatch = last(matches) @@ -92,7 +75,7 @@ export function DocsLayout({ ) : ( { detailsRef.current.removeAttribute('open') }} @@ -142,6 +125,15 @@ export function DocsLayout({ ) }) + const logo = ( + + ) + const smallMenu = (
- {framework?.selected ? ( + {frameworkConfig?.selected ? ( ) : null}
@@ -200,22 +192,22 @@ export function DocsLayout({ />
- {framework?.selected ? ( + {frameworkConfig?.selected ? ( ) : null}
@@ -238,7 +230,7 @@ export function DocsLayout({ {largeMenu}
- {children || } + {children}
{prevItem ? ( { + const { name, version, colorFrom, colorTo } = props + + const gradientText = `inline-block text-transparent bg-clip-text bg-gradient-to-r ${colorFrom} ${colorTo}` + + return ( + <> + + TanStack + + + {name}{' '} + {version} + + + ) +} diff --git a/app/projects/form.tsx b/app/projects/form.tsx index bd6887d7..898445bb 100644 --- a/app/projects/form.tsx +++ b/app/projects/form.tsx @@ -1,4 +1,3 @@ -import { Link } from '@remix-run/react' import reactLogo from '~/images/react-logo.svg' import solidLogo from '~/images/solid-logo.svg' import vueLogo from '~/images/vue-logo.svg' @@ -12,8 +11,9 @@ export const latestBranch = 'main' export const latestVersion = 'v0' export const availableVersions = ['v0'] -export const gradientText = - 'inline-block text-transparent bg-clip-text bg-gradient-to-r from-yellow-500 to-yellow-600' +export const colorFrom = 'from-yellow-500' +export const colorTo = 'to-yellow-600' +export const textColor = 'text-yellow-600' const frameworks = { react: { label: 'React', logo: reactLogo, value: 'react' }, @@ -23,20 +23,6 @@ const frameworks = { export type Framework = keyof typeof frameworks -export const createLogo = (version?: string) => ( - <> - - TanStack - - - Form{' '} - - {version === 'latest' ? latestVersion : version} - - - -) - export const localMenu: MenuItem = { label: 'Menu', children: [ diff --git a/app/projects/query.tsx b/app/projects/query.tsx index 290a5ff0..f8a8f1ec 100644 --- a/app/projects/query.tsx +++ b/app/projects/query.tsx @@ -5,7 +5,6 @@ import vueLogo from '~/images/vue-logo.svg' import svelteLogo from '~/images/svelte-logo.svg' import angularLogo from '~/images/angular-logo.svg' import { useDocsConfig } from '~/utils/config' -import { Link } from '@remix-run/react' import type { ConfigSchema, MenuItem } from '~/utils/config' export const repo = 'tanstack/query' @@ -14,8 +13,9 @@ export const latestBranch = 'main' export const latestVersion = 'v5' export const availableVersions = ['v5', 'v4', 'v3'] -export const gradientText = - 'inline-block text-transparent bg-clip-text bg-gradient-to-r from-red-500 to-amber-500' +export const colorFrom = 'from-red-500' +export const colorTo = 'to-amber-500' +export const textColor = 'text-amber-500' export const frameworks = { react: { label: 'React', logo: reactLogo, value: 'react' }, @@ -27,20 +27,6 @@ export const frameworks = { export type Framework = keyof typeof frameworks -export const createLogo = (version?: string) => ( - <> - - TanStack - - - Query{' '} - - {version === 'latest' ? latestVersion : version} - - - -) - export const localMenu: MenuItem = { label: 'Menu', children: [ diff --git a/app/projects/ranger.tsx b/app/projects/ranger.tsx index 1a73ae82..ed7671bd 100644 --- a/app/projects/ranger.tsx +++ b/app/projects/ranger.tsx @@ -1,4 +1,3 @@ -import { Link } from '@remix-run/react' import reactLogo from '~/images/react-logo.svg' import { FaDiscord, FaGithub } from 'react-icons/fa/index' import { useDocsConfig } from '~/utils/config' @@ -10,8 +9,9 @@ export const latestBranch = 'main' export const latestVersion = 'v0' export const availableVersions = ['v0'] -export const gradientText = - 'inline-block text-transparent bg-clip-text bg-gradient-to-r from-lime-500 to-emerald-500' +export const colorFrom = 'from-lime-500' +export const colorTo = 'to-emerald-500' +export const textColor = 'text-emerald-500' const frameworks = { react: { label: 'React', logo: reactLogo, value: 'react' }, @@ -19,20 +19,6 @@ const frameworks = { export type Framework = keyof typeof frameworks -export const createLogo = (version?: string) => ( - <> - - TanStack - - - Ranger{' '} - - {version === 'latest' ? latestVersion : version} - - - -) - const localMenu: MenuItem = { label: 'Menu', children: [ diff --git a/app/projects/router.tsx b/app/projects/router.tsx index 3269ee6a..61584026 100644 --- a/app/projects/router.tsx +++ b/app/projects/router.tsx @@ -1,4 +1,3 @@ -import { Link } from '@remix-run/react' import reactLogo from '~/images/react-logo.svg' import { FaDiscord, FaGithub } from 'react-icons/fa/index' import { useDocsConfig } from '~/utils/config' @@ -10,8 +9,9 @@ export const latestBranch = 'main' export const latestVersion = 'v1' export const availableVersions = ['v1'] -export const gradientText = - 'inline-block text-transparent bg-clip-text bg-gradient-to-r from-lime-500 to-emerald-500' +export const colorFrom = 'from-lime-500' +export const colorTo = 'to-emerald-500' +export const textColor = 'text-emerald-500' const frameworks = { react: { label: 'React', logo: reactLogo, value: 'react' }, @@ -19,20 +19,6 @@ const frameworks = { export type Framework = keyof typeof frameworks -export const createLogo = (version?: string) => ( - <> - - TanStack - - - Router - - {version === 'latest' ? latestVersion : version} - - - -) - export const localMenu: MenuItem = { label: 'Menu', children: [ diff --git a/app/projects/store.tsx b/app/projects/store.tsx index dc5b86c3..31639b80 100644 --- a/app/projects/store.tsx +++ b/app/projects/store.tsx @@ -1,4 +1,3 @@ -import { Link } from '@remix-run/react' import reactLogo from '~/images/react-logo.svg' import solidLogo from '~/images/solid-logo.svg' import vueLogo from '~/images/vue-logo.svg' @@ -12,8 +11,9 @@ export const latestBranch = 'main' export const latestVersion = 'v0' export const availableVersions = ['v0'] -export const gradientText = - 'inline-block text-transparent bg-clip-text bg-gradient-to-r from-gray-500 to-gray-700' +export const colorFrom = 'from-gray-500' +export const colorTo = 'to-gray-700' +export const textColor = 'text-gray-700' const frameworks = { react: { label: 'React', logo: reactLogo, value: 'react' }, @@ -23,20 +23,6 @@ const frameworks = { export type Framework = keyof typeof frameworks -export const createLogo = (version?: string) => ( - <> - - TanStack - - - Store{' '} - - {version === 'latest' ? latestVersion : version} - - - -) - export const localMenu: MenuItem = { label: 'Menu', children: [ diff --git a/app/projects/table.tsx b/app/projects/table.tsx index 927dc36d..6918c63a 100644 --- a/app/projects/table.tsx +++ b/app/projects/table.tsx @@ -1,4 +1,3 @@ -import { Link } from '@remix-run/react' import reactLogo from '~/images/react-logo.svg' import solidLogo from '~/images/solid-logo.svg' import vueLogo from '~/images/vue-logo.svg' @@ -13,8 +12,9 @@ export const latestBranch = 'main' export const latestVersion = 'v8' export const availableVersions = ['v8'] -export const gradientText = - 'inline-block text-transparent bg-clip-text bg-gradient-to-r from-teal-500 to-blue-600' +export const colorFrom = 'from-teal-500' +export const colorTo = 'to-blue-600' +export const textColor = 'text-blue-600' const frameworks = { react: { label: 'React', logo: reactLogo, value: 'react' }, @@ -57,20 +57,6 @@ export const localMenu: MenuItem = { ], } -export const createLogo = (version?: string) => ( - <> - - TanStack - - - Table{' '} - - {version === 'latest' ? latestVersion : version} - - - -) - export const useTableDocsConfig = (config: ConfigSchema) => { return useDocsConfig({ config, diff --git a/app/projects/virtual.tsx b/app/projects/virtual.tsx index 1735e986..bfbfa72c 100644 --- a/app/projects/virtual.tsx +++ b/app/projects/virtual.tsx @@ -1,4 +1,3 @@ -import { Link } from '@remix-run/react' import reactLogo from '~/images/react-logo.svg' import solidLogo from '~/images/solid-logo.svg' import vueLogo from '~/images/vue-logo.svg' @@ -12,8 +11,9 @@ export const latestBranch = 'main' export const latestVersion = 'v3' export const availableVersions = ['v3'] -export const gradientText = - 'inline-block text-transparent bg-clip-text bg-gradient-to-r from-rose-500 to-violet-600' +export const colorFrom = 'from-rose-500' +export const colorTo = 'to-violet-600' +export const textColor = 'text-violet-600' const frameworks = { react: { label: 'React', logo: reactLogo, value: 'react' }, @@ -56,20 +56,6 @@ export const localMenu: MenuItem = { ], } -export const createLogo = (version?: string) => ( - <> - - TanStack - - - Virtual{' '} - - {version === 'latest' ? latestVersion : version} - - - -) - export const useVirtualDocsConfig = (config: ConfigSchema) => { return useDocsConfig({ config, diff --git a/app/routes/form.$version._index.tsx b/app/routes/form.$version._index.tsx index c0b497d0..f1ddc7b1 100644 --- a/app/routes/form.$version._index.tsx +++ b/app/routes/form.$version._index.tsx @@ -17,7 +17,13 @@ import { Footer } from '~/components/Footer' import { VscPreview, VscWand } from 'react-icons/vsc' import { TbHeartHandshake } from 'react-icons/tb' import SponsorPack from '~/components/SponsorPack' -import { getBranch, gradientText, latestVersion, repo } from '~/projects/form' +import { + colorFrom, + colorTo, + getBranch, + latestVersion, + repo, +} from '~/projects/form' import { Logo } from '~/components/Logo' import { getSponsorsForSponsorPack } from '~/server/sponsors' import type { Framework } from '~/projects/form' @@ -92,6 +98,8 @@ export default function RouteVersion() { setIsDark(window.matchMedia?.(`(prefers-color-scheme: dark)`).matches) }, []) + const gradientText = `inline-block text-transparent bg-clip-text bg-gradient-to-r ${colorFrom} ${colorTo}` + return ( <>
diff --git a/app/routes/form.$version.docs.tsx b/app/routes/form.$version.docs.tsx index 86f2d5b1..8490874f 100644 --- a/app/routes/form.$version.docs.tsx +++ b/app/routes/form.$version.docs.tsx @@ -4,9 +4,12 @@ import { Outlet, useLoaderData } from '@remix-run/react' import { DocsLayout } from '~/components/DocsLayout' import { availableVersions, - createLogo, + colorFrom, + colorTo, getBranch, + latestVersion, repo, + textColor, useFormDocsConfig, } from '~/projects/form' import { getTanstackDocsConfig } from '~/utils/config' @@ -32,14 +35,12 @@ export default function Component() { let config = useFormDocsConfig(tanstackDocsConfig) return ( diff --git a/app/routes/query.$version._index.tsx b/app/routes/query.$version._index.tsx index 9a1e500a..ad73ad52 100644 --- a/app/routes/query.$version._index.tsx +++ b/app/routes/query.$version._index.tsx @@ -18,7 +18,13 @@ import { VscPreview, VscWand } from 'react-icons/vsc' import { TbHeartHandshake } from 'react-icons/tb' import SponsorPack from '~/components/SponsorPack' import { QueryGGBanner } from '~/components/QueryGGBanner' -import { getBranch, gradientText, latestVersion, repo } from '~/projects/query' +import { + colorFrom, + colorTo, + getBranch, + latestVersion, + repo, +} from '~/projects/query' import { Logo } from '~/components/Logo' import { LogoQueryGG } from '~/components/LogoQueryGG' import { getSponsorsForSponsorPack } from '~/server/sponsors' @@ -94,6 +100,8 @@ export default function RouteVersion() { setIsDark(window.matchMedia?.(`(prefers-color-scheme: dark)`).matches) }, []) + const gradientText = `inline-block text-transparent bg-clip-text bg-gradient-to-r ${colorFrom} ${colorTo}` + return ( <> diff --git a/app/routes/query.$version.docs.tsx b/app/routes/query.$version.docs.tsx index fc3193ff..63a672b9 100644 --- a/app/routes/query.$version.docs.tsx +++ b/app/routes/query.$version.docs.tsx @@ -1,15 +1,18 @@ import * as React from 'react' import type { LoaderFunctionArgs, MetaFunction } from '@remix-run/node' -import { json, redirect, useLoaderData } from '@remix-run/react' +import { Outlet, json, redirect, useLoaderData } from '@remix-run/react' import { seo } from '~/utils/seo' import { DocsLayout } from '~/components/DocsLayout' import { QueryGGBanner } from '~/components/QueryGGBanner' import { getBranch, - createLogo, + colorFrom, + colorTo, + textColor, repo, useQueryDocsConfig, availableVersions, + latestVersion, } from '~/projects/query' import { getTanstackDocsConfig } from '~/utils/config' @@ -44,15 +47,15 @@ export default function RouteFrameworkParam() { <> + > + + ) } diff --git a/app/routes/ranger.$version._index.tsx b/app/routes/ranger.$version._index.tsx index c1872dcd..74d27090 100644 --- a/app/routes/ranger.$version._index.tsx +++ b/app/routes/ranger.$version._index.tsx @@ -12,7 +12,7 @@ import { json } from '@remix-run/node' import { TbHeartHandshake, TbZoomQuestion } from 'react-icons/tb' import { VscPreview } from 'react-icons/vsc' import { RiLightbulbFlashLine } from 'react-icons/ri' -import { gradientText, getBranch } from '~/projects/ranger' +import { colorFrom, colorTo, getBranch } from '~/projects/ranger' import { Carbon } from '~/components/Carbon' import { Footer } from '~/components/Footer' import SponsorPack from '~/components/SponsorPack' @@ -89,6 +89,8 @@ export default function TanStackRouterRoute() { setIsDark(window.matchMedia?.(`(prefers-color-scheme: dark)`).matches) }, []) + const gradientText = `inline-block text-transparent bg-clip-text bg-gradient-to-r ${colorFrom} ${colorTo}` + return (
{ const { version } = context.params @@ -40,14 +43,12 @@ export default function DocsRoute() { let config = useRangerDocsConfig(tanstackDocsConfig) return ( diff --git a/app/routes/router.$version._index.tsx b/app/routes/router.$version._index.tsx index cb2eb146..5f3d0b75 100644 --- a/app/routes/router.$version._index.tsx +++ b/app/routes/router.$version._index.tsx @@ -12,7 +12,7 @@ import { json } from '@remix-run/node' import { TbHeartHandshake, TbZoomQuestion } from 'react-icons/tb' import { VscPreview } from 'react-icons/vsc' import { RiLightbulbFlashLine } from 'react-icons/ri' -import { gradientText, getBranch } from '~/projects/router' +import { colorFrom, colorTo, getBranch } from '~/projects/router' import { Carbon } from '~/components/Carbon' import { Footer } from '~/components/Footer' import SponsorPack from '~/components/SponsorPack' @@ -91,6 +91,8 @@ export default function TanStackRouterRoute() { setIsDark(window.matchMedia?.(`(prefers-color-scheme: dark)`).matches) }, []) + const gradientText = `inline-block text-transparent bg-clip-text bg-gradient-to-r ${colorFrom} ${colorTo}` + return (
diff --git a/app/routes/store.$version._index.tsx b/app/routes/store.$version._index.tsx index 417043f0..04add8d6 100644 --- a/app/routes/store.$version._index.tsx +++ b/app/routes/store.$version._index.tsx @@ -9,7 +9,7 @@ import { Footer } from '~/components/Footer' import { VscPreview } from 'react-icons/vsc' import { TbHeartHandshake } from 'react-icons/tb' import SponsorPack from '~/components/SponsorPack' -import { gradientText, latestVersion, repo } from '~/projects/store' +import { colorFrom, colorTo, latestVersion, repo } from '~/projects/store' import { Logo } from '~/components/Logo' import { getSponsorsForSponsorPack } from '~/server/sponsors' @@ -76,6 +76,8 @@ export default function RouteVersion() { const { sponsors } = useLoaderData() const { version } = useParams() + const gradientText = `inline-block text-transparent bg-clip-text bg-gradient-to-r ${colorFrom} ${colorTo}` + return ( <>
diff --git a/app/routes/store.$version.docs.tsx b/app/routes/store.$version.docs.tsx index a31fd03a..6901598c 100644 --- a/app/routes/store.$version.docs.tsx +++ b/app/routes/store.$version.docs.tsx @@ -3,9 +3,12 @@ import { Outlet, useLoaderData } from '@remix-run/react' import { DocsLayout } from '~/components/DocsLayout' import { availableVersions, - createLogo, getBranch, + latestVersion, repo, + textColor, + colorFrom, + colorTo, useStoreDocsConfig, } from '~/projects/store' import { getTanstackDocsConfig } from '~/utils/config' @@ -32,14 +35,12 @@ export default function Component() { return ( diff --git a/app/routes/table.$version._index.tsx b/app/routes/table.$version._index.tsx index c81731fe..19a5eea4 100644 --- a/app/routes/table.$version._index.tsx +++ b/app/routes/table.$version._index.tsx @@ -11,7 +11,7 @@ import { } from 'react-icons/fa' import { Link, useLoaderData } from '@remix-run/react' import { json } from '@remix-run/node' -import { gradientText, getBranch } from '~/projects/table' +import { colorFrom, colorTo, getBranch } from '~/projects/table' import { Carbon } from '~/components/Carbon' import { Footer } from '~/components/Footer' import { IoIosBody } from 'react-icons/io' @@ -94,6 +94,8 @@ export default function ReactTableRoute() { setIsDark(window.matchMedia?.(`(prefers-color-scheme: dark)`).matches) }, []) + const gradientText = `inline-block text-transparent bg-clip-text bg-gradient-to-r ${colorFrom} ${colorTo}` + return (
diff --git a/app/routes/virtual.$version._index.tsx b/app/routes/virtual.$version._index.tsx index e9baae7b..46e7956d 100644 --- a/app/routes/virtual.$version._index.tsx +++ b/app/routes/virtual.$version._index.tsx @@ -12,7 +12,7 @@ import { } from 'react-icons/fa' import { Link, useLoaderData } from '@remix-run/react' import { json } from '@remix-run/node' -import { gradientText, getBranch } from '~/projects/virtual' +import { colorFrom, colorTo, getBranch } from '~/projects/virtual' import { Carbon } from '~/components/Carbon' import { Footer } from '~/components/Footer' import { IoIosBody } from 'react-icons/io' @@ -95,6 +95,8 @@ export default function ReactTableRoute() { setIsDark(window.matchMedia?.(`(prefers-color-scheme: dark)`).matches) }, []) + const gradientText = `inline-block text-transparent bg-clip-text bg-gradient-to-r ${colorFrom} ${colorTo}` + return (
diff --git a/app/utils/config.ts b/app/utils/config.ts index 11241c2d..a5fd19e6 100644 --- a/app/utils/config.ts +++ b/app/utils/config.ts @@ -15,6 +15,7 @@ export type MenuItem = { children: { label: string | React.ReactNode to: string + badge?: string }[] } @@ -24,7 +25,6 @@ const menuItemSchema = z.object({ z.object({ label: z.string(), to: z.string(), - badge: z.string().optional(), }) ), @@ -42,7 +42,7 @@ const configSchema = z.object({ indexName: z.string(), }), menu: z.array(menuItemSchema), - frameworkMenus: z.array(frameworkMenuSchema).optional(), + frameworkMenus: z.array(frameworkMenuSchema), users: z.array(z.string()).optional(), }) @@ -98,33 +98,23 @@ export const useDocsConfig = ({ const match = matches[matches.length - 1] const params = useParams() const version = params.version! - const framework = localStorage.getItem('framework') || 'react' + const localStorageFramework = localStorage.getItem('framework') + const framework = localStorageFramework + ? frameworks[localStorageFramework] + ? localStorageFramework + : 'react' + : 'react' const navigate = useNavigate() const frameworkMenuItems = - config.frameworkMenus?.find((d) => d.framework === framework)?.menuItems ?? + config.frameworkMenus.find((d) => d.framework === framework)?.menuItems ?? [] const frameworkConfig = useMemo(() => { - if (!config.frameworkMenus) { - return undefined - } - - const availableFrameworks = config.frameworkMenus?.reduce( - (acc: AvailableOptions, menuEntry) => { - if (menuEntry.framework in frameworks) { - acc[menuEntry.framework] = - frameworks[menuEntry.framework as keyof typeof frameworks] - } - return acc - }, - { react: frameworks['react'] } - ) - return { label: 'Framework', selected: frameworks[framework] ? framework : 'react', - available: availableFrameworks, + available: frameworks, onSelect: (option: { label: string; value: string }) => { const url = generatePath(match.id, { ...match.params, @@ -136,7 +126,7 @@ export const useDocsConfig = ({ navigate(url) }, } - }, [config, frameworks, framework, match, navigate]) + }, [frameworks, framework, match, navigate]) const versionConfig = useMemo(() => { const available = availableVersions.reduce( @@ -169,16 +159,8 @@ export const useDocsConfig = ({ } }, [version, match, navigate, availableVersions]) - const docSearch: NonNullable = - config.docSearch || { - appId: '', - apiKey: '', - indexName: '', - } - return { ...config, - docSearch, menu: [ localMenu, // Merge the two menus together based on their group labels @@ -200,3 +182,5 @@ export const useDocsConfig = ({ versionConfig, } } + +export type DocsConfig = ReturnType diff --git a/tanstack-docs-config.schema.json b/tanstack-docs-config.schema.json index e64799b1..cb791dd8 100644 --- a/tanstack-docs-config.schema.json +++ b/tanstack-docs-config.schema.json @@ -4,7 +4,7 @@ "title": "TanStack Docs Config", "description": "Config file for the documentation of a TanStack project.", "type": "object", - "required": ["docSearch", "menu"], + "required": ["docSearch", "menu", "frameworkMenus"], "additionalProperties": false, "properties": { "$schema": {