From 03325f79a08def1dba39ba0ed9222cda3db6186b Mon Sep 17 00:00:00 2001 From: Benjamin Leonard Date: Wed, 20 Aug 2025 10:24:39 +0100 Subject: [PATCH] Example script dropdown --- app/components/ascii-art-generator.tsx | 37 ++++++-------------- app/components/ascii-preview.tsx | 48 ++++++++++++++++++++++---- app/components/project-management.tsx | 4 +-- 3 files changed, 55 insertions(+), 34 deletions(-) diff --git a/app/components/ascii-art-generator.tsx b/app/components/ascii-art-generator.tsx index 43ab023..72f38e9 100644 --- a/app/components/ascii-art-generator.tsx +++ b/app/components/ascii-art-generator.tsx @@ -681,20 +681,6 @@ export function AsciiArtGenerator() { [processFile], ) - const handleExampleScriptClick = useCallback(() => { - // Open code sidebar and load the clock example - setShowCodeSidebar(true) - const template = TEMPLATES.sin - setPendingCode(template.source.code) - updateSettings('source', template.source) - updateSettings('output', template.output) - updateSettings('export', template.export) - updateSettings('preprocessing', template.preprocessing) - updateSettings('meta', template.meta) - updateSettings('source', template.source) - updateSettings('animation', template.animation) - }, [updateSettings]) - const handleTemplateChange = (template: TemplateType) => { if (template !== 'custom' && TEMPLATES[template]) { loadTemplate(template) @@ -811,18 +797,8 @@ export function AsciiArtGenerator() { disabled={!program} exportSettings={settings.export} /> -
- {/* Project Management */} - -
+
+ {/* Project Management */} + @@ -890,7 +875,7 @@ export function AsciiArtGenerator() { animationController={animationController} setAnimationController={setAnimationController} isExporting={isExporting} - onExampleScriptClick={handleExampleScriptClick} + onExampleScriptClick={(template) => loadTemplate(template)} onExampleImageClick={() => updateSourceAndAspectRatio(exampleImage, 'image', 'example-grad.png') } diff --git a/app/components/ascii-preview.tsx b/app/components/ascii-preview.tsx index 3745f8b..7df79ed 100644 --- a/app/components/ascii-preview.tsx +++ b/app/components/ascii-preview.tsx @@ -8,18 +8,21 @@ import { Action16Icon, AutoRestart12Icon, + DirectionDownIcon, DirectionRightIcon, DocumentApi16Icon, Folder16Icon, Resize16Icon, } from '@oxide/design-system/icons/react' import useResizeObserver from '@react-hook/resize-observer' +import cn from 'classnames' import { motion } from 'motion/react' import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react' import { useHotkeys } from 'react-hotkeys-hook' import type { createAnimation, Program } from '~/lib/animation' import { InputButton, InputNumber } from '~/lib/ui/src' +import { TEMPLATES, type TemplateType } from '~/templates' import AsciiAnimation from './ascii-animation' import type { GridType } from './ascii-art-generator' @@ -43,7 +46,7 @@ interface AsciiPreviewProps { setAnimationController: (controller: AnimationController) => void isExporting: boolean onUploadClick?: () => void - onExampleScriptClick?: () => void + onExampleScriptClick?: (templateType: TemplateType) => void onExampleImageClick?: () => void } @@ -54,13 +57,17 @@ const DemoCard = ({ title, onClick, index, + hasDropdown = false, + onDropdownChange, }: { icon: React.ReactNode title: string onClick?: () => void index: number + hasDropdown?: boolean + onDropdownChange?: (value: string) => void }) => ( -
{icon}
{title}
-
+ {hasDropdown && ( +
+ + +
+ )} +