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

Add qrcode field type #6506

Merged
merged 4 commits into from
Apr 13, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type {ElementRef} from 'react';

export type InputProps<T: ?string | ?number> = {|
alignment: 'left' | 'center' | 'right',
alignment?: 'left' | 'center' | 'right',
autocomplete?: string,
collapsed?: boolean,
disabled: boolean,
Expand Down Expand Up @@ -31,7 +31,7 @@ export type InputProps<T: ?string | ?number> = {|
segmentDelimiter?: string,
skin?: 'default' | 'dark',
step?: ?T,
type: string,
type?: string,
valid: boolean,
value: ?T,
|};
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// @flow
import React, {Fragment} from 'react';
import QRCodeComponent from 'react-qr-code';
import Input from '../Input';
import qrCodeStyles from './qrcode.scss';
import type {QRCodeProps} from './types';

export default class QRCode<T: ?string | ?number> extends React.PureComponent<QRCodeProps<T>> {
render() {
return (
<Fragment>
<Input
{...this.props}
/>
<QRCodeComponent
className={qrCodeStyles.qrcode}
value={this.props.value || ''}
viewBox="0 0 256 256"
/>
</Fragment>
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
The qr-code component can be used to get an input from the user as a qr-code.

```javascript
const [value, setValue] = React.useState('');

<QRCode value={value} onChange={setValue} />
```

The attributes will be passed to the input component.

```javascript
const [value, setValue] = React.useState('');

<QRCode icon="fa-key" type="password" placeholder="Password" value={value} onChange={setValue} />
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @flow
import QRCode from './QRCode';
import type {QRCodeProps} from './types';

export default QRCode;
export type {QRCodeProps};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@import '../../containers/Application/colors.scss';

.qrcode {
background: white;
height: auto;
margin-top: 20px;
alexander-schranz marked this conversation as resolved.
Show resolved Hide resolved
max-width: 100%;
padding: 16px;
width: auto;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @flow
import React from 'react';
import {render} from 'enzyme';
import QRCode from '../QRCode';

jest.mock('../../../utils/Translator', () => ({
translate: jest.fn((key) => key),
}));

test('QRCode should render', () => {
const onChange = jest.fn();
expect(render(<QRCode
disabled={false}
onBlur={jest.fn()}
onChange={onChange}
valid={false}
value="My value"
/>)).toMatchSnapshot();
});
Loading