Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

refactor(editor): route dialog buttons through the shared Button primitive

esenginee3929a007feb
diff --git a/desktop/src/components/BuildDialog.tsx b/desktop/src/components/BuildDialog.tsx
index 52c989260..a863809f6 100644
--- a/desktop/src/components/BuildDialog.tsx
+++ b/desktop/src/components/BuildDialog.tsx
@@ -14,6 +14,7 @@ import { useState, useSyncExternalStore } from 'react';
import { Loader2, FolderOpen, CheckCircle2, AlertCircle, Boxes, Info, Copy, ExternalLink, Play } from 'lucide-react';
import { Modal } from '@/components/Modal';
import { Segmented } from '@/components/Segmented';
+import { Button } from '@/components/Button';
import { ProjectStore } from '@/project/ProjectStore';
import { useEditorStore } from '@/store/editorStore';
@@ -183,10 +184,10 @@ export function BuildDialog() {
const footer = (
<>
- <button type="button" className="btn-soft" onClick={close} disabled={running}>
+ <Button onClick={close} disabled={running}>
{phase === 'done' ? 'Close' : 'Cancel'}
- </button>
- <button type="button" className="btn-soft is-primary" onClick={() => void build()} disabled={running || !project}>
+ </Button>
+ <Button variant="primary" onClick={() => void build()} disabled={running || !project}>
{running ? (
<>
<Loader2 size={14} className="spin" /> Packaging…
@@ -196,7 +197,7 @@ export function BuildDialog() {
<Boxes size={14} /> Package
</>
)}
- </button>
+ </Button>
</>
);
@@ -243,9 +244,9 @@ export function BuildDialog() {
spellCheck={false}
onChange={(e) => setOutDir(e.target.value)}
/>
- <button type="button" className="btn-soft" onClick={() => void browse()}>
+ <Button onClick={() => void browse()}>
<FolderOpen size={13} /> Browse
- </button>
+ </Button>
</div>
</div>
@@ -342,13 +343,13 @@ export function BuildDialog() {
{result.ok && (
<div className="build__actions">
{def.httpPreview && (
- <button type="button" className="btn-soft is-primary" onClick={() => void preview()}>
+ <Button variant="primary" onClick={() => void preview()}>
<ExternalLink size={13} /> Preview over http
- </button>
+ </Button>
)}
- <button type="button" className="btn-soft" onClick={() => void window.estella.shell?.openPath?.(result.outDir)}>
+ <Button onClick={() => void window.estella.shell?.openPath?.(result.outDir)}>
<FolderOpen size={13} /> Open folder
- </button>
+ </Button>
</div>
)}
</>
diff --git a/desktop/src/components/Button.tsx b/desktop/src/components/Button.tsx
index 14af3e459..ffe09db87 100644
--- a/desktop/src/components/Button.tsx
+++ b/desktop/src/components/Button.tsx
@@ -5,30 +5,27 @@
* @brief The shared text button (with an optional leading icon) — one recipe
* behind dialog actions, toolbar commands, and empty-state CTAs.
* Variants: soft (default), primary (accent fill), danger (error fill).
- * Styled by the `.btn-soft` recipe in theme/app.css.
+ * Styled by the `.btn-soft` recipe in theme/app.css. Forwards a ref so a
+ * dialog can autofocus its confirm action.
*/
-import type { ReactNode, MouseEvent } from 'react';
+import { forwardRef, type ReactNode, type MouseEvent } from 'react';
-export function Button({
- children,
- onClick,
- variant = 'soft',
- disabled,
- title,
- type = 'button',
- className,
-}: {
- children: ReactNode;
- onClick?: (e: MouseEvent) => void;
- variant?: 'soft' | 'primary' | 'danger';
- disabled?: boolean;
- title?: string;
- type?: 'button' | 'submit';
- className?: string;
-}) {
+export const Button = forwardRef<
+ HTMLButtonElement,
+ {
+ children: ReactNode;
+ onClick?: (e: MouseEvent) => void;
+ variant?: 'soft' | 'primary' | 'danger';
+ disabled?: boolean;
+ title?: string;
+ type?: 'button' | 'submit';
+ className?: string;
+ }
+>(function Button({ children, onClick, variant = 'soft', disabled, title, type = 'button', className }, ref) {
const mod = variant === 'primary' ? ' is-primary' : variant === 'danger' ? ' is-danger' : '';
return (
<button
+ ref={ref}
type={type}
className={`btn-soft${mod}${className ? ` ${className}` : ''}`}
disabled={disabled}
@@ -38,4 +35,4 @@ export function Button({
{children}
</button>
);
-}
+});
diff --git a/desktop/src/components/ConfirmDialog.tsx b/desktop/src/components/ConfirmDialog.tsx
index 2beb2152a..da766399b 100644
--- a/desktop/src/components/ConfirmDialog.tsx
+++ b/desktop/src/components/ConfirmDialog.tsx
@@ -8,6 +8,7 @@
*/
import { useEffect, useRef, type ReactNode } from 'react';
import { Modal } from './Modal';
+import { Button } from './Button';
export function ConfirmDialog({
title,
@@ -36,17 +37,10 @@ export function ConfirmDialog({
width={420}
footer={
<>
- <button type="button" className="btn-soft" onClick={onCancel}>
- Cancel
- </button>
- <button
- ref={btn}
- type="button"
- className={`btn-soft ${danger ? 'is-danger' : 'is-primary'}`}
- onClick={onConfirm}
- >
+ <Button onClick={onCancel}>Cancel</Button>
+ <Button ref={btn} variant={danger ? 'danger' : 'primary'} onClick={onConfirm}>
{confirmLabel}
- </button>
+ </Button>
</>
}
>