Skip to content

Commit

Permalink
fixup! fixup! fixup! feat: add border to media in media-block
Browse files Browse the repository at this point in the history
  • Loading branch information
niktverd committed Jan 16, 2024
1 parent 50d5125 commit 234300c
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 45 deletions.
7 changes: 7 additions & 0 deletions src/blocks/Map/Map.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@import '../../../styles/mixins';

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

#{$block} {
@include media-border();
}
27 changes: 20 additions & 7 deletions src/blocks/Map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,26 @@ import React from 'react';
import Map from '../../components/Map/Map';
import MediaBase from '../../components/MediaBase/MediaBase';
import {MapBlockProps} from '../../models';
import {block} from '../../utils';
import {getMediaBorder} from '../../utils/borderSelector';

export const MapBlock = ({map, ...props}: MapBlockProps) => (
<MediaBase {...props}>
<MediaBase.Card>
<Map {...map} />
</MediaBase.Card>
</MediaBase>
);
import './Map.scss';

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

export const MapBlock = ({map, border, disableShadow, ...props}: MapBlockProps) => {
const borderSelected = getMediaBorder({
border,
disableShadow,
});

return (
<MediaBase {...props}>
<MediaBase.Card>
<Map {...map} className={b({border: borderSelected})} />
</MediaBase.Card>
</MediaBase>
);
};

export default MapBlock;
2 changes: 1 addition & 1 deletion src/blocks/Map/__stories__/Map.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import * as MapStories from './Map.stories.tsx';

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

`disableShadow?: boolean`Disable shadow for the block.
`border?: 'shadow' | 'line' | 'none`Select border of the block.

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

Expand Down
22 changes: 8 additions & 14 deletions src/blocks/Media/Media.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,27 @@ import MediaBase from '../../components/MediaBase/MediaBase';
import {useTheme} from '../../context/theme';
import {MediaBlockProps} from '../../models';
import {block, getThemedValue} from '../../utils';
import {getMediaBorder} from '../../utils/borderSelector';

import './Media.scss';

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

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

const mediaBorder = disableShadow && border === 'shadow' ? 'none' : border;
const {media, border, disableShadow} = props;
const borderSelected = getMediaBorder({
border,
disableShadow,
});

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

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

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

`disableShadow?: boolean`Disable shadow for the block (Deprecated).
`border?: 'shadow' | 'line' | 'none`Select border of the block.

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

Expand Down
4 changes: 2 additions & 2 deletions src/components/Map/GoogleMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function getScriptSrc(params: GoogleMapLinkParams) {
}

const GoogleMap: React.FC<GMapProps> = (props) => {
const {address, zoom} = props;
const {address, zoom, className} = props;
const {apiKey, scriptSrc} = useContext(MapsContext);
const {lang = Lang.Ru} = useContext(LocaleContext);
const isMobile = useContext(MobileContext);
Expand Down Expand Up @@ -63,7 +63,7 @@ const GoogleMap: React.FC<GMapProps> = (props) => {

return (
<iframe
className={b()}
className={b(null, className)}
ref={ref}
style={{
height,
Expand Down
9 changes: 7 additions & 2 deletions src/components/Map/YMap/YandexMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const DEFAULT_ZOOM = 9;
const INITIAL_CENTER = [0, 0];

const YandexMap: React.FC<YMapProps> = (props) => {
const {markers, zoom, id} = props;
const {markers, zoom, id, className} = props;
const {apiKey, scriptSrc, nonce} = useContext(MapsContext);
const isMobile = useContext(MobileContext);

Expand Down Expand Up @@ -108,7 +108,12 @@ const YandexMap: React.FC<YMapProps> = (props) => {
>
<div className={b('wrapper')}>
{/* hidden - to show the map after calculating the center */}
<div id={containerId} className={b({hidden: !ready})} ref={ref} style={{height}} />
<div
id={containerId}
className={b({hidden: !ready}, className)}
ref={ref}
style={{height}}
/>
{loading ? <Spin size="xl" className={b('spinner')} /> : null}
</div>
</ErrorWrapper>
Expand Down
16 changes: 1 addition & 15 deletions src/components/MediaBase/MediaBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ export const MediaBase = (props: MediaBaseProps) => {
mobileDirection = 'content-media',
animated,
mediaOnly,
/**
* @deprecated use custom class for media-component
*/
disableShadow = false,
border = 'shadow',
onScroll,
mediaOnlyColSizes = {all: 12, md: 8},
...mediaContentProps
Expand All @@ -50,8 +45,6 @@ export const MediaBase = (props: MediaBaseProps) => {

const mediaContent = !mediaOnly && <MediaContent {...mediaContentProps} />;
const card = children.type === Card ? children?.props.children : null;
const isShadowDisabled = disableShadow || border !== 'shadow';
const specialBorderRadius = border === 'line';

return (
<AnimateBlock className={b()} onScroll={onScroll} animate={animated}>
Expand All @@ -75,14 +68,7 @@ export const MediaBase = (props: MediaBaseProps) => {
</Col>
{card ? (
<Col sizes={mediaSizes}>
<div
className={b('card', {
shadow: !isShadowDisabled,
specialBorderRadius: specialBorderRadius,
})}
>
{card}
</div>
<div>{card}</div>
</Col>
) : null}
</Row>
Expand Down
5 changes: 2 additions & 3 deletions src/models/constructor-items/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,11 @@ export interface CompaniesBlockProps extends Animatable {
images: ThemeSupporting<ImageDeviceProps>;
}

export interface MediaBaseBlockProps extends Animatable, MediaContentProps, WithBorder {
export interface MediaBaseBlockProps extends Animatable, MediaContentProps {
direction?: MediaDirection;
mobileDirection?: MediaDirection;
largeMedia?: boolean;
mediaOnly?: boolean;
disableShadow?: boolean;
mediaOnlyColSizes?: GridColumnSizesType;
}

Expand All @@ -239,7 +238,7 @@ export interface MediaBlockProps extends MediaBaseBlockProps, WithBorder {
media: ThemeSupporting<MediaProps>;
}

export interface MapBlockProps extends MediaBaseBlockProps {
export interface MapBlockProps extends MediaBaseBlockProps, WithBorder {
map: MapProps;
}

Expand Down
5 changes: 5 additions & 0 deletions src/models/constructor-items/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export type Coordinate = number[];

export interface MapBaseProps {
zoom?: number;
className?: string;
}

export interface GMapProps extends MapBaseProps {
Expand Down Expand Up @@ -480,4 +481,8 @@ export interface YandexFormProps extends AnalyticsEventsBase {

export interface WithBorder {
border?: MediaBorder;
/**
* @deprecated use custom class for media-component
*/
disableShadow?: boolean;
}
24 changes: 24 additions & 0 deletions src/utils/borderSelector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This is a crutch
// The crutch is created in order to help us to work with sites, which use
// "disableShadow" flag in their content.
// We have deprecated the flag.
// We have to remove it after deleting of "disableShadow" and migration of projects content

import {MediaBorder} from '../models';

type GetMediaBorderArgs = {
border?: MediaBorder;
disableShadow?: boolean;
};

export const getMediaBorder = ({border, disableShadow}: GetMediaBorderArgs) => {
if (border) {
return border;
}

if (disableShadow) {
return 'none' as MediaBorder;
}

return 'shadow' as MediaBorder;
};

0 comments on commit 234300c

Please sign in to comment.