Skip to content

Commit 8ea3fd4

Browse files
authored
fix: card layout block background (#767)
* fix: update card, content layouts background prop schema validation * feat: add card layout background border
1 parent 1678b88 commit 8ea3fd4

File tree

10 files changed

+67
-22
lines changed

10 files changed

+67
-22
lines changed

src/blocks/CardLayout/CardLayout.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ $block: '.#{$ns}card-layout-block';
2929
object-fit: cover;
3030
object-position: left;
3131
}
32+
33+
@include card-border();
3234
}
3335

3436
@include animate-slides(#{$block}__item);

src/blocks/CardLayout/CardLayout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const CardLayout: React.FC<CardLayoutBlockProps> = ({
3333
titleClassName,
3434
background,
3535
}) => {
36+
const {border, ...backgroundImageProps} = background || {};
3637
return (
3738
<AnimateBlock className={b(null, className)} animate={animated}>
3839
{(title || description) && (
@@ -43,7 +44,7 @@ const CardLayout: React.FC<CardLayoutBlockProps> = ({
4344
'with-background': !isEmpty(background),
4445
})}
4546
>
46-
<BackgroundImage className={b('image')} {...background} />
47+
<BackgroundImage className={b('image', {border})} {...backgroundImageProps} />
4748
<Row>
4849
{React.Children.map(children, (child, index) => (
4950
<Col key={index} sizes={colSizes} className={b('item')}>

src/blocks/CardLayout/__stories__/CardLayout.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import * as CardLayoutStories from './CardLayout.stories.tsx';
1515

1616
`colSizes?: Object` — more info [here](?path=/docs/documentation-types--docs#colsizes).
1717

18-
`background?: BackgroundImage` — See [background](?path=/story/components-pics-video-datalens-backgroundimage--docs&viewMode=docs) properties.
18+
`background?: Object`
19+
- `BackgroundImage` [properties](?path=/story/components-pics-video-datalens-backgroundimage--docs&viewMode=docs).
20+
- `border?: 'none' | 'shadow' | 'border'`
1921

2022
`children:[]` — You can add an array of any available cards here.
2123

src/blocks/CardLayout/__stories__/CardLayout.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ const WithBackgroundTemplate: StoryFn<CardLayoutBlockModel> = (args) => (
187187
{
188188
...args,
189189
background: {
190+
border: 'shadow',
190191
style: {
191192
backgroundColor: '#7CCEA0',
192193
},

src/blocks/CardLayout/schema.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import {ImageObjectProps} from '../../components/Image/schema';
1+
import {ImageBaseObjectProps, ImageDeviceProps} from '../../components/Image/schema';
22
import {
33
AnimatableProps,
44
BlockBaseProps,
55
BlockHeaderProps,
6+
BorderProps,
67
ChildrenCardsProps,
78
containerSizesObject,
89
} from '../../schema/validators/common';
@@ -15,7 +16,20 @@ export const CardLayoutProps = {
1516
...AnimatableProps,
1617
...BlockHeaderProps,
1718
colSizes: containerSizesObject,
18-
background: ImageObjectProps,
19+
background: {
20+
anyOf: [
21+
{
22+
...ImageBaseObjectProps,
23+
properties: {...ImageBaseObjectProps.properties, border: BorderProps},
24+
optionName: 'options',
25+
},
26+
{
27+
...ImageDeviceProps,
28+
properties: {...ImageDeviceProps.properties, border: BorderProps},
29+
optionName: 'device options',
30+
},
31+
],
32+
},
1933
children: ChildrenCardsProps,
2034
},
2135
};

src/blocks/ContentLayout/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {ImageObjectProps} from '../../components/Image/schema';
1+
import {BackgroundImageProps} from '../../components/Image/schema';
22
import {
33
BlockBaseProps,
44
FileLinkProps,
@@ -14,7 +14,7 @@ const ContentLayoutBlockProperties = {
1414
type: 'string',
1515
enum: contentSizes,
1616
},
17-
background: ImageObjectProps,
17+
background: BackgroundImageProps,
1818
centered: {
1919
type: 'boolean',
2020
},

src/components/Image/schema.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ export const ImageDeviceProps = {
4343
},
4444
};
4545

46-
export const ImageObjectProps = {
46+
export const ImageBaseObjectProps = {
4747
type: 'object',
4848
additionalProperties: false,
49-
required: ['src'],
5049
properties: {
5150
...ImageBase,
5251
src: {
@@ -57,6 +56,11 @@ export const ImageObjectProps = {
5756
},
5857
};
5958

59+
export const ImageObjectProps = {
60+
...ImageBaseObjectProps,
61+
required: ['src'],
62+
};
63+
6064
export const ImageProps = {
6165
oneOf: [
6266
{
@@ -74,3 +78,16 @@ export const ImageProps = {
7478
}),
7579
],
7680
};
81+
82+
export const BackgroundImageProps = {
83+
anyOf: [
84+
{
85+
...ImageBaseObjectProps,
86+
optionName: 'options',
87+
},
88+
{
89+
...ImageDeviceProps,
90+
optionName: 'device options',
91+
},
92+
],
93+
};

src/models/constructor-items/blocks.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
Animatable,
1212
BackgroundImageProps,
1313
ButtonProps,
14+
CardBorder,
1415
ContentSize,
1516
ContentTextSize,
1617
ContentTheme,
@@ -305,7 +306,9 @@ export interface CardLayoutBlockProps extends Childable, Animatable, LoadableChi
305306
titleClassName?: string;
306307
description?: string;
307308
colSizes?: GridColumnSizesType;
308-
background?: BackgroundImageProps;
309+
background?: BackgroundImageProps & {
310+
border?: CardBorder;
311+
};
309312
}
310313

311314
export type FilterTag = {

src/schema/validators/common.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,13 @@ export const MapProps = {
702702
},
703703
};
704704

705+
export const BorderProps = {
706+
type: 'string',
707+
enum: ['line', 'shadow', 'none'],
708+
};
709+
705710
export const CardBase = {
706-
border: {
707-
type: 'string',
708-
enum: ['line', 'shadow', 'none'],
709-
},
711+
border: BorderProps,
710712
};
711713

712714
export const BlockHeaderProps = {

styles/mixins.scss

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,7 @@
252252
border-radius: $borderRadius;
253253
}
254254

255-
@mixin card($hover: false) {
256-
min-height: 248px;
257-
height: 100%;
258-
overflow-x: hidden;
259-
border-radius: $borderRadius;
260-
background-color: var(--g-color-base-float);
261-
262-
transition: box-shadow 0.3s $ease-out-cubic;
263-
255+
@mixin card-border($hover: false) {
264256
&_border_line {
265257
border: 1px solid var(--g-color-line-generic);
266258
}
@@ -283,6 +275,17 @@
283275
}
284276
}
285277

278+
@mixin card($hover: false) {
279+
min-height: 248px;
280+
height: 100%;
281+
overflow-x: hidden;
282+
border-radius: $borderRadius;
283+
background-color: var(--g-color-base-float);
284+
285+
transition: box-shadow 0.3s $ease-out-cubic;
286+
@include card-border($hover);
287+
}
288+
286289
@mixin card-image {
287290
margin: $imagePadding;
288291
border-radius: calc(#{$borderRadius} - #{$imagePadding});

0 commit comments

Comments
 (0)