Files
supabase/apps/ui-library/components/framework-selector.tsx
Gildas Garcia 5d97339d41 chore: remove <Select> _Shadcn_ suffix (#45988)
## Problem

The `_Shadcn_` suffix isn't needed anymore on `Select` components

## Solution

Remove it. No other changes

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Refactor**
* Updated internal component architecture to standardize and simplify
the codebase. These changes improve code maintainability and consistency
across the application without affecting existing functionality or user
experience.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45988)

<!-- review_stack_entry_end -->

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-05-15 16:39:57 +02:00

81 lines
2.4 KiB
TypeScript

'use client'
import { usePathname, useRouter } from 'next/navigation'
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from 'ui'
import { componentPages, frameworkTitles } from '@/config/docs'
import { useFramework } from '@/context/framework-context'
const frameworks = Object.keys(frameworkTitles)
export function FrameworkSelector() {
const pathname = usePathname()
// Extract framework and docTitle from pathname
// Example: /ui/docs/nextjs/password-based-auth
const pathParts = pathname.split('/')
const docTitle = pathParts[pathParts.length - 1]
const framework = pathParts[pathParts.length - 2]
const router = useRouter()
const { setFramework: setPreferredFramework } = useFramework()
const selectedFramework = frameworks.includes(framework) ? framework : 'nextjs'
if (!framework) {
return null
}
// Get the supported frameworks for this component
const componentItem = componentPages.items.find(
(item) => item.href?.split('/').pop() === docTitle.toLowerCase()
)
// Use the supportedFrameworks property if it exists, otherwise default to all frameworks
const supportedFrameworks = componentItem?.supportedFrameworks
if (!supportedFrameworks) {
return null
}
// Don't show selector if component only supports one framework
if (supportedFrameworks && supportedFrameworks.length <= 1) {
return null
}
const onSelect = (value: string) => {
// Get current path parts
const currentPathParts = [...pathParts]
// Replace the framework part (second to last) with the new framework
currentPathParts[currentPathParts.length - 2] = value
// Build the new path
const newPath = currentPathParts.join('/')
router.push(newPath)
// Also update the context/localStorage for future use
setPreferredFramework(value as keyof typeof frameworkTitles)
}
const options =
supportedFrameworks?.map((f) => ({
label: frameworkTitles[f],
value: f,
})) || []
return (
<Select value={selectedFramework} onValueChange={onSelect}>
<SelectTrigger className="w-[180px] mt-4 lg:mt-0">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectGroup>
{options.map((f) => (
<SelectItem key={f.value} value={f.value}>
{f.label}
</SelectItem>
))}
</SelectGroup>
</SelectContent>
</Select>
)
}