Spaces:
Running
Running
File size: 4,758 Bytes
db9635c bc9b59d db9635c bc9b59d db9635c bc9b59d db9635c bc9b59d db9635c bc9b59d db9635c bc9b59d db9635c bc9b59d db9635c bc9b59d db9635c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
<script lang="ts">
import { onMount, onDestroy } from "svelte";
import { fade } from "svelte/transition";
import gsap from "gsap";
export let onSendMessage: (message: string) => void;
export let visible: boolean = true;
const examples = [
{ icon: "🏀", text: "add another ball" },
{ icon: "📝", text: "explain what the code does" },
{ icon: "🎮", text: "make a moving platform" },
{ icon: "⬆️", text: "increase the player jump height" }
];
let exampleCards: HTMLButtonElement[] = [];
onMount(() => {
if (visible) {
exampleCards.forEach((card, index) => {
if (!card) return;
gsap.fromTo(card, {
opacity: 0,
x: -10,
scale: 0.95
}, {
opacity: 1,
x: 0,
scale: 1,
duration: 0.15,
delay: index * 0.03,
ease: "power2.out"
});
});
}
});
onDestroy(() => {
exampleCards.forEach((card) => {
if (card) {
gsap.killTweensOf(card);
}
});
});
function handleClick(text: string) {
onSendMessage(text);
}
function handleMouseEnter(event: MouseEvent) {
const card = event.currentTarget as HTMLButtonElement;
gsap.to(card, {
scale: 1.05,
duration: 0.08,
ease: "power2.out"
});
}
function handleMouseLeave(event: MouseEvent) {
const card = event.currentTarget as HTMLButtonElement;
gsap.to(card, {
scale: 1,
duration: 0.1,
ease: "power2.out"
});
}
function handleMouseDown(event: MouseEvent) {
const card = event.currentTarget as HTMLButtonElement;
gsap.to(card, {
scale: 0.97,
duration: 0.03,
ease: "power2.in"
});
}
function handleMouseUp(event: MouseEvent) {
const card = event.currentTarget as HTMLButtonElement;
gsap.to(card, {
scale: 1.05,
duration: 0.05,
ease: "back.out(1.5)"
});
}
</script>
{#if visible}
<div class="examples-row" transition:fade={{ duration: 200 }}>
<span class="examples-label">Try an example:</span>
<div class="examples-list">
{#each examples as example, i}
<button
bind:this={exampleCards[i]}
class="example-pill"
on:click={() => handleClick(example.text)}
on:mouseenter={handleMouseEnter}
on:mouseleave={handleMouseLeave}
on:mousedown={handleMouseDown}
on:mouseup={handleMouseUp}
>
<span class="example-icon">{example.icon}</span>
<span class="example-text">{example.text}</span>
</button>
{/each}
</div>
</div>
{/if}
<style>
.examples-row {
display: flex;
align-items: center;
gap: 1rem;
padding: 0.75rem 1rem;
background: rgba(0, 0, 0, 0.3);
border-top: 1px solid rgba(255, 255, 255, 0.03);
}
.examples-label {
font-size: 0.7rem;
color: rgba(255, 255, 255, 0.35);
text-transform: uppercase;
letter-spacing: 0.08em;
font-weight: 500;
font-family: "Monaco", "Menlo", monospace;
flex-shrink: 0;
}
.examples-list {
display: flex;
gap: 0.5rem;
flex-wrap: wrap;
flex: 1;
}
.example-pill {
display: inline-flex;
align-items: center;
gap: 0.375rem;
padding: 0.3rem 0.625rem;
background: rgba(255, 255, 255, 0.02);
border: 1px solid rgba(255, 255, 255, 0.05);
border-radius: 16px;
cursor: pointer;
transition: none;
font-family: "Monaco", "Menlo", monospace;
font-size: 0.7rem;
color: rgba(255, 255, 255, 0.65);
will-change: transform, box-shadow;
flex-shrink: 0;
min-width: 0;
}
.example-pill:hover {
background: rgba(255, 255, 255, 0.04);
border-color: rgba(255, 255, 255, 0.08);
color: rgba(255, 255, 255, 0.85);
}
.example-icon {
font-size: 0.75rem;
opacity: 0.8;
flex-shrink: 0;
}
.example-text {
font-size: 0.7rem;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
@media (max-width: 768px) {
.examples-row {
gap: 0.75rem;
padding: 0.75rem;
}
.examples-list {
gap: 0.4rem;
}
.example-pill {
padding: 0.25rem 0.5rem;
font-size: 0.65rem;
}
.example-text {
font-size: 0.65rem;
}
}
@media (max-width: 480px) {
.examples-row {
flex-direction: column;
align-items: stretch;
gap: 0.5rem;
}
.examples-label {
text-align: center;
font-size: 0.65rem;
}
.examples-list {
justify-content: center;
}
.example-pill {
flex: 0 1 auto;
max-width: calc(50% - 0.25rem);
}
}
@media (max-width: 360px) {
.example-pill {
max-width: 100%;
}
}
</style> |