forked from TanStack/tanstack.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.$version.docs.framework.$framework.examples.$.tsx
96 lines (86 loc) · 3.22 KB
/
query.$version.docs.framework.$framework.examples.$.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import React from 'react'
import { json } from '@remix-run/node'
import { useLoaderData } from '@tanstack/react-router'
import { DocTitle } from '~/components/DocTitle'
import { repo, getBranch } from '~/projects/query'
import { seo } from '~/utils/seo'
import { capitalize, slugToTitle } from '~/utils/utils'
import { FaExternalLinkAlt } from 'react-icons/fa'
export const loader = async (context) => {
const { version, framework, _splat: name } = context.params
return json({ version, framework, name })
}
export const meta: MetaFunction<typeof loader> = ({ data }) => {
return seo({
title: `${capitalize(data.framework)} Query ${slugToTitle(
data.name
)} Example | TanStack Query Docs`,
description: `An example showing how to implement ${slugToTitle(
data.name
)} in ${capitalize(data.framework)} Query`,
})
}
export default function RouteExamples() {
const { version, framework, name } = Route.useLoaderData()
const branch = getBranch(version)
const examplePath = [framework, name].join('/')
const [isDark, setIsDark] = React.useState(true)
React.useEffect(() => {
setIsDark(window.matchMedia?.(`(prefers-color-scheme: dark)`).matches)
}, [])
const githubUrl = `https://github.com/${repo}/tree/${branch}/examples/${examplePath}`
// preset=node can be removed once Stackblitz runs Angular as webcontainer by default
// https://github.com/stackblitz/core/issues/2957
const stackBlitzUrl = `https://stackblitz.com/github/${repo}/tree/${branch}/examples/${examplePath}?embed=1&theme=${
isDark ? 'dark' : 'light'
}&preset=node`
const codesandboxUrl = `https://codesandbox.io/s/github/${repo}/tree/${branch}/examples/${examplePath}?embed=1&theme=${
isDark ? 'dark' : 'light'
}`
return (
<div className="flex-1 flex flex-col min-h-0 overflow-auto">
<div className="p-4 lg:p-6">
<DocTitle>
<span>
{capitalize(framework)} Example: {slugToTitle(name)}
</span>
<div className="flex items-center gap-4 flex-wrap font-normal text-xs">
<a
href={githubUrl}
target="_blank"
className="flex gap-1 items-center"
rel="noreferrer"
>
<FaExternalLinkAlt /> Github
</a>
<a
href={stackBlitzUrl}
target="_blank"
className="flex gap-1 items-center"
rel="noreferrer"
>
<FaExternalLinkAlt /> StackBlitz
</a>
<a
href={codesandboxUrl}
target="_blank"
className="flex gap-1 items-center"
rel="noreferrer"
>
<FaExternalLinkAlt /> CodeSandbox
</a>
</div>
</DocTitle>
</div>
<div className="flex-1 lg:px-6 flex flex-col min-h-0">
<iframe
src={stackBlitzUrl}
title={`tanstack/query: ${examplePath}`}
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
className="flex-1 w-full overflow-hidden lg:rounded-lg shadow-xl shadow-gray-700/20 bg-white dark:bg-black"
/>
</div>
<div className="lg:h-16 lg:mt-2" />
</div>
)
}