Skip to content

Commit b70e1bd

Browse files
committed
feat: add props lang
1 parent b24f5c2 commit b70e1bd

File tree

9 files changed

+61
-14
lines changed

9 files changed

+61
-14
lines changed

.storybook/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// const path = require("path");
1+
const path = require("path");
22
module.exports = {
33
async viteFinal(config, { configType }) {
44
if (configType === "DEVELOPMENT") {
@@ -10,6 +10,8 @@ module.exports = {
1010
port: 443,
1111
protocol: "ws",
1212
};
13+
} else {
14+
config.base = "/vue3-colorpicker/";
1315
}
1416
// return the customized config
1517
return config;

README.ZH-cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
[在线 demo 演示](https://aesoper101.github.io/vue3-colorpicker/)
88

9-
[English](./README.md)
9+
[English](https://github.com/aesoper101/vue3-colorpicker/blob/main/README.md)
1010

1111
## 安装
1212

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Note: This document is for Vue3ColorPicker v2. If you are looking for an older v
66

77
[Live Demo](https://aesoper101.github.io/vue3-colorpicker/)
88

9-
[中文文档](./README.ZH-cn.md)
9+
[中文文档](https://github.com/aesoper101/vue3-colorpicker/blob/main/README.ZH-cn.md)
1010

1111
## Installation
1212

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue3-colorpicker",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"main": "dist/index.es.js",
55
"types": "dist/types/index.d.ts",
66
"author": "aesoper",
@@ -24,9 +24,10 @@
2424
"pub": "cd dist && npm publish --registry=https://registry.npmjs.org --access public && cd ..",
2525
"unpub": "npm unpublish vue3-colorpicker --force --registry=https://registry.npmjs.org",
2626
"prelink": "cd dist && yarn link && cd .. && yarn link vue3-colorpicker",
27-
"deploy": "rimraf dist && yarn build && gh-pages -d dist",
27+
"deploy": "gh-pages -d storybook-static",
2828
"storybook": "start-storybook -p 6006",
29-
"build-storybook": "build-storybook"
29+
"build-storybook": "rimraf storybook-static && build-storybook",
30+
"reinstall": "rimraf node_modules && yarn install"
3031
},
3132
"dependencies": {
3233
"@aesoper/normal-utils": "^0.1.5",

packages/ColorPicker.vue

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,15 @@
3030
</template>
3131

3232
<script lang="ts">
33-
import { computed, defineComponent, ExtractPropTypes, PropType, reactive, ref } from "vue";
33+
import {
34+
computed,
35+
defineComponent,
36+
ExtractPropTypes,
37+
PropType,
38+
provide,
39+
reactive,
40+
ref,
41+
} from "vue";
3442
import FkColorPicker from "./fk/FkColorPicker.vue";
3543
import ChromeColorPicker from "./chrome/ChromeColorPicker.vue";
3644
import GradientColorPicker from "./gradient/GradientColorPicker.vue";
@@ -41,6 +49,7 @@
4149
import { onClickOutside, tryOnMounted, whenever } from "@vueuse/core";
4250
import { createPopper } from "@popperjs/core";
4351
import { GradientNode, parse, stringify } from "gradient-parser";
52+
import { ColorPickerProvider, ColorPickerProviderKey, SupportLang } from "./utils/type";
4453
4554
const colorPickerProps = {
4655
isWidget: propTypes.bool.def(false),
@@ -60,6 +69,10 @@
6069
roundHistory: propTypes.bool.def(false),
6170
useType: propTypes.oneOf(["single", "gradient", "both"]).def("single"),
6271
activeKey: propTypes.oneOf(["single", "gradient"]).def("single"),
72+
lang: {
73+
type: String as PropType<SupportLang>,
74+
default: "ZH-cn",
75+
},
6376
};
6477
6578
export type ColorPickerProps = Partial<ExtractPropTypes<typeof colorPickerProps>>;
@@ -84,6 +97,10 @@
8497
isAdvanceMode: false,
8598
});
8699
100+
provide<ColorPickerProvider>(ColorPickerProviderKey, {
101+
lang: computed(() => props.lang || "ZH-cn"),
102+
});
103+
87104
const instance = new Color(state.pureColor);
88105
const colorInstance = ref(instance);
89106

packages/common/WrapContainer.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
@click="onActiveKeyChange('single')"
1414
>
1515
<button>
16-
<div class="vc-btn__content">纯色</div>
16+
<div class="vc-btn__content">{{ lang === "ZH-cn" ? "纯色" : "Pure" }}</div>
1717
</button>
1818
</div>
1919
<div
@@ -26,7 +26,7 @@
2626
@click="onActiveKeyChange('gradient')"
2727
>
2828
<button>
29-
<div class="vc-btn__content">渐变色</div>
29+
<div class="vc-btn__content">{{ lang === "ZH-cn" ? "渐变色" : "Gradient" }}</div>
3030
</button>
3131
</div>
3232
<div
@@ -44,9 +44,10 @@
4444
</template>
4545

4646
<script lang="ts">
47-
import { defineComponent, reactive } from "vue";
47+
import { defineComponent, inject, reactive } from "vue";
4848
import propTypes from "vue-types";
4949
import { whenever } from "@vueuse/core";
50+
import { ColorPickerProvider, ColorPickerProviderKey } from "../utils/type";
5051
5152
export default defineComponent({
5253
name: "WrapContainer",
@@ -60,6 +61,8 @@
6061
activeKey: props.activeKey,
6162
});
6263
64+
const parent = inject<ColorPickerProvider>(ColorPickerProviderKey);
65+
6366
const onActiveKeyChange = (key: string) => {
6467
state.activeKey = key;
6568
emit("update:activeKey", key);
@@ -73,7 +76,7 @@
7376
}
7477
);
7578
76-
return { state, onActiveKeyChange };
79+
return { state, onActiveKeyChange, lang: parent?.lang };
7780
},
7881
});
7982
</script>

