diff --git a/site/mobile/mobile.config.js b/site/mobile/mobile.config.js index 95d205af..147a1406 100644 --- a/site/mobile/mobile.config.js +++ b/site/mobile/mobile.config.js @@ -212,5 +212,10 @@ export default { name: 'notice-bar', component: () => import('tdesign-mobile-react/notice-bar/_example/mobile.jsx'), }, + { + title: 'Result 结果', + name: 'result', + component: () => import('tdesign-mobile-react/result/_example/index.tsx'), + } ], }; diff --git a/site/web/site.config.js b/site/web/site.config.js index 928e5823..4ede83ce 100644 --- a/site/web/site.config.js +++ b/site/web/site.config.js @@ -251,6 +251,12 @@ export default { // path: '/mobile-react/components/image-viewer', // component: () => import('tdesign-mobile-react/image-viewer/image-viewer.md'), // }, + { + title: 'Result 结果', + name: 'result', + path: '/mobile-react/components/result', + component: () => import('tdesign-mobile-react/result/result.md'), + }, { title: 'Skeleton 骨架屏', name: 'skeleton', diff --git a/src/index.ts b/src/index.ts index 8688946d..84e6ed45 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,6 +45,7 @@ export * from './sticky'; export * from './swiper'; export * from './swipe-cell'; export * from './tag'; +export * from './result'; /** * 消息提醒(7个) diff --git a/src/result/Result.tsx b/src/result/Result.tsx new file mode 100644 index 00000000..bb8235d3 --- /dev/null +++ b/src/result/Result.tsx @@ -0,0 +1,68 @@ +import React from 'react'; +import classNames from 'classnames'; +import { InfoCircleIcon, CheckCircleIcon, CloseCircleIcon } from 'tdesign-icons-react'; +import { TdResultProps } from './type'; +import { resultDefaultProps } from './defaultProps'; +import withNativeProps, { NativeProps } from '../_util/withNativeProps'; +import useConfig from '../_util/useConfig'; +import useDefaultProps from '../hooks/useDefaultProps'; + +export interface ResultProps extends TdResultProps, NativeProps { +} + +const Result: React.FC = (props) => { + const { description, image, theme, title } = useDefaultProps(props, resultDefaultProps); + const { classPrefix } = useConfig(); + const rootClassName = `${classPrefix}-result`; + const resultClassName = classNames(rootClassName, `${rootClassName}--theme-${theme || 'default'}`); + + const renderIcon = () => { + const defaultIcons = { + default: InfoCircleIcon, + success: CheckCircleIcon, + warning: InfoCircleIcon, + error: CloseCircleIcon, + }; + const RenderIcon = defaultIcons[theme]; + return RenderIcon ? : null; + }; + const renderImage = () => { + if (!image) { + return null; + } + if (typeof image === 'string') { + return ; + } + return image; + }; + + const renderThumb = () => { + const image = renderImage(); + const icon = renderIcon(); + return
{image || icon}
; + }; + + const renderTitle = () => { + if (!title) { + return null; + } + return
{title}
; + }; + + const renderDescription = () => { + if (!description) { + return null; + } + return
{description}
; + }; + return withNativeProps( + props, +
+ {renderThumb()} + {renderTitle()} + {renderDescription()} +
, + ); +}; +Result.displayName = 'Result'; +export default Result; diff --git a/src/result/_example/custom.tsx b/src/result/_example/custom.tsx new file mode 100644 index 00000000..4ba91ca5 --- /dev/null +++ b/src/result/_example/custom.tsx @@ -0,0 +1,13 @@ +import React from 'react'; +import { Image, Result } from 'tdesign-mobile-react'; +import './style/index.less'; + +export default function CustomResult() { + return ( + } + title="自定义结果" + description="描述文字" + /> + ); +} diff --git a/src/result/_example/index.tsx b/src/result/_example/index.tsx new file mode 100644 index 00000000..5e648b09 --- /dev/null +++ b/src/result/_example/index.tsx @@ -0,0 +1,44 @@ +import React, { useState } from 'react'; +import { Button, Result } from 'tdesign-mobile-react'; +import TDemoHeader from '../../../site/mobile/components/DemoHeader'; +import TDemoBlock from '../../../site/mobile/components/DemoBlock'; +import CustomResult from './custom'; +import ThemeResult from './theme'; +import './style/index.less'; + +export default function ResultDemo() { + const [showResultPage, setShowResultPage] = useState(false); + return ( + <> + {!showResultPage ? ( +
+ + + + + + + + +
+ +
+
+
+ ) : ( +
+
+ +
+
+ +
+
+ )} + + ); +} diff --git a/src/result/_example/style/index.less b/src/result/_example/style/index.less new file mode 100644 index 00000000..030f504f --- /dev/null +++ b/src/result/_example/style/index.less @@ -0,0 +1,24 @@ +.extra-class-image { + width: 108px; +} + +.space { + margin-bottom: 48px; +} + +.tdesign-mobile-demo { + background-color: var(--bg-color-demo, #fff); + + .padding { + padding: 0 16px 16px; + } +} + +.result-page { + height: calc(100vh - 50px); + background-color: var(--bg-color-demo, #fff); + + .demo-section__wrapper { + padding: 24px 16px; + } +} diff --git a/src/result/_example/theme.tsx b/src/result/_example/theme.tsx new file mode 100644 index 00000000..715a3908 --- /dev/null +++ b/src/result/_example/theme.tsx @@ -0,0 +1,41 @@ +import React from 'react'; +import { Result, ResultProps } from 'tdesign-mobile-react'; +import './style/index.less'; + +export default function ThemeResult() { + const resultList: Array = [ + { + title: '成功状态', + theme: 'success', + description: '描述文字', + }, + { + title: '失败状态', + theme: 'error', + description: '描述文字', + }, + { + title: '警示状态', + theme: 'warning', + description: '描述文字', + }, + { + title: '默认状态', + theme: 'default', + description: '描述文字', + }, + ]; + return ( +
+ {resultList.map((resultInfo) => ( + + ))} +
+ ); +} diff --git a/src/result/defaultProps.ts b/src/result/defaultProps.ts new file mode 100644 index 00000000..54947583 --- /dev/null +++ b/src/result/defaultProps.ts @@ -0,0 +1,7 @@ +/** + * 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC + * */ + +import { TdResultProps } from './type'; + +export const resultDefaultProps: TdResultProps = { theme: 'default', title: '' }; diff --git a/src/result/index.ts b/src/result/index.ts new file mode 100644 index 00000000..35b31092 --- /dev/null +++ b/src/result/index.ts @@ -0,0 +1,8 @@ +import _Result from './Result'; +import './style/index.js'; + +export type { ResultProps } from './Result'; +export * from './type'; + +export const Result = _Result; +export default Result; diff --git a/src/result/result.en-US.md b/src/result/result.en-US.md new file mode 100644 index 00000000..5f794397 --- /dev/null +++ b/src/result/result.en-US.md @@ -0,0 +1,15 @@ +:: BASE_DOC :: + +## API + + +### Result Props + +name | type | default | description | required +-- | -- | -- | -- | -- +className | String | - | className of component | N +style | Object | - | CSS(Cascading Style Sheets),Typescript:`React.CSSProperties` | N +description | TNode | - | Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-react/blob/develop/src/common.ts) | N +image | TNode | - | Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-react/blob/develop/src/common.ts) | N +theme | String | default | options: default/success/warning/error | N +title | TNode | '' | Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-react/blob/develop/src/common.ts) | N diff --git a/src/result/result.md b/src/result/result.md new file mode 100644 index 00000000..a04ca97b --- /dev/null +++ b/src/result/result.md @@ -0,0 +1,15 @@ +:: BASE_DOC :: + +## API + + +### Result Props + +名称 | 类型 | 默认值 | 描述 | 必传 +-- | -- | -- | -- | -- +className | String | - | 类名 | N +style | Object | - | 样式,TS 类型:`React.CSSProperties` | N +description | TNode | - | 描述文字。TS 类型:`string \| TNode`。[通用类型定义](https://github.com/Tencent/tdesign-mobile-react/blob/develop/src/common.ts) | N +image | TNode | - | 图片地址。TS 类型:`string \| TNode`。[通用类型定义](https://github.com/Tencent/tdesign-mobile-react/blob/develop/src/common.ts) | N +theme | String | default | 内置主题。可选项:default/success/warning/error | N +title | TNode | '' | 标题。TS 类型:`string \| TNode`。[通用类型定义](https://github.com/Tencent/tdesign-mobile-react/blob/develop/src/common.ts) | N diff --git a/src/result/style/css.js b/src/result/style/css.js new file mode 100644 index 00000000..6a9a4b13 --- /dev/null +++ b/src/result/style/css.js @@ -0,0 +1 @@ +import './index.css'; diff --git a/src/result/style/index.js b/src/result/style/index.js new file mode 100644 index 00000000..6102c35f --- /dev/null +++ b/src/result/style/index.js @@ -0,0 +1 @@ +import '../../_common/style/mobile/components/result/v2/_index.less'; diff --git a/src/result/type.ts b/src/result/type.ts new file mode 100644 index 00000000..8e0de125 --- /dev/null +++ b/src/result/type.ts @@ -0,0 +1,28 @@ +/* eslint-disable */ + +/** + * 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC + * */ + +import { TNode } from '../common'; + +export interface TdResultProps { + /** + * 描述文字 + */ + description?: TNode; + /** + * 图片地址 + */ + image?: TNode; + /** + * 内置主题 + * @default default + */ + theme?: 'default' | 'success' | 'warning' | 'error'; + /** + * 标题 + * @default '' + */ + title?: TNode; +} diff --git a/test/snap/__snapshots__/csr.test.jsx.snap b/test/snap/__snapshots__/csr.test.jsx.snap index 0eef74d0..cf509620 100644 --- a/test/snap/__snapshots__/csr.test.jsx.snap +++ b/test/snap/__snapshots__/csr.test.jsx.snap @@ -1923,6 +1923,492 @@ exports[`csr snapshot test > csr test src/progress/_example/transition.tsx 1`] = `; +exports[`csr snapshot test > csr test src/result/_example/custom.tsx 1`] = ` +
+
+
+
+
+ + + +
+ +
+
+
+ 自定义结果 +
+
+ 描述文字 +
+
+
+`; + +exports[`csr snapshot test > csr test src/result/_example/index.tsx 1`] = ` +
+
+
+

