Skip to content

Feat: Add gallery page with ten pre-built widget templates, template prop support, and accessibility#2

Merged
foreleven merged 7 commits intomainfrom
copilot/complete-gallery-page-widget
Nov 8, 2025
Merged

Feat: Add gallery page with ten pre-built widget templates, template prop support, and accessibility#2
foreleven merged 7 commits intomainfrom
copilot/complete-gallery-page-widget

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 7, 2025

Gallery Page Implementation

This PR implements a complete gallery page for the widget builder with ten pre-built beautiful widgets.

Screenshots:

Completed:

  • Create directory structure for gallery widgets (src/pages/gallery/widgets/)
  • Design and create ten beautiful pre-built widgets using existing components
    • Widget 1: User Profile Card - profile with avatar, stats, and actions
    • Widget 2: Task List Item - task with priority badge and progress
    • Widget 3: Notification Card - activity notifications with timestamps
    • Widget 4: Weather Widget - current weather with forecast details
    • Widget 5: Stats Dashboard Card - metrics with trend indicators
    • Widget 6: Product Card - e-commerce product with image and details
    • Widget 7: Music Player - compact player with album art and controls
    • Widget 8: Social Media Post - post card with engagement metrics
    • Widget 9: Calendar Event - meeting/event card with participants
    • Widget 10: Email Preview - email card with sender info and actions
  • Implement gallery page UI with grid layout
  • Add dialog component to display widget JSX template on click with syntax highlighting
  • Add "Use This Widget" button in dialog to create new widget and navigate to editor
  • Update AppSidebar to include Gallery menu item with sparkles icon
  • Test all functionality manually
  • Code review and refactoring
  • Security scanning (no issues found)
  • Add template prop support to WidgetRenderer
  • Optimize template parsing performance with useRef and useEffect
  • Update all image URLs to use picsum.photos
  • Add keyboard accessibility support

Features:

  • Grid layout displaying all 10 pre-built widgets with live previews
  • Click any widget card to open a dialog showing:
    • Full widget preview
    • JSX template with syntax highlighting
    • Widget name and description
  • "Use This Widget" button creates a new widget instance and opens it in the editor
  • New "Gallery" menu item in sidebar for easy navigation
  • Fully responsive design
  • Error boundaries to handle rendering issues gracefully
  • WidgetRenderer now supports template prop: automatically parses JSX template to schema when schema is not provided
  • Performance optimized: Template parsing is cached and only re-runs when template changes
  • Consistent placeholder images: All widget images now use picsum.photos for reliable placeholder images
  • Keyboard accessible: Gallery items are fully navigable via keyboard with proper ARIA labels, focus indicators, and support for Enter/Space key activation
Original prompt

Feat: complete the gallery page

  • create ten beautiful widgets using the basic components
  • complete the gallery page and add the menu and router
  • put these pre-built widgets in src/pages/gallery/widgets/
  • Use WidgetRenderer to render the widget in the gallery
  • Add dialog to show the widget's jsx template when click
  • Add a 'using this' button on the dialog to create a new widget and edit it on the editor page

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 7, 2025 16:37
- Created 10 beautiful pre-built widgets using basic components:
  1. User Profile Card - profile with avatar, stats, and actions
  2. Task List Item - task with priority badge and progress
  3. Notification Card - activity notifications with timestamps
  4. Weather Widget - current weather with forecast details
  5. Stats Dashboard Card - metrics with trend indicators
  6. Product Card - e-commerce product with image and details
  7. Music Player - compact player with album art and controls
  8. Social Media Post - post card with engagement metrics
  9. Calendar Event - meeting/event card with participants
  10. Email Preview - email card with sender info and actions

- Implemented gallery page with:
  - Grid layout displaying all widgets
  - Interactive preview of each widget
  - Dialog showing widget's JSX template with syntax highlighting
  - "Use This Widget" button to create and edit widget in editor
  - Navigation integration with sidebar menu

Co-authored-by: foreleven <4785594+foreleven@users.noreply.github.com>
- Extract selectedWidgetData to reduce duplication in dialog rendering
- Use computed variable instead of repeated null checks and array access
- Improve code readability and maintainability

Co-authored-by: foreleven <4785594+foreleven@users.noreply.github.com>
Copilot AI changed the title [WIP] Complete the gallery page with widgets and routing Feat: Add gallery page with ten pre-built widget templates Nov 7, 2025
Copilot AI requested a review from foreleven November 7, 2025 16:46
schema={undefined}
components={components}
data={item.widget.states?.[0]?.data ?? {}}
template={item.widget.template}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot The WidgetRenderer is not support template not. You can add this support, parse the schema from template when the schema prop not provided

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added template prop support to WidgetRenderer in commit ab14c6e. When schema is not provided but template is, the renderer now automatically parses the template using parseJSXTemplate and renders the widget.

Changes:

  • Added template?: string to WidgetRendererProps
  • Parse template to schema when schema is undefined
  • Gallery widgets now render correctly using the template prop

Dialog with template support

- Parse template string to schema when schema is not provided
- Allows rendering widgets directly from JSX template strings
- Enables gallery to use template prop instead of pre-parsing schemas

