2022-11-30 11:05:41 +08:00
/* eslint-disable react/jsx-pascal-case */
2022-12-11 20:39:46 +08:00
import React , { useContext } from 'react' ;
2023-07-28 16:17:43 +08:00
import dayjs from 'dayjs' ;
import { CustomerServiceOutlined , QuestionCircleOutlined , SyncOutlined } from '@ant-design/icons' ;
import { createStyles , css , useTheme } from 'antd-style' ;
import classNames from 'classnames' ;
2022-11-09 12:28:04 +08:00
import {
Space ,
Typography ,
Tour ,
Tag ,
DatePicker ,
Alert ,
Modal ,
FloatButton ,
Progress ,
2022-12-11 20:39:46 +08:00
Carousel ,
2022-11-09 12:28:04 +08:00
} from 'antd' ;
2022-11-17 23:15:27 +08:00
import useLocale from '../../../hooks/useLocale' ;
2022-12-19 11:42:41 +08:00
import SiteContext from '../../../theme/slots/SiteContext' ;
2023-07-20 19:27:33 +08:00
import { getCarouselStyle } from './util' ;
2022-11-09 12:28:04 +08:00
2022-11-17 23:15:27 +08:00
const SAMPLE_CONTENT_EN =
2022-11-09 12:28:04 +08:00
'Ant Design 5.0 use CSS-in-JS technology to provide dynamic & mix theme ability. And which use component level CSS-in-JS solution get your application a better performance.' ;
2022-11-17 23:15:27 +08:00
const SAMPLE_CONTENT_CN =
'Ant Design 5.0 使用 CSS-in-JS 技术以提供动态与混合主题的能力。与此同时,我们使用组件级别的 CSS-in-JS 解决方案,让你的应用获得更好的性能。' ;
2022-11-09 12:28:04 +08:00
2022-11-17 23:15:27 +08:00
const locales = {
cn : {
yesterday : '昨天' ,
lastWeek : '上周' ,
lastMonth : '上月' ,
lastYear : '去年' ,
new : '新增' ,
update : '更新' ,
sampleContent : SAMPLE_CONTENT_CN ,
inProgress : '进行中' ,
success : '成功' ,
taskFailed : '任务失败' ,
tour : '漫游导览帮助用户对新加的功能进行快速了解' ,
2022-11-09 12:28:04 +08:00
} ,
2022-11-17 23:15:27 +08:00
en : {
yesterday : 'Yesterday' ,
lastWeek : 'Last Week' ,
lastMonth : 'Last Month' ,
lastYear : 'Last Year' ,
new : 'New' ,
update : 'Update' ,
sampleContent : SAMPLE_CONTENT_EN ,
inProgress : 'In Progress' ,
success : 'Success' ,
taskFailed : 'Task Failed' ,
tour : 'A quick guide for new come user about how to use app.' ,
2022-11-09 12:28:04 +08:00
} ,
2022-11-17 23:15:27 +08:00
} ;
2022-11-09 12:28:04 +08:00
2023-07-20 19:27:33 +08:00
const useStyle = createStyles ( ( { token } ) = > {
const { carousel } = getCarouselStyle ( ) ;
2022-11-09 12:28:04 +08:00
return {
card : css `
border - radius : $ { token . borderRadius } px ;
background : # f5f8ff ;
padding : $ { token . paddingXL } px ;
flex : none ;
overflow : hidden ;
position : relative ;
display : flex ;
flex - direction : column ;
align - items : stretch ;
> * {
flex : none ;
}
` ,
cardCircle : css `
position : absolute ;
width : 120px ;
height : 120px ;
background : # 1677 ff ;
border - radius : 50 % ;
filter : blur ( 40 px ) ;
opacity : 0.1 ;
` ,
2022-12-11 20:39:46 +08:00
mobileCard : css `
height : 395px ;
` ,
carousel ,
2022-11-09 12:28:04 +08:00
} ;
2023-07-20 19:27:33 +08:00
} ) ;
2022-11-09 12:28:04 +08:00
2022-12-11 20:39:46 +08:00
interface ComponentItemProps {
title : React.ReactNode ;
node : React.ReactNode ;
type : 'new' | 'update' ;
index : number ;
}
2022-11-09 12:28:04 +08:00
export default function ComponentsList() {
2023-07-20 19:27:33 +08:00
const token = useTheme ( ) ;
const { styles } = useStyle ( ) ;
2022-11-17 23:15:27 +08:00
const [ locale ] = useLocale ( locales ) ;
2022-12-11 20:39:46 +08:00
const { isMobile } = useContext ( SiteContext ) ;
2022-11-17 23:15:27 +08:00
const COMPONENTS : {
title : React.ReactNode ;
type : 'new' | 'update' ;
node : React.ReactNode ;
} [ ] = React . useMemo (
( ) = > [
{
title : 'Modal' ,
type : 'update' ,
node : (
< Modal._InternalPanelDoNotUseOrYouWillBeFired title = "Ant Design 5.0" width = { 300 } >
{ locale . sampleContent }
< / Modal._InternalPanelDoNotUseOrYouWillBeFired >
) ,
} ,
{
title : 'DatePicker' ,
type : 'update' ,
node : (
< DatePicker._InternalPanelDoNotUseOrYouWillBeFired
showToday = { false }
2022-12-11 20:39:46 +08:00
presets = {
isMobile
? [ ]
: [
{ label : locale.yesterday , value : dayjs ( ) . add ( - 1 , 'd' ) } ,
{ label : locale.lastWeek , value : dayjs ( ) . add ( - 7 , 'd' ) } ,
{ label : locale.lastMonth , value : dayjs ( ) . add ( - 1 , 'month' ) } ,
{ label : locale.lastYear , value : dayjs ( ) . add ( - 1 , 'year' ) } ,
]
}
2022-11-17 23:15:27 +08:00
value = { dayjs ( '2022-11-18 14:00:00' ) }
/ >
) ,
} ,
{
title : 'Progress' ,
type : 'update' ,
node : (
< Space direction = "vertical" >
< Space >
2023-03-14 22:01:15 +08:00
< Progress type = "circle" trailColor = "#e6f4ff" percent = { 60 } size = { 14 } / >
2022-11-17 23:15:27 +08:00
{ locale . inProgress }
< / Space >
< Space >
2023-03-14 22:01:15 +08:00
< Progress type = "circle" percent = { 100 } size = { 14 } / >
2022-11-17 23:15:27 +08:00
{ locale . success }
< / Space >
< Space >
2023-03-14 22:01:15 +08:00
< Progress type = "circle" status = "exception" percent = { 88 } size = { 14 } / >
2022-11-17 23:15:27 +08:00
{ locale . taskFailed }
< / Space >
< / Space >
) ,
} ,
{
title : 'Tour' ,
type : 'new' ,
node : (
< Tour._InternalPanelDoNotUseOrYouWillBeFired
title = "Ant Design 5.0"
description = { locale . tour }
2022-12-11 20:39:46 +08:00
style = { { width : isMobile ? 'auto' : 350 } }
2022-11-17 23:15:27 +08:00
current = { 3 }
total = { 9 }
/ >
) ,
} ,
{
title : 'FloatButton' ,
type : 'new' ,
node : (
< Space size = "large" >
< FloatButton._InternalPanelDoNotUseOrYouWillBeFired
shape = "square"
items = { [
{
icon : < QuestionCircleOutlined / > ,
} ,
{
icon : < CustomerServiceOutlined / > ,
} ,
{
icon : < SyncOutlined / > ,
} ,
] }
/ >
< FloatButton._InternalPanelDoNotUseOrYouWillBeFired backTop / >
< FloatButton._InternalPanelDoNotUseOrYouWillBeFired
items = { [
{
icon : < QuestionCircleOutlined / > ,
} ,
{
icon : < CustomerServiceOutlined / > ,
} ,
{
icon : < SyncOutlined / > ,
} ,
] }
/ >
< / Space >
) ,
} ,
// {
// title: 'Steps',
// type: 'update',
// node: <Button style={{ width: PLACEHOLDER_WIDTH }}>Placeholder</Button>,
// },
{
title : 'Alert' ,
type : 'update' ,
node : (
< Alert
style = { { width : 400 } }
message = "Ant Design 5.0"
description = { locale . sampleContent }
closable
/ >
) ,
} ,
] ,
2022-12-11 20:39:46 +08:00
[ isMobile ] ,
2022-11-17 23:15:27 +08:00
) ;
2022-11-09 12:28:04 +08:00
2023-07-30 19:16:30 +08:00
const ComponentItem : React.FC < ComponentItemProps > = ( { title , node , type , index } ) = > {
2022-12-11 20:39:46 +08:00
const tagColor = type === 'new' ? 'processing' : 'warning' ;
const tagText = type === 'new' ? locale.new : locale.update ;
2022-11-09 12:28:04 +08:00
2022-12-11 20:39:46 +08:00
return (
2023-07-20 19:27:33 +08:00
< div key = { index } className = { classNames ( styles . card , isMobile && styles . mobileCard ) } >
2022-12-11 20:39:46 +08:00
{ /* Decorator */ }
< div
2023-07-20 19:27:33 +08:00
className = { styles . cardCircle }
2022-12-11 20:39:46 +08:00
style = { {
right : ( index % 2 ) * - 20 - 20 ,
bottom : ( index % 3 ) * - 40 - 20 ,
} }
/ >
2022-11-09 12:28:04 +08:00
2022-12-11 20:39:46 +08:00
{ /* Title */ }
< Space >
< Typography.Title level = { 4 } style = { { fontWeight : 'normal' , margin : 0 } } >
{ title }
< / Typography.Title >
< Tag color = { tagColor } > { tagText } < / Tag >
< / Space >
2022-11-09 12:28:04 +08:00
2022-12-11 20:39:46 +08:00
< div
style = { {
marginTop : token.paddingLG ,
flex : 'auto' ,
display : 'flex' ,
alignItems : 'center' ,
justifyContent : 'center' ,
} }
>
{ node }
< / div >
< / div >
) ;
} ;
return isMobile ? (
< div style = { { margin : '0 16px' } } >
2023-07-20 19:27:33 +08:00
< Carousel className = { styles . carousel } >
2022-12-11 20:39:46 +08:00
{ COMPONENTS . map ( ( { title , node , type } , index ) = > (
< ComponentItem title = { title } node = { node } type = { type } index = { index } key = { index } / >
) ) }
< / Carousel >
< / div >
) : (
< div style = { { width : '100%' , overflow : 'hidden' , display : 'flex' , justifyContent : 'center' } } >
< div style = { { display : 'flex' , alignItems : 'stretch' , columnGap : token.paddingLG } } >
{ COMPONENTS . map ( ( { title , node , type } , index ) = > (
< ComponentItem title = { title } node = { node } type = { type } index = { index } key = { index } / >
) ) }
2022-11-09 12:28:04 +08:00
< / div >
< / div >
) ;
}