+ Result 结果 +

+

+ 结果反馈 +

+
+
+
+

+ 01类型 +

+

+ 不同结果反馈 +

+
+
+
+
+
+ + + + +
+
+ 成功状态 +
+
+ 描述文字 +
+
+
+
+ + + + +
+
+ 失败状态 +
+
+ 描述文字 +
+
+
+
+ + + + +
+
+ 警示状态 +
+
+ 描述文字 +
+
+
+
+ + + + +
+
+ 默认状态 +
+
+ 描述文字 +
+
+
+
+
+
+
+ +

+ 自定义结果 +

+
+
+
+
+
+
+ + + +
+ +
+
+
+ 自定义结果 +
+
+ 描述文字 +
+
+
+
+
+
+ +

+ 页面位置展示 +

+
+
+
+ +
+
+
+
+
+`; + +exports[`csr snapshot test > csr test src/result/_example/theme.tsx 1`] = ` +
+
+
+
+ + + + +
+
+ 成功状态 +
+
+ 描述文字 +
+
+
+
+ + + + +
+
+ 失败状态 +
+
+ 描述文字 +
+
+
+
+ + + + +
+
+ 警示状态 +
+
+ 描述文字 +
+
+
+
+ + + + +
+
+ 默认状态 +
+
+ 描述文字 +
+
+
+
+`; + exports[`ssr snapshot test > ssr test src/divider/_example/base.tsx 1`] = `"
水平分割线
带文字水平分割线
垂直分割线
文字信息文字信息文字信息
"`; exports[`ssr snapshot test > ssr test src/divider/_example/index.tsx 1`] = `"

