mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-22 14:44:47 +08:00
3851af9607
* feat: support custom status render in qrcode * feat: support custom status render in qrcode * feat: add test case * fix: code review * fix: code review * fix: code review * fix: code review * feat: optimize code * feat: optimize code * Update components/qr-code/index.zh-CN.md Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: kiner-tang <1127031143@qq.com> * Update components/qr-code/index.en-US.md Co-authored-by: lijianan <574980606@qq.com> Signed-off-by: kiner-tang <1127031143@qq.com> * feat: opt code Signed-off-by: kiner-tang <1127031143@qq.com> * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * Update components/qr-code/index.en-US.md Signed-off-by: kiner-tang <1127031143@qq.com> * Update components/qr-code/index.zh-CN.md Signed-off-by: kiner-tang <1127031143@qq.com> --------- Signed-off-by: kiner-tang <1127031143@qq.com> Co-authored-by: lijianan <574980606@qq.com>
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import React from 'react';
|
|
import { ReloadOutlined } from '@ant-design/icons';
|
|
|
|
import Button from '../button';
|
|
import type { Locale } from '../locale';
|
|
import Spin from '../spin';
|
|
import type { QRCodeProps, StatusRenderInfo } from './interface';
|
|
|
|
export type QRcodeStatusProps = {
|
|
prefixCls: string;
|
|
locale?: Locale['QRCode'];
|
|
onRefresh?: QRCodeProps['onRefresh'];
|
|
statusRender?: QRCodeProps['statusRender'];
|
|
status: StatusRenderInfo['status'];
|
|
};
|
|
|
|
const defaultSpin = <Spin />;
|
|
|
|
export default function QRcodeStatus({
|
|
prefixCls,
|
|
locale,
|
|
onRefresh,
|
|
statusRender,
|
|
status,
|
|
}: QRcodeStatusProps) {
|
|
const defaultExpiredNode = (
|
|
<>
|
|
<p className={`${prefixCls}-expired`}>{locale?.expired}</p>
|
|
{onRefresh && (
|
|
<Button type="link" icon={<ReloadOutlined />} onClick={onRefresh}>
|
|
{locale?.refresh}
|
|
</Button>
|
|
)}
|
|
</>
|
|
);
|
|
|
|
const defaultScannedNode = <p className={`${prefixCls}-scanned`}>{locale?.scanned}</p>;
|
|
|
|
const defaultNodes = {
|
|
expired: defaultExpiredNode,
|
|
loading: defaultSpin,
|
|
scanned: defaultScannedNode,
|
|
};
|
|
|
|
const defaultStatusRender: QRCodeProps['statusRender'] = (info) => defaultNodes[info.status];
|
|
|
|
const mergedStatusRender = statusRender ?? defaultStatusRender;
|
|
|
|
return mergedStatusRender({
|
|
status,
|
|
locale,
|
|
});
|
|
}
|