Skip to content

Commit bb51c0e

Browse files
authored
feat: add ability to centered title in cardLayoutBlock (#1337)
* feat: add ability to centered title in cardLayoutBlock * feat: after review rename prop * feat: fix styles for centered
1 parent 89442cc commit bb51c0e

File tree

7 files changed

+59
-6
lines changed

7 files changed

+59
-6
lines changed

memory-bank/activeContext.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ Recent development has focused on:
7373
- **Flexible Styling**: Allows any valid CSS color value (hex, rgb, rgba, named colors, etc.)
7474
- **Backward Compatibility**: Optional property that doesn't affect existing implementations
7575

76+
11. **CardLayout Title Centering Enhancement**: Added title centering support for CardLayout block:
77+
78+
- **New Prop**: Added `centered?: boolean` prop to `CardLayoutBlockProps` for centering title and subtitle
79+
- **Default Behavior**: Default value is `false`, maintaining backward compatibility (left-aligned by default)
80+
- **Title Component Enhancement**: Extended `Title` component with `colJustifyContent?: GridJustifyContent` prop for controlling title and subtitle alignment
81+
- **Responsive Behavior**: Dynamic `colSizes` based on `centered` prop:
82+
- When `centered === false`: `sm: 8` (allows left-aligned title with narrower column)
83+
- When `centered === true`: `sm: 12` (full width for centered title)
84+
- **Implementation Logic**: Uses conditional check `centered ? GridJustifyContent.Center : GridJustifyContent.Start` for alignment and `centered ? 12 : 8` for column size
85+
- **No Breaking Changes**: All changes are backward compatible with default `centered: false` value
86+
7687
## Active Decisions and Considerations
7788

7889
### Architecture

memory-bank/progress.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ Recently updated sub-block components with enhanced consistency:
4949
- **ContentList**: Enhanced with Gravity icons support for list items
5050
- **IconWrapper**: Updated to support both traditional image icons and Gravity UI icons
5151

52+
### Layout Blocks Enhancement
53+
54+
- **CardLayout Block**: Enhanced with title centering support:
55+
- **Title Centering Control**: New `centered?: boolean` prop allows centering title and subtitle
56+
- **Title Component**: Extended with `colJustifyContent` prop for alignment control
57+
- **Responsive Layout**: Dynamic column sizes adapt based on `centered` prop:
58+
- When `centered === false`: uses `sm: 8` for narrower left-aligned title column
59+
- When `centered === true`: uses `sm: 12` for full-width centered title
60+
- **Implementation**: Conditional logic `centered ? GridJustifyContent.Center : GridJustifyContent.Start` for alignment and `centered ? 12 : 8` for column size
61+
- **Backward Compatible**: Default `centered: false` maintains existing left-aligned behavior
62+
5263
### Icon System
5364

5465
Enhanced icon capabilities with Gravity UI integration:

src/blocks/CardLayout/CardLayout.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ $largeBorderRadius: 32px;
1919
}
2020
}
2121

