mirror of
https://github.com/supabase/supabase.git
synced 2026-09-07 02:20:52 +08:00
## Problem Our `<Button>` component breaks the default `button` contract by redefining the `type` prop to set its variant (`primary`, `default`, etc) instead of the button type (`submit`, `button`, etc). This is confusing and forces to write more code when using it with shadcn components that expect/inject the standard button props. ## Solution - rename the `type` prop to `variant` - rename the `htmlType` prop to `type` - propagate the changes where necessary - format code ## How to test As this is just prop renaming, if it builds it's ok --------- Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
88 lines
2.5 KiB
TypeScript
88 lines
2.5 KiB
TypeScript
import { ChevronDown, Terminal } from 'lucide-react'
|
|
import { useState } from 'react'
|
|
import {
|
|
Button,
|
|
Command,
|
|
CommandGroup,
|
|
CommandItem,
|
|
CommandList,
|
|
Popover,
|
|
PopoverContent,
|
|
PopoverTrigger,
|
|
} from 'ui'
|
|
|
|
import { BASE_PATH } from '@/lib/constants'
|
|
import { useAppStateSnapshot } from '@/state/app-state'
|
|
|
|
interface LanguageSelectorProps {
|
|
/**
|
|
* Only show icons to represent the language
|
|
*/
|
|
simplifiedVersion?: boolean
|
|
}
|
|
|
|
const LanguageSelector = ({ simplifiedVersion = false }: LanguageSelectorProps) => {
|
|
const snap = useAppStateSnapshot()
|
|
const [showLanguage, setShowLanguage] = useState(false)
|
|
|
|
const updateLanguage = (value: 'js' | 'bash') => {
|
|
snap.setDocsLanguage(value)
|
|
setShowLanguage(false)
|
|
}
|
|
|
|
return (
|
|
<div className="flex items-center gap-x-2">
|
|
<Popover modal={false} open={showLanguage} onOpenChange={setShowLanguage}>
|
|
<PopoverTrigger asChild>
|
|
<Button
|
|
variant="default"
|
|
className={simplifiedVersion ? 'px-1' : ''}
|
|
icon={
|
|
simplifiedVersion ? (
|
|
snap.docsLanguage === 'js' ? (
|
|
<img
|
|
src={`${BASE_PATH}/img/libraries/javascript-icon.svg`}
|
|
alt={`javascript logo`}
|
|
width="14"
|
|
/>
|
|
) : (
|
|
<Terminal size={14} strokeWidth={2.5} />
|
|
)
|
|
) : undefined
|
|
}
|
|
iconRight={!simplifiedVersion && <ChevronDown size={14} strokeWidth={2} />}
|
|
>
|
|
{!simplifiedVersion
|
|
? `Language: ${snap.docsLanguage === 'js' ? 'Javascript' : 'Bash'}`
|
|
: undefined}
|
|
</Button>
|
|
</PopoverTrigger>
|
|
<PopoverContent className="p-0 w-24" side="bottom" align="end">
|
|
<Command>
|
|
<CommandList>
|
|
<CommandGroup>
|
|
<CommandItem
|
|
className="cursor-pointer"
|
|
onSelect={() => updateLanguage('js')}
|
|
onClick={() => updateLanguage('js')}
|
|
>
|
|
<p>Javascript</p>
|
|
</CommandItem>
|
|
<CommandItem
|
|
className="cursor-pointer"
|
|
onSelect={() => updateLanguage('bash')}
|
|
onClick={() => updateLanguage('bash')}
|
|
>
|
|
<p>Bash</p>
|
|
</CommandItem>
|
|
</CommandGroup>
|
|
</CommandList>
|
|
</Command>
|
|
</PopoverContent>
|
|
</Popover>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default LanguageSelector
|