generated from arvinxx/monorepo-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: 调整 props imageList 成 data, 并支持传入字符串
- Loading branch information
Showing
8 changed files
with
215 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* compact: true | ||
*/ | ||
import React from 'react'; | ||
import ImageGallery from '@arvinxu/image-gallery'; | ||
|
||
import { yml } from './yml'; | ||
|
||
const YAMLDemo = () => { | ||
return ( | ||
<div | ||
style={{ | ||
background: '#fafafa', | ||
padding: 24, | ||
}} | ||
> | ||
<ImageGallery data={yml} darkBackground={'black'} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default YAMLDemo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export const yml = ` | ||
素材列表: | ||
- 标题: 渐变色 Logo | ||
描述: 渐变色 | ||
链接: https://gw.alipayobjects.com/zos/antfincdn/LFmaI3%26OJh/logo.svg | ||
- 标题: 黑色 Logo | ||
描述: 亮色背景下使用 | ||
链接: https://gw.alipayobjects.com/zos/antfincdn/FEuGy%26pKf2/black-logo.svg | ||
- 标题: 黑色方形 Logo | ||
描述: 亮色背景下使用 | ||
链接: https://gw.alipayobjects.com/zos/antfincdn/iCZHoHFqZM/squre-black.svg | ||
- 标题: 白色方形 Logo | ||
描述: 亮色背景下使用 | ||
反色: true | ||
链接: https://gw.alipayobjects.com/zos/antfincdn/9IE%24pNh%26d3/squre-white.svg | ||
- 标题: 白色 Logo | ||
描述: 暗色背景下使用 | ||
反色: true | ||
padding: 12 | ||
反色背景色: black | ||
链接: https://gw.alipayobjects.com/zos/antfincdn/5qY87lPw9U/white-logo.svg | ||
- 标题: 白色 Logo | ||
描述: 暗色背景下使用 | ||
反色: true | ||
反色背景色: "#1fadd3" | ||
链接: https://gw.alipayobjects.com/zos/antfincdn/3vXiuFe18O/black-white.svg | ||
- 标题: 黑色 Logo | ||
描述: 亮色背景下使用 | ||
链接: https://gw.alipayobjects.com/zos/antfincdn/fmXECsJXUY/light.svg | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { YMLToJSON } from './yml'; | ||
|
||
describe('YML 数据转换', () => { | ||
it('正常转换', () => { | ||
const yml = ` | ||
素材列表: | ||
- 标题: 渐变色 Logo | ||
描述: 渐变色 | ||
链接: https://gw.alipayobjects.com/zos/antfincdn/LFmaI3%26OJh/logo.svg | ||
- 标题: 黑色 Logo | ||
描述: 亮色背景下使用 | ||
链接: https://gw.alipayobjects.com/zos/antfincdn/FEuGy%26pKf2/black-logo.svg | ||
- 标题: 黑色方形 Logo | ||
描述: 亮色背景下使用 | ||
链接: https://gw.alipayobjects.com/zos/antfincdn/iCZHoHFqZM/squre-black.svg | ||
- 标题: 白色方形 Logo | ||
描述: 亮色背景下使用 | ||
反色: true | ||
链接: https://gw.alipayobjects.com/zos/antfincdn/9IE%24pNh%26d3/squre-white.svg | ||
- 标题: 白色 Logo | ||
描述: 暗色背景下使用 | ||
反色: true | ||
padding: 12 | ||
反色背景色: black | ||
链接: https://gw.alipayobjects.com/zos/antfincdn/5qY87lPw9U/white-logo.svg | ||
- 标题: 白色 Logo | ||
描述: 暗色背景下使用 | ||
反色: true | ||
反色背景色: "#1fadd3" | ||
链接: https://gw.alipayobjects.com/zos/antfincdn/3vXiuFe18O/black-white.svg | ||
- 标题: 黑色 Logo | ||
描述: 亮色背景下使用 | ||
链接: https://gw.alipayobjects.com/zos/antfincdn/fmXECsJXUY/light.svg | ||
`; | ||
|
||
expect(YMLToJSON(yml)).toEqual({ | ||
data: [ | ||
{ | ||
description: '渐变色', | ||
title: '渐变色 Logo', | ||
url: 'https://gw.alipayobjects.com/zos/antfincdn/LFmaI3%26OJh/logo.svg', | ||
}, | ||
{ | ||
description: '亮色背景下使用', | ||
title: '黑色 Logo', | ||
url: 'https://gw.alipayobjects.com/zos/antfincdn/FEuGy%26pKf2/black-logo.svg', | ||
}, | ||
{ | ||
description: '亮色背景下使用', | ||
title: '黑色方形 Logo', | ||
url: 'https://gw.alipayobjects.com/zos/antfincdn/iCZHoHFqZM/squre-black.svg', | ||
}, | ||
{ | ||
dark: true, | ||
description: '亮色背景下使用', | ||
title: '白色方形 Logo', | ||
url: 'https://gw.alipayobjects.com/zos/antfincdn/9IE%24pNh%26d3/squre-white.svg', | ||
}, | ||
{ | ||
dark: true, | ||
darkBackground: 'black', | ||
description: '暗色背景下使用', | ||
padding: 12, | ||
title: '白色 Logo', | ||
url: 'https://gw.alipayobjects.com/zos/antfincdn/5qY87lPw9U/white-logo.svg', | ||
}, | ||
{ | ||
dark: true, | ||
darkBackground: '#1fadd3', | ||
description: '暗色背景下使用', | ||
title: '白色 Logo', | ||
url: 'https://gw.alipayobjects.com/zos/antfincdn/3vXiuFe18O/black-white.svg', | ||
}, | ||
{ | ||
description: '亮色背景下使用', | ||
title: '黑色 Logo', | ||
url: 'https://gw.alipayobjects.com/zos/antfincdn/fmXECsJXUY/light.svg', | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { load } from 'js-yaml'; | ||
import type { ImageGalleryData, ImageGalleryYML, ImageEntry } from '../types'; | ||
|
||
/** | ||
* YML 转 JSON | ||
* @param yml | ||
* @constructor | ||
*/ | ||
export const YMLToJSON = (yml: string): ImageGalleryData => { | ||
try { | ||
const { 素材列表 } = load(yml) as ImageGalleryYML; | ||
|
||
return { | ||
data: 素材列表.map( | ||
(item): ImageEntry => ({ | ||
title: item.标题, | ||
description: item.描述, | ||
dark: item.反色, | ||
padding: item.padding, | ||
url: item.链接, | ||
darkBackground: item.反色背景色, | ||
}), | ||
), | ||
}; | ||
} catch (e) { | ||
throw Error(`YML 不符合规范: \n${e}`); | ||
} | ||
}; |