-
Notifications
You must be signed in to change notification settings - Fork 0
feat(VariantSelector): Add Shopify product variant selection component with Shadow DOM #357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ith full test coverage Co-authored-by: timowestnosto <[email protected]>
…Shopify products Co-authored-by: timowestnosto <[email protected]>
Updated the VariantSelector Storybook stories to use the same example data as SimpleCard component. Now uses the same product handles ( The stories now show working variant selection with proper Shopify product structures including multi-option ("Awesome Sneakers" with Color and Size) and single-option ("Good Ol' Shoes" with Color only) examples. Commit: cb235d2 Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot fix these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new Shopify variant selector component that allows users to select product variants in e-commerce environments. The component fetches product data from Shopify's API, renders interactive dropdown controls for product options (color, size, etc.), and emits events when variant selections change.
Key changes:
- Adds a complete
<nosto-variant-selector>
custom element with reactive UI generation - Provides TypeScript interfaces for Shopify product data structures
- Includes comprehensive test coverage (95.57%) with 9 test cases covering various scenarios
- Integrates with Storybook using consistent example data and mock fetch implementation
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
src/components/VariantSelector/VariantSelector.ts |
Core component implementation with Shopify API integration and event handling |
src/components/VariantSelector/types.ts |
TypeScript interfaces for Shopify product, variant, and option data structures |
src/components/VariantSelector/VariantSelector.stories.tsx |
Storybook documentation with interactive examples using mock data |
test/components/VariantSelector.spec.tsx |
Comprehensive test suite covering component functionality and edge cases |
test/utils/jsx.ts |
JSX type mapping for the new VariantSelector component |
src/main.ts |
Export statement for the new VariantSelector component |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot fix these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot fix these
} | ||
|
||
// Mock Shopify product data based on the handles used in SimpleCard | ||
const mockProducts: Record<string, ShopifyProduct> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop this mock declaration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the mock Shopify declaration from stories. The component now uses real Shopify endpoints for authentic testing and demonstration.
Commit: 12c3733
Co-authored-by: timowestnosto <[email protected]>
Addressed all code review feedback by refactoring the VariantSelector component architecture:
The refactored component provides better maintainability and consistency with the rest of the codebase. Commit: 4d03b52 |
…tton-based UI Co-authored-by: timowestnosto <[email protected]>
Addressed all code review feedback by implementing major architectural improvements: ✅ Shadow DOM with CSS Variables: Complete styling encapsulation with 20+ customizable CSS variables The component now provides a modern, accessible, and highly customizable variant selection experience with proper Shadow DOM encapsulation. Commit: 12c3733
All requested changes have been implemented: 🎯 Shadow DOM Implementation: Complete with CSS variables for theming The VariantSelector now provides a modern, accessible experience with comprehensive CSS variable support for styling customization. Commit: 12c3733 Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot fix these
…o separate module Co-authored-by: timowestnosto <[email protected]>
Addressed all architectural improvements: ✅ Simplified Error Handling: Removed try-catch blocks for cleaner code flow The component now features a clean, modern architecture with proper separation of concerns and better maintainability. Commit: b4c8ed4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot fix these
…riables Co-authored-by: timowestnosto <[email protected]>
Applied all function optimizations: ✅ Single Option Rendering: Converted The component now features optimized function design with better performance, readability, and maintainability. Commit: 160a4a0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot fix these
|
||
const { options } = element.product | ||
|
||
if (options.length === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop empty options logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the empty options logic from the render function. The component now handles only the core use case of products with options, eliminating unnecessary conditional branches and simplifying the code flow.
Commit: bf224ec
if (!element.shadowRoot) return | ||
|
||
const buttons = Array.from(element.shadowRoot.querySelectorAll<HTMLButtonElement>(".option-button")) | ||
element.buttons = buttons // Store buttons instead of selects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the redundant comment "Store buttons instead of selects" from the setupEventListeners function. The code is now cleaner without unnecessary inline explanations.
Commit: bf224ec
… comment Co-authored-by: timowestnosto <[email protected]>
Applied both simplifications: ✅ Dropped Empty Options Logic: Removed conditional handling for products with no options, simplifying the render function The component now features a streamlined architecture focused on core functionality without unnecessary complexity. Commit: bf224ec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot fix these
…onent rendering Co-authored-by: timowestnosto <[email protected]>
Applied all Storybook simplifications: ✅ Basic Story: Only CSS variables for nosto-variant-selector, removed wrapper elements, titles, descriptions, variant info, and scripts The stories now provide clean, minimal examples focused purely on component functionality. Commit: ef44b15 |
VariantSelector
component insrc/components/VariantSelector/VariantSelector.ts
/products/<handle>.js
endpointtest/components/VariantSelector.spec.tsx
✅ Implementation Complete - Minimalist Storybook Stories
Successfully implemented the
<nosto-variant-selector>
custom element with all requested features and cleaned up Storybook stories to focus purely on component functionality:🔄 Storybook Simplification
Basic Story Cleanup:
Single Option Story Cleanup:
🎨 Clean Story Architecture
The Storybook stories now feature:
🏗️ Technical Improvements
📊 Quality Maintained
The VariantSelector now provides clean, minimal Storybook stories that showcase the component's capabilities without unnecessary complexity or demo artifacts.
Fixes #356.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.