Skip to content
TheChatArchiveThe Chat Archive
DeepSeekdeepseek-r1-0528· DeepSeekHugging Face LMArena Human Preference 140K

create a svelte 5 component for a shopping list form

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with gpt-4.1-mini-2025-04-14’s answer.
  1. User

    create a svelte 5 component for a shopping list form

  2. DeepSeek Assistant

    Here's a Svelte 5 shopping list form component with modern features:

    <script>
        let newItem = $state('')
        let items = $state([])
    
        function addItem() {
            if (newItem.trim()) {
                items = [...items, {
                    id: crypto.randomUUID(),
                    name: newItem.trim(),
                    completed: false
                }]
                newItem = ''
            }
        }
    
        function removeItem(id) {
            items = items.filter(item => item.id !== id)
        }
    
        function toggleComplete(id) {
            items = items.map(item => 
                item.id === id ? {...item, completed: !item.completed} : item
            )
        }
    </script>
    
    <form on:submit|preventDefault={addItem} class="shopping-form">
        <div class="input-group">
            <input
                type="text"
                bind:value={newItem}
                placeholder="Add grocery item..."
                aria-label="Shopping item"
                class="item-input"
            >
            <button type="submit" class="add-btn" disabled={!newItem.trim()}>
                Add
            </button>
        </div>
    </form>
    
    <ul class="items-list">
        {#each items as item (item.id)}
            <li class:completed={item.completed}>
                <div class="item-content">
                    <input
                        type="checkbox"
                        checked={item.completed}
                        on:change={() => toggleComplete(item.id)}
                        aria-label="Toggle completion"
                    >
                    <span>{item.name}</span>
                </div>
                <button
                    on:click={() => removeItem(item.id)}
                    class="remove-btn"
                    aria-label="Remove item"
                >
                    &times;
                </button>
            </li>
        {:else}
            <li class="empty-state">No items yet. Add your first grocery!</li>
        {/each}
    </ul>
    
    <style>
        .shopping-form {
            margin-bottom: 1.5rem;
        }
        
        .input-group {
            display: flex;
            gap: 0.5rem;
        }
        
        .item-input {
            flex-grow: 1;
            padding: 0.75rem;
            border: 1px solid #e0e0e0;
            border-radius: 4px;
            font-size: 1rem;
        }
        
        .add-btn {
            background: #4f46e5;
            color: white;
            border: none;
            border-radius: 4px;
            padding: 0 1.5rem;
            cursor: pointer;
            font-weight: 600;
        }
        
        .add-btn:disabled {
            opacity: 0.6;
            cursor: not-allowed;
        }
        
        .items-list {
            list-style: none;
            padding: 0;
            margin: 0;
        }
        
        .items-list li {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0.75rem;
            border-bottom: 1px solid #f0f0f0;
        }
        
        .item-content {
            display: flex;
            align-items: center;
            gap: 0.75rem;
        }
        
        .completed span {
            text-decoration: line-through;
            color: #94a3b8;
        }
        
        .remove-btn {
            background: transparent;
            border: none;
            color: #ef4444;
            font-size: 1.5rem;
            cursor: pointer;
            line-height: 1;
            padding: 0 0.5rem;
        }
        
        .empty-state {
            color: #64748b;
            font-style: italic;
            padding: 1.5rem;
            text-align: center;
            border-bottom: none;
        }
    </style>
    

    Key features:

    1. Modern Svelte 5 Syntax:

      • Uses $state for reactive variables
      • Utilizes Svelte's enhanced reactivity system
    2. Core Functionality:

      • Add items with Enter key or button click
      • Mark items as completed
      • Remove items from list
      • Input validation (prevents empty items)
      • Unique IDs for list items
    3. UX Enhancements:

      • Disabled "Add" button for empty input
      • Visual feedback for completed items
      • Placeholder text
      • Accessible ARIA labels
      • Empty state message
      • Responsive design
    4. Styling:

      • Clean, modern interface
      • Visual feedback for interactions
      • Appropriate spacing and typography
      • Hover effects on interactive elements
      • Cross-browser compatible

    To use this component:

    1. Create a new Svelte 5 project
    2. Place this code in ShoppingList.svelte
    3. Import and use it in your routes:
    <script>
        import ShoppingList from './ShoppingList.svelte';
    </script>
    
    <ShoppingList />
    

    The component includes:

    • Form with input validation
    • Dynamic list rendering
    • Item completion tracking
    • Modern UI transitions
    • Mobile-friendly layout
    • Accessible controls
    • Clean visual hierarchy

    You can customize the styling by modifying the CSS variables or adjusting the style block. The component uses semantic HTML and follows accessibility best practices.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.