Skip to content

Commit ab95422

Browse files
authored
feat(ContentList)(BasicCard): add gravity icon (#1246)
1 parent e6823df commit ab95422

29 files changed

+1175
-43
lines changed

memory-bank/activeContext.md

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,25 @@ The Page Constructor library is currently focused on providing a comprehensive s
1313

1414
Recent development has focused on:
1515

16-
1. **Button Component Enhancement**: Added support for icons through the `img` prop
16+
1. **Gravity Icons Integration** (Commits a72c3f3 and 8a8aa02):
17+
18+
- **New Icon Component**: Created universal component `src/components/Icon/Icon.tsx` for working with icons
19+
- **Gravity UI Icons Support**: Integration with `@gravity-ui/icons` library for using ready-made icons
20+
- **New GravityIconProps Type**: Added type for gravity icons configuration with color support ('brand' | 'text-color')
21+
- **BasicCard Update**: Added support for `gravityIcon` prop in BasicCard component
22+
- **ContentList Update**: Added support for gravity icons in content lists
23+
- **IconWrapper Update**: Extended support for gravity icons in IconWrapper component
24+
- **Schema Validation**: Added validation for GravityIconProps in BasicCard and Content schemas
25+
- **Storybook Examples**: Added new stories to demonstrate gravity icons
26+
27+
2. **Button Component Enhancement**: Added support for icons through the `img` prop
1728

1829
- Support for Gravity UI icons (React components)
1930
- Support for custom SVG strings
2031
- Configurable icon positioning (left/right)
2132
- Configurable icon size
2233

23-
2. **HeaderBlock Enhancements**: Significant updates to HeaderBlock with new functionality:
34+
3. **HeaderBlock Enhancements**: Significant updates to HeaderBlock with new functionality:
2435

2536
- **New Content Properties**: Added `additionalInfo`, `overtitle`, and `status` for richer content structure
2637
- **Custom Rendering**: Added `renderTitle` function prop for custom title rendering
@@ -33,18 +44,26 @@ Recent development has focused on:
3344
- **Component Architecture**: Refactored background rendering into separate `Background` and `FullWidthBackground` components
3445
- **Props Refactoring**: Renamed `containerFluidClassName` to `contentWrapperClassName` for better clarity
3546

36-
3. **Card Component Standardization**: Updated BasicCard, LayoutItem, BackgroundCard, and ImageCard with consistent patterns:
47+
4. **Text Size Enhancement**: Updated `textSize` constant in `src/schema/validators/common.ts`:
48+
49+
- **Previous values**: `['s', 'm', 'l']`
50+
- **Current values**: `['xs', 's', 'sm', 'm', 'l']`
51+
- Added new smaller sizes: `'xs'` (extra small) and `'sm'` (small-medium)
52+
- This affects all components that use text sizing: Links, FileLinkProps, TitleProps, and various blocks
53+
- Updated TypeScript type `TextSize` to include new values
54+
55+
5. **Card Component Standardization**: Updated BasicCard, LayoutItem, BackgroundCard, and ImageCard with consistent patterns:
3756

3857
- Standardized `controlPosition` prop for flexible control placement ('content' vs 'footer')
3958
- Enhanced accessibility with `useUniqId()` for proper ARIA labeling
4059
- Consistent size defaults (size='s') across all card components
4160
- Unified theme support using `getThemedValue` utility
4261
- Improved integration with the Content sub-block
4362

44-
4. **Accessibility Improvements**: Enhanced ARIA attributes and ID management across card components
45-
5. **Control Positioning**: New flexible control positioning system allowing buttons/links in footer area
46-
6. **Performance Optimization**: Reducing bundle size and improving rendering performance
47-
7. **Documentation**: Expanding Storybook examples and documentation
63+
6. **Accessibility Improvements**: Enhanced ARIA attributes and ID management across card components
64+
7. **Control Positioning**: New flexible control positioning system allowing buttons/links in footer area
65+
8. **Performance Optimization**: Reducing bundle size and improving rendering performance
66+
9. **Documentation**: Expanding Storybook examples and documentation
4867

4968
## Active Decisions and Considerations
5069

@@ -129,8 +148,9 @@ The following areas are being considered for future development:
129148
### Documentation Updates
130149

131150
- Created detailed documentation of card component updates in [`cardComponentUpdates.md`](cardComponentUpdates.md)
132-
- Updated system patterns to reflect new card architecture
133-
- Enhanced progress tracking to include sub-block component improvements
151+
- Created comprehensive documentation of Gravity Icons integration in [`gravityIconsIntegration.md`](gravityIconsIntegration.md)
152+
- Updated system patterns to reflect new card architecture and icon system
153+
- Enhanced progress tracking to include sub-block component improvements and icon system enhancements
134154

135155
### Challenges
136156

Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
# Gravity Icons Integration
2+
3+
## Overview
4+
5+
Commits a72c3f3 and 8a8aa02 added full support for Gravity UI Icons in Page Constructor, creating a hybrid icon system that supports both traditional images and vector icons from the @gravity-ui/icons library.
6+
7+
## Key Changes
8+
9+
### New Components
10+
11+
#### Icon Component (`src/components/Icon/Icon.tsx`)
12+
13+
Universal component for working with icons:
14+
15+
```typescript
16+
type Props = {
17+
gravityIcon?: GravityIconProps;
18+
icon?: ImageProps;
19+
className?: string;
20+
} & Pick<ImageComponentProps, 'containerClassName'> &
21+
QAProps;
22+
```
23+
24+
**Functionality:**
25+
26+
- Support for Gravity UI icons via `gravityIcon` prop
27+
- Support for traditional images via `icon` prop
28+
- Automatic icon type detection
29+
- Integration with theming through CSS variables
30+
31+
#### Icon Styles (`src/components/Icon/Icon.scss`)
32+
33+
Styles for icon color theming:
34+
35+
```scss
36+
&_color {
37+
&_brand {
38+
color: var(--g-color-base-brand) !important;
39+
}
40+
&_text-color {
41+
// as in nearest text
42+
}
43+
}
44+
```
45+
46+
### Type System Updates
47+
48+
#### GravityIconProps Type
49+
50+
New type in `src/models/constructor-items/common.ts`:
51+
52+
```typescript
53+
export type GravityIconProps =
54+
| string
55+
| {
56+
name: keyof typeof icons;
57+
color: 'brand' | 'text-color';
58+
};
59+
```
60+
61+
**Supported formats:**
62+
63+
- String: `"ChartColumn"` (uses 'brand' color by default)
64+
- Object: `{name: "ChartColumn", color: "text-color"}` (with color configuration)
65+
66+
### Component Updates
67+
68+
#### BasicCard Enhancement
69+
70+
Added support for `gravityIcon` prop:
71+
72+
```typescript
73+
interface BasicCardProps {
74+
// ... existing props
75+
gravityIcon?: ThemeSupporting<GravityIconProps>;
76+
}
77+
```
78+
79+
**Integration with IconWrapper:**
80+
81+
```typescript
82+
<IconWrapper
83+
icon={themedIcon ? {value: themedIcon, position: iconPosition} : undefined}
84+
gravityIcon={
85+
themedGravityIcon
86+
? {value: themedGravityIcon, position: iconPosition}
87+
: undefined
88+
}
89+
className={b('wrapper')}
90+
size={size}
91+
>
92+
```
93+
94+
#### ContentList Enhancement
95+
96+
Updated to support Gravity icons in list items:
97+
98+
```typescript
99+
interface ContentItemProps {
100+
title?: string;
101+
text?: string;
102+
icon?: ThemeSupporting<ImageProps | SVGIcon>;
103+
gravityIcon?: ThemeSupporting<GravityIconProps>;
104+
}
105+
```
106+
107+
**ContentListItemIcon updated:**
108+
109+
- Support for both `icon` and `gravityIcon` props
110+
- Priority given to `gravityIcon` if both are present
111+
- Uses new universal `Icon` component
112+
113+
#### IconWrapper Enhancement
114+
115+
Extended support for Gravity icons:
116+
117+
```typescript
118+
interface IconWrapperProps {
119+
icon?: PositionedIcon;
120+
gravityIcon?: PositionedGravityIcon;
121+
size?: 's' | 'm' | 'l';
122+
}
123+
```
124+
125+
**New interface:**
126+
127+
```typescript
128+
interface PositionedGravityIcon {
129+
value: GravityIconProps;
130+
position?: IconPosition;
131+
}
132+
```
133+
134+
### Schema Validation
135+
136+
#### Common Validators (`src/schema/validators/common.ts`)
137+
138+
Added validation for GravityIconProps:
139+
140+
```typescript
141+
export const GravityIconProps = {
142+
oneOf: [
143+
{
144+
type: 'string',
145+
},
146+
{
147+
type: 'object',
148+
additionalProperties: false,
149+
required: ['name'],
150+
properties: {
151+
name: {
152+
type: 'string',
153+
},
154+
color: {
155+
type: 'string',
156+
enum: ['brand', 'text-color'],
157+
},
158+
},
159+
},
160+
],
161+
};
162+
```
163+
164+
#### BasicCard Schema (`src/sub-blocks/BasicCard/schema.ts`)
165+
166+
Added support for `gravityIcon` in schema:
167+
168+
```typescript
169+
export const BasicCard = {
170+
// ... existing properties
171+
properties: {
172+
// ... existing properties
173+
gravityIcon: GravityIconProps,
174+
},
175+
};
176+
```
177+
178+
#### Content Schema (`src/sub-blocks/Content/schema.ts`)
179+
180+
Added support in Content elements:
181+
182+
```typescript
183+
export const ContentItem = {
184+
properties: {
185+
// ... existing properties
186+
gravityIcon: withTheme(GravityIconProps),
187+
},
188+
};
189+
```
190+
191+
### Storybook Integration
192+
193+
#### BasicCard Stories
194+
195+
Added new `GravityIcons` story with examples:
196+
197+
```json
198+
"gravityIcons": [
199+
{
200+
"text": "Icon in content list",
201+
"list": [
202+
{
203+
"gravityIcon": "ChartColumn",
204+
"title": "Brand icon color",
205+
"text": "Nisi ut aliquip ex ea commodo consequat."
206+
},
207+
{
208+
"gravityIcon": {
209+
"name": "ChartColumn",
210+
"color": "text-color"
211+
},
212+
"title": "Text icon color",
213+
"text": "Nisi ut aliquip ex ea commodo consequat."
214+
}
215+
]
216+
}
217+
]
218+
```
219+
220+
## Technical Implementation
221+
222+
### Icon Resolution Logic
223+
224+
1. **Gravity Icon Priority**: If `gravityIcon` is present, it is used
225+
2. **Fallback to Image**: If `gravityIcon` is absent, `icon` is used
226+
3. **Color Application**: Color is applied through CSS classes and variables
227+
4. **Theme Integration**: Support for `getThemedValue` for theming
228+
229+
### CSS Integration
230+
231+
Icons are integrated with Gravity UI CSS variable system:
232+
233+
- `--g-color-base-brand` for brand color
234+
- Text color inheritance for `text-color`
235+
236+
### Backward Compatibility
237+
238+
- All existing `icon` props continue to work
239+
- New `gravityIcon` props are optional
240+
- Components automatically detect icon type
241+
- Validation schemas support both formats
242+
243+
## Usage Examples
244+
245+
### Simple String Format
246+
247+
```json
248+
{
249+
"gravityIcon": "ChartColumn"
250+
}
251+
```
252+
253+
### Object Format with Color
254+
255+
```json
256+
{
257+
"gravityIcon": {
258+
"name": "ChartColumn",
259+
"color": "text-color"
260+
}
261+
}
262+
```
263+
264+
### In BasicCard
265+
266+
```json
267+
{
268+
"gravityIcon": "ChartColumn",
269+
"iconPosition": "left",
270+
"text": "Card with Gravity icon",
271+
"buttons": [
272+
{
273+
"text": "Action",
274+
"theme": "action",
275+
"url": "#"
276+
}
277+
]
278+
}
279+
```
280+
281+
### In ContentList
282+
283+
```json
284+
{
285+
"list": [
286+
{
287+
"gravityIcon": "ChartColumn",
288+
"title": "List item with icon",
289+
"text": "Description text"
290+
}
291+
]
292+
}
293+
```
294+
295+
## Benefits
296+
297+
1. **Consistency**: Unified icon style through Gravity UI
298+
2. **Performance**: Vector icons instead of raster images
299+
3. **Theming**: Automatic color theme support
300+
4. **Scalability**: Icons scale without quality loss
301+
5. **Maintenance**: Centralized icon management through library
302+
6. **Backward Compatibility**: Existing code continues to work
303+
304+
## Future Considerations
305+
306+
1. **Icon Library Expansion**: Ability to add custom icons
307+
2. **Animation Support**: Support for animated icons
308+
3. **Size Variants**: Additional icon sizes
309+
4. **Accessibility**: Improved icon accessibility
310+
5. **Performance Optimization**: Tree-shaking of unused icons

0 commit comments

Comments
 (0)