Skip to content

Commit c05c95f

Browse files
Improve the flow of prompt quick start
1 parent 4344bce commit c05c95f

File tree

2 files changed

+121
-21
lines changed

2 files changed

+121
-21
lines changed

src/components/QuickStartPromptButton.jsx

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useState, useRef, useEffect } from 'react';
22
import styles from './QuickStartPromptButton.module.css';
33

44
const PROMPT = `Go step by step to create an Apify Actor:
@@ -35,31 +35,66 @@ apify run
3535

3636
export default function QuickStartPromptButton({ prompt = PROMPT }) {
3737
const [copied, setCopied] = useState(false);
38+
const [showPrompt, setShowPrompt] = useState(false);
39+
const timeoutRef = useRef(null);
40+
41+
useEffect(() => {
42+
return () => {
43+
if (timeoutRef.current) {
44+
clearTimeout(timeoutRef.current);
45+
}
46+
};
47+
}, []);
3848

3949
const handleCopy = async () => {
4050
try {
4151
await navigator.clipboard.writeText(prompt);
4252

53+
if (timeoutRef.current) {
54+
clearTimeout(timeoutRef.current);
55+
}
56+
4357
setCopied(true);
44-
setTimeout(() => setCopied(false), 2000);
58+
timeoutRef.current = setTimeout(() => setCopied(false), 2000);
4559
} catch (err) {
4660
console.error('Failed to copy prompt:', err);
4761
}
4862
};
4963

64+
const togglePrompt = () => {
65+
setShowPrompt(!showPrompt);
66+
};
67+
5068
return (
51-
<div className={styles['quick-start-prompt-card']}>
52-
<div className={styles['prompt-content']}>
53-
<div className={styles['prompt-text']}>
54-
<span>Use this pre-built prompt to get started faster.</span>
69+
<>
70+
<div className={styles['quick-start-prompt-card']}>
71+
<div className={styles['prompt-content']}>
72+
<div className={styles['prompt-text']}>
73+
<span>Use this pre-built prompt to get started faster.</span>
74+
</div>
75+
</div>
76+
<div className={styles['button-container']}>
77+
<button
78+
className={styles['toggle-button']}
79+
onClick={togglePrompt}
80+
>
81+
{showPrompt ? 'Hide the prompt' : 'Show the prompt'}
82+
</button>
83+
<button
84+
className={`${styles['copy-button']} ${copied ? styles['copied'] : ''}`}
85+
onClick={handleCopy}
86+
>
87+
{copied ? 'Copied!' : 'Copy prompt'}
88+
</button>
5589
</div>
5690
</div>
57-
<button
58-
className={`${styles['copy-button']} ${copied ? styles['copied'] : ''}`}
59-
onClick={handleCopy}
60-
>
61-
{copied ? 'Copied!' : 'Copy prompt'}
62-
</button>
63-
</div>
91+
{showPrompt && (
92+
<div className={styles['full-prompt-container']}>
93+
<div className={styles['full-prompt']}>
94+
<pre>{prompt}</pre>
95+
</div>
96+
</div>
97+
)}
98+
</>
6499
);
65100
}

src/components/QuickStartPromptButton.module.css

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,11 @@
77
border-radius: 8px;
88
padding: 1.6rem;
99
box-shadow: 0 1.5px 3px 0 rgb(0 0 0 / 15%);
10-
transition: all var(--ifm-transition-fast) ease;
11-
transition-property: border, box-shadow;
1210
width: 100%;
1311
position: relative;
1412
overflow: hidden;
1513
}
1614

17-
.quick-start-prompt-card:hover {
18-
border-color: var(--ifm-color-primary);
19-
box-shadow: 0 3px 6px 0 rgb(0 0 0 / 20%);
20-
}
21-
2215
/* Light purple glow effect */
2316
.quick-start-prompt-card::before {
2417
content: '';
@@ -68,6 +61,7 @@
6861
}
6962

7063
.copy-button {
64+
width: 150px;
7165
background: var(--ifm-color-primary);
7266
color: var(--ifm-color-primary-contrast-background);
7367
border: 1px solid var(--ifm-color-primary);
@@ -102,6 +96,71 @@
10296
border-color: var(--ifm-color-success-darker);
10397
}
10498

99+
.button-container {
100+
display: flex;
101+
gap: 0.8rem;
102+
align-items: center;
103+
position: relative;
104+
z-index: 1;
105+
}
106+
107+
.toggle-button {
108+
width: 150px;
109+
background: transparent;
110+
color: var(--ifm-color-primary);
111+
border: 1px solid var(--ifm-color-primary);
112+
border-radius: 6px;
113+
padding: 0.8rem 1.6rem;
114+
font-size: 1.4rem;
115+
font-weight: 500;
116+
cursor: pointer;
117+
transition: all var(--ifm-transition-fast) ease;
118+
white-space: nowrap;
119+
flex: 1;
120+
}
121+
122+
.toggle-button:hover {
123+
background: var(--ifm-color-primary);
124+
color: var(--ifm-color-primary-contrast-background);
125+
transform: translateY(-1px);
126+
}
127+
128+
.toggle-button:active {
129+
transform: translateY(0);
130+
}
131+
132+
.full-prompt {
133+
margin-top: 1.2rem;
134+
padding: 1.2rem;
135+
background: var(--ifm-background-surface-color);
136+
border: 1px solid var(--ifm-color-emphasis-200);
137+
border-radius: 6px;
138+
max-height: 400px;
139+
overflow-y: auto;
140+
}
141+
142+
.full-prompt-container {
143+
margin-top: 1.2rem;
144+
width: 100%;
145+
}
146+
147+
.full-prompt-container .full-prompt {
148+
margin-top: 0;
149+
background: var(--ifm-background-color);
150+
border: 1px solid var(--ifm-color-emphasis-200);
151+
border-radius: 8px;
152+
box-shadow: 0 1.5px 3px 0 rgb(0 0 0 / 15%);
153+
}
154+
155+
.full-prompt pre {
156+
margin: 0;
157+
font-size: 1.3rem;
158+
line-height: 1.5;
159+
color: var(--ifm-color-content);
160+
white-space: pre-wrap;
161+
word-wrap: break-word;
162+
}
163+
105164
/* Responsive design */
106165
@media (max-width: 768px) {
107166
.quick-start-prompt-card {
@@ -115,7 +174,13 @@
115174
gap: 0.8rem;
116175
}
117176

118-
.copy-button {
177+
.button-container {
178+
flex-direction: column;
179+
width: 100%;
180+
}
181+
182+
.copy-button,
183+
.toggle-button {
119184
width: 100%;
120185
}
121186
}

0 commit comments

Comments
 (0)