Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions src/blocks/Share/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
`type: share-block`;

`title?: string` — Title

`items?: []` - Share icons

- `telegram`
- `facebook`
- `twitter`
- `vk`
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, {useContext} from 'react';
import {ShareList, ShareSocialNetwork} from '@gravity-ui/uikit';

import {block, getAbsolutePath} from '../../utils';
import {PCShareSocialNetwork} from '../../models';
import {PCShareSocialNetwork, ShareBlockProps} from '../../models';
import {LocationContext} from '../../context/locationContext';
import i18n from './i18n';

Expand All @@ -19,12 +19,7 @@ const pcShareSocialNetwork = {
[PCShareSocialNetwork.Facebook]: ShareSocialNetwork.Facebook,
};

export interface ShareProps {
items: PCShareSocialNetwork[];
title?: string;
}

const Share = ({items, title}: ShareProps) => {
const Share = ({items, title}: ShareBlockProps) => {
const {pathname, hostname} = useContext(LocationContext);

return (
Expand Down
27 changes: 27 additions & 0 deletions src/blocks/Share/__stories__/Share.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {Meta, Story} from '@storybook/react/types-6-0';
import React from 'react';
import {configure as uikitConfigure, Lang as UIKitLang} from '@gravity-ui/uikit';

import Share from '../Share';
import {BLOCKS} from '../../../demo/constants';
import {PageConstructor} from '../../../containers/PageConstructor';
import {ShareBLockModel, ShareBlockProps} from '../../../models';

import data from './data.json';

export default {
component: Share,
title: `${BLOCKS}/Share`,
} as Meta;

uikitConfigure({lang: UIKitLang.En});

const DefaultTemplate: Story<ShareBLockModel> = (args) => (
<PageConstructor content={{blocks: [args]}} />
);

export const Default = DefaultTemplate.bind({});
export const CustomTitle = DefaultTemplate.bind({});

Default.args = data.default.content as ShareBlockProps;
CustomTitle.args = data.customTitle.content as ShareBlockProps;
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"default": {
"content": {
"type": "share-block",
"items": ["facebook", "vk", "telegram", "twitter"]
}
},
"customTitle": {
"content": {
"type": "share-block",
"title": "Share on social networks",
"items": ["facebook", "vk", "telegram", "twitter"]
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions src/blocks/Share/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {filteredArray} from '../../schema/validators/utils';
import {BaseProps} from '../../schema/validators/common';

export const ShareBlock = {
'share-block': {
additionalProperties: false,
required: ['items'],
properties: {
...BaseProps,
title: {
type: 'string',
},
items: filteredArray({
properties: {
type: 'string',
enum: ['telegram', 'facebook', 'twitter', 'vk'],
},
}),
},
},
};
1 change: 1 addition & 0 deletions src/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export {default as IconsBlock} from './Icons/Icons';
export {default as HeaderSliderBlock} from './HeaderSlider/HeaderSlider';
export {default as CardLayoutBlock} from './CardLayout/CardLayout';
export {default as ContentLayoutBlock} from './ContentLayout/ContentLayout';
export {default as ShareBlock} from './Share/Share';
1 change: 1 addition & 0 deletions src/blocks/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * from './Security/schema';
export * from './Simple/schema';
export * from './Slider/schema';
export * from './Table/schema';
export * from './Share/schema';
5 changes: 0 additions & 5 deletions src/components/Share/README.md

This file was deleted.

23 changes: 0 additions & 23 deletions src/components/Share/__stories__/Share.stories.tsx

This file was deleted.

2 changes: 2 additions & 0 deletions src/constructor-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
HeaderSliderBlock,
CardLayoutBlock,
ContentLayoutBlock,
ShareBlock,
} from './blocks';

export const blockMap = {
Expand All @@ -57,6 +58,7 @@ export const blockMap = {
[BlockType.HeaderSliderBlock]: HeaderSliderBlock,
[BlockType.CardLayoutBlock]: CardLayoutBlock,
[BlockType.ContentLayoutBlock]: ContentLayoutBlock,
[BlockType.ShareBlock]: ShareBlock,
};

export const subBlockMap = {
Expand Down
7 changes: 0 additions & 7 deletions src/models/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,3 @@ export type ArrowDirection = 'left' | 'right';
export interface ReactPlayerBlockHandler {
pause: () => void;
}

export enum PCShareSocialNetwork {
Vk = 'vk',
Telegram = 'telegram',
Twitter = 'twitter',
Facebook = 'facebook',
}
22 changes: 20 additions & 2 deletions src/models/constructor-items/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
ImageDeviceProps,
} from './common';
import {ThemeSupporting} from '../../utils';
import {GridColumnSize, GridColumnSizesType} from '../../grid/types';
import {GridColumnSize, GridColumnSizesType} from '../../grid';
import {BannerCardProps, SubBlock} from './sub-blocks';

export enum BlockType {
Expand All @@ -55,6 +55,7 @@ export enum BlockType {
IconsBlock = 'icons-block',
CardLayoutBlock = 'card-layout-block',
ContentLayoutBlock = 'content-layout-block',
ShareBlock = 'share-block',
}

export const BlockTypes = Object.values(BlockType);
Expand Down Expand Up @@ -350,6 +351,18 @@ export interface ContentBlockProps {
theme?: ContentTheme;
}

export enum PCShareSocialNetwork {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we take it form uikit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't find this kind of enum in uikit

Vk = 'vk',
Telegram = 'telegram',
Twitter = 'twitter',
Facebook = 'facebook',
}

export interface ShareBlockProps {
items: PCShareSocialNetwork[];
title?: string;
}

//block models
export type HeaderBlockModel = {
type: BlockType.HeaderBlock;
Expand Down Expand Up @@ -435,6 +448,10 @@ export type ContentLayoutBlockModel = {
type: BlockType.ContentLayoutBlock;
} & ContentLayoutBlockProps;

export type ShareBLockModel = {
type: BlockType.ShareBlock;
} & ShareBlockProps;

type BlockModels =
| SliderBlockModel
| ServiceDemoBlockModel
Expand All @@ -456,6 +473,7 @@ type BlockModels =
| IconsBlockModel
| HeaderSliderBlockModel
| CardLayoutBlockModel
| ContentLayoutBlockModel;
| ContentLayoutBlockModel
| ShareBLockModel;

export type Block = BlockModels & BlockBaseProps;
2 changes: 2 additions & 0 deletions src/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
HeaderSliderBlock,
IconsBlock,
CardLayoutBlock,
ShareBlock,
} from './validators/blocks';

import {
Expand Down Expand Up @@ -117,6 +118,7 @@ export function generateDefaultSchema(config?: SchemaCustomConfig) {
...CardLayoutBlock,
...ContentLayoutBlock,
...Divider,
...ShareBlock,
...getBlocksCases(blocks),
},
}),
Expand Down
1 change: 1 addition & 0 deletions src/schema/validators/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export * from '../../blocks/HeaderSlider/schema';
export * from '../../blocks/Icons/schema';
export * from '../../blocks/CardLayout/schema';
export * from '../../blocks/ContentLayout/schema';
export * from '../../blocks/Share/schema';
6 changes: 6 additions & 0 deletions src/text-transform/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,12 @@ const config: BlocksConfig = {
parser: parseContentLayoutTitle,
},
],
[BlockType.ShareBlock]: [
{
fields: ['title'],
transformer: typografTransformer,
},
],
};

function addRandomOrder(block: ConstructorBlock) {
Expand Down