Skip to content

Commit bf950c8

Browse files
author
Juli Ovechkina
authored
feat(Share): create block (#79)
1 parent 444726d commit bf950c8

File tree

19 files changed

+95
-44
lines changed

19 files changed

+95
-44
lines changed

src/blocks/Share/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
`type: share-block`;
2+
3+
`title?: string` — Title
4+
5+
`items?: []` - Share icons
6+
7+
- `telegram`
8+
- `facebook`
9+
- `twitter`
10+
- `vk`
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, {useContext} from 'react';
33
import {ShareList, ShareSocialNetwork} from '@gravity-ui/uikit';
44

55
import {block, getAbsolutePath} from '../../utils';
6-
import {PCShareSocialNetwork} from '../../models';
6+
import {PCShareSocialNetwork, ShareBlockProps} from '../../models';
77
import {LocationContext} from '../../context/locationContext';
88
import i18n from './i18n';
99

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

22-
export interface ShareProps {
23-
items: PCShareSocialNetwork[];
24-
title?: string;
25-
}
26-
27-
const Share = ({items, title}: ShareProps) => {
22+
const Share = ({items, title}: ShareBlockProps) => {
2823
const {pathname, hostname} = useContext(LocationContext);
2924

3025
return (
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {Meta, Story} from '@storybook/react/types-6-0';
2+
import React from 'react';
3+
import {configure as uikitConfigure, Lang as UIKitLang} from '@gravity-ui/uikit';
4+
5+
import Share from '../Share';
6+
import {BLOCKS} from '../../../demo/constants';
7+
import {PageConstructor} from '../../../containers/PageConstructor';
8+
import {ShareBLockModel, ShareBlockProps} from '../../../models';
9+
10+
import data from './data.json';
11+
12+
export default {
13+
component: Share,
14+
title: `${BLOCKS}/Share`,
15+
} as Meta;
16+
17+
uikitConfigure({lang: UIKitLang.En});
18+
19+
const DefaultTemplate: Story<ShareBLockModel> = (args) => (
20+
<PageConstructor content={{blocks: [args]}} />
21+
);
22+
23+
export const Default = DefaultTemplate.bind({});
24+
export const CustomTitle = DefaultTemplate.bind({});
25+
26+
Default.args = data.default.content as ShareBlockProps;
27+
CustomTitle.args = data.customTitle.content as ShareBlockProps;

src/components/Share/__stories__/data.json renamed to src/blocks/Share/__stories__/data.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
22
"default": {
33
"content": {
4+
"type": "share-block",
45
"items": ["facebook", "vk", "telegram", "twitter"]
56
}
67
},
78
"customTitle": {
89
"content": {
10+
"type": "share-block",
911
"title": "Share on social networks",
1012
"items": ["facebook", "vk", "telegram", "twitter"]
1113
}

src/blocks/Share/schema.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {filteredArray} from '../../schema/validators/utils';
2+
import {BaseProps} from '../../schema/validators/common';
3+
4+
export const ShareBlock = {
5+
'share-block': {
6+
additionalProperties: false,
7+
required: ['items'],
8+
properties: {
9+
...BaseProps,
10+
title: {
11+
type: 'string',
12+
},
13+
items: filteredArray({
14+
properties: {
15+
type: 'string',
16+
enum: ['telegram', 'facebook', 'twitter', 'vk'],
17+
},
18+
}),
19+
},
20+
},
21+
};

src/blocks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ export {default as IconsBlock} from './Icons/Icons';
1717
export {default as HeaderSliderBlock} from './HeaderSlider/HeaderSlider';
1818
export {default as CardLayoutBlock} from './CardLayout/CardLayout';
1919
export {default as ContentLayoutBlock} from './ContentLayout/ContentLayout';
20+
export {default as ShareBlock} from './Share/Share';

0 commit comments

Comments
 (0)