Skip to content

Commit 648adf8

Browse files
authored
Merge pull request #307 from linx4200/dev/v3.1-vue2
Support Vue 2.7
2 parents 2cee832 + e05ae89 commit 648adf8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+14593
-244
lines changed

.github/dependabot.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ updates:
44
- package-ecosystem: "npm"
55
# Look for `package.json` and `lock` files in the `root` directory
66
directory: "/"
7-
schedule:
8-
interval: "monthly"
7+
# ❌ Removed schedule to prevent auto-trigger
8+
# schedule:
9+
# interval: "monthly"
910
labels:
1011
- "dependencies"
1112
groups:

.github/workflows/npm-publish.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ jobs:
3737
- name: Build
3838
run: npm run build
3939

40+
- name: Install and build for Vue 2.7
41+
working-directory: vue2
42+
run: |
43+
npm ci
44+
npm run build
45+
4046
- name: Publish package
4147
run: npm publish
4248
env:

.github/workflows/prerelease-check.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,10 @@ jobs:
3131
run: npm run build
3232

3333
- name: Demo Build
34-
run: npm run demo:build
34+
run: npm run demo:build
35+
36+
- name: Install and build for Vue 2.7
37+
working-directory: vue2
38+
run: |
39+
npm ci
40+
npm run build

.github/workflows/test.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,23 @@ jobs:
2525
- name: Set up Node
2626
uses: actions/setup-node@v4
2727

28-
- name: Install dependencies
28+
- name: Install dependencies (root)
2929
run: npm ci
3030

3131
- name: Install Playwright browsers
3232
run: npx playwright install
3333

34-
- name: Run tests
34+
- name: Run root tests
3535
run: npm run coverage
3636

37+
- name: Install and run Vue 2.7 tests
38+
working-directory: vue2
39+
run: |
40+
npm ci
41+
npm run test
42+
3743
- name: Upload results to Codecov
3844
uses: codecov/codecov-action@v5
3945
with:
4046
token: ${{ secrets.CODECOV_TOKEN }}
47+

README.md

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
<a href="https://github.com/linx4200/vue-color"><img src="https://img.shields.io/github/stars/linx4200/vue-color?style=social" alt="Github stars" /></a>
66
</p>
77

