Skip to content

Commit f194229

Browse files
authored
feat: add gradient fill functionality for QR codes (#87)
* feat: add gradient fill functionality for QR codes - Introduced gradient-related properties in the QrcodeVue component to allow for customizable QR code appearances. - Implemented both linear and radial gradient options for enhanced visual appeal. - Updated the README documentation with examples and instructions for using the gradient features. - Modified the example project to include controls related to gradient options for user testing and demonstration. * refactor: optimize image property handling in QrcodeSvg component - Removed the ref wrapping of imageProps, converting it to a plain object for simpler management. - Simplified the assignment logic of imageProps for better readability and maintainability. - Eliminated unnecessary handling of null values to streamline the code. * feat: retain named parameters for QrcodeVue component props
1 parent 6cb96f1 commit f194229

File tree

6 files changed

+409
-31
lines changed

6 files changed

+409
-31
lines changed

README-ja.md

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dist/
2828

2929
## 使用方法
3030

31-
例:
31+
e.g.
3232

3333
```javascript
3434
import { createApp } from 'vue'
@@ -45,7 +45,7 @@ createApp({
4545
}).mount('#root')
4646
```
4747

48-
または、`*.vue`拡張子の単一ファイルコンポーネントで使用します:
48+
- または、`*.vue`拡張子の単一ファイルコンポーネントで使用します:
4949

5050
```html
5151
<template>
@@ -68,7 +68,46 @@ createApp({
6868
</script>
6969
```
7070

71-
Vue 3で`TypeScript`を使用する場合:
71+
- グラデーションの使用例
72+
73+
> グラデーションをサポートする `QrcodeVue` コンポーネントを使用するには、グラデーション関連のプロパティを渡すことができます:
74+
75+
```html
76+
<template>
77+
<qrcode-vue
78+
:size="size"
79+
:value="fullUrl"
80+
:level="level"
81+
:margin="margin"
82+
:render-as="renderAs"
83+
:background="background"
84+
:gradient="true"
85+
:gradient-type="gradientType"
86+
:gradient-start-color="gradientStartColor"
87+
:gradient-end-color="gradientEndColor"
88+
/>
89+
</template>
90+
91+
<script>
92+
export default {
93+
data() {
94+
return {
95+
size: 200,
96+
fullUrl: 'https://example.com',
97+
level: 'H',
98+
margin: 4,
99+
renderAs: 'svg', // or 'canvas'
100+
background: '#ffffff',
101+
gradient: true,
102+
gradientType: 'linear', // or 'radial'
103+
gradientStartColor: '#ff0000', // グラデーションの開始色
104+
gradientEndColor: '#0000ff', // グラデーションの終了色
105+
}
106+
},
107+
}
108+
</script>
109+
110+
- Vue 3で`TypeScript`を使用する場合:
72111

73112
```html
74113
<template>
@@ -78,20 +117,28 @@ Vue 3で`TypeScript`を使用する場合:
78117
:render-as="renderAs"
79118
:background="background"
80119
:foreground='foreground'
120+
:gradient="gradient"
121+
:gradient-type="gradientType"
122+
:gradient-start-color="gradientStartColor"
123+
:gradient-end-color="gradientEndColor"
81124
:image-settings='imageSettings'
82125
/>
83126
</template>
84127
<script setup lang="ts">
85128
import { ref } from 'vue'
86129
import QrcodeVue from 'qrcode.vue'
87-
import type { Level, RenderAs, ImageSettings } from 'qrcode.vue'
130+
import type { Level, RenderAs, GradientType, ImageSettings } from 'qrcode.vue'
88131
89132
const value = ref('qrcode')
90133
const level = ref<Level>('M')
91134
const renderAs = ref<RenderAs>('svg')
92135
const background = ref('#ffffff')
93136
const foreground = ref('#000000')
94137
const margin = ref(0)
138+
const gradient = ref(false)
139+
const gradientType = ref<GradientType>('linear')
140+
const gradientStartColor = ref('#000000')
141+
const gradientEndColor = ref('#38bdf8')
95142
const imageSettings = ref<ImageSettings>({
96143
src: 'https://github.com/scopewu.png',
97144
width: 30,
@@ -154,6 +201,34 @@ QRコードの背景色。
154201

155202
QRコードの前景色。
156203

204+
### `gradient`
205+
206+
- タイプ:`boolean`
207+
- デフォルト:`false`
208+
209+
QRコードのグラデーション塗りつぶしを有効にします。
210+
211+
### `gradient-type`
212+
213+
- タイプ:`GradientType('linear' | 'radial')`
214+
- デフォルト:`linear`
215+
216+
グラデーションの種類を指定します。
217+
218+
### `gradient-start-color`
219+
220+
- タイプ:`string`
221+
- デフォルト:`#000000`
222+
223+
グラデーションの開始色。
224+
225+
### `gradient-end-color`
226+
227+
- タイプ:`string`
228+
- デフォルト:`#ffffff`
229+
230+
グラデーションの終了色。
231+
157232
### `image-settings`
158233

159234
- タイプ: `ImageSettings`

README-zh_cn.md

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ createApp({
4343
}).mount('#root')
4444
```
4545

46-
或者,在独有单文件扩展 `*.vue` 中使用:
46+
- 或者,在独有单文件扩展 `*.vue` 中使用:
4747

4848
```html
4949
<template>
@@ -66,7 +66,46 @@ createApp({
6666
</script>
6767
```
6868

69-
在 Vue 3 中配合 `TypeScript` 使用:
69+
- 渐变示例用法
70+
71+
> 要使用带渐变支持的 `QrcodeVue` 组件,你可以传入渐变相关的属性:
72+
73+
```html
74+
<template>
75+
<qrcode-vue
76+
:size="size"
77+
:value="fullUrl"
78+
:level="level"
79+
:margin="margin"
80+
:render-as="renderAs"
81+
:background="background"
82+
:gradient="true"
83+
:gradient-type="gradientType"
84+
:gradient-start-color="gradientStartColor"
85+
:gradient-end-color="gradientEndColor"
86+
/>
87+
</template>
88+
89+
<script>
90+
export default {
91+
data() {
92+
return {
93+
size: 200,
94+
fullUrl: 'https://example.com',
95+
level: 'H',
96+
margin: 4,
97+
renderAs: 'svg', // or 'canvas'
98+
background: '#ffffff',
99+
gradient: true,
100+
gradientType: 'linear', // or 'radial'
101+
gradientStartColor: '#ff0000', // 渐变的起始颜色
102+
gradientEndColor: '#0000ff', // 渐变的结束颜色
103+
}
104+
},
105+
}
106+
</script>
107+
108+
- 在 Vue 3 中配合 `TypeScript` 使用:
70109

71110
```html
72111
<template>
@@ -76,20 +115,28 @@ createApp({
76115
:render-as="renderAs"
77116
:background="background"
78117
:foreground='foreground'
118+
:gradient="gradient"
119+
:gradient-type="gradientType"
120+
:gradient-start-color="gradientStartColor"
121+
:gradient-end-color="gradientEndColor"
79122
:image-settings='imageSettings'
80123
/>
81124
</template>
82125
<script setup lang="ts">
83126
import { ref } from 'vue'
84127
import QrcodeVue from 'qrcode.vue'
85-
import type { Level, RenderAs, ImageSettings } from 'qrcode.vue'
128+
import type { Level, RenderAs, GradientType, ImageSettings } from 'qrcode.vue'
86129
87130
const value = ref('qrcode')
88131
const level = ref<Level>('M')
89132
const renderAs = ref<RenderAs>('svg')
90133
const background = ref('#ffffff')
91134
const foreground = ref('#000000')
92135
const margin = ref(0)
136+
const gradient = ref(false)
137+
const gradientType = ref<GradientType>('linear')
138+
const gradientStartColor = ref('#000000')
139+
const gradientEndColor = ref('#38bdf8')
93140
const imageSettings = ref<ImageSettings>({
94141
src: 'https://github.com/scopewu.png',
95142
width: 30,
@@ -152,6 +199,34 @@ createApp({
152199

153200
二维码前景颜色。
154201

202+
### `gradient`
203+
204+
- 类型: `boolean`
205+
- 默认值: `false`
206+
207+
启用二维码的渐变填充。
208+
209+
### `gradient-type`
210+
211+
- 类型: `GradientType('linear' | 'radial')`
212+
- 默认值: `linear`
213+
214+
指定渐变类型。
215+
216+
### `gradient-start-color`
217+
218+
- 类型: `string`
219+
- 默认值: `#000000`
220+
221+
渐变的起始颜色。
222+
223+
### `gradient-end-color`
224+
225+
- 类型: `string`
226+
- 默认值: `#ffffff`
227+
228+
渐变的结束颜色。
229+
155230
### `image-settings`
156231

157232
- 类型: `ImageSettings`
@@ -191,20 +266,20 @@ createApp({
191266
+ exports: 'named',
192267
```
193268

194-
195269
现在在 common.js 和 cdn 直接引用 `QrcodeVue` 需要使用 `default` 字段:
196270

197271
```js
198272
const QrcodeVue = require('qrcode.vue').default
199273
const { default: QrcodeVue, QrcodeCanvas, QrcodeSvg } = require('qrcode.vue')
200274
```
275+
201276
```html
202277
<!--With HTML-->
203278
<div id="root">
204279
<p class="flex space-x">
205280
<qrcode-vue :value="test" render-as="svg"></qrcode-vue>
206-
<qrcode-canvas :value="test"></qrcode-canvas>
207-
</p>
281+
<qrcode-canvas :value="test"></qrcode-canvas>
282+
</p>
208283
<p><input v-model="test" /></p>
209284
</div>
210285
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.global.prod.js"></script>

0 commit comments

Comments
 (0)