Divider 分割符

用于分割、组织、细化有一定逻辑的组织元素内容和页面结构。

01 组件类型

水平分割线
带文字水平分割线
垂直分割线
文字信息文字信息文字信息

02 组件状态

虚线样式
"`; @@ -1944,3 +2430,9 @@ exports[`ssr snapshot test > ssr test src/progress/_example/line.tsx 1`] = `" ssr test src/progress/_example/plump.tsx 1`] = `"
80%
88%
88%
88%
"`; exports[`ssr snapshot test > ssr test src/progress/_example/transition.tsx 1`] = `"
88%
"`; + +exports[`ssr snapshot test > ssr test src/result/_example/custom.tsx 1`] = `"
自定义结果
描述文字
"`; + +exports[`ssr snapshot test > ssr test src/result/_example/index.tsx 1`] = `"

Result 结果

结果反馈

01类型

不同结果反馈

成功状态
描述文字
失败状态
描述文字
警示状态
描述文字
默认状态
描述文字

自定义结果

自定义结果
描述文字

页面位置展示

"`; + +exports[`ssr snapshot test > ssr test src/result/_example/theme.tsx 1`] = `"
成功状态
描述文字
失败状态
描述文字
警示状态
描述文字
默认状态
描述文字
"`; diff --git a/test/snap/__snapshots__/ssr.test.jsx.snap b/test/snap/__snapshots__/ssr.test.jsx.snap index df22fc63..e50fd44d 100644 --- a/test/snap/__snapshots__/ssr.test.jsx.snap +++ b/test/snap/__snapshots__/ssr.test.jsx.snap @@ -21,3 +21,9 @@ exports[`ssr snapshot test > ssr test src/progress/_example/line.tsx 1`] = `" ssr test src/progress/_example/plump.tsx 1`] = `"
80%
88%
88%
88%
"`; exports[`ssr snapshot test > ssr test src/progress/_example/transition.tsx 1`] = `"
88%
"`; + +exports[`ssr snapshot test > ssr test src/result/_example/custom.tsx 1`] = `"
自定义结果
描述文字
"`; + +exports[`ssr snapshot test > ssr test src/result/_example/index.tsx 1`] = `"

Result 结果

结果反馈

01类型

不同结果反馈

成功状态
描述文字
失败状态
描述文字
警示状态
描述文字
默认状态
描述文字

自定义结果

自定义结果
描述文字

页面位置展示

"`; + +exports[`ssr snapshot test > ssr test src/result/_example/theme.tsx 1`] = `"
成功状态
描述文字
失败状态
描述文字
警示状态
描述文字
默认状态
描述文字
"`;