odyssey-frontend / src /lib /components /ChoiceInterface.svelte
Fraser's picture
Initial backend setup with Gradio
7ac86fa
<script lang="ts">
import type { StoryChoice } from '$lib/types';
export let choices: StoryChoice[];
export let onChoiceSelected: ((choice: StoryChoice) => void) | undefined = undefined;
export let disabled: boolean = false;
function handleChoice(choice: StoryChoice) {
if (!disabled) {
onChoiceSelected?.(choice);
}
}
</script>
{#if choices && choices.length > 0}
<div class="choice-interface">
<h3>What do you do?</h3>
<div class="choices">
{#each choices as choice}
<button
class="choice-button"
class:disabled={disabled}
on:click={() => handleChoice(choice)}
disabled={disabled}
>
<span class="choice-text">{choice.text}</span>
{#if choice.description}
<span class="choice-description">{choice.description}</span>
{/if}
</button>
{/each}
</div>
</div>
{/if}
<style>
.choice-interface {
padding: 2rem;
background: #f8f9fa;
border-radius: 0.5rem;
margin: 1.5rem 0;
}
h3 {
margin: 0 0 1.5rem 0;
color: #1a1a1a;
font-size: 1.5rem;
text-align: center;
}
.choices {
display: flex;
flex-direction: column;
gap: 1rem;
max-width: 600px;
margin: 0 auto;
}
.choice-button {
display: flex;
flex-direction: column;
align-items: flex-start;
padding: 1.25rem 1.5rem;
background: white;
border: 2px solid #dee2e6;
border-radius: 0.5rem;
cursor: pointer;
transition: all 0.2s;
text-align: left;
}
.choice-button:hover:not(.disabled) {
border-color: #007bff;
background: #f0f8ff;
transform: translateX(5px);
}
.choice-button.disabled {
opacity: 0.5;
cursor: not-allowed;
}
.choice-text {
font-size: 1.1rem;
font-weight: 600;
color: #1a1a1a;
margin-bottom: 0.5rem;
}
.choice-description {
font-size: 0.9rem;
color: #666;
line-height: 1.4;
}
@media (max-width: 768px) {
.choice-interface {
padding: 1.5rem 1rem;
}
h3 {
font-size: 1.25rem;
}
.choice-button {
padding: 1rem 1.25rem;
}
.choice-text {
font-size: 1rem;
}
.choice-description {
font-size: 0.85rem;
}
}
</style>