Files
Gildas GarciaandIvan Vasilov 96d43099bb chore: refactor Button API so that it can be used a standard button (#46880)
## 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>
2026-06-16 23:59:58 +02:00

65 lines
2.5 KiB
TypeScript

import { useParams } from 'common'
import { Download } from 'lucide-react'
import { useState } from 'react'
import { toast } from 'sonner'
import { Button } from 'ui'
import ContentSnippet from '../ContentSnippet'
import { DOCS_CONTENT } from '../ProjectAPIDocs.constants'
import type { ContentProps } from './Content.types'
import { DocsButton } from '@/components/ui/DocsButton'
import { useProjectPostgrestConfigQuery } from '@/data/config/project-postgrest-config-query'
import { generateTypes } from '@/data/projects/project-type-generation-query'
import { DOCS_URL } from '@/lib/constants'
export const Entities = ({ language }: ContentProps) => {
const { ref } = useParams()
const [isGeneratingTypes, setIsGeneratingTypes] = useState(false)
const { data: config } = useProjectPostgrestConfigQuery({ projectRef: ref })
const onClickGenerateTypes = async () => {
try {
setIsGeneratingTypes(true)
const res = await generateTypes({ ref, included_schemas: config?.db_schema })
let element = document.createElement('a')
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(res.types))
element.setAttribute('download', 'supabase.ts')
element.style.display = 'none'
document.body.appendChild(element)
element.click()
document.body.removeChild(element)
toast.success(`Successfully generated types! File is being downloaded`)
} catch (error: any) {
toast.error(`Failed to generate types: ${error.message}`)
} finally {
setIsGeneratingTypes(false)
}
}
return (
<>
<ContentSnippet selectedLanguage={language} snippet={DOCS_CONTENT.entitiesIntroduction} />
<div>
<ContentSnippet selectedLanguage={language} snippet={DOCS_CONTENT.generatingTypes} />
<div className="flex items-center gap-x-2 px-4 mt-3">
<DocsButton href={`${DOCS_URL}/guides/database/api/generating-types`} />
<Button
variant="default"
disabled={isGeneratingTypes}
loading={isGeneratingTypes}
icon={<Download strokeWidth={1.5} />}
onClick={onClickGenerateTypes}
>
Generate and download types
</Button>
</div>
<p className="text-xs text-foreground-light px-4 mt-2">
Remember to re-generate and download this file as you make changes to your tables.
</p>
</div>
<ContentSnippet selectedLanguage={language} snippet={DOCS_CONTENT.graphql} />
</>
)
}