Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adjust the order of QRCode style prop #48053

Merged
merged 3 commits into from Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -211,7 +211,7 @@ exports[`renders components/qr-code/demo/download.tsx extend context correctly 1
>
<div
class="ant-qrcode"
style="margin-bottom: 16px; width: 160px; height: 160px; background-color: rgb(255, 255, 255);"
style="width: 160px; height: 160px; background-color: rgb(255, 255, 255); margin-bottom: 16px;"
>
<canvas
height="160"
Expand All @@ -235,7 +235,7 @@ exports[`renders components/qr-code/demo/errorlevel.tsx extend context correctly
Array [
<div
class="ant-qrcode"
style="margin-bottom: 16px; width: 160px; height: 160px; background-color: transparent;"
style="width: 160px; height: 160px; background-color: transparent; margin-bottom: 16px;"
>
<canvas
height="160"
Expand Down
4 changes: 2 additions & 2 deletions components/qr-code/__tests__/__snapshots__/demo.test.ts.snap
Expand Up @@ -169,7 +169,7 @@ exports[`renders components/qr-code/demo/download.tsx correctly 1`] = `
>
<div
class="ant-qrcode"
style="margin-bottom:16px;width:160px;height:160px;background-color:#fff"
style="width:160px;height:160px;background-color:#fff;margin-bottom:16px"
>
<canvas
height="160"
Expand All @@ -191,7 +191,7 @@ exports[`renders components/qr-code/demo/errorlevel.tsx correctly 1`] = `
Array [
<div
class="ant-qrcode"
style="margin-bottom:16px;width:160px;height:160px;background-color:transparent"
style="width:160px;height:160px;background-color:transparent;margin-bottom:16px"
>
<canvas
height="160"
Expand Down
17 changes: 10 additions & 7 deletions components/qr-code/demo/customSize.tsx
@@ -1,15 +1,18 @@
import React, { useState } from 'react';
import { MinusOutlined, PlusOutlined } from '@ant-design/icons';
import { QRCode, Button } from 'antd';
import { Button, QRCode } from 'antd';

const MIN_SIZE = 48;
const MAX_SIZE = 300;

const App: React.FC = () => {
const [size, setSize] = useState<number>(160);

const increase = () => {
setSize((prevSize) => {
const newSize = prevSize + 10;
if (newSize > 300) {
return 300;
if (newSize >= MAX_SIZE) {
return MAX_SIZE;
}
return newSize;
});
Expand All @@ -18,8 +21,8 @@ const App: React.FC = () => {
const decline = () => {
setSize((prevSize) => {
const newSize = prevSize - 10;
if (newSize < 48) {
return 48;
if (newSize <= MIN_SIZE) {
return MIN_SIZE;
}
return newSize;
});
Expand All @@ -28,10 +31,10 @@ const App: React.FC = () => {
return (
<>
<Button.Group style={{ marginBottom: 16 }}>
<Button onClick={decline} disabled={size <= 48} icon={<MinusOutlined />}>
<Button onClick={decline} disabled={size <= MIN_SIZE} icon={<MinusOutlined />}>
Smaller
</Button>
<Button onClick={increase} disabled={size >= 300} icon={<PlusOutlined />}>
<Button onClick={increase} disabled={size >= MAX_SIZE} icon={<PlusOutlined />}>
Larger
</Button>
</Button.Group>
Expand Down
12 changes: 8 additions & 4 deletions components/qr-code/index.tsx
Expand Up @@ -78,11 +78,15 @@ const QRCode: React.FC<QRCodeProps> = (props) => {
[`${prefixCls}-borderless`]: !bordered,
});

const mergedStyle: React.CSSProperties = {
width: size,
height: size,
backgroundColor: bgColor,
...style,
};

return wrapCSSVar(
<div
className={mergedCls}
style={{ ...style, width: size, height: size, backgroundColor: bgColor }}
>
<div className={mergedCls} style={mergedStyle}>
{status !== 'active' && (
<div className={`${prefixCls}-mask`}>
{status === 'loading' && <Spin />}
Expand Down