Skip to content

Commit ad1ad10

Browse files
authored
Merge pull request #644 from LGLabGreg/claude/laughing-albattani-dlej78
Add frame settings to wrap QR codes with decorative labels
2 parents ec5e9a1 + f8c39a1 commit ad1ad10

27 files changed

Lines changed: 1188 additions & 21 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@lglab/react-qr-code': patch
3+
---
4+
5+
Fix JPEG downloads of QR codes without a background: transparent areas were exported as black, making the code unscannable. JPEG downloads now use a white background; PNG downloads stay transparent.

‎.changeset/qr-code-frames.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@lglab/react-qr-code': minor
3+
---
4+
5+
Add `frameSettings` to draw a frame with a call-to-action label around the QR code. Available styles: `banner-bottom`, `banner-top`, `ticket`, `bubble` and `border`.

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ A highly customizable and lightweight QR code generator for React applications.
1212
## Quick Features
1313

1414
- **Highly Customizable** - Style the finder patterns, modules, and colors exactly how you want.
15+
- **Frames** - Wrap the QR code in a frame with a call-to-action label like "Scan me!".
1516
- **Performance Optimized** - Generates QR codes efficiently without sacrificing quality.
1617
- **SVG-Based Rendering** - Crisp and scalable output for web and print
1718
- **Developer-Friendly** - Built with TypeScript, easy to use, and well-documented.

‎apps/docs/public/llms-full.txt‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The main component exported by the library.
2424
| `finderPatternOuterSettings` | `FinderPatternOuterSettings` | - | Configuration for outer finder patterns. |
2525
| `finderPatternInnerSettings` | `FinderPatternInnerSettings` | - | Configuration for inner finder patterns. |
2626
| `imageSettings` | `ImageSettings` | - | Settings for an embedded logo or image. |
27+
| `frameSettings` | `FrameSettings` | - | Draws a frame with a call-to-action label around the QR code. `size` then applies to the frame width; the height grows to fit the label. |
2728
| `svgProps` | `React.SVGProps<SVGSVGElement>` | - | Additional props passed to the root SVG element. |
2829

2930
---
@@ -75,6 +76,21 @@ Includes all `FinderPatternOuterStyle` plus: `'diamond'`, `'star'`, `'heart'`, `
7576
| `opacity` | `number` | `1` | Image opacity (0-1). |
7677
| `crossOrigin` | `CrossOrigin` | - | CORS setting for the image. |
7778

79+
### FrameSettings
80+
81+
| Property | Type | Default | Description |
82+
| --- | --- | --- | --- |
83+
| `style` | `FrameStyle` | - | **Required.** Style of the frame. |
84+
| `text` | `string` | `'Scan me!'` | Label rendered in the frame. Long labels are condensed to fit. An empty string hides it and the frame wraps the code evenly. |
85+
| `color` | `string` | `'#000000'` | Frame color. |
86+
| `textColor` | `string` | - | Label color. Defaults to white on filled frames and to `color` on `'border'`. |
87+
| `fontFamily` | `string` | `'sans-serif'` | Label font family (CSS font-family list). Web fonts loaded by the page work on screen, but downloads only keep the name: SVG files need the font installed where they are opened, and PNG/JPEG exports cannot use page web fonts, only fonts installed on the device. End the list with a generic family. |
88+
89+
**Available Styles (`FrameStyle`):**
90+
`'banner-bottom'`, `'banner-top'`, `'ticket'`, `'bubble'`, `'border'`
91+
92+
When a frame is set, the QR code sits on a light panel (the `background` color when it is a string, white otherwise) with a quiet zone of at least 2 modules, so it stays scannable on dark frames.
93+
7894
### GradientSettings
7995

8096
| Property | Type | Default | Description |
@@ -137,3 +153,17 @@ import { ReactQRCode } from '@lglab/react-qr-code';
137153
/>
138154
```
139155

156+
### Frame
157+
```tsx
158+
<ReactQRCode
159+
value="https://reactqrcode.com"
160+
size={256}
161+
marginSize={2}
162+
frameSettings={{
163+
style: 'ticket',
164+
text: 'Scan me!',
165+
color: '#000000'
166+
}}
167+
/>
168+
```
169+

‎apps/docs/public/llms.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This site serves as the central hub for the `@lglab/react-qr-code` library, prov
1717
- [Finder Pattern Outer Settings](https://reactqrcode.com/finder-pattern-outer-settings)
1818
- [Gradient Settings](https://reactqrcode.com/gradient-settings)
1919
- [Image Settings](https://reactqrcode.com/image-settings)
20+
- [Frame Settings](https://reactqrcode.com/frame-settings)
2021
- [Examples](https://reactqrcode.com/examples)
2122

2223
## External Links
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import type { Metadata } from 'next'
2+
import Link from 'next/link'
3+
4+
import {
5+
DemoCustom,
6+
DemoStyles,
7+
customCodeBlock,
8+
stylesCodeBlock,
9+
} from '@/components/demos/frame'
10+
import { PageHeading } from '@/components/page-heading'
11+
import { ExampleTabs } from '@/components/ui/example-tabs'
12+
import { TypographyH3, TypographyP } from '@/components/ui/typography'
13+
14+
export const metadata: Metadata = {
15+
title: 'Frame Example',
16+
description:
17+
'Example showing how to add a frame with a "Scan me!" call-to-action label around QR codes using the FrameSettings options in @lglab/react-qr-code.',
18+
}
19+
20+
export default function Page() {
21+
return (
22+
<>
23+
<PageHeading heading='Frame example' />
24+
<TypographyP>
25+
The @lglab/react-qr-code library can draw a frame with a call-to-action label
26+
around your QR codes, making them easier to spot on print and screens. Frames are
27+
part of the SVG, so they are included when you download the QR code. See{' '}
28+
<Link className='underline' href='/frame-settings'>
29+
Frame Settings
30+
</Link>{' '}
31+
api reference for more information.
32+
</TypographyP>
33+
34+
<TypographyH3>Styles</TypographyH3>
35+
<ExampleTabs codeBlock={stylesCodeBlock} preview={<DemoStyles />} />
36+
37+
<hr className='border-0' />
38+
39+
<TypographyH3>Custom label and colors</TypographyH3>
40+
<ExampleTabs codeBlock={customCodeBlock} preview={<DemoCustom />} />
41+
</>
42+
)
43+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import type { Metadata } from 'next'
2+
3+
import { PageHeading } from '@/components/page-heading'
4+
import { PropsTable } from '@/components/props-table'
5+
import {
6+
TypographyH2,
7+
TypographyInlineCode,
8+
TypographyP,
9+
} from '@/components/ui/typography'
10+
import type { Prop } from '@/types/props'
11+
12+
export const metadata: Metadata = {
13+
title: 'FrameSettings',
14+
description:
15+
'Configuration options for FrameSettings in @lglab/react-qr-code, used to draw a frame with a call-to-action label such as "Scan me!" around QR codes.',
16+
}
17+
18+
const props: Prop[] = [
19+
{
20+
name: 'style',
21+
type: 'FrameStyle',
22+
description: 'The style of the frame.',
23+
required: true,
24+
possibleValues: ['banner-bottom', 'banner-top', 'border', 'bubble', 'ticket'],
25+
},
26+
{
27+
name: 'text',
28+
type: 'string',
29+
description:
30+
'The label rendered in the frame. Long labels are condensed to fit the frame width. Pass an empty string to hide the label, the frame then wraps the QR Code evenly.',
31+
defaultValue: 'Scan me!',
32+
},
33+
{
34+
name: 'color',
35+
type: 'string',
36+
description: 'The frame color.',
37+
defaultValue: '#000000',
38+
},
39+
{
40+
name: 'textColor',
41+
type: 'string',
42+
description:
43+
'The label color. Defaults to white on filled frames (banner-bottom, banner-top, ticket, bubble) and to the frame color on border.',
44+
},
45+
{
46+
name: 'fontFamily',
47+
type: 'string',
48+
description:
49+
'The label font family, as a CSS font-family value. See the font family section below for how it behaves in downloads.',
50+
defaultValue: 'sans-serif',
51+
},
52+
]
53+
54+
export default function Page() {
55+
return (
56+
<>
57+
<PageHeading heading='FrameSettings' />
58+
<TypographyP>
59+
These are the properties you can use to draw a frame with a call-to-action label
60+
around the QR Code. When a frame is set, the size prop applies to the frame width
61+
and the height grows to fit the label. The QR Code sits on a light panel (the
62+
background color, white by default) with a quiet zone of at least 2 modules, so it
63+
stays scannable on dark frames.
64+
</TypographyP>
65+
<PropsTable props={props} />
66+
67+
<TypographyH2>Font family</TypographyH2>
68+
<TypographyP>
69+
The fontFamily value is set as the font-family of the SVG label, so it accepts any
70+
CSS font-family list such as{' '}
71+
<TypographyInlineCode>&apos;Georgia, serif&apos;</TypographyInlineCode>. The label
72+
is always bold. Which font is actually used depends on where the QR Code is
73+
displayed:
74+
</TypographyP>
75+
<TypographyP>
76+
On the page, the label can use system fonts and any web font your page has already
77+
loaded, for example through Google Fonts, next/font or @font-face, as long as the
78+
name matches.
79+
</TypographyP>
80+
<TypographyP>
81+
Downloads only keep the font name, not the font file. An SVG download shows the
82+
font if it is installed where the file is opened. PNG and JPEG downloads are
83+
rendered as an isolated image that cannot see your page&apos;s web fonts, so they
84+
use the font only if it is installed on the user&apos;s device.
85+
</TypographyP>
86+
<TypographyP>
87+
In every case a missing font falls back to the next font in the list, so always
88+
end it with a generic family such as sans-serif or serif. For labels that must
89+
look the same everywhere, prefer widely installed fonts like Arial, Helvetica,
90+
Georgia or Verdana.
91+
</TypographyP>
92+
</>
93+
)
94+
}

‎apps/docs/src/app/react-qr-code-props/page.tsx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,19 @@ const props: Prop[] = [
105105
</>
106106
),
107107
},
108+
{
109+
name: 'frameSettings',
110+
type: 'FrameSettings',
111+
description: (
112+
<>
113+
Draws a frame with a call-to-action label around the QR code. When set, size
114+
applies to the frame width and the height grows to fit the label. See{' '}
115+
<Link className='underline' href='/frame-settings'>
116+
FrameSettings
117+
</Link>
118+
</>
119+
),
120+
},
108121
{
109122
name: 'level',
110123
type: 'ErrorCorrectionLevel',

‎apps/docs/src/app/sitemap.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ const PAGES = [
1717
{ path: '/finder-pattern-inner-settings', priority: 0.7 },
1818
{ path: '/gradient-settings', priority: 0.7 },
1919
{ path: '/image-settings', priority: 0.7 },
20+
{ path: '/frame-settings', priority: 0.7 },
2021
{ path: '/ref-api', priority: 0.7 },
2122
{ path: '/examples/basic', priority: 0.7 },
2223
{ path: '/examples/data-modules', priority: 0.7 },
2324
{ path: '/examples/finder-patterns', priority: 0.7 },
2425
{ path: '/examples/background', priority: 0.7 },
2526
{ path: '/examples/image', priority: 0.7 },
27+
{ path: '/examples/frame', priority: 0.7 },
2628
{ path: '/examples/download', priority: 0.7 },
2729
]
2830

‎apps/docs/src/components/demo/demo.tsx‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client'
22

33
import {
4+
type FrameSettings,
45
ReactQRCode,
56
type ReactQRCodeProps,
67
type ReactQRCodeRef,
@@ -19,6 +20,7 @@ import { Colors } from './colors'
1920
import { DataModules } from './data-modules'
2021
import { FinderPatternInner } from './finder-pattern-inner'
2122
import { FinderPatternOuter } from './finder-pattern-outer'
23+
import { FrameSettingsDemo } from './frame-settings'
2224
import { ImageSettingsDemo } from './image-settings'
2325
import { MainSettings } from './main-settings'
2426

@@ -32,6 +34,12 @@ export const defaultImageSettings = {
3234
y: undefined,
3335
}
3436

37+
export const defaultFrameSettings: FrameSettings = {
38+
style: 'ticket',
39+
text: 'Scan me!',
40+
color: '#000000',
41+
}
42+
3543
export const defaultBgColor = '#FFFFFF'
3644
export const defaultBgGradient = {
3745
type: 'linear',
@@ -120,6 +128,12 @@ export const Demo = () => {
120128
<ImageSettingsDemo qrProps={qrProps} setQrProps={setQrProps} />
121129
</AccContent>
122130
</AccordionItem>
131+
<AccordionItem value='frame-settings'>
132+
<AccordionTrigger>Frame</AccordionTrigger>
133+
<AccContent>
134+
<FrameSettingsDemo qrProps={qrProps} setQrProps={setQrProps} />
135+
</AccContent>
136+
</AccordionItem>
123137
</Accordion>
124138
</div>
125139
<div className='flex flex-col items-center gap-3 sm:col-span-2 [&>svg]:h-auto'>

0 commit comments

Comments
 (0)