mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
## What kind of change does this PR introduce? Mechanical cleanup on top of the Button default-variant change (#50160). ## What is the current behavior? Many callsites still pass `variant="default"` even though that is now the component default. ## What is the new behavior? Removes redundant static `variant="default"` from legacy `Button` and `ButtonTooltip` callsites. Keeps explicit defaults where they document the API: - `button-default.tsx` and `button-sizes.tsx` demos - `DocsButton`, which pins neutral styling at the wrapper boundary ## To test Studio: - [Auth → Rate Limits](https://studio-staging-2s957kwc4-supabase.vercel.app/dashboard/project/_/auth/rate-limits): dirty the form so Cancel appears; Cancel stays neutral, Save stays green - [Project Settings → API Keys](https://studio-staging-2s957kwc4-supabase.vercel.app/dashboard/project/_/settings/api-keys): `DocsButton` in the header actions stays neutral Design system: - [Design system → Button](https://design-system-git-dnywh-dc924ac1-supabase.vercel.app/design-system/docs/components/button): `button-default` / `button-sizes` still show explicit default styling; Primary (green) is restricted to the Primary section (and `asChild`) WWW: - [www → Brand assets](https://zone-www-dot-com-git-dnywh-dc924ac1-supabase.vercel.app/brand-assets): Download logo kit / Download button kit stay neutral
98 lines
2.9 KiB
TypeScript
98 lines
2.9 KiB
TypeScript
import { useEffect, useState } from 'react'
|
|
import {
|
|
Button,
|
|
Dialog,
|
|
DialogContent,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogSection,
|
|
DialogSectionSeparator,
|
|
DialogTitle,
|
|
Input,
|
|
} from 'ui'
|
|
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
|
|
|
|
import { CodeEditor } from '@/components/ui/CodeEditor/CodeEditor'
|
|
import { tryParseJson } from '@/lib/helpers'
|
|
|
|
interface SendMessageModalProps {
|
|
visible: boolean
|
|
onSelectCancel: () => void
|
|
onSelectConfirm: (v: { message: string; payload: string }) => void
|
|
}
|
|
|
|
const defaultPayload = {
|
|
message: 'Test message',
|
|
payload: '{ "message": "Hello World" }',
|
|
}
|
|
|
|
export const SendMessageModal = ({
|
|
visible,
|
|
onSelectCancel,
|
|
onSelectConfirm,
|
|
}: SendMessageModalProps) => {
|
|
const [error, setError] = useState<string>()
|
|
const [values, setValues] = useState(defaultPayload)
|
|
|
|
useEffect(() => {
|
|
if (visible) {
|
|
setError(undefined)
|
|
setValues(defaultPayload)
|
|
}
|
|
}, [visible])
|
|
|
|
return (
|
|
<Dialog open={visible} onOpenChange={onSelectCancel}>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>Broadcast a message to all clients</DialogTitle>
|
|
</DialogHeader>
|
|
<DialogSectionSeparator />
|
|
<DialogSection>
|
|
<div className="flex flex-col gap-y-4">
|
|
<FormItemLayout label="Message name" layout="vertical" isReactForm={false}>
|
|
<Input
|
|
size="small"
|
|
value={values.message}
|
|
onChange={(v) => setValues({ ...values, message: v.target.value })}
|
|
/>
|
|
</FormItemLayout>
|
|
|
|
<div className="flex flex-col gap-y-2">
|
|
<FormItemLayout label="Message payload" layout="vertical" isReactForm={false}>
|
|
<CodeEditor
|
|
id="message-payload"
|
|
language="json"
|
|
className="mb-0! h-32 overflow-hidden rounded-sm border"
|
|
onInputChange={(e: string | undefined) =>
|
|
setValues({ ...values, payload: e ?? '{}' })
|
|
}
|
|
options={{ wordWrap: 'off', contextmenu: false }}
|
|
value={values.payload}
|
|
/>
|
|
{error !== undefined && <p className="text-sm text-red-900">{error}</p>}
|
|
</FormItemLayout>
|
|
</div>
|
|
</div>
|
|
</DialogSection>
|
|
<DialogFooter>
|
|
<Button onClick={onSelectCancel}>Cancel</Button>
|
|
<Button
|
|
onClick={() => {
|
|
const payload = tryParseJson(values.payload)
|
|
if (payload === undefined) {
|
|
setError('Please provide a valid JSON')
|
|
} else {
|
|
onSelectConfirm({ ...values, payload })
|
|
}
|
|
}}
|
|
variant="primary"
|
|
>
|
|
Confirm
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
)
|
|
}
|