Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add border to media in media-block #722

Merged
merged 4 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/blocks/Media/Media.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@import '../../../styles/mixins';

$block: '.#{$ns}media-block';

#{$block} {
@include media-border();
}
18 changes: 14 additions & 4 deletions src/blocks/Media/Media.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,29 @@ import Media from '../../components/Media/Media';
import MediaBase from '../../components/MediaBase/MediaBase';
import {useTheme} from '../../context/theme';
import {MediaBlockProps} from '../../models';
import {getThemedValue} from '../../utils';
import {block, getThemedValue} from '../../utils';

import './Media.scss';

const b = block('media-block');

export const MediaBlock = (props: MediaBlockProps) => {
const {media} = props;
const {media, border = 'shadow', disableShadow} = props;

const mediaBaseShadow = disableShadow || border !== 'shadow';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need another naming for mediaBaseShadow because it is boolean flag

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed


const [play, setPlay] = useState<boolean>(false);
const theme = useTheme();
const mediaThemed = getThemedValue(media, theme);

return (
<MediaBase {...props} onScroll={() => setPlay(true)}>
<MediaBase {...props} onScroll={() => setPlay(true)} disableShadow={mediaBaseShadow}>
<MediaBase.Card>
<Media {...mediaThemed} playVideo={play} />
<Media
{...mediaThemed}
playVideo={play}
className={b({border: disableShadow ? 'none' : border})}
/>
</MediaBase.Card>
</MediaBase>
);
Expand Down
4 changes: 3 additions & 1 deletion src/blocks/Media/__stories__/Media.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import * as MediaStories from './Media.stories.tsx';

`largeMedia?: boolean` — An image/video takes 8 columns.

`disableShadow?: boolean` — Disable shadow for the block.
`disableShadow?: boolean` — Disable shadow for the block (Deprecated).

`additionalInfo?: string` — Gray text (with YFM support)

[`links?: Link[]` — An array with link objects](?path=/docs/documentation-types--docs#link)

[`buttons?: Button[]` — An array with button objects](?path=/docs/documentation-types--docs#button)

`border?: 'shadow' | 'line' | 'none'` — Image border

</StoryTemplate>
14 changes: 13 additions & 1 deletion src/blocks/Media/__stories__/Media.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ export const Video = VideoTemplate.bind({});
export const DataLens = ImageSliderTemplate.bind({});
export const Size = SizeTemplate.bind({});
export const Direction = DirectionTemplate.bind({});
export const WithoutShadowDeprecated = ImageSliderTemplate.bind({});
export const WithoutShadow = ImageSliderTemplate.bind({});
export const WithBorder = ImageSliderTemplate.bind({});
export const Iframe = IframeTemplate.bind({});

const DefaultArgs = {
Expand All @@ -214,11 +216,21 @@ DataLens.args = {
} as MediaBlockProps;
Size.args = DefaultArgs as MediaBlockProps;
Direction.args = DefaultArgs as MediaBlockProps;
WithoutShadow.args = {
WithoutShadowDeprecated.args = {
...DefaultArgs,
...data.withoutShadow.content,
disableShadow: true,
} as MediaBlockProps;
WithoutShadow.args = {
...DefaultArgs,
...data.withoutShadow.content,
border: 'none',
} as MediaBlockProps;
WithBorder.args = {
...DefaultArgs,
...data.withoutShadow.content,
border: 'line',
} as MediaBlockProps;
Iframe.args = {
...DefaultArgs,
} as MediaBlockProps;
7 changes: 7 additions & 0 deletions src/blocks/Media/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,18 @@ export const MediaBlockBaseProps = {
mediaOnly: {
type: 'boolean',
},
/**
* @deprecated use border='none' or border='line' instead
*/
disableShadow: {
type: 'boolean',
},
button: ButtonBlock,
mediaOnlyColSizes: containerSizesObject,
border: {
type: 'string',
enum: ['shadow', 'line', 'none'],
},
};

export const MediaBlock = {
Expand Down
3 changes: 3 additions & 0 deletions src/components/MediaBase/MediaBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export const MediaBase = (props: MediaBaseProps) => {
mobileDirection = 'content-media',
animated,
mediaOnly,
/**
* @deprecated use custom class for media-component
*/
disableShadow = false,
onScroll,
mediaOnlyColSizes = {all: 12, md: 8},
Expand Down
3 changes: 2 additions & 1 deletion src/models/constructor-items/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
ThemedMediaVideoProps,
TitleItemBaseProps,
TitleItemProps,
WithBorder,
YandexFormProps,
} from './common';
import {BannerCardProps, HubspotFormProps, SubBlock, SubBlockModels} from './sub-blocks';
Expand Down Expand Up @@ -234,7 +235,7 @@ export interface MediaContentProps
button?: ButtonProps;
}

export interface MediaBlockProps extends MediaBaseBlockProps {
export interface MediaBlockProps extends MediaBaseBlockProps, WithBorder {
media: ThemeSupporting<MediaProps>;
}

Expand Down
7 changes: 6 additions & 1 deletion src/models/constructor-items/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ export interface TitleItemBaseProps {
}

// card
export type CardBorder = 'shadow' | 'line' | 'none';
export type MediaBorder = 'shadow' | 'line' | 'none';
export type CardBorder = MediaBorder;

export interface CardBaseProps {
border?: CardBorder;
Expand Down Expand Up @@ -476,3 +477,7 @@ export interface YandexFormProps extends AnalyticsEventsBase {
metrikaGoals?: string | string[];
pixelEvents?: string | string[] | PixelEvent | PixelEvent[];
}

export interface WithBorder {
border?: MediaBorder;
}
13 changes: 13 additions & 0 deletions styles/mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -616,3 +616,16 @@ unpredictable css rules order in build */
}
}
}

@mixin media-border() {
&_border {
&_shadow {
@include image-shadow();
}

&_line {
border-radius: $borderRadius;
border: 1px solid var(--g-color-line-generic);
}
}
}
Loading