Co-authored-by: foreleven <4785594+foreleven@users.noreply.github.com>
Copilot AI changed the title Feat: Add gallery page with ten pre-built widget templates Feat: Add gallery page with ten pre-built widget templates and template prop support Nov 8, 2025
Copilot AI requested a review from foreleven November 8, 2025 01:30
Copy link
Copy Markdown

Copilot AI left a 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 adds a widget gallery feature that displays pre-built widget templates and allows users to preview and use them in their projects. The implementation includes template parsing support in the WidgetRenderer component and ten example widget templates.

Key changes:

  • Enhanced WidgetRenderer to support direct template parsing via a new template prop
  • Added a new gallery page with preview and detailed view functionality
  • Created ten pre-built widget templates (weather, profile card, task list, etc.)

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/widget-renderer/src/WidgetRenderer.tsx Added template parsing support via new template prop and parseJSXTemplate function
apps/widget-builder/src/pages/layout/AppSidebar.tsx Added gallery navigation link with Sparkles icon
apps/widget-builder/src/pages/gallery/WidgetGallery.tsx Implemented gallery UI with grid layout, preview cards, and detail dialog
apps/widget-builder/src/pages/gallery/widgets/*.ts Ten widget template definitions with JSX templates and sample data
apps/widget-builder/src/pages/gallery/widgets/index.ts Aggregates and exports all gallery widgets

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +64 to +68
<div
key={index}
className="group relative cursor-pointer rounded-lg border bg-card p-6 hover:border-primary hover:shadow-lg transition-all"
onClick={() => handleWidgetClick(index)}
>
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clickable gallery item div lacks keyboard accessibility. Add role=\"button\", tabIndex={0}, and an onKeyDown handler to support keyboard navigation (Enter/Space keys) for users who cannot use a mouse.

Copilot uses AI. Check for mistakes.
Comment on lines +74 to +79
<WidgetRenderer
schema={undefined}
components={components}
data={item.widget.states?.[0]?.data ?? {}}
template={item.widget.template}
/>
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The WidgetRenderer parses the template on every render. Consider memoizing the parsed schema with useMemo to avoid redundant parsing operations, especially since the template is static for each gallery item.

Copilot uses AI. Check for mistakes.
Comment on lines +121 to +126
<WidgetRenderer
schema={undefined}
components={components}
data={selectedWidgetData.widget.states?.[0]?.data ?? {}}
template={selectedWidgetData.widget.template}
/>
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The WidgetRenderer parses the template on every render in the dialog. Consider memoizing the parsed schema with useMemo to avoid redundant parsing operations when the dialog is opened.

Copilot uses AI. Check for mistakes.
Comment on lines +28 to +37
let effectiveSchema = schema;
if (!effectiveSchema && template) {
const parseResult = parseJSXTemplate(template);
if (parseResult.success && parseResult.schema) {
effectiveSchema = parseResult.schema;
} else {
console.warn("Failed to parse template:", parseResult.errors);
return null;
}
}
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The template is parsed on every render of the component. Consider using useMemo to cache the parsed schema based on the template string to avoid redundant parsing operations.

Copilot uses AI. Check for mistakes.
- Cache parsed schema in useRef to avoid re-parsing on every render
- Only parse template when it changes using useEffect
- Track last template value to detect changes
- Improves performance by preventing unnecessary parsing operations

Co-authored-by: foreleven <4785594+foreleven@users.noreply.github.com>
@foreleven
Copy link
Copy Markdown
Contributor

@copilot Change the avatar or image url to https://picsum.photos/{w}/{h} in the gallery widgets

- Replace pravatar.cc URLs with picsum.photos/150/150?random=X
- Replace unsplash URLs with picsum.photos/{width}/{height}?random=X
- All avatar images now use 150x150 format
- Album art and product images use appropriate dimensions
- Social media post image uses 600x400 aspect ratio

Co-authored-by: foreleven <4785594+foreleven@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 8, 2025

@copilot Change the avatar or image url to https://picsum.photos/{w}/{h} in the gallery widgets

Updated all image URLs to use picsum.photos in commit b370f1d.

Changes:

  • Avatar images: https://picsum.photos/150/150?random=X
  • Product/album images: https://picsum.photos/400/400?random=X
  • Social media post image: https://picsum.photos/600/400?random=X

All widgets now use consistent placeholder images from picsum.photos.

Gallery with picsum.photos images

- Add role="button" to clickable gallery items
- Add tabIndex={0} for keyboard navigation
- Add onKeyDown handler for Enter and Space keys
- Add aria-label for screen reader support
- Add focus ring styling with focus:ring-2 focus:ring-primary
- Improves accessibility for users who rely on keyboard navigation

Co-authored-by: foreleven <4785594+foreleven@users.noreply.github.com>
Copilot AI changed the title Feat: Add gallery page with ten pre-built widget templates and template prop support Feat: Add gallery page with ten pre-built widget templates, template prop support, and accessibility Nov 8, 2025
@foreleven foreleven marked this pull request as ready for review November 8, 2025 03:15
@foreleven foreleven merged commit cd9a104 into main Nov 8, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants