Skip to content

Commit

Permalink
Add qrcode field type (#6506)
Browse files Browse the repository at this point in the history
  • Loading branch information
wachterjohannes committed Apr 13, 2022
1 parent 2de5870 commit 55e8d43
Show file tree
Hide file tree
Showing 13 changed files with 2,346 additions and 3 deletions.
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;
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

0 comments on commit 55e8d43

Please sign in to comment.