Files
supabase/apps/studio/components/interfaces/ProjectAPIDocs/LanguageSelector.tsx
Ivan Vasilov 05a542ccea chore: Migrate all feather icons to lucide icons (#29038)
* Add lucide-react to docs (to make the autocomplete work).

* Migrate the docs app icons.

* Migrate the ui-patterns.

* Remove the old icons from ui package.

* Migrate the www app from react-feather icons.

* Migrate all of studio icons.

* Migrate the only component in design-system.

* Fix an old import in ui package. Revert an import in docs app.

* Fix some pages in www.

* Remove unneeded files used in generation of icons.

* Fix a prettier error.

* Fix more issues in www.

* Fix an issue in Log Date picker.

* Replace all string sizes with number sizes because the icons grew in some cases.

* Fix more imports in security page.

* Fix an extra import.

* Remove the size prop from all icons if they're in a button and they match the button size.

* Minor fixes for docs and www.

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2024-09-04 19:46:21 +08:00

87 lines
2.7 KiB
TypeScript

import { BASE_PATH } from 'lib/constants'
import { Terminal, ChevronDown } from 'lucide-react'
import { useState } from 'react'
import { useAppStateSnapshot } from 'state/app-state'
import {
Button,
CommandGroup_Shadcn_,
CommandItem_Shadcn_,
CommandList_Shadcn_,
Command_Shadcn_,
PopoverContent_Shadcn_,
PopoverTrigger_Shadcn_,
Popover_Shadcn_,
} from 'ui'
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_Shadcn_ modal={false} open={showLanguage} onOpenChange={setShowLanguage}>
<PopoverTrigger_Shadcn_ asChild>
<Button
type="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_Shadcn_>
<PopoverContent_Shadcn_ className="p-0 w-24" side="bottom" align="end">
<Command_Shadcn_>
<CommandList_Shadcn_>
<CommandGroup_Shadcn_>
<CommandItem_Shadcn_
className="cursor-pointer"
onSelect={() => updateLanguage('js')}
onClick={() => updateLanguage('js')}
>
<p>Javascript</p>
</CommandItem_Shadcn_>
<CommandItem_Shadcn_
className="cursor-pointer"
onSelect={() => updateLanguage('bash')}
onClick={() => updateLanguage('bash')}
>
<p>Bash</p>
</CommandItem_Shadcn_>
</CommandGroup_Shadcn_>
</CommandList_Shadcn_>
</Command_Shadcn_>
</PopoverContent_Shadcn_>
</Popover_Shadcn_>
</div>
)
}
export default LanguageSelector