Skip to content

Commit 82b6a11

Browse files
authored
New version picker for stable (#151)
* Feature/version switch (#149) * added version switch * added changeset * added version picker for stable * refactored version picker (#150) * update version switch
1 parent e32b32f commit 82b6a11

File tree

5 files changed

+97
-7
lines changed

5 files changed

+97
-7
lines changed

.changeset/fair-bats-drop.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tiptap-docs': minor
3+
---
4+
5+
Added a new version switch and versioning constants to the constant config

src/components/VersionSwitch.tsx

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use client'
2+
3+
import * as DropdownMenu from '@radix-ui/react-dropdown-menu'
4+
import { ChevronDownIcon } from 'lucide-react'
5+
import { NavLinkButton } from './ui/NavLinkButton'
6+
import { NavLink } from './NavLink'
7+
import { Tag } from './ui/Tag'
8+
import { VERSIONS, CURRENT_VERSION } from '@/utils/constants'
9+
import type { VersionData } from '@/types'
10+
11+
const getItemLabel = ({ version }: { version: VersionData }) => {
12+
if (version.isLegacy) return 'Legacy'
13+
if (version.isBeta) return 'Beta'
14+
if (version.isAlpha) return 'Alpha'
15+
if (version.isRc) return 'RC'
16+
return false
17+
}
18+
19+
const VersionItem = ({ version }: { version: VersionData }) => {
20+
const label = getItemLabel({ version })
21+
const isCurrentVersion = version.version === CURRENT_VERSION
22+
23+
return (
24+
<DropdownMenu.Item asChild>
25+
<NavLink href={version.url} target={!isCurrentVersion ? '_blank' : ''} hideIcon>
26+
{version.version}
27+
{label ? <Tag className="ml-1">{label}</Tag> : null}
28+
</NavLink>
29+
</DropdownMenu.Item>
30+
)
31+
}
32+
33+
export const VersionSwitch = () => {
34+
return (
35+
<DropdownMenu.Root>
36+
<DropdownMenu.Trigger asChild>
37+
<NavLinkButton className="p-1 text-base">
38+
{CURRENT_VERSION}
39+
<ChevronDownIcon className="w-3 h-3" />
40+
</NavLinkButton>
41+
</DropdownMenu.Trigger>
42+
<DropdownMenu.Portal>
43+
<DropdownMenu.Content className="z-50 flex flex-col gap-6 px-2 py-6 text-black bg-white border rounded-lg shadow-md lg:py-3 border-grayAlpha-100">
44+
<div>
45+
{VERSIONS.map((version) => (
46+
<VersionItem key={version.version} version={version} />
47+
))}
48+
</div>
49+
</DropdownMenu.Content>
50+
</DropdownMenu.Portal>
51+
</DropdownMenu.Root>
52+
)
53+
}

src/components/layouts/Layout.tsx

+9-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { MobileNavigationButton } from '../MobileNavigationButton'
1111
import { DocsSidebar } from '../SidebarRenderer'
1212
import { MobileNavigationDropdown } from '../MobileNavigationDropdown'
1313
import { SidebarTableOfContent } from '../SidebarTableOfContent'
14+
import { VersionSwitch } from '../VersionSwitch'
1415
import Link from '@/components/Link'
1516
import { cn } from '@/utils'
1617
import { getAllMetadata } from '@/server/getAllMetadata'
@@ -38,7 +39,8 @@ export const LayoutHeader = forwardRef<HTMLDivElement, { config?: SidebarConfig
3839
<span className="font-semibold">Tiptap</span> Docs
3940
</span>
4041
</Link>
41-
<span className="hidden lg:block select-none text-black/15">/</span>
42+
<VersionSwitch />
43+
<span className="hidden select-none lg:block text-black/15">/</span>
4244
<nav className="hidden lg:flex items-center gap-[0.5px]">
4345
<ProductDropdown />
4446
<NavLink href="/guides">Guides</NavLink>
@@ -49,11 +51,11 @@ export const LayoutHeader = forwardRef<HTMLDivElement, { config?: SidebarConfig
4951
</NavLink>
5052
</nav>
5153
</div>
52-
<div className="ml-auto flex items-center gap-2">
54+
<div className="flex items-center gap-2 ml-auto">
5355
<div className="hidden xl:block">
5456
<SearchButton />
5557
</div>
56-
<div className="hidden lg:flex items-center gap-1 xl:hidden">
58+
<div className="items-center hidden gap-1 lg:flex xl:hidden">
5759
<ToCButton />
5860
<SearchButton />
5961
</div>
@@ -73,11 +75,11 @@ export const LayoutHeader = forwardRef<HTMLDivElement, { config?: SidebarConfig
7375
</div>
7476
</div>
7577
<div className="block lg:hidden py-1.5 bg-white px-[1.125rem] shadow-slim rounded-bl-pilled rounded-br-pilled border-t border-neutral-200">
76-
<div className="h-8 py-1 flex items-center">
77-
<div className="mr-auto flex items-center gap-2">
78+
<div className="flex items-center h-8 py-1">
79+
<div className="flex items-center gap-2 mr-auto">
7880
<MobileNavigationButton config={config} />
7981
</div>
80-
<div className="ml-auto flex items-center gap-2">
82+
<div className="flex items-center gap-2 ml-auto">
8183
<ToCButton />
8284
<SearchButton />
8385
</div>
@@ -176,7 +178,7 @@ export const LayoutContent = forwardRef<HTMLDivElement, LayoutContentProps>(
176178
<div className="pt-6 pb-16 sm:pb-24 sm:pt-8 lg:pb-32 lg:pt-10">{children}</div>
177179

178180
<footer className="border-t border-grayAlpha-300 pt-8 pb-[3.125rem]">
179-
<div className="flex flex-col lg:flex-row items-start justify-between gap-4">
181+
<div className="flex flex-col items-start justify-between gap-4 lg:flex-row">
180182
<div className="flex flex-col items-start flex-none">
181183
<PageEditFooter />
182184
</div>

src/types.ts

+9
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,12 @@ export interface UIComponentMetaWithUrl extends UIComponentMeta {
159159
path: string
160160
url: string
161161
}
162+
163+
export interface VersionData {
164+
version: string
165+
url: string
166+
isBeta?: boolean
167+
isAlpha?: boolean
168+
isRc?: boolean
169+
isLegacy?: boolean
170+
}

src/utils/constants.ts

+21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { VersionData } from '@/types'
2+
13
export const DEMO_URL = process.env.NEXT_PUBLIC_DEMO_URL ?? 'https://embed.tiptap.dev/preview'
24

35
export const PRO_DEMO_URL =
@@ -9,3 +11,22 @@ export const FULL_DOMAIN = `${DOMAIN}${BASE_PATH}`
911

1012
export const GTM_ID = process.env.NEXT_PUBLIC_GTM_ID || null
1113
export const ENVIRONMENT = process.env.NEXT_PUBLIC_ENVIRONMENT || 'development'
14+
15+
export const CURRENT_VERSION = '2.x'
16+
17+
export const VERSIONS: Array<VersionData> = [
18+
{
19+
version: '3.x',
20+
isBeta: true,
21+
url: 'https://next.tiptap.dev',
22+
},
23+
{
24+
version: '2.x',
25+
url: 'https://tiptap.dev/docs',
26+
},
27+
{
28+
version: '1.x',
29+
isLegacy: true,
30+
url: 'https://v1.tiptap.dev/',
31+
},
32+
]

0 commit comments

Comments
 (0)