22+
&__title {
23+
&_centered {
24+
display: flex;
25+
flex-direction: column;
26+
align-items: center;
27+
text-align: center;
28+
}
29+
}
30+
2231
&__image {
2332
position: absolute;
2433
top: 0;

src/blocks/CardLayout/CardLayout.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import isEmpty from 'lodash/isEmpty';
44

55
import {AnimateBlock, BackgroundImage, Title} from '../../components';
66
import {useTheme} from '../../context/theme';
7-
import {Col, GridColumnSizesType, Row} from '../../grid';
7+
import {Col, GridColumnSizesType, GridJustifyContent, Row} from '../../grid';
88
import {CardLayoutBlockProps as CardLayoutBlockParams, ClassNameProps} from '../../models';
99
import {block, getThemedValue} from '../../utils';
1010

@@ -15,6 +15,7 @@ const DEFAULT_SIZES: GridColumnSizesType = {
1515
sm: 6,
1616
md: 4,
1717
};
18+
1819
export type CardLayoutBlockProps = React.PropsWithChildren<
1920
Omit<CardLayoutBlockParams, 'children'>
2021
> &
@@ -31,13 +32,21 @@ const CardLayout = ({
3132
className,
3233
titleClassName,
3334
background,
35+
centered = false,
3436
}: CardLayoutBlockProps) => {
3537
const theme = useTheme();
3638
const {border, ...backgroundImageProps} = getThemedValue(background || {}, theme);
3739
return (
3840
<AnimateBlock className={b(null, className)} animate={animated}>
3941
{(title || description) && (
40-
<Title title={title} subtitle={description} className={titleClassName} />
42+
<Title
43+
title={title}
44+
subtitle={description}
45+
className={b('title', {centered}, titleClassName)}
46+
colJustifyContent={
47+
centered ? GridJustifyContent.Center : GridJustifyContent.Start
48+
}
49+
/>
4150
)}
4251
<div
4352
className={b('content', {

src/blocks/CardLayout/__stories__/data.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@
110110
"content": {
111111
"type": "card-layout-block",
112112
"title": "Card layout with basic cards",
113-
"description": "Three cards in a row on the desktop, two cards in a row on a tablet, one card in a row on a mobile phone."
113+
"description": "Three cards in a row on the desktop, two cards in a row on a tablet, one card in a row on a mobile phone.",
114+
"centered": false
114115
}
115116
},
116117
"colSizes": {
@@ -172,6 +173,7 @@
172173
"type": "card-layout-block",
173174
"title": "Card layout with background image (basic cards)",
174175
"description": "Four cards in a row on the desktop, three cards in a row on the mini-desktop, two cards in a row on a tablet, one card in a row on a mobile phone.",
176+
"centered": false,
175177
"colSizes": {
176178
"all": 12,
177179
"sm": 6,

src/components/Title/Title.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Col, GridColumnSizesType} from '../../grid';
1+
import {Col, GridColumnSizesType, GridJustifyContent} from '../../grid';
22
import {ClassNameProps, TitleItemProps, TitleProps as TitleParams} from '../../models';
33
import {block} from '../../utils';
44
import YFMWrapper from '../YFMWrapper/YFMWrapper';
@@ -11,6 +11,7 @@ const b = block('title');
1111

1212
export interface TitleProps extends TitleParams {
1313
colSizes?: GridColumnSizesType;
14+
colJustifyContent?: GridJustifyContent;
1415
id?: string;
1516
}
1617

@@ -19,6 +20,7 @@ const Title = ({
1920
subtitle,
2021
className,
2122
colSizes = {all: 12, sm: 8},
23+
colJustifyContent,
2224
id,
2325
}: TitleProps & ClassNameProps) => {
2426
if (!title && !subtitle) {
@@ -31,12 +33,20 @@ const Title = ({
3133
return (
3234
<div className={b(null, className)} id={id}>
3335
{text && (
34-
<Col reset sizes={colSizes}>
36+
<Col
37+
reset
38+
sizes={colSizes}
39+
{...(colJustifyContent && {justifyContent: colJustifyContent})}
40+
>
3541
<TitleItem text={text} {...titleProps} />
3642
</Col>
3743
)}
3844
{subtitle && (
39-
<Col reset sizes={colSizes}>
45+
<Col
46+
reset
47+
sizes={colSizes}
48+
{...(colJustifyContent && {justifyContent: colJustifyContent})}
49+
>
4050
<div className={b('description', {titleSize: titleProps?.textSize})}>
4151
<YFMWrapper content={subtitle} modifiers={{constructor: true}} />
4252
</div>

src/models/constructor-items/blocks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ export interface TabsBlockProps extends Animatable {
357357
export interface CardLayoutBlockProps extends Childable, Animatable, LoadableChildren {
358358
title?: TitleItemProps | string;
359359
titleClassName?: string;
360+
centered?: boolean;
360361
description?: string;
361362
colSizes?: GridColumnSizesType;
362363
background?: ThemeSupporting<

0 commit comments

Comments
 (0)