---
name: polaris-fundamentals
description: Core Polaris Web Components fundamentals including component library structure, design tokens, responsive patterns, and SSR compatibility. Auto-invoked when working with Polaris components.
allowed-tools: [Read, Grep, Glob]
documentation_path: ../../../polaris-web-components
---
# Polaris Fundamentals Skill
## Purpose
Provides foundational knowledge of Polaris Web Components, including setup, component categories, design tokens, and best practices.
## When This Skill Activates
- Working with Polaris Web Components
- Building Shopify app UIs
- Implementing design system patterns
- Choosing components for specific use cases
## Core Concepts
### Component Categories
Polaris Web Components are organized into six categories:
**1. Actions** - Interactive elements that trigger actions
- Buttons, links, icon buttons, button groups
**2. Forms** - Input and selection components
- Text fields, checkboxes, selects, file uploads, color pickers
**3. Feedback** - Status and notification components
- Banners, toasts, progress bars, spinners, skeletons
**4. Media** - Visual content components
- Avatars, icons, thumbnails, video thumbnails
**5. Structure** - Layout and organization components
- Pages, cards, sections, boxes, grids, stacks, tables
**6. Titles and Text** - Typography components
- Headings, text, paragraphs, badges, chips
### Design Tokens
#### Spacing Scale
```tsx
gap="050" // 2px
gap="100" // 4px
gap="200" // 8px
gap="300" // 12px
gap="400" // 16px (default)
gap="500" // 20px
gap="600" // 24px
gap="800" // 32px
gap="1000" // 40px
gap="1600" // 64px
```
#### Background Colors
```tsx
background="bg-surface" // Default surface
background="bg-surface-secondary" // Secondary surface
background="bg-surface-tertiary" // Tertiary surface
background="bg-surface-success" // Success state
background="bg-surface-warning" // Warning state
background="bg-surface-critical" // Error state
```
#### Border Options
```tsx
border="base" // Default border
border="success" // Success border
border="warning" // Warning border
border="critical" // Error border
```
#### Border Radius
```tsx
borderRadius="base" // 4px
borderRadius="large" // 8px
borderRadius="full" // 50% (circular)
```
#### Text Tones
```tsx
tone="subdued" // Secondary text
tone="success" // Success message
tone="warning" // Warning message
tone="critical" // Error message
```
### Typography Variants
```tsx
variant="heading3xl" // Page titles
variant="heading2xl" // Section headers
variant="headingXl" // Card titles
variant="headingLg" // Subsection headers
variant="headingMd" // Card headers
variant="headingSm" // Small headers
variant="bodyLg" // Large body text
variant="bodyMd" // Default body text (default)
variant="bodySm" // Small body text
```
### Responsive Breakpoints
```tsx
// Mobile first approach
columns="1" // Mobile (default)
sm-columns="2" // Small devices (≥577px)
md-columns="3" // Medium devices (≥769px)
lg-columns="4" // Large devices (≥1025px)
// Example usage
Column 1
Column 2
Column 3
Column 4
```
## React Hydration (SSR Apps)
### ⚠️ CRITICAL: Event Handler Pattern
**NEVER use inline event handlers** - they cause hydration mismatches in SSR apps.
```tsx
// ❌ WRONG - Hydration mismatch
Click
// ✅ CORRECT - Use data attributes + useEffect
Click
useEffect(() => {
const button = document.querySelector('[data-my-button]');
if (button) {
button.addEventListener('click', handleClick);
}
return () => button?.removeEventListener('click', handleClick);
}, []);
```
## Common Component Patterns
### Button Variants
```tsx
Default
Primary
Delete
Plain
Small
Loading
Disabled
```
### Text Field States
```tsx
```
### Card Structure
```tsx
Card Title
Card content
Save
Cancel
```
### Loading Pattern
```tsx
{isLoading ? (
) : (
{/* Actual content */}
)}
```
### Empty State Pattern
```tsx
{items.length === 0 ? (
Get started by adding your first item
Add Item
) : (
// Item list
)}
```
## Page Structure
### Standard Page Layout
```tsx
{/* First section */}
{/* Second section */}
```
### Page with Primary Action
```tsx
{/* Page content */}
```
## Accessibility
### Semantic HTML
```tsx
Main Title
Section Title
Paragraph text
```
### ARIA Labels
```tsx
```
### Keyboard Navigation
- All interactive elements are keyboard accessible
- Use Tab to navigate
- Enter/Space to activate buttons
- Escape to close modals
## Best Practices
1. **Use Design Tokens** - Never hardcode colors, spacing, or typography
2. **Mobile First** - Start with mobile layout, enhance for desktop
3. **Semantic HTML** - Use the `as` prop for proper HTML elements
4. **Loading States** - Always show skeleton loaders during data fetch
5. **Empty States** - Provide guidance when no data exists
6. **Error Handling** - Use inline errors for form validation
7. **Accessibility** - Ensure keyboard navigation and ARIA labels
8. **Consistent Spacing** - Use Polaris spacing scale (gap="400")
9. **SSR Compatible** - Use data attributes for event handlers
10. **Follow Patterns** - Use established Polaris patterns
## Component Selection Guide
| Need | Component | Example |
|------|-----------|---------|
| Primary action | `` | Save, Submit |
| Secondary action | `` | Cancel, Back |
| Destructive action | `` | Delete, Remove |
| Page container | `` | All pages |
| Content container | `` | Forms, data displays |
| Text input | `` | Title, description |
| Selection | `` | Category, status |
| Multiple choices | `` | Features, options |
| Success message | `` | Saved successfully |
| Error message | `` | Failed to save |
| Status indicator | `` | Active, Draft |
| Data table | `` | Products, orders |
| Vertical spacing | `` | Form fields |
| Horizontal layout | `` | Dashboard cards |
## Documentation Reference
For complete component documentation, see:
- `polaris-web-components/components/` - All component docs
- `polaris-web-components/patterns/` - Composition patterns
- `polaris-web-components/using-polaris-web-components.md` - Setup guide
---
**Remember**: Polaris ensures your app matches Shopify's design system and provides a consistent, accessible user experience.