|
| 1 | +# Card Component Updates |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This document details the recent updates made to the card components in the Page Constructor library: BasicCard, LayoutItem, BackgroundCard, and ImageCard. |
| 6 | + |
| 7 | +## Updated Components |
| 8 | + |
| 9 | +### 1. BasicCard (`src/sub-blocks/BasicCard/BasicCard.tsx`) |
| 10 | + |
| 11 | +**Key Changes:** |
| 12 | + |
| 13 | +- Added `controlPosition` prop with default value `'content'` |
| 14 | +- Implemented `useUniqId()` for accessibility IDs (`titleId`, `descriptionId`) |
| 15 | +- Added proper ARIA attributes (`aria-describedby`, `aria-labelledby`) |
| 16 | +- Standardized size default to `'s'` |
| 17 | +- Enhanced theme support with `getThemedValue` for icons |
| 18 | +- Improved integration with `Content` sub-block |
| 19 | + |
| 20 | +**Props Added/Modified:** |
| 21 | + |
| 22 | +- `controlPosition = 'content'` - Controls where buttons/links are positioned |
| 23 | +- `size = 's'` - Standardized default size |
| 24 | +- Enhanced accessibility with proper ID management |
| 25 | + |
| 26 | +### 2. LayoutItem (`src/sub-blocks/LayoutItem/LayoutItem.tsx`) |
| 27 | + |
| 28 | +**Key Changes:** |
| 29 | + |
| 30 | +- Added `controlPosition` prop with default value `'content'` |
| 31 | +- Implemented `useUniqId()` for `titleId` |
| 32 | +- Enhanced theme support for both icons and media |
| 33 | +- Improved media handling with fullscreen capabilities |
| 34 | +- Better integration with `Content` sub-block for consistent rendering |
| 35 | + |
| 36 | +**Props Added/Modified:** |
| 37 | + |
| 38 | +- `controlPosition = 'content'` - Controls positioning of content controls |
| 39 | +- Enhanced media processing with theme support |
| 40 | +- Improved accessibility with proper ID management |
| 41 | + |
| 42 | +### 3. BackgroundCard (`src/sub-blocks/BackgroundCard/BackgroundCard.tsx`) |
| 43 | + |
| 44 | +**Key Changes:** |
| 45 | + |
| 46 | +- Added `controlPosition` prop with default value `'content'` |
| 47 | +- Implemented `useUniqId()` for `titleId` |
| 48 | +- Enhanced logic for control positioning based on `paddingBottom` |
| 49 | +- Standardized size default to `'s'` |
| 50 | +- Improved theme integration for background properties |
| 51 | + |
| 52 | +**Props Added/Modified:** |
| 53 | + |
| 54 | +- `controlPosition = 'content'` - Controls where buttons/links are positioned |
| 55 | +- `size = 's'` - Standardized default size |
| 56 | +- Enhanced background theme support |
| 57 | + |
| 58 | +### 4. ImageCard (`src/sub-blocks/ImageCard/ImageCard.tsx`) |
| 59 | + |
| 60 | +**Key Changes:** |
| 61 | + |
| 62 | +- Added `controlPosition` prop with default value `'content'` |
| 63 | +- Implemented `useUniqId()` for `titleId` |
| 64 | +- Standardized size default to `'s'` |
| 65 | +- Enhanced theme support for images |
| 66 | +- Improved content detection logic |
| 67 | + |
| 68 | +**Props Added/Modified:** |
| 69 | + |
| 70 | +- `controlPosition = 'content'` - Controls positioning of content controls |
| 71 | +- `size = 's'` - Standardized default size |
| 72 | +- Enhanced image theme support |
| 73 | + |
| 74 | +## Common Patterns Implemented |
| 75 | + |
| 76 | +### 1. Control Positioning |
| 77 | + |
| 78 | +All card components now support flexible control positioning: |
| 79 | + |
| 80 | +```typescript |
| 81 | +const areControlsInFooter = controlPosition === 'footer'; |
| 82 | + |
| 83 | +// In Content component usage: |
| 84 | +controlPosition={areControlsInFooter ? 'bottom' : 'default'} |
| 85 | +``` |
| 86 | + |
| 87 | +### 2. Accessibility Enhancement |
| 88 | + |
| 89 | +Consistent accessibility pattern across all cards: |
| 90 | + |
| 91 | +```typescript |
| 92 | +const titleId = useUniqId(); |
| 93 | +const descriptionId = useUniqId(); // where applicable |
| 94 | + |
| 95 | +// Usage in components: |
| 96 | +<Content titleId={titleId} /> |
| 97 | +// And proper ARIA attributes in card wrappers |
| 98 | +``` |
| 99 | + |
| 100 | +### 3. Theme Integration |
| 101 | + |
| 102 | +Standardized theme support: |
| 103 | + |
| 104 | +```typescript |
| 105 | +const theme = useTheme(); |
| 106 | +const themedIcon = getThemedValue(icon, theme); |
| 107 | +const themedMedia = getThemedValue(media, theme); |
| 108 | +``` |
| 109 | + |
| 110 | +### 4. Size Standardization |
| 111 | + |
| 112 | +All components now default to size `'s'`: |
| 113 | + |
| 114 | +```typescript |
| 115 | +size = 's'; |
| 116 | +``` |
| 117 | + |
| 118 | +## Content Sub-block Integration |
| 119 | + |
| 120 | +All card components now consistently use the `Content` sub-block with: |
| 121 | + |
| 122 | +- Proper `titleId` passing for accessibility |
| 123 | +- Consistent `controlPosition` mapping |
| 124 | +- Standardized `colSizes` configuration |
| 125 | +- Theme support where applicable |
| 126 | + |
| 127 | +## Benefits of Updates |
| 128 | + |
| 129 | +1. **Consistency**: All card components now follow the same patterns and conventions |
| 130 | +2. **Accessibility**: Enhanced ARIA support and proper ID management |
| 131 | +3. **Flexibility**: Control positioning allows for better layout control |
| 132 | +4. **Maintainability**: Shared patterns make the codebase easier to maintain |
| 133 | +5. **Theme Support**: Improved theme integration across all card types |
| 134 | + |
| 135 | +## Migration Notes |
| 136 | + |
| 137 | +These updates are backward compatible. The new props have sensible defaults: |
| 138 | + |
| 139 | +- `controlPosition` defaults to `'content'` (existing behavior) |
| 140 | +- `size` defaults to `'s'` (consistent with library standards) |
| 141 | +- Accessibility improvements are automatic and don't require changes to existing usage |
| 142 | + |
| 143 | +## Testing |
| 144 | + |
| 145 | +All updated components maintain their existing Storybook stories and visual tests, ensuring no regression in functionality while adding the new capabilities. |
0 commit comments