Skip to content

Commit

Permalink
feat: add border to media in media-block
Browse files Browse the repository at this point in the history
  • Loading branch information
niktverd committed Dec 5, 2023
1 parent 4206568 commit 13f5128
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 8 deletions.
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';

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 @@ -41,10 +41,17 @@ export const MediaBlockBaseProps = {
mediaOnly: {
type: 'boolean',
},
/**
* @deprecated use border='none' or border='line' instead
*/
disableShadow: {
type: 'boolean',
},
button: ButtonBlock,
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,
...mediaContentProps
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 @@ -233,7 +234,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 @@ -475,3 +476,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);
}
}
}

0 comments on commit 13f5128

Please sign in to comment.