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.
- Loading branch information
Showing
9 changed files
with
301 additions
and
73 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 |
---|---|---|
@@ -1,5 +1,10 @@ | ||
export const sketch = ` | ||
- 名称: 矩形 | ||
- 标题: 矩形 | ||
sketch: https://gw.alipayobjects.com/os/kitchen/oLQZFZVkmdvqpKRQDCuU.json | ||
链接: https://gw.alipayobjects.com/zos/antfincdn/G5sZluNGGA/25c4fe16-7d52-4b32-904e-3eccb4a1ff47.png | ||
- 标题: 卡片组件 | ||
sketch: https://gw.alipayobjects.com/os/kitchen/IiFvADxdyqKABLzWKZWT.json | ||
描述: 一个 C2D 组件 | ||
链接: https://gw.alipayobjects.com/zos/antfincdn/KGTSum12Re/qiapianzujian.png | ||
`; |
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 type { FC } from 'react'; | ||
import React from 'react'; | ||
import useMergeValue from 'use-merge-value'; | ||
|
||
import Layout from './Layout'; | ||
|
||
import AssetCard from './AssetCard'; | ||
|
||
import { YMLToJSON } from './utils/yml'; | ||
import type { AssetList } from './types'; | ||
import './style.less'; | ||
|
||
export interface AssetGalleryProps { | ||
/** | ||
* 图片清单 | ||
*/ | ||
data: AssetList | string; | ||
/** | ||
* 暗色背景下默认的背景色 | ||
* @default #1890ff | ||
*/ | ||
darkBackground?: string; | ||
/** | ||
* 使用的布局方式: 瀑布流与网格 | ||
* @default masonry | ||
*/ | ||
layout?: 'masonry' | 'grid'; | ||
|
||
/** | ||
* 配置网格 | ||
*/ | ||
grid?: { | ||
/** | ||
* 列数 | ||
*/ | ||
columns?: number; | ||
/** | ||
* 显示滑杆 | ||
*/ | ||
showSlider?: boolean; | ||
}; | ||
} | ||
|
||
const AssetGallery: FC<AssetGalleryProps> = ({ | ||
data, | ||
darkBackground, | ||
layout = 'masonry', | ||
grid = { columns: 1, showSlider: true }, | ||
}) => { | ||
const imageList = typeof data === 'string' ? YMLToJSON(data).data : data; | ||
|
||
const [columns, setColumn] = useMergeValue(grid.columns); | ||
|
||
return ( | ||
<Layout | ||
layout={layout} | ||
grid={{ columns, setColumn, showSlider: grid.showSlider }} | ||
> | ||
{imageList.map((item, index) => { | ||
const { description, padding, url, title, dark, sketch } = item; | ||
|
||
const backgroundColor = | ||
item.darkBackground || darkBackground || '#1890ff'; | ||
|
||
return ( | ||
<AssetCard | ||
key={index} | ||
padding={padding} | ||
url={url} | ||
dark={dark} | ||
darkBackground={backgroundColor} | ||
title={title} | ||
description={description} | ||
sketch={sketch} | ||
/> | ||
); | ||
})} | ||
<canvas id="canvas" style={{ display: 'none' }} /> | ||
</Layout> | ||
); | ||
}; | ||
|
||
export default AssetGallery; |
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,44 @@ | ||
import type { FC } from 'react'; | ||
import React from 'react'; | ||
import { Columns } from '@bedrock-layout/columns'; | ||
import { Inline } from '@bedrock-layout/inline'; | ||
import { Slider } from 'antd'; | ||
|
||
interface LayoutProps { | ||
layout?: 'grid' | 'masonry'; | ||
grid?: { | ||
columns?: number; | ||
setColumn?: (value: number) => void; | ||
showSlider?: boolean; | ||
}; | ||
} | ||
|
||
const Layout: FC<LayoutProps> = ({ children, layout, grid }) => { | ||
if (layout === 'grid') { | ||
const { columns, setColumn } = grid; | ||
return ( | ||
<div> | ||
<Inline justify={'end'} style={{ paddingRight: 8 }}> | ||
<Slider | ||
style={{ width: 100 }} | ||
value={-columns} | ||
tooltipVisible={false} | ||
onChange={(v) => setColumn(-v)} | ||
max={-1} | ||
min={-4} | ||
/> | ||
</Inline> | ||
<Columns columns={columns}>{children}</Columns> | ||
</div> | ||
); | ||
} | ||
|
||
if (layout === 'masonry') | ||
return ( | ||
<div className={'avx-image-gallery-container avx-image-gallery-masonry'}> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Layout; |
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 |
---|---|---|
@@ -1,61 +1,5 @@ | ||
import type { FC } from 'react'; | ||
import React from 'react'; | ||
import AssetCard from './AssetCard'; | ||
|
||
import './style.less'; | ||
import type { AssetList } from './types'; | ||
import { YMLToJSON } from './utils/yml'; | ||
import AssetGallery from './AssetGallery'; | ||
|
||
export * from './types'; | ||
|
||
export interface AssetGalleryProps { | ||
/** | ||
* 图片清单 | ||
*/ | ||
data: AssetList | string; | ||
/** | ||
* 暗色背景下默认的背景色 | ||
* @default #1890ff | ||
*/ | ||
darkBackground?: string; | ||
/** | ||
* 使用的布局方式: 瀑布流与网格 | ||
* @default masonry | ||
*/ | ||
layout?: 'masonry' | 'grid'; | ||
} | ||
|
||
const AssetGallery: FC<AssetGalleryProps> = ({ | ||
data, | ||
darkBackground, | ||
layout = 'masonry', | ||
}) => { | ||
const imageList = typeof data === 'string' ? YMLToJSON(data).data : data; | ||
|
||
return ( | ||
<div className={`avx-image-gallery-container avx-image-gallery-${layout}`}> | ||
{imageList.map((item, index) => { | ||
const { description, padding, url, title, dark, sketch } = item; | ||
|
||
const backgroundColor = | ||
item.darkBackground || darkBackground || '#1890ff'; | ||
|
||
return ( | ||
<AssetCard | ||
key={index} | ||
padding={padding} | ||
url={url} | ||
dark={dark} | ||
darkBackground={backgroundColor} | ||
title={title} | ||
description={description} | ||
sketch={sketch} | ||
/> | ||
); | ||
})} | ||
<canvas id="canvas" style={{ display: 'none' }} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default AssetGallery; |
Oops, something went wrong.