Skip to content
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
41 changes: 39 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion src/pages/tools/image/generic/qr-code/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const initialValues: InitialValuesType = {
size: '200',
bgColor: '#FFFFFF',
fgColor: '#000000',
correctionLevel: 'M',

// URL
url: 'https://example.com',
Expand Down Expand Up @@ -117,6 +118,9 @@ const validationSchema = Yup.object().shape({
.required('Size is required'),
bgColor: Yup.string().required('Background color is required'),
fgColor: Yup.string().required('Foreground color is required'),
correctionLevel: Yup.mixed<'L' | 'M' | 'Q' | 'H'>()
.oneOf(['L', 'M', 'Q', 'H'])
.required('Correction level is required'),

// URL
url: Yup.string().when('qrCodeType', {
Expand Down Expand Up @@ -211,6 +215,25 @@ export default function QRCodeGenerator({ title }: ToolComponentProps) {
max: 1000
}}
/>
<TextField
select
fullWidth
label="Error Correction Level"
margin="normal"
value={values.correctionLevel}
onChange={(e) =>
updateField(
'correctionLevel',
e.target.value as 'L' | 'M' | 'Q' | 'H'
)
}
helperText="Higher levels survive more damage but encode less data"
>
<MenuItem value="L">L (~7%)</MenuItem>
<MenuItem value="M">M (~15%)</MenuItem>
<MenuItem value="Q">Q (~25%)</MenuItem>
<MenuItem value="H">H (~30%)</MenuItem>
</TextField>
<ColorSelector
description="Background Color"
value={values.bgColor}
Expand Down Expand Up @@ -440,7 +463,8 @@ export default function QRCodeGenerator({ title }: ToolComponentProps) {
dark: options.fgColor,
light: options.bgColor
},
width: Number(options.size) || 200
width: Number(options.size) || 200,
errorCorrectionLevel: options.correctionLevel
},
async (error, url) => {
const res = await fetch(url);
Expand Down
3 changes: 3 additions & 0 deletions src/pages/tools/image/generic/qr-code/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export type QRCodeType =
| 'WiFi'
| 'vCard';

export type QRErrorCorrectionLevel = 'L' | 'M' | 'Q' | 'H';

export type WifiEncryptionType = 'WPA' | 'WEP' | 'None';

export interface InitialValuesType {
Expand All @@ -16,6 +18,7 @@ export interface InitialValuesType {
size: string;
bgColor: string;
fgColor: string;
correctionLevel: QRErrorCorrectionLevel;

// URL
url: string;
Expand Down