mirror of
https://github.com/supabase/supabase.git
synced 2026-10-17 07:09:07 +03:00
## Problem design-system, ui-library and learn highlight code through `@shikijs/compat` and `rehype-pretty-code` 0.9, which both predate shiki 1 compat has no v4 release, so these apps were stuck on shiki 1.6 and couldn't pick up the injection fix from the previous pr ## Solution - drops `@shikijs/compat` - moves all three apps to `rehype-pretty-code` <!-- ## Preview links If relevant, include links to changed pages for easy review access. Copy the preview base URL from the Vercel bot comment on this PR. Use the following table as an example template. | Site | Live | Preview | Search for | | -------------- | ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | ----------------------------- | | WWW | [/blog/your-post](https://supabase.com/blog/your-post) | [/blog/your-post](https://zone-www-dot-com-git-branch-name-supabase.vercel.app/blog/your-post) | unique phrase from the change | | Docs | [/docs/guides/your-page](https://supabase.com/docs/guides/your-page) | [/docs/guides/your-page](https://docs-git-branch-name-supabase.vercel.app/docs/guides/your-page) | unique phrase from the change | | Studio | [/dashboard](https://supabase.com/dashboard) | [/dashboard](https://studio-git-branch-name-supabase.vercel.app/dashboard) | unique phrase from the change | | Design system | [/design-system](https://supabase.com/design-system) | [/design-system](https://design-system-git-branch-name-supabase.vercel.app/design-system) | unique phrase from the change | | UI library | [/library](https://supabase.com/library) | [/library](https://ui-library-git-branch-name-supabase.vercel.app/library) | unique phrase from the change | | Knowledge base | [/kb/guides/your-page](https://supabase.com/kb/guides/your-page) | [/kb/guides/your-page](https://kb-git-branch-name-supabase.vercel.app/kb/guides/your-page) | unique phrase from the change | --> <!-- ## Additional context Optionally add any other context or screenshots. --> ## Review instructions 1. open [/design-system/docs/accessibility](https://design-system-gd7xzujta-supabase.vercel.app/design-system/docs/accessibility) on the preview and on production side by side _ highlighted lines should keep the left border and background, and line numbers should line up 2. open [/design-system/docs/components/chart](https://design-system-gd7xzujta-supabase.vercel.app/design-system/docs/components/chart) _ highlighted words should have the gray pill, with no yellow background or black text + code blocks with titles should still show the title above the block 3. toggle light and dark mode on both pages _ token colors and the block background should match production 4. open [ui-library preview](https://ui-library-hmuv1teie-supabase.vercel.app/library/docs/starters/nextjs-starter) and do a copy check 5. open a learn lesson with code `/foundations/authentication` and compare it with production. ## Checklist Check all before review: - [x] I have read [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [x] If I wrote a new docs topic or edited an existing topic, I used the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs [style guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)
98 lines
3.5 KiB
TypeScript
98 lines
3.5 KiB
TypeScript
'use client'
|
|
|
|
import * as React from 'react'
|
|
import { cn, Tabs, TabsContent, TabsList, TabsTrigger } from 'ui'
|
|
|
|
import {
|
|
// CopyButton,
|
|
CopyWithClassNames,
|
|
} from '@/components/copy-button'
|
|
|
|
interface ComponentExampleProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
extractClassname?: boolean
|
|
extractedClassNames?: string
|
|
align?: 'center' | 'start' | 'end'
|
|
src?: string
|
|
}
|
|
|
|
export function ComponentExample({
|
|
children,
|
|
className,
|
|
extractClassname,
|
|
extractedClassNames,
|
|
align = 'center',
|
|
src: _,
|
|
...props
|
|
}: ComponentExampleProps) {
|
|
const [Example, Code, ...Children] = React.Children.toArray(children) as React.ReactElement<{
|
|
children: React.ReactNode
|
|
'data-rehype-pretty-code-figure'?: unknown
|
|
}>[]
|
|
|
|
const codeString = React.useMemo(() => {
|
|
if (typeof Code?.props['data-rehype-pretty-code-figure'] !== 'undefined') {
|
|
const [, Button] = React.Children.toArray(Code.props.children) as React.ReactElement<{
|
|
value?: string
|
|
__rawString__?: string
|
|
}>[]
|
|
return Button?.props?.value || Button?.props?.__rawString__ || null
|
|
}
|
|
}, [Code])
|
|
|
|
return (
|
|
<div className={cn('group relative my-4 flex flex-col gap-2', className)} {...props}>
|
|
<Tabs defaultValue="preview" className="relative mr-auto w-full">
|
|
<div className="flex items-center justify-between pb-3">
|
|
<TabsList className="w-full justify-start rounded-none border-b bg-transparent p-0">
|
|
<TabsTrigger
|
|
value="preview"
|
|
className="relative rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 font-semibold text-muted-foreground shadow-none transition-none data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none"
|
|
>
|
|
Preview
|
|
</TabsTrigger>
|
|
<TabsTrigger
|
|
value="code"
|
|
className="relative rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 font-semibold text-muted-foreground shadow-none transition-none data-[state=active]:border-b-primary data-[state=active]:text-foreground data-[state=active]:shadow-none"
|
|
>
|
|
Code
|
|
</TabsTrigger>
|
|
</TabsList>
|
|
{
|
|
extractedClassNames && codeString ? (
|
|
<CopyWithClassNames
|
|
value={codeString}
|
|
classNames={extractedClassNames}
|
|
className="absolute right-4 top-20"
|
|
/>
|
|
) : undefined
|
|
// codeString && <CopyButton value={codeString} className="absolute right-4 top-20" />
|
|
}
|
|
</div>
|
|
<TabsContent value="preview" className="rounded-md border">
|
|
<div
|
|
className={cn('flex min-h-[350px] justify-center p-10', {
|
|
'items-center': align === 'center',
|
|
'items-start': align === 'start',
|
|
'items-end': align === 'end',
|
|
})}
|
|
>
|
|
{Example}
|
|
</div>
|
|
</TabsContent>
|
|
<TabsContent value="code">
|
|
<div className="flex flex-col space-y-4">
|
|
<div className="w-full rounded-md [&_button]:hidden [&_pre]:my-0 [&_pre]:max-h-[350px] [&_pre]:overflow-auto">
|
|
{Code}
|
|
</div>
|
|
{Children?.length ? (
|
|
<div className="rounded-md [&_button]:hidden [&_pre]:my-0 [&_pre]:max-h-[350px] [&_pre]:overflow-auto">
|
|
{Children}
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
</TabsContent>
|
|
</Tabs>
|
|
</div>
|
|
)
|
|
}
|