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

feat(qrcode): publish version 3.0 #438

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"rax-types": "^1.0.0",
"semver": "^6.3.0",
"semver-regex": "^3.1.3",
"shelljs": "0.8.3",
"shelljs": "0.8.5",
"typescript": "^3.8.3"
},
"resolutions": {
Expand Down
7 changes: 6 additions & 1 deletion packages/rax-qrcode/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 3.0.0

- [feat] update rax-canvas version to v2.0
- [feat] support passing strings with px of width and height in style

## 2.0.2

- [fix] can't get correct screenWidth in some Android Phones, use windowWidth instead
- [fix] can't get correct screenWidth in some Android Phones, use windowWidth instead
2 changes: 1 addition & 1 deletion packages/rax-qrcode/demo/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function App() {
return (
<QRCode
data="http://market.m.taobao.com/apps/market/m-vip/88-festival.html?wh_weex=true&wx_navbar_transparent=true"
style={{ width: 400, height: 400 }}
style={{ width: '400', height: '400' }}
/>
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/rax-qrcode/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rax-qrcode",
"version": "2.0.2",
"version": "3.0.0",
"description": "QRCode component for Rax.",
"license": "BSD-3-Clause",
"main": "lib/index.js",
Expand Down Expand Up @@ -31,7 +31,7 @@
],
"dependencies": {
"qr.js": "0.0.0",
"rax-canvas": "^1.0.0"
"rax-canvas": "^2.0.0"
},
"peerDependencies": {
"rax": "^1.0.0"
Expand Down
21 changes: 20 additions & 1 deletion packages/rax-qrcode/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ const styles = {
}
};

const ENDS_WITH_PX_EXCEPT_RPX = /^[0-9\.]+\s*([^r]px)?$/;

function processDimensions(width: string | number, height: string | number) {
let w = width;
let h = height;
if (typeof width === 'string' && ENDS_WITH_PX_EXCEPT_RPX.test(width)){
w = parseFloat(width);
}

if (typeof height === 'string' && ENDS_WITH_PX_EXCEPT_RPX.test(height)){
h = parseFloat(height);
}

return {
width: w as number,
height: h as number
};
}

class QRCode extends Component<QRCodeProps, {}> {
public width = 0;
public height = 0;
Expand All @@ -38,7 +57,7 @@ class QRCode extends Component<QRCodeProps, {}> {
public constructor(props) {
super(props);
const { style = {} } = props;
const { width = 300, height = 300 } = style;
const { width, height } = processDimensions(style.width || 300, style.height || 300);
this.width = width;
this.height = height;
this.canvas = createRef();
Expand Down