Skip to content

Commit

Permalink
fix: card layout block background (#767)
Browse files Browse the repository at this point in the history
* fix: update card, content layouts background prop schema validation

* feat: add card layout background border
  • Loading branch information
qradle-yndx authored Jan 16, 2024
1 parent 1678b88 commit 8ea3fd4
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 22 deletions.
2 changes: 2 additions & 0 deletions src/blocks/CardLayout/CardLayout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ $block: '.#{$ns}card-layout-block';
object-fit: cover;
object-position: left;
}

@include card-border();
}

@include animate-slides(#{$block}__item);
Expand Down
3 changes: 2 additions & 1 deletion src/blocks/CardLayout/CardLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const CardLayout: React.FC<CardLayoutBlockProps> = ({
titleClassName,
background,
}) => {
const {border, ...backgroundImageProps} = background || {};
return (
<AnimateBlock className={b(null, className)} animate={animated}>
{(title || description) && (
Expand All @@ -43,7 +44,7 @@ const CardLayout: React.FC<CardLayoutBlockProps> = ({
'with-background': !isEmpty(background),
})}
>
<BackgroundImage className={b('image')} {...background} />
<BackgroundImage className={b('image', {border})} {...backgroundImageProps} />
<Row>
{React.Children.map(children, (child, index) => (
<Col key={index} sizes={colSizes} className={b('item')}>
Expand Down
4 changes: 3 additions & 1 deletion src/blocks/CardLayout/__stories__/CardLayout.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import * as CardLayoutStories from './CardLayout.stories.tsx';

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

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

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

Expand Down
1 change: 1 addition & 0 deletions src/blocks/CardLayout/__stories__/CardLayout.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ const WithBackgroundTemplate: StoryFn<CardLayoutBlockModel> = (args) => (
{
...args,
background: {
border: 'shadow',
style: {
backgroundColor: '#7CCEA0',
},
Expand Down
18 changes: 16 additions & 2 deletions src/blocks/CardLayout/schema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import {ImageObjectProps} from '../../components/Image/schema';
import {ImageBaseObjectProps, ImageDeviceProps} from '../../components/Image/schema';
import {
AnimatableProps,
BlockBaseProps,
BlockHeaderProps,
BorderProps,
ChildrenCardsProps,
containerSizesObject,
} from '../../schema/validators/common';
Expand All @@ -15,7 +16,20 @@ export const CardLayoutProps = {
...AnimatableProps,
...BlockHeaderProps,
colSizes: containerSizesObject,
background: ImageObjectProps,
background: {
anyOf: [
{
...ImageBaseObjectProps,
properties: {...ImageBaseObjectProps.properties, border: BorderProps},
optionName: 'options',
},
{
...ImageDeviceProps,
properties: {...ImageDeviceProps.properties, border: BorderProps},
optionName: 'device options',
},
],
},
children: ChildrenCardsProps,
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/ContentLayout/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ImageObjectProps} from '../../components/Image/schema';
import {BackgroundImageProps} from '../../components/Image/schema';
import {
BlockBaseProps,
FileLinkProps,
Expand All @@ -14,7 +14,7 @@ const ContentLayoutBlockProperties = {
type: 'string',
enum: contentSizes,
},
background: ImageObjectProps,
background: BackgroundImageProps,
centered: {
type: 'boolean',
},
Expand Down
21 changes: 19 additions & 2 deletions src/components/Image/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ export const ImageDeviceProps = {
},
};

export const ImageObjectProps = {
export const ImageBaseObjectProps = {
type: 'object',
additionalProperties: false,
required: ['src'],
properties: {
...ImageBase,
src: {
Expand All @@ -57,6 +56,11 @@ export const ImageObjectProps = {
},
};

export const ImageObjectProps = {
...ImageBaseObjectProps,
required: ['src'],
};

export const ImageProps = {
oneOf: [
{
Expand All @@ -74,3 +78,16 @@ export const ImageProps = {
}),
],
};

export const BackgroundImageProps = {
anyOf: [
{
...ImageBaseObjectProps,
optionName: 'options',
},
{
...ImageDeviceProps,
optionName: 'device options',
},
],
};
5 changes: 4 additions & 1 deletion src/models/constructor-items/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Animatable,
BackgroundImageProps,
ButtonProps,
CardBorder,
ContentSize,
ContentTextSize,
ContentTheme,
Expand Down Expand Up @@ -305,7 +306,9 @@ export interface CardLayoutBlockProps extends Childable, Animatable, LoadableChi
titleClassName?: string;
description?: string;
colSizes?: GridColumnSizesType;
background?: BackgroundImageProps;
background?: BackgroundImageProps & {
border?: CardBorder;
};
}

export type FilterTag = {
Expand Down
10 changes: 6 additions & 4 deletions src/schema/validators/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,11 +702,13 @@ export const MapProps = {
},
};

export const BorderProps = {
type: 'string',
enum: ['line', 'shadow', 'none'],
};

export const CardBase = {
border: {
type: 'string',
enum: ['line', 'shadow', 'none'],
},
border: BorderProps,
};

export const BlockHeaderProps = {
Expand Down
21 changes: 12 additions & 9 deletions styles/mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,7 @@
border-radius: $borderRadius;
}

@mixin card($hover: false) {
min-height: 248px;
height: 100%;
overflow-x: hidden;
border-radius: $borderRadius;
background-color: var(--g-color-base-float);

transition: box-shadow 0.3s $ease-out-cubic;

@mixin card-border($hover: false) {
&_border_line {
border: 1px solid var(--g-color-line-generic);
}
Expand All @@ -283,6 +275,17 @@
}
}

@mixin card($hover: false) {
min-height: 248px;
height: 100%;
overflow-x: hidden;
border-radius: $borderRadius;
background-color: var(--g-color-base-float);

transition: box-shadow 0.3s $ease-out-cubic;
@include card-border($hover);
}

@mixin card-image {
margin: $imagePadding;
border-radius: calc(#{$borderRadius} - #{$imagePadding});
Expand Down

0 comments on commit 8ea3fd4

Please sign in to comment.