packages/gradient/GradientColorPicker.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
]"
2020
ref="startGradientRef"
21-
title="开始"
21+
:title="lang === 'ZH-cn' ? '开始' : 'Start'"
2222
:style="{ left: getStartColorLeft + 'px' }"
2323
>
2424
<span class="vc-gradient__stop--inner"></span>
@@ -31,7 +31,7 @@
3131
},
3232
]"
3333
ref="stopGradientRef"
34-
title="结束"
34+
:title="lang === 'ZH-cn' ? '结束' : 'End'"
3535
:style="{ left: getEndColorLeft + 'px' }"
3636
>
3737
<span class="vc-gradient__stop--inner"></span>
@@ -66,7 +66,7 @@
6666
</template>
6767

6868
<script lang="ts">
69-
import { computed, defineComponent, reactive, ref } from "vue";
69+
import { computed, defineComponent, inject, reactive, ref } from "vue";
7070
import propTypes from "vue-types";
7171
import { Angle } from "vue3-angle";
7272
import Alpha from "../common/Alpha.vue";
@@ -82,6 +82,7 @@
8282
import { tryOnMounted, useDebounceFn, useLocalStorage, whenever } from "@vueuse/core";
8383
import { DOMUtils } from "@aesoper/normal-utils";
8484
import tinycolor from "tinycolor2";
85+
import { ColorPickerProvider, ColorPickerProviderKey } from "../utils/type";
8586
8687
export default defineComponent({
8788
name: "GradientColorPicker",
@@ -123,6 +124,8 @@
123124
endColorRgba: props.endColor.toRgbString(),
124125
});
125126
127+
const parent = inject<ColorPickerProvider>(ColorPickerProviderKey);
128+
126129
const advancePanelShow = ref(false);
127130
128131
// Ref
@@ -364,6 +367,7 @@
364367
historyColors,
365368
onBack,
366369
onDegreeChange,
370+
lang: parent?.lang,
367371
};
368372
},
369373
});

packages/utils/type.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { ComputedRef } from "vue";
2+
3+
export type SupportLang = "ZH-cn" | "En";
4+
5+
export interface ColorPickerProvider {
6+
lang: ComputedRef<SupportLang>;
7+
}
8+
9+
export const ColorPickerProviderKey = "Vue3ColorPickerProvider";

src/stories/ColorPicker.stories.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,17 @@ export default {
103103
},
104104
description: "",
105105
},
106+
lang: {
107+
type: "string",
108+
description: "ZH-cn | En",
109+
control: { type: "select" },
110+
options: ["ZH-cn", "En"],
111+
table: {
112+
defaultValue: {
113+
summary: "ZH-cn",
114+
},
115+
},
116+
},
106117
} as Partial<ArgTypes<ColorPickerProps>>,
107118
} as Meta;
108119

0 commit comments

Comments
 (0)