8-
![Vue 3](https://img.shields.io/badge/Vue-3.0-brightgreen)
98
![Package Size](https://img.shields.io/bundlephobia/minzip/vue-color)
109
![Test Coverage](https://codecov.io/gh/linx4200/vue-color/branch/main/graph/badge.svg)
1110

12-
A collection of efficient and customizable color pickers built with [Vue 3](https://vuejs.org/), designed for modern web development.
11+
A collection of efficient and customizable color pickers, designed for modern web development.
1312

1413
## 🧪 Live Demo
1514

@@ -19,6 +18,8 @@ Explore the components in action: 👉 [Open Live Demo](https://linx4200.github.
1918

2019
## ✨ Features
2120

21+
- **Dual Vue Compatibility** – Supports both Vue 2.7 and Vue 3 out of the box
22+
2223
- **Modular & Tree-Shakable** – Import only what you use
2324

2425
- **TypeScript Ready** – Full typings for better DX
@@ -68,6 +69,8 @@ const color = defineModel({
6869
</script>
6970
```
7071

72+
If you plan to use `vue-color` with Vue 2.7, please refer to [Use with Vue 2.7](#use-with-vue-27).
73+
7174
> 📘 For a full list of available components, see the [Documentation](#all-available-pickers).
7275
7376
## 📚 Documentation
@@ -166,7 +169,7 @@ Since `vue-color` relies on DOM interaction, components must be rendered client-
166169
167170
<script setup lang="ts">
168171
import { ClientOnly } from '#components';
169-
import {ChromePicker } from 'vue-color';
172+
import { ChromePicker } from 'vue-color';
170173
</script>
171174
```
172175

@@ -180,6 +183,65 @@ By default, `vue-color` uses CSS variables defined under the :root scope. To ena
180183
</html>
181184
```
182185

186+
### Use with Vue 2.7
187+
188+
To use `vue-color` with Vue 2.7:
189+
190+
```vue
191+
<template>
192+
<ChromePicker v-model="color" />
193+
</template>
194+
195+
<script>
196+
import { ref } from 'vue'
197+
// Note: use the Vue 2.7 specific entry point
198+
import { ChromePicker } from 'vue-color/vue2'
199+
200+
export default {
201+
setup() {
202+
const color = ref('#5c8f94');
203+
return { color };
204+
}
205+
}
206+
</script>
207+
```
208+
209+
The Vue 2.7 build is fully compatible with the Vue Composition API introduced in 2.7.
210+
211+
Make sure to use `vue-color/vue2` as the import path, and include the correct stylesheet:
212+
import `vue-color/vue2/style.css` in your main entry file.
213+
214+
#### TypeScript Support in Vue 2.7
215+
216+
Vue 2.7 has full TypeScript support, but `vue-color` does **not include type declarations** for the Vue 2.7 build.
217+
218+
You can work around this by manually adding the following shim:
219+
220+
```ts
221+
// vue-color-shims.d.ts
222+
declare module 'vue-color/vue2' {
223+
import { Component } from 'vue';
224+
import tinycolor from 'tinycolor2';
225+
226+
export const ChromePicker: Component;
227+
export const SketchPicker: Component;
228+
export const PhotoshopPicker: Component;
229+
export const CompactPicker: Component;
230+
export const GrayscalePicker: Component;
231+
export const MaterialPicker: Component;
232+
export const SliderPicker: Component;
233+
export const TwitterPicker: Component;
234+
export const SwatchesPicker: Component;
235+
export const HueSlider: Component;
236+
export const tinycolor: typeof tinycolor;
237+
}
238+
239+
declare module '*.css' {
240+
const content: { [className: string]: string };
241+
export default content;
242+
}
243+
```
244+
183245
## 🧩 FAQ / Issue Guide
184246

185247
| Error / Symptom | Related Issue |

demo/App.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<script lang="ts">
2+
const DEFAULT_COLOR = 'F5F7FA';
3+
const DEFAULT_COLOR_DARK = '#004035';
4+
25
import { parseSearchParams } from './utils';
36
const pickers = ['chrome', 'sketch', 'photoshop', 'compact', 'grayscale', 'material', 'slider', 'twitter', 'swatches', 'hue'] as const;
47
const searchParams = parseSearchParams(location.search);
58
const manualEnabledPickers = searchParams.picker?.split(',');
69
7-
const DEFAULT_COLOR = 'F5F7FA';
8-
const DEFAULT_COLOR_DARK = '#004035';
9-
1010
function invertColor({ r, g, b, a}: { r: number; g: number; b: number, a: number }): string {
1111
const invert = (val: number, alpha: number) => alpha === 0 ? 0 : 255 - val;
1212
const inverted = {
@@ -108,6 +108,7 @@ const onModeChange = (isDark: boolean) => {
108108
<main class="intro text">
109109
A collection of efficient color pickers designed for modern web development.
110110
<ul class="feature-list text">
111+
<li>✅ Supports both Vue 2.7 and Vue 3</li>
111112
<li>✅ Modular & Tree-Shakable</li>
112113
<li>✅ TypeScript Ready</li>
113114
<li>✅ SSR-Friendly</li>

demo/vite.config.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import { defineConfig } from 'vite'
2-
import vue from '@vitejs/plugin-vue'
1+
import { defineConfig } from 'vite';
2+
import vue from '@vitejs/plugin-vue';
33

44
// https://vite.dev/config/
55
export default defineConfig({
66
plugins: [vue()],
7-
base: 'https://linx4200.github.io/vue-color/'
7+
base: 'https://linx4200.github.io/vue-color/',
8+
define: {
9+
__IS_DEBUG__: !!process.env.VITE_DEBUG
10+
},
811
})

0 commit comments

Comments
 (0)