@redneckz/wildless-cms-uni-blocks 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/blocks.schema.json +1 -1
- package/bundle/bundle.umd.js +38 -11
- package/bundle/bundle.umd.min.js +1 -1
- package/dist/components/BenefitsBlock/BenefitsBlock.js +32 -9
- package/dist/components/BenefitsBlock/BenefitsBlock.js.map +1 -1
- package/dist/components/BenefitsBlock/BenefitsBlockContent.d.ts +9 -2
- package/dist/content-page-repository/transformContentPage.js +9 -3
- package/dist/content-page-repository/transformContentPage.js.map +1 -1
- package/dist/content-page-repository/transformImg.d.ts +11 -0
- package/dist/content-page-repository/transformImg.js +100 -0
- package/dist/content-page-repository/transformImg.js.map +1 -0
- package/dist/content-page-repository/transformPicture.js +15 -40
- package/dist/content-page-repository/transformPicture.js.map +1 -1
- package/dist/content-page-repository/transformSrc.d.ts +3 -0
- package/dist/content-page-repository/transformSrc.js +20 -0
- package/dist/content-page-repository/transformSrc.js.map +1 -0
- package/dist/model/ImageSize.d.ts +6 -0
- package/dist/model/ImageSize.js +2 -0
- package/dist/model/ImageSize.js.map +1 -0
- package/dist/model/Picture.d.ts +19 -6
- package/dist/ui-kit/Img/ImgAsPicture.js +6 -2
- package/dist/ui-kit/Img/ImgAsPicture.js.map +1 -1
- package/dist/utils/isPictureSizeEmpty.d.ts +2 -0
- package/dist/utils/isPictureSizeEmpty.js +7 -0
- package/dist/utils/isPictureSizeEmpty.js.map +1 -0
- package/lib/common.css +1 -1
- package/lib/components/BenefitsBlock/BenefitsBlock.fixture.d.ts +2 -0
- package/lib/components/BenefitsBlock/BenefitsBlock.js +32 -9
- package/lib/components/BenefitsBlock/BenefitsBlock.js.map +1 -1
- package/lib/components/BenefitsBlock/BenefitsBlockContent.d.ts +9 -2
- package/lib/content-page-repository/transformContentPage.js +9 -3
- package/lib/content-page-repository/transformContentPage.js.map +1 -1
- package/lib/content-page-repository/transformImg.d.ts +11 -0
- package/lib/content-page-repository/transformImg.js +94 -0
- package/lib/content-page-repository/transformImg.js.map +1 -0
- package/lib/content-page-repository/transformPicture.js +15 -40
- package/lib/content-page-repository/transformPicture.js.map +1 -1
- package/lib/content-page-repository/transformSrc.d.ts +3 -0
- package/lib/content-page-repository/transformSrc.js +14 -0
- package/lib/content-page-repository/transformSrc.js.map +1 -0
- package/lib/model/ImageSize.d.ts +6 -0
- package/lib/model/ImageSize.js +2 -0
- package/lib/model/ImageSize.js.map +1 -0
- package/lib/model/Picture.d.ts +19 -6
- package/lib/ui-kit/Img/ImgAsPicture.js +6 -2
- package/lib/ui-kit/Img/ImgAsPicture.js.map +1 -1
- package/lib/utils/isPictureSizeEmpty.d.ts +2 -0
- package/lib/utils/isPictureSizeEmpty.js +4 -0
- package/lib/utils/isPictureSizeEmpty.js.map +1 -0
- package/mobile/bundle/bundle.umd.js +6 -2
- package/mobile/bundle/bundle.umd.min.js +1 -1
- package/mobile/dist/components/BenefitsBlock/BenefitsBlock.js +32 -9
- package/mobile/dist/components/BenefitsBlock/BenefitsBlock.js.map +1 -1
- package/mobile/dist/components/BenefitsBlock/BenefitsBlockContent.d.ts +9 -2
- package/mobile/dist/content-page-repository/transformContentPage.js +9 -3
- package/mobile/dist/content-page-repository/transformContentPage.js.map +1 -1
- package/mobile/dist/content-page-repository/transformImg.d.ts +11 -0
- package/mobile/dist/content-page-repository/transformImg.js +100 -0
- package/mobile/dist/content-page-repository/transformImg.js.map +1 -0
- package/mobile/dist/content-page-repository/transformPicture.js +15 -40
- package/mobile/dist/content-page-repository/transformPicture.js.map +1 -1
- package/mobile/dist/content-page-repository/transformSrc.d.ts +3 -0
- package/mobile/dist/content-page-repository/transformSrc.js +20 -0
- package/mobile/dist/content-page-repository/transformSrc.js.map +1 -0
- package/mobile/dist/model/ImageSize.d.ts +6 -0
- package/mobile/dist/model/ImageSize.js +2 -0
- package/mobile/dist/model/ImageSize.js.map +1 -0
- package/mobile/dist/model/Picture.d.ts +19 -6
- package/mobile/dist/ui-kit/Img/ImgAsPicture.js +6 -2
- package/mobile/dist/ui-kit/Img/ImgAsPicture.js.map +1 -1
- package/mobile/dist/utils/isPictureSizeEmpty.d.ts +2 -0
- package/mobile/dist/utils/isPictureSizeEmpty.js +7 -0
- package/mobile/dist/utils/isPictureSizeEmpty.js.map +1 -0
- package/mobile/lib/components/BenefitsBlock/BenefitsBlock.js +32 -9
- package/mobile/lib/components/BenefitsBlock/BenefitsBlock.js.map +1 -1
- package/mobile/lib/components/BenefitsBlock/BenefitsBlockContent.d.ts +9 -2
- package/mobile/lib/content-page-repository/transformContentPage.js +9 -3
- package/mobile/lib/content-page-repository/transformContentPage.js.map +1 -1
- package/mobile/lib/content-page-repository/transformImg.d.ts +11 -0
- package/mobile/lib/content-page-repository/transformImg.js +94 -0
- package/mobile/lib/content-page-repository/transformImg.js.map +1 -0
- package/mobile/lib/content-page-repository/transformPicture.js +15 -40
- package/mobile/lib/content-page-repository/transformPicture.js.map +1 -1
- package/mobile/lib/content-page-repository/transformSrc.d.ts +3 -0
- package/mobile/lib/content-page-repository/transformSrc.js +14 -0
- package/mobile/lib/content-page-repository/transformSrc.js.map +1 -0
- package/mobile/lib/model/ImageSize.d.ts +6 -0
- package/mobile/lib/model/ImageSize.js +2 -0
- package/mobile/lib/model/ImageSize.js.map +1 -0
- package/mobile/lib/model/Picture.d.ts +19 -6
- package/mobile/lib/ui-kit/Img/ImgAsPicture.js +6 -2
- package/mobile/lib/ui-kit/Img/ImgAsPicture.js.map +1 -1
- package/mobile/lib/utils/isPictureSizeEmpty.d.ts +2 -0
- package/mobile/lib/utils/isPictureSizeEmpty.js +4 -0
- package/mobile/lib/utils/isPictureSizeEmpty.js.map +1 -0
- package/mobile/src/components/BenefitsBlock/BenefitsBlock.example.json +1 -0
- package/mobile/src/components/BenefitsBlock/BenefitsBlock.tsx +78 -28
- package/mobile/src/components/BenefitsBlock/BenefitsBlockContent.ts +10 -2
- package/mobile/src/components/ContentPage/ContentPage.page.json +1 -2
- package/mobile/src/components/__snapshots__/Blocks.spec.tsx.snap +1 -1
- package/mobile/src/content-page-repository/transformContentPage.ts +10 -3
- package/mobile/src/content-page-repository/transformImg.ts +157 -0
- package/mobile/src/content-page-repository/transformPicture.ts +24 -58
- package/mobile/src/content-page-repository/transformSrc.ts +21 -0
- package/mobile/src/model/ImageSize.ts +6 -0
- package/mobile/src/model/Picture.ts +29 -6
- package/mobile/src/ui-kit/Img/ImgAsPicture.tsx +8 -2
- package/mobile/src/utils/isPictureSizeEmpty.ts +5 -0
- package/package.json +2 -1
- package/src/components/BenefitsBlock/BenefitsBlock.example.json +1 -0
- package/src/components/BenefitsBlock/BenefitsBlock.fixture.tsx +94 -1
- package/src/components/BenefitsBlock/BenefitsBlock.tsx +78 -28
- package/src/components/BenefitsBlock/BenefitsBlockContent.ts +10 -2
- package/src/components/ContentPage/ContentPage.page.json +1 -2
- package/src/components/__snapshots__/Blocks.spec.tsx.snap +1 -1
- package/src/content-page-repository/transformContentPage.ts +10 -3
- package/src/content-page-repository/transformImg.ts +157 -0
- package/src/content-page-repository/transformPicture.ts +24 -58
- package/src/content-page-repository/transformSrc.ts +21 -0
- package/src/model/ImageSize.ts +6 -0
- package/src/model/Picture.ts +29 -6
- package/src/ui-kit/Img/ImgAsPicture.tsx +8 -2
- package/src/utils/isPictureSizeEmpty.ts +5 -0
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
1
|
import path from 'path';
|
|
3
2
|
import sharp from 'sharp';
|
|
4
|
-
import
|
|
5
|
-
import type { ImgSource, Picture } from '../model/Picture';
|
|
3
|
+
import type { Picture } from '../model/Picture';
|
|
6
4
|
import type { TransformationOptions } from './TransformationOptions';
|
|
7
|
-
|
|
8
|
-
const mkdir = util.promisify(fs.mkdir);
|
|
5
|
+
import { transformImg } from './transformImg';
|
|
9
6
|
|
|
10
7
|
export async function transformPicture(
|
|
11
8
|
pagePath: string,
|
|
@@ -14,8 +11,27 @@ export async function transformPicture(
|
|
|
14
11
|
): Promise<Picture> {
|
|
15
12
|
const sources = picture.sources || [];
|
|
16
13
|
const src = picture?.src || '';
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
|
|
15
|
+
const transformedPicture = await transformImg({
|
|
16
|
+
pagePath,
|
|
17
|
+
src,
|
|
18
|
+
transformationOptions: { ...options, ...picture },
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const { width, height } = await sharp(
|
|
22
|
+
path.resolve(options.publicDir, transformedPicture),
|
|
23
|
+
).metadata();
|
|
24
|
+
const containerSize = width && height ? { width, height } : undefined;
|
|
25
|
+
|
|
26
|
+
const transformedSources = await Promise.all(
|
|
27
|
+
sources.map((_) =>
|
|
28
|
+
transformImg({
|
|
29
|
+
pagePath,
|
|
30
|
+
src,
|
|
31
|
+
containerSize,
|
|
32
|
+
transformationOptions: { ...options, ..._ },
|
|
33
|
+
}),
|
|
34
|
+
),
|
|
19
35
|
);
|
|
20
36
|
|
|
21
37
|
return {
|
|
@@ -24,57 +40,7 @@ export async function transformPicture(
|
|
|
24
40
|
sources: transformedSources.map((_, i) => ({
|
|
25
41
|
...sources[i],
|
|
26
42
|
src: _,
|
|
43
|
+
size: { width, height },
|
|
27
44
|
})),
|
|
28
45
|
};
|
|
29
46
|
}
|
|
30
|
-
|
|
31
|
-
async function transformImg(
|
|
32
|
-
pagePath: string,
|
|
33
|
-
src: string,
|
|
34
|
-
transformationOptions: TransformationOptions & ImgSource,
|
|
35
|
-
): Promise<string> {
|
|
36
|
-
const { contentDir, publicDir, format, options, size } = transformationOptions;
|
|
37
|
-
|
|
38
|
-
const pageDir = path.dirname(pagePath);
|
|
39
|
-
const imgPath = `${pageDir}/${src}`;
|
|
40
|
-
let chain = sharp(imgPath);
|
|
41
|
-
if (size) {
|
|
42
|
-
chain = chain.resize(size?.width, size?.height, {
|
|
43
|
-
fit: sharp.fit.contain,
|
|
44
|
-
background: [0, 0, 0, 0],
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
if (format) {
|
|
48
|
-
chain = chain.toFormat(format, options);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const transformedSrc = transformSrc(src, transformationOptions);
|
|
52
|
-
const transformedImgPath = `${publicDir}/${path.relative(
|
|
53
|
-
contentDir,
|
|
54
|
-
`${path.dirname(pagePath)}/${transformedSrc}`,
|
|
55
|
-
)}`;
|
|
56
|
-
|
|
57
|
-
await mkdir(path.dirname(transformedImgPath), { recursive: true });
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
await chain.toFile(transformedImgPath);
|
|
61
|
-
} catch (e) {
|
|
62
|
-
console.error(e);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return transformedSrc;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function transformSrc(src: string, { format, size }: TransformationOptions & ImgSource): string {
|
|
69
|
-
const noTransform = !format && !size;
|
|
70
|
-
if (noTransform) {
|
|
71
|
-
return src;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const fileName = path.basename(src, path.extname(src));
|
|
75
|
-
const fileSizes = [size?.width, size?.height].filter(Boolean);
|
|
76
|
-
const suffix = fileSizes.length ? `-${fileSizes.join('-')}` : '';
|
|
77
|
-
const ext = String(format) || path.extname(src);
|
|
78
|
-
|
|
79
|
-
return `${fileName}${suffix}.${ext}`;
|
|
80
|
-
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import type { ImgSource } from '../model/Picture';
|
|
3
|
+
import type { TransformationOptions } from './TransformationOptions';
|
|
4
|
+
import { isPictureSizeEmpty } from '../utils/isPictureSizeEmpty';
|
|
5
|
+
|
|
6
|
+
export function transformSrc(
|
|
7
|
+
src: string,
|
|
8
|
+
{ format, size }: TransformationOptions & ImgSource,
|
|
9
|
+
): string {
|
|
10
|
+
const noTransform = isPictureSizeEmpty(size) && !format;
|
|
11
|
+
if (noTransform) {
|
|
12
|
+
return src;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const fileName = path.basename(src, path.extname(src));
|
|
16
|
+
const fileSizes = [size?.width, size?.height].filter(Boolean);
|
|
17
|
+
const suffix = fileSizes.length ? `-${fileSizes.join('-')}` : '';
|
|
18
|
+
const ext = format ? String(format) : 'webp';
|
|
19
|
+
|
|
20
|
+
return `${fileName}${suffix}.${ext}`;
|
|
21
|
+
}
|
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
import type { IconName } from '../icons/IconName';
|
|
2
2
|
import type { IconVersion } from './IconVersion';
|
|
3
|
+
import { ImageSize } from './ImageSize';
|
|
3
4
|
|
|
4
5
|
export type ImgFormats = 'jpeg' | 'jpg' | 'png' | 'gif' | 'webp' | 'heif' | 'avif';
|
|
5
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @title Позиционирование
|
|
9
|
+
* @enumNames [
|
|
10
|
+
* "Сверху слева",
|
|
11
|
+
* "Сверху по центру",
|
|
12
|
+
* "Сверху справа",
|
|
13
|
+
* "Посередине слева",
|
|
14
|
+
* "Посередине по центру",
|
|
15
|
+
* "Посередине справа",
|
|
16
|
+
* "Снизу слева",
|
|
17
|
+
* "Снизу по центру",
|
|
18
|
+
* "Снизу справа"
|
|
19
|
+
* ]
|
|
20
|
+
* @default "center"
|
|
21
|
+
*/
|
|
22
|
+
export type ImgAlignment =
|
|
23
|
+
| 'northwest'
|
|
24
|
+
| 'north'
|
|
25
|
+
| 'northeast'
|
|
26
|
+
| 'west'
|
|
27
|
+
| 'center'
|
|
28
|
+
| 'east'
|
|
29
|
+
| 'southwest'
|
|
30
|
+
| 'south'
|
|
31
|
+
| 'southeast';
|
|
32
|
+
|
|
6
33
|
export interface Img {
|
|
7
34
|
/** @title Картинка */
|
|
8
35
|
src?: string;
|
|
@@ -19,6 +46,7 @@ export interface Img {
|
|
|
19
46
|
export type MediaQuery = 1919 | 1439 | 1279;
|
|
20
47
|
|
|
21
48
|
export interface ImgSource {
|
|
49
|
+
alignment?: ImgAlignment;
|
|
22
50
|
/** @title Иконка */
|
|
23
51
|
icon?: IconName;
|
|
24
52
|
iconVersion?: IconVersion;
|
|
@@ -30,12 +58,7 @@ export interface ImgSource {
|
|
|
30
58
|
options?: Record<string, any>;
|
|
31
59
|
media?: MediaQuery;
|
|
32
60
|
/** @title Размер изображения */
|
|
33
|
-
size?:
|
|
34
|
-
/** @title Ширина */
|
|
35
|
-
width?: number;
|
|
36
|
-
/** @title Высота */
|
|
37
|
-
height?: number;
|
|
38
|
-
};
|
|
61
|
+
size?: Partial<ImageSize>;
|
|
39
62
|
}
|
|
40
63
|
|
|
41
64
|
/** @title Изображение */
|
|
@@ -23,13 +23,13 @@ export const ImgAsPicture = JSX<ImageProps<Picture>>(
|
|
|
23
23
|
{image?.sources?.length
|
|
24
24
|
? image.sources
|
|
25
25
|
.sort(sourcesComparator)
|
|
26
|
-
.map(({ src, format, media
|
|
26
|
+
.map(({ src, format, media }, index) => (
|
|
27
27
|
<source
|
|
28
28
|
key={`${index}_${src}`}
|
|
29
29
|
srcSet={src}
|
|
30
30
|
type={formatToMimeType(format)}
|
|
31
31
|
media={media ? `(max-width: ${media}px)` : ''}
|
|
32
|
-
{...size}
|
|
32
|
+
{...image.size}
|
|
33
33
|
/>
|
|
34
34
|
))
|
|
35
35
|
: null}
|
|
@@ -40,6 +40,11 @@ export const ImgAsPicture = JSX<ImageProps<Picture>>(
|
|
|
40
40
|
);
|
|
41
41
|
|
|
42
42
|
const renderImg = (image: Picture, imageClassName = '', isMobile = false) => {
|
|
43
|
+
const style = {
|
|
44
|
+
width: image.size?.width ? `${image.size?.width}px` : '100%',
|
|
45
|
+
height: image.size?.height ? `${image.size?.height}px` : '100%',
|
|
46
|
+
};
|
|
47
|
+
|
|
43
48
|
const title = image.title || '';
|
|
44
49
|
const alt = image.alt || image.title;
|
|
45
50
|
const imgStyle = isMobile ? 'm-auto' : 'm-0';
|
|
@@ -50,6 +55,7 @@ const renderImg = (image: Picture, imageClassName = '', isMobile = false) => {
|
|
|
50
55
|
className={`${imgStyle} ${imageClassName}`}
|
|
51
56
|
alt={alt}
|
|
52
57
|
title={title}
|
|
58
|
+
style={style}
|
|
53
59
|
{...image.size}
|
|
54
60
|
/>
|
|
55
61
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redneckz/wildless-cms-uni-blocks",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ЦК",
|
|
@@ -127,6 +127,7 @@
|
|
|
127
127
|
"@testing-library/react": "^12.1.5",
|
|
128
128
|
"@types/glob": "^8.0.0",
|
|
129
129
|
"@types/jest": "^28.1.5",
|
|
130
|
+
"@types/sharp": "^0.31.0",
|
|
130
131
|
"@typescript-eslint/eslint-plugin": "^5.30.6",
|
|
131
132
|
"@typescript-eslint/experimental-utils": "^5.30.6",
|
|
132
133
|
"@typescript-eslint/parser": "^5.30.6",
|
|
@@ -61,6 +61,7 @@ export default {
|
|
|
61
61
|
icon: image,
|
|
62
62
|
},
|
|
63
63
|
]}
|
|
64
|
+
benefitsBlockVersion="primary"
|
|
64
65
|
/>
|
|
65
66
|
</div>
|
|
66
67
|
),
|
|
@@ -104,10 +105,10 @@ export default {
|
|
|
104
105
|
icon: { icon: 'GlobalIcon' },
|
|
105
106
|
},
|
|
106
107
|
]}
|
|
108
|
+
benefitsBlockVersion="primary"
|
|
107
109
|
/>
|
|
108
110
|
</div>
|
|
109
111
|
),
|
|
110
|
-
|
|
111
112
|
list: (
|
|
112
113
|
<div className="container grid grid-cols-12">
|
|
113
114
|
<BenefitsBlock
|
|
@@ -155,4 +156,96 @@ export default {
|
|
|
155
156
|
/>
|
|
156
157
|
</div>
|
|
157
158
|
),
|
|
159
|
+
'list-green': (
|
|
160
|
+
<div className="container grid grid-cols-12">
|
|
161
|
+
<BenefitsBlock
|
|
162
|
+
context={context}
|
|
163
|
+
className="col-span-12"
|
|
164
|
+
title="Преимущества кредита"
|
|
165
|
+
benefitList={[
|
|
166
|
+
{
|
|
167
|
+
label: 'Без комиссии',
|
|
168
|
+
icon: { icon: 'ClockIcon' },
|
|
169
|
+
description: {
|
|
170
|
+
bullets: true,
|
|
171
|
+
items: itemsList,
|
|
172
|
+
benefitType: 'list',
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
label: 'Оформление по паспорту',
|
|
177
|
+
description: {
|
|
178
|
+
bullets: true,
|
|
179
|
+
items: itemsList,
|
|
180
|
+
benefitType: 'list',
|
|
181
|
+
},
|
|
182
|
+
icon: { icon: 'SignDocsIcon' },
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
label: 'Без залога и поручительства',
|
|
186
|
+
description: {
|
|
187
|
+
bullets: true,
|
|
188
|
+
items: itemsList,
|
|
189
|
+
benefitType: 'list',
|
|
190
|
+
},
|
|
191
|
+
icon: { icon: 'ComfortableCompIcon' },
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
label: 'Деньги за 3 дня',
|
|
195
|
+
description: {
|
|
196
|
+
bullets: true,
|
|
197
|
+
items: itemsList,
|
|
198
|
+
benefitType: 'list',
|
|
199
|
+
},
|
|
200
|
+
icon: { icon: 'ActualBalanceIcon' },
|
|
201
|
+
},
|
|
202
|
+
]}
|
|
203
|
+
benefitsBlockVersion="secondary"
|
|
204
|
+
/>
|
|
205
|
+
</div>
|
|
206
|
+
),
|
|
207
|
+
'desc-icon-green': (
|
|
208
|
+
<div className="container grid grid-cols-12">
|
|
209
|
+
<BenefitsBlock
|
|
210
|
+
context={context}
|
|
211
|
+
className="col-span-12"
|
|
212
|
+
title="Преимущества кредита"
|
|
213
|
+
benefitList={[
|
|
214
|
+
{
|
|
215
|
+
label: 'Без комиссии',
|
|
216
|
+
description: {
|
|
217
|
+
name: 'Комиссия за выдачу ',
|
|
218
|
+
benefitType: 'text',
|
|
219
|
+
},
|
|
220
|
+
icon: { icon: 'MoneyIcon' },
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
label: 'Оформление',
|
|
224
|
+
description: {
|
|
225
|
+
name: 'Обеспечение ',
|
|
226
|
+
benefitType: 'text',
|
|
227
|
+
},
|
|
228
|
+
icon: { icon: 'PersonalCardIcon' },
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
label: 'Без залога ',
|
|
232
|
+
description: {
|
|
233
|
+
name: 'Единовременное перечисление ',
|
|
234
|
+
benefitType: 'text',
|
|
235
|
+
},
|
|
236
|
+
icon: { icon: 'CalendarTickIcon' },
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
label: 'Деньги за 3 дня',
|
|
240
|
+
description: {
|
|
241
|
+
name: 'Рассмотрение ',
|
|
242
|
+
benefitType: 'text',
|
|
243
|
+
},
|
|
244
|
+
icon: { icon: 'GlobalIcon' },
|
|
245
|
+
},
|
|
246
|
+
]}
|
|
247
|
+
benefitsBlockVersion="secondary"
|
|
248
|
+
/>
|
|
249
|
+
</div>
|
|
250
|
+
),
|
|
158
251
|
};
|
|
@@ -3,64 +3,114 @@ import { BlockWrapper } from '../../ui-kit/BlockWrapper';
|
|
|
3
3
|
import type { UniBlockProps } from '../../types';
|
|
4
4
|
import { Heading } from '../../ui-kit/Heading/Heading';
|
|
5
5
|
import { Img } from '../../ui-kit/Img/Img';
|
|
6
|
-
import type {
|
|
7
|
-
import {
|
|
6
|
+
import type { BenefitsBlockContent, ListBenefitDef, TextBenefitDef } from './BenefitsBlockContent';
|
|
7
|
+
import {
|
|
8
|
+
BenefitBlockItemProps,
|
|
9
|
+
BenefitsBlockVersion,
|
|
10
|
+
DescriptionDef,
|
|
11
|
+
} from './BenefitsBlockContent';
|
|
12
|
+
import { Picture } from '../../model/Picture';
|
|
8
13
|
|
|
9
14
|
export interface BenefitsBlockProps extends BenefitsBlockContent, UniBlockProps {}
|
|
10
15
|
|
|
16
|
+
const benefitsBlockStyleMap = {
|
|
17
|
+
primary: 'bg-white',
|
|
18
|
+
secondary: 'bg-primary-main',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const benefitsTextStyleMap = {
|
|
22
|
+
primary: '',
|
|
23
|
+
secondary: 'text-white',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const benefitsDescriptionStyleMap = {
|
|
27
|
+
primary: 'text-secondary-text',
|
|
28
|
+
secondary: 'text-white opacity-80',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const benefitsIconStyleMap = {
|
|
32
|
+
primary: 'bg-main-divider text-primary-main',
|
|
33
|
+
secondary: 'bg-white/30 text-black',
|
|
34
|
+
};
|
|
35
|
+
|
|
11
36
|
export const BenefitsBlock = JSX<BenefitsBlockProps>(
|
|
12
|
-
({ className = '', title, benefitList, ...rest }) => {
|
|
37
|
+
({ className = '', title, benefitList, benefitsBlockVersion = 'primary', ...rest }) => {
|
|
13
38
|
return (
|
|
14
39
|
<BlockWrapper
|
|
15
|
-
className={`font-sans text-primary-text
|
|
40
|
+
className={`font-sans text-primary-text p-12 flex flex-col items-center ${className} ${benefitsBlockStyleMap[benefitsBlockVersion]}`}
|
|
16
41
|
{...rest}
|
|
17
42
|
>
|
|
18
43
|
{title ? (
|
|
19
|
-
<Heading
|
|
44
|
+
<Heading
|
|
45
|
+
headingType="h3"
|
|
46
|
+
as="h2"
|
|
47
|
+
className={`max-w-[47rem] text-center ${benefitsTextStyleMap[benefitsBlockVersion]}`}
|
|
48
|
+
title={title}
|
|
49
|
+
/>
|
|
20
50
|
) : null}
|
|
21
|
-
{benefitList?.length ? renderBenefits(benefitList) : null}
|
|
51
|
+
{benefitList?.length ? renderBenefits(benefitList, benefitsBlockVersion) : null}
|
|
22
52
|
</BlockWrapper>
|
|
23
53
|
);
|
|
24
54
|
},
|
|
25
55
|
);
|
|
26
56
|
|
|
27
|
-
const renderBenefits = (
|
|
57
|
+
const renderBenefits = (
|
|
58
|
+
benefitList: BenefitBlockItemProps[],
|
|
59
|
+
benefitsBlockVersion: BenefitsBlockVersion,
|
|
60
|
+
) => {
|
|
28
61
|
return (
|
|
29
62
|
<div className="flex flex-wrap w-full justify-center gap-x-20 mt-8">
|
|
30
|
-
{
|
|
63
|
+
{benefitList.map(renderStep(benefitsBlockVersion))}
|
|
31
64
|
</div>
|
|
32
65
|
);
|
|
33
66
|
};
|
|
34
67
|
|
|
35
|
-
const
|
|
36
|
-
|
|
68
|
+
const setIconVersion = (benefitIcon: Picture, benefitsBlockVersion: BenefitsBlockVersion) => {
|
|
69
|
+
if (!benefitIcon.icon) {
|
|
70
|
+
return benefitIcon;
|
|
71
|
+
}
|
|
72
|
+
benefitIcon.iconVersion = benefitsBlockVersion === 'secondary' ? 'white' : 'normal';
|
|
37
73
|
|
|
38
|
-
return
|
|
39
|
-
<div key={String(i)} className="flex items-center basis-1/2 max-w-[500px] mb-14">
|
|
40
|
-
{benefit?.icon?.icon ? (
|
|
41
|
-
<Img
|
|
42
|
-
className="w-[50px] h-[50px] min-w-[50px] p-3 rounded-full bg-main-divider"
|
|
43
|
-
image={benefit.icon}
|
|
44
|
-
asSVG
|
|
45
|
-
/>
|
|
46
|
-
) : null}
|
|
47
|
-
{benefit?.icon?.src ? <Img image={benefit.icon} /> : null}
|
|
48
|
-
<div className="ml-5">
|
|
49
|
-
{benefit?.label ? <h3 className="text-h6 m-0">{benefit.label}</h3> : null}
|
|
50
|
-
{renderDescription(description)}
|
|
51
|
-
</div>
|
|
52
|
-
</div>
|
|
53
|
-
);
|
|
74
|
+
return benefitIcon;
|
|
54
75
|
};
|
|
55
76
|
|
|
56
|
-
const
|
|
77
|
+
const renderStep =
|
|
78
|
+
(benefitsBlockVersion: BenefitsBlockVersion) => (benefit: BenefitBlockItemProps, i: number) => {
|
|
79
|
+
const description = (benefit?.description || undefined) as DescriptionDef;
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<div key={String(i)} className="flex items-center basis-1/2 max-w-[500px] mb-14">
|
|
83
|
+
{benefit?.icon?.icon ? (
|
|
84
|
+
<Img
|
|
85
|
+
className={`w-[50px] h-[50px] min-w-[50px] p-3 rounded-full ${benefitsIconStyleMap[benefitsBlockVersion]}`}
|
|
86
|
+
image={setIconVersion(benefit.icon, benefitsBlockVersion)}
|
|
87
|
+
asSVG
|
|
88
|
+
/>
|
|
89
|
+
) : null}
|
|
90
|
+
{benefit?.icon?.src ? <Img image={benefit.icon} /> : null}
|
|
91
|
+
<div className="ml-5">
|
|
92
|
+
{benefit?.label ? (
|
|
93
|
+
<h3 className={`text-h6 m-0 ${benefitsTextStyleMap[benefitsBlockVersion]}`}>
|
|
94
|
+
{benefit.label}
|
|
95
|
+
</h3>
|
|
96
|
+
) : null}
|
|
97
|
+
{renderDescription(description, benefitsBlockVersion)}
|
|
98
|
+
</div>
|
|
99
|
+
</div>
|
|
100
|
+
);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const renderDescription = (
|
|
104
|
+
description: DescriptionDef,
|
|
105
|
+
benefitsBlockVersion: BenefitsBlockVersion,
|
|
106
|
+
) => {
|
|
57
107
|
const benefitType = description ? description?.benefitType : null;
|
|
58
108
|
if (!benefitType) {
|
|
59
109
|
return null;
|
|
60
110
|
}
|
|
61
111
|
|
|
62
112
|
return description ? (
|
|
63
|
-
<div className=
|
|
113
|
+
<div className={`text-l-light mt-2 ${benefitsDescriptionStyleMap[benefitsBlockVersion]}`}>
|
|
64
114
|
{benefitType === 'list'
|
|
65
115
|
? renderListBenefit(description as ListBenefitDef)
|
|
66
116
|
: renderTextBenefit(description as TextBenefitDef)}
|
|
@@ -37,7 +37,7 @@ export type DescriptionDef = EmptyOption | TextBenefitDef | ListBenefitDef;
|
|
|
37
37
|
/**
|
|
38
38
|
* @title Преимущество
|
|
39
39
|
*/
|
|
40
|
-
export interface
|
|
40
|
+
export interface BenefitBlockItemProps {
|
|
41
41
|
/** @title Название */
|
|
42
42
|
label?: string;
|
|
43
43
|
/** @title Описание */
|
|
@@ -45,6 +45,12 @@ export interface BenefitItemProps {
|
|
|
45
45
|
icon?: Picture;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* @title Цвет блока
|
|
50
|
+
* @enumNames ["Основная", "Второстепенная"]
|
|
51
|
+
*/
|
|
52
|
+
export type BenefitsBlockVersion = 'primary' | 'secondary';
|
|
53
|
+
|
|
48
54
|
/**
|
|
49
55
|
* @title Блок преимущества
|
|
50
56
|
*/
|
|
@@ -53,5 +59,7 @@ export type BenefitsBlockContent = TitleProps & {
|
|
|
53
59
|
* @title Список преимуществ
|
|
54
60
|
* @maxItems 6
|
|
55
61
|
*/
|
|
56
|
-
benefitList?:
|
|
62
|
+
benefitList?: BenefitBlockItemProps[];
|
|
63
|
+
/** @default primary */
|
|
64
|
+
benefitsBlockVersion?: BenefitsBlockVersion;
|
|
57
65
|
};
|
|
@@ -8,7 +8,7 @@ exports[`Blocks Accordion should render block "Accordion" without content 1`] =
|
|
|
8
8
|
|
|
9
9
|
exports[`Blocks BenefitsBlock should render block "BenefitsBlock" without content 1`] = `
|
|
10
10
|
<section
|
|
11
|
-
class="font-sans text-primary-text
|
|
11
|
+
class="font-sans text-primary-text p-12 flex flex-col items-center bg-white"
|
|
12
12
|
/>
|
|
13
13
|
`;
|
|
14
14
|
|
|
@@ -18,11 +18,16 @@ export async function transformContentPage(
|
|
|
18
18
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
19
19
|
return mapJSON<ContentPageDef>(JSON.parse(content), async (value: any, [key]) => {
|
|
20
20
|
const isMarkdown = typeof value === 'string' && key?.endsWith('__md');
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
if (isMarkdown) {
|
|
23
23
|
return await transformMarkdown(value);
|
|
24
|
-
} else if (isPicture) {
|
|
25
|
-
|
|
24
|
+
} else if (isPicture(value)) {
|
|
25
|
+
try {
|
|
26
|
+
return await transformPicture(pagePath, value, options);
|
|
27
|
+
} catch (ex) {
|
|
28
|
+
console.warn('Error while transforming picture on page: %s', pagePath);
|
|
29
|
+
console.error(ex);
|
|
30
|
+
}
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
return value;
|
|
@@ -34,3 +39,5 @@ const isLocalPath = (_: any): boolean => isString(_) && _.length < 512 && !isURL
|
|
|
34
39
|
const isString = (_: any): _ is string => Boolean(_ && typeof _ === 'string');
|
|
35
40
|
|
|
36
41
|
const isURL = (src: string) => ['data:', 'https:', 'http:'].some((proto) => src.startsWith(proto));
|
|
42
|
+
|
|
43
|
+
const isPicture = (_: any): _ is Picture => Boolean(_ && isLocalPath(_?.src));
|