@oiij/naive-ui 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -23
- package/dist/_virtual/rolldown_runtime.cjs +30 -0
- package/dist/components/_utils/cssr-bem.d.ts +1 -0
- package/dist/components/_utils/index.d.ts +3 -0
- package/dist/components/_utils/prismjs.d.ts +1 -0
- package/dist/components/_utils/transition.cssr.d.ts +10 -0
- package/dist/components/bubble/Bubble.vue.d.ts +26 -0
- package/dist/components/bubble/bubble.cssr.d.ts +2 -0
- package/dist/components/bubble/index.d.ts +16 -0
- package/dist/components/config-providers/ConfigProviders.vue.d.ts +18 -0
- package/dist/components/config-providers/index.d.ts +20 -0
- package/dist/components/copy-button/CopyButton.vue.d.ts +24 -0
- package/dist/components/copy-button/index.d.ts +9 -0
- package/dist/components/icons/MageCopyFill.vue.d.ts +2 -0
- package/dist/components/icons/RiSearch2Line.vue.d.ts +2 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/components/search-input/SearchInput.vue.d.ts +23 -0
- package/dist/components/search-input/index.d.ts +10 -0
- package/dist/components/tooltip-button/TooltipButton.vue.d.ts +24 -0
- package/dist/components/tooltip-button/index.d.ts +7 -0
- package/dist/components/type-writer/TypeWriter.vue.d.ts +17 -0
- package/dist/components/type-writer/index.d.ts +9 -0
- package/dist/components/type-writer/type-writer.cssr.d.ts +2 -0
- package/dist/components.cjs +38 -0
- package/dist/components.d.ts +1 -0
- package/dist/components.js +5686 -0
- package/dist/components.umd.cjs +38 -0
- package/dist/composables/useNaiveForm.cjs +61 -0
- package/dist/composables/useNaiveForm.d.cts +36 -0
- package/dist/composables/useNaiveForm.d.ts +36 -0
- package/dist/composables/useNaiveForm.js +60 -0
- package/dist/composables/useNaiveTheme.cjs +120 -0
- package/dist/composables/useNaiveTheme.d.cts +165 -0
- package/dist/composables/useNaiveTheme.d.ts +165 -0
- package/dist/composables/useNaiveTheme.js +119 -0
- package/dist/index.cjs +4 -172
- package/dist/index.d.cts +3 -178
- package/dist/index.d.ts +3 -178
- package/dist/index.js +3 -150
- package/package.json +72 -93
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as vue1 from "vue";
|
|
2
|
+
import { FormInst, FormItemRule, FormRules } from "naive-ui";
|
|
3
|
+
import * as async_validator11 from "async-validator";
|
|
4
|
+
|
|
5
|
+
//#region src/composables/useNaiveForm.d.ts
|
|
6
|
+
interface ClearRules {
|
|
7
|
+
string?: string | null;
|
|
8
|
+
number?: number | null;
|
|
9
|
+
boolean?: boolean | null;
|
|
10
|
+
}
|
|
11
|
+
type FormType = Record<string, unknown>;
|
|
12
|
+
type NaiveFormRules<T extends FormType> = Partial<Record<keyof T, FormRules | FormItemRule | FormItemRule[]>> | undefined;
|
|
13
|
+
interface NaiveFormOptions<T extends FormType> {
|
|
14
|
+
rules?: NaiveFormRules<T>;
|
|
15
|
+
clearRules?: ClearRules;
|
|
16
|
+
}
|
|
17
|
+
declare function useNaiveForm<T extends FormType>(value: T, options?: NaiveFormOptions<T>): {
|
|
18
|
+
formRef: vue1.Ref<FormInst | undefined, FormInst | undefined>;
|
|
19
|
+
formValue: vue1.Reactive<T> extends infer T_1 ? T_1 extends vue1.Reactive<T> ? T_1 extends (() => infer R) ? Readonly<vue1.Ref<R, R>> : T_1 extends vue1.Ref<any, any> ? T_1 : vue1.Ref<vue1.UnwrapRef<T_1>, vue1.UnwrapRef<T_1>> : never : never;
|
|
20
|
+
rules: NaiveFormRules<T>;
|
|
21
|
+
formProps: {
|
|
22
|
+
ref: vue1.Ref<FormInst | undefined, FormInst | undefined>;
|
|
23
|
+
model: vue1.Reactive<T>;
|
|
24
|
+
rules: NaiveFormRules<T>;
|
|
25
|
+
};
|
|
26
|
+
validate: () => Promise<{
|
|
27
|
+
warnings: async_validator11.ValidateError[][] | undefined;
|
|
28
|
+
}> | undefined;
|
|
29
|
+
resetValidation: () => void;
|
|
30
|
+
resetForm: () => void;
|
|
31
|
+
reset: () => void;
|
|
32
|
+
clear: () => void;
|
|
33
|
+
};
|
|
34
|
+
type NaiveFormReturns = ReturnType<typeof useNaiveForm>;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { NaiveFormOptions, NaiveFormReturns, NaiveFormRules, useNaiveForm };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { reactive, ref, toRef } from "vue";
|
|
2
|
+
|
|
3
|
+
//#region src/composables/useNaiveForm.ts
|
|
4
|
+
function clearObjectValues(obj, rules) {
|
|
5
|
+
const { string: _string = "", number: _number = null, boolean: _boolean = false } = rules ?? {};
|
|
6
|
+
if (Array.isArray(obj)) {
|
|
7
|
+
obj.length = 0;
|
|
8
|
+
return obj;
|
|
9
|
+
}
|
|
10
|
+
if (typeof obj === "object" && obj !== null) {
|
|
11
|
+
for (const key in obj) if (Object.prototype.hasOwnProperty.call(obj, key)) obj[key] = clearObjectValues(obj[key], rules);
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
if (typeof obj === "string") return _string;
|
|
15
|
+
if (typeof obj === "number") return _number;
|
|
16
|
+
if (typeof obj === "boolean") return _boolean;
|
|
17
|
+
return obj;
|
|
18
|
+
}
|
|
19
|
+
function useNaiveForm(value, options) {
|
|
20
|
+
const { rules, clearRules } = options ?? {};
|
|
21
|
+
const formValue = reactive(structuredClone(value));
|
|
22
|
+
const formRules = rules;
|
|
23
|
+
const formRef = ref();
|
|
24
|
+
const formProps = {
|
|
25
|
+
ref: formRef,
|
|
26
|
+
model: formValue,
|
|
27
|
+
rules: formRules
|
|
28
|
+
};
|
|
29
|
+
function validate() {
|
|
30
|
+
return formRef.value?.validate();
|
|
31
|
+
}
|
|
32
|
+
function resetValidation() {
|
|
33
|
+
formRef.value?.restoreValidation();
|
|
34
|
+
}
|
|
35
|
+
function clear() {
|
|
36
|
+
clearObjectValues(formValue, clearRules);
|
|
37
|
+
}
|
|
38
|
+
function resetForm() {
|
|
39
|
+
clear();
|
|
40
|
+
Object.assign(formValue, structuredClone(value));
|
|
41
|
+
}
|
|
42
|
+
function reset() {
|
|
43
|
+
resetValidation();
|
|
44
|
+
resetForm();
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
formRef,
|
|
48
|
+
formValue: toRef(formValue),
|
|
49
|
+
rules: formRules,
|
|
50
|
+
formProps,
|
|
51
|
+
validate,
|
|
52
|
+
resetValidation,
|
|
53
|
+
resetForm,
|
|
54
|
+
reset,
|
|
55
|
+
clear
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
export { useNaiveForm };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const vue = require_rolldown_runtime.__toESM(require("vue"));
|
|
3
|
+
const colord = require_rolldown_runtime.__toESM(require("colord"));
|
|
4
|
+
const naive_ui = require_rolldown_runtime.__toESM(require("naive-ui"));
|
|
5
|
+
|
|
6
|
+
//#region src/composables/useNaiveTheme.ts
|
|
7
|
+
function getStatusColor(color = "#ff461f") {
|
|
8
|
+
return {
|
|
9
|
+
color,
|
|
10
|
+
hover: (0, colord.colord)(color).lighten(.1).toHex(),
|
|
11
|
+
pressed: (0, colord.colord)(color).darken(.1).toHex(),
|
|
12
|
+
suppl: (0, colord.colord)(color).lighten(.1).toHex()
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const naiveLocaleMap = {
|
|
16
|
+
"zh-CN": {
|
|
17
|
+
name: "简体中文",
|
|
18
|
+
dateLocale: naive_ui.dateZhCN,
|
|
19
|
+
locale: naive_ui.zhCN
|
|
20
|
+
},
|
|
21
|
+
"en-US": {
|
|
22
|
+
name: "English",
|
|
23
|
+
dateLocale: naive_ui.dateEnUS,
|
|
24
|
+
locale: naive_ui.enUS
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function getColors(color) {
|
|
28
|
+
const { primary, info, success, warning, error } = color;
|
|
29
|
+
return {
|
|
30
|
+
primary: getStatusColor(primary),
|
|
31
|
+
info: getStatusColor(info),
|
|
32
|
+
success: getStatusColor(success),
|
|
33
|
+
warning: getStatusColor(warning),
|
|
34
|
+
error: getStatusColor(error)
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function useNaiveTheme(options) {
|
|
38
|
+
const { language, darkMode, color, globalThemeOverrides } = options ?? {};
|
|
39
|
+
const languageRef = (0, vue.ref)((0, vue.toValue)(language));
|
|
40
|
+
(0, vue.watchEffect)(() => {
|
|
41
|
+
languageRef.value = (0, vue.toValue)(language);
|
|
42
|
+
});
|
|
43
|
+
const darkModeRef = (0, vue.ref)((0, vue.toValue)(darkMode));
|
|
44
|
+
(0, vue.watchEffect)(() => {
|
|
45
|
+
darkModeRef.value = (0, vue.toValue)(darkMode);
|
|
46
|
+
});
|
|
47
|
+
const { common, Dialog,...extra } = globalThemeOverrides ?? {};
|
|
48
|
+
const colorRef = (0, vue.ref)({
|
|
49
|
+
primary: "#64748B",
|
|
50
|
+
info: "#06b6d4",
|
|
51
|
+
success: "#10b981",
|
|
52
|
+
warning: "#fbbf24",
|
|
53
|
+
error: "#f43f5e",
|
|
54
|
+
...color
|
|
55
|
+
});
|
|
56
|
+
function setColor(v) {
|
|
57
|
+
colorRef.value = v;
|
|
58
|
+
}
|
|
59
|
+
const theme = (0, vue.computed)(() => {
|
|
60
|
+
return darkModeRef?.value ? naive_ui.darkTheme : void 0;
|
|
61
|
+
});
|
|
62
|
+
const themeOverrides = (0, vue.computed)(() => {
|
|
63
|
+
const { primary, info, success, warning, error } = getColors(colorRef.value);
|
|
64
|
+
return {
|
|
65
|
+
common: {
|
|
66
|
+
bodyColor: darkModeRef?.value ? "#1f1f1f" : "#f5f5f5",
|
|
67
|
+
primaryColor: primary.color,
|
|
68
|
+
primaryColorHover: primary.hover,
|
|
69
|
+
primaryColorPressed: primary.pressed,
|
|
70
|
+
primaryColorSuppl: primary.suppl,
|
|
71
|
+
infoColor: info.color,
|
|
72
|
+
infoColorHover: info.hover,
|
|
73
|
+
infoColorPressed: info.pressed,
|
|
74
|
+
infoColorSuppl: info.suppl,
|
|
75
|
+
successColor: success.color,
|
|
76
|
+
successColorHover: success.hover,
|
|
77
|
+
successColorPressed: success.pressed,
|
|
78
|
+
successColorSuppl: success.suppl,
|
|
79
|
+
warningColor: warning.color,
|
|
80
|
+
warningColorHover: warning.hover,
|
|
81
|
+
warningColorPressed: warning.pressed,
|
|
82
|
+
warningColorSuppl: warning.suppl,
|
|
83
|
+
errorColor: error.color,
|
|
84
|
+
errorColorHover: error.hover,
|
|
85
|
+
errorColorPressed: error.pressed,
|
|
86
|
+
errorColorSuppl: error.suppl,
|
|
87
|
+
borderRadius: "6px",
|
|
88
|
+
...common
|
|
89
|
+
},
|
|
90
|
+
Dialog: {
|
|
91
|
+
borderRadius: "12px",
|
|
92
|
+
padding: "20px",
|
|
93
|
+
closeMargin: "20px 20px 0 0",
|
|
94
|
+
...Dialog
|
|
95
|
+
},
|
|
96
|
+
...extra
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
const locale = (0, vue.computed)(() => {
|
|
100
|
+
if (!languageRef?.value || !naiveLocaleMap[languageRef.value]) return naiveLocaleMap["zh-CN"].locale;
|
|
101
|
+
return naiveLocaleMap[languageRef.value].locale;
|
|
102
|
+
});
|
|
103
|
+
const dateLocale = (0, vue.computed)(() => {
|
|
104
|
+
if (!languageRef?.value || !naiveLocaleMap[languageRef.value]) return naiveLocaleMap["zh-CN"].dateLocale;
|
|
105
|
+
return naiveLocaleMap[languageRef.value].dateLocale;
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
language: languageRef,
|
|
109
|
+
darkMode: darkModeRef,
|
|
110
|
+
theme,
|
|
111
|
+
themeOverrides,
|
|
112
|
+
locale,
|
|
113
|
+
dateLocale,
|
|
114
|
+
color: colorRef,
|
|
115
|
+
setColor
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
//#endregion
|
|
120
|
+
exports.useNaiveTheme = useNaiveTheme;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { ComputedRef, Ref } from "vue";
|
|
2
|
+
import { GlobalThemeOverrides, NDateLocale } from "naive-ui";
|
|
3
|
+
import * as naive_ui_es_themes_interface0 from "naive-ui/es/themes/interface";
|
|
4
|
+
|
|
5
|
+
//#region src/composables/useNaiveTheme.d.ts
|
|
6
|
+
interface Color {
|
|
7
|
+
primary: string;
|
|
8
|
+
info: string;
|
|
9
|
+
success: string;
|
|
10
|
+
warning: string;
|
|
11
|
+
error: string;
|
|
12
|
+
}
|
|
13
|
+
interface NaiveThemeOptions {
|
|
14
|
+
language?: string | Ref<string>;
|
|
15
|
+
darkMode?: boolean | Ref<boolean>;
|
|
16
|
+
color?: Color;
|
|
17
|
+
globalThemeOverrides?: GlobalThemeOverrides;
|
|
18
|
+
}
|
|
19
|
+
declare function useNaiveTheme(options?: NaiveThemeOptions): {
|
|
20
|
+
language: Ref<string | undefined, string | undefined>;
|
|
21
|
+
darkMode: Ref<boolean | undefined, boolean | undefined>;
|
|
22
|
+
theme: ComputedRef<naive_ui_es_themes_interface0.BuiltInGlobalTheme | undefined>;
|
|
23
|
+
themeOverrides: ComputedRef<GlobalThemeOverrides>;
|
|
24
|
+
locale: ComputedRef<{
|
|
25
|
+
name: string;
|
|
26
|
+
global: {
|
|
27
|
+
undo: string;
|
|
28
|
+
redo: string;
|
|
29
|
+
confirm: string;
|
|
30
|
+
clear: string;
|
|
31
|
+
};
|
|
32
|
+
Popconfirm: {
|
|
33
|
+
positiveText: string;
|
|
34
|
+
negativeText: string;
|
|
35
|
+
};
|
|
36
|
+
Cascader: {
|
|
37
|
+
placeholder: string;
|
|
38
|
+
loading: string;
|
|
39
|
+
loadingRequiredMessage: (label: string) => string;
|
|
40
|
+
};
|
|
41
|
+
Time: {
|
|
42
|
+
dateFormat: string;
|
|
43
|
+
dateTimeFormat: string;
|
|
44
|
+
};
|
|
45
|
+
DatePicker: {
|
|
46
|
+
yearFormat: string;
|
|
47
|
+
monthFormat: string;
|
|
48
|
+
dayFormat: string;
|
|
49
|
+
yearTypeFormat: string;
|
|
50
|
+
monthTypeFormat: string;
|
|
51
|
+
dateFormat: string;
|
|
52
|
+
dateTimeFormat: string;
|
|
53
|
+
quarterFormat: string;
|
|
54
|
+
weekFormat: string;
|
|
55
|
+
clear: string;
|
|
56
|
+
now: string;
|
|
57
|
+
confirm: string;
|
|
58
|
+
selectTime: string;
|
|
59
|
+
selectDate: string;
|
|
60
|
+
datePlaceholder: string;
|
|
61
|
+
datetimePlaceholder: string;
|
|
62
|
+
monthPlaceholder: string;
|
|
63
|
+
yearPlaceholder: string;
|
|
64
|
+
quarterPlaceholder: string;
|
|
65
|
+
weekPlaceholder: string;
|
|
66
|
+
startDatePlaceholder: string;
|
|
67
|
+
endDatePlaceholder: string;
|
|
68
|
+
startDatetimePlaceholder: string;
|
|
69
|
+
endDatetimePlaceholder: string;
|
|
70
|
+
startMonthPlaceholder: string;
|
|
71
|
+
endMonthPlaceholder: string;
|
|
72
|
+
monthBeforeYear: boolean;
|
|
73
|
+
firstDayOfWeek: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
74
|
+
today: string;
|
|
75
|
+
};
|
|
76
|
+
DataTable: {
|
|
77
|
+
checkTableAll: string;
|
|
78
|
+
uncheckTableAll: string;
|
|
79
|
+
confirm: string;
|
|
80
|
+
clear: string;
|
|
81
|
+
};
|
|
82
|
+
LegacyTransfer: {
|
|
83
|
+
sourceTitle: string;
|
|
84
|
+
targetTitle: string;
|
|
85
|
+
};
|
|
86
|
+
Transfer: {
|
|
87
|
+
selectAll: string;
|
|
88
|
+
unselectAll: string;
|
|
89
|
+
clearAll: string;
|
|
90
|
+
total: (num: number) => string;
|
|
91
|
+
selected: (num: number) => string;
|
|
92
|
+
};
|
|
93
|
+
Empty: {
|
|
94
|
+
description: string;
|
|
95
|
+
};
|
|
96
|
+
Select: {
|
|
97
|
+
placeholder: string;
|
|
98
|
+
};
|
|
99
|
+
TimePicker: {
|
|
100
|
+
placeholder: string;
|
|
101
|
+
positiveText: string;
|
|
102
|
+
negativeText: string;
|
|
103
|
+
now: string;
|
|
104
|
+
clear: string;
|
|
105
|
+
};
|
|
106
|
+
Pagination: {
|
|
107
|
+
goto: string;
|
|
108
|
+
selectionSuffix: string;
|
|
109
|
+
};
|
|
110
|
+
DynamicTags: {
|
|
111
|
+
add: string;
|
|
112
|
+
};
|
|
113
|
+
Log: {
|
|
114
|
+
loading: string;
|
|
115
|
+
};
|
|
116
|
+
Input: {
|
|
117
|
+
placeholder: string;
|
|
118
|
+
};
|
|
119
|
+
InputNumber: {
|
|
120
|
+
placeholder: string;
|
|
121
|
+
};
|
|
122
|
+
DynamicInput: {
|
|
123
|
+
create: string;
|
|
124
|
+
};
|
|
125
|
+
ThemeEditor: {
|
|
126
|
+
title: string;
|
|
127
|
+
clearAllVars: string;
|
|
128
|
+
clearSearch: string;
|
|
129
|
+
filterCompName: string;
|
|
130
|
+
filterVarName: string;
|
|
131
|
+
import: string;
|
|
132
|
+
export: string;
|
|
133
|
+
restore: string;
|
|
134
|
+
};
|
|
135
|
+
Image: {
|
|
136
|
+
tipPrevious: string;
|
|
137
|
+
tipNext: string;
|
|
138
|
+
tipCounterclockwise: string;
|
|
139
|
+
tipClockwise: string;
|
|
140
|
+
tipZoomOut: string;
|
|
141
|
+
tipZoomIn: string;
|
|
142
|
+
tipDownload: string;
|
|
143
|
+
tipClose: string;
|
|
144
|
+
tipOriginalSize: string;
|
|
145
|
+
};
|
|
146
|
+
}>;
|
|
147
|
+
dateLocale: ComputedRef<NDateLocale>;
|
|
148
|
+
color: Ref<{
|
|
149
|
+
primary: string;
|
|
150
|
+
info: string;
|
|
151
|
+
success: string;
|
|
152
|
+
warning: string;
|
|
153
|
+
error: string;
|
|
154
|
+
}, Color | {
|
|
155
|
+
primary: string;
|
|
156
|
+
info: string;
|
|
157
|
+
success: string;
|
|
158
|
+
warning: string;
|
|
159
|
+
error: string;
|
|
160
|
+
}>;
|
|
161
|
+
setColor: (v: Color) => void;
|
|
162
|
+
};
|
|
163
|
+
type NaiveThemeReturns = ReturnType<typeof useNaiveTheme>;
|
|
164
|
+
//#endregion
|
|
165
|
+
export { NaiveThemeReturns, useNaiveTheme };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { ComputedRef, Ref } from "vue";
|
|
2
|
+
import { GlobalThemeOverrides, NDateLocale } from "naive-ui";
|
|
3
|
+
import * as naive_ui_es_themes_interface0 from "naive-ui/es/themes/interface";
|
|
4
|
+
|
|
5
|
+
//#region src/composables/useNaiveTheme.d.ts
|
|
6
|
+
interface Color {
|
|
7
|
+
primary: string;
|
|
8
|
+
info: string;
|
|
9
|
+
success: string;
|
|
10
|
+
warning: string;
|
|
11
|
+
error: string;
|
|
12
|
+
}
|
|
13
|
+
interface NaiveThemeOptions {
|
|
14
|
+
language?: string | Ref<string>;
|
|
15
|
+
darkMode?: boolean | Ref<boolean>;
|
|
16
|
+
color?: Color;
|
|
17
|
+
globalThemeOverrides?: GlobalThemeOverrides;
|
|
18
|
+
}
|
|
19
|
+
declare function useNaiveTheme(options?: NaiveThemeOptions): {
|
|
20
|
+
language: Ref<string | undefined, string | undefined>;
|
|
21
|
+
darkMode: Ref<boolean | undefined, boolean | undefined>;
|
|
22
|
+
theme: ComputedRef<naive_ui_es_themes_interface0.BuiltInGlobalTheme | undefined>;
|
|
23
|
+
themeOverrides: ComputedRef<GlobalThemeOverrides>;
|
|
24
|
+
locale: ComputedRef<{
|
|
25
|
+
name: string;
|
|
26
|
+
global: {
|
|
27
|
+
undo: string;
|
|
28
|
+
redo: string;
|
|
29
|
+
confirm: string;
|
|
30
|
+
clear: string;
|
|
31
|
+
};
|
|
32
|
+
Popconfirm: {
|
|
33
|
+
positiveText: string;
|
|
34
|
+
negativeText: string;
|
|
35
|
+
};
|
|
36
|
+
Cascader: {
|
|
37
|
+
placeholder: string;
|
|
38
|
+
loading: string;
|
|
39
|
+
loadingRequiredMessage: (label: string) => string;
|
|
40
|
+
};
|
|
41
|
+
Time: {
|
|
42
|
+
dateFormat: string;
|
|
43
|
+
dateTimeFormat: string;
|
|
44
|
+
};
|
|
45
|
+
DatePicker: {
|
|
46
|
+
yearFormat: string;
|
|
47
|
+
monthFormat: string;
|
|
48
|
+
dayFormat: string;
|
|
49
|
+
yearTypeFormat: string;
|
|
50
|
+
monthTypeFormat: string;
|
|
51
|
+
dateFormat: string;
|
|
52
|
+
dateTimeFormat: string;
|
|
53
|
+
quarterFormat: string;
|
|
54
|
+
weekFormat: string;
|
|
55
|
+
clear: string;
|
|
56
|
+
now: string;
|
|
57
|
+
confirm: string;
|
|
58
|
+
selectTime: string;
|
|
59
|
+
selectDate: string;
|
|
60
|
+
datePlaceholder: string;
|
|
61
|
+
datetimePlaceholder: string;
|
|
62
|
+
monthPlaceholder: string;
|
|
63
|
+
yearPlaceholder: string;
|
|
64
|
+
quarterPlaceholder: string;
|
|
65
|
+
weekPlaceholder: string;
|
|
66
|
+
startDatePlaceholder: string;
|
|
67
|
+
endDatePlaceholder: string;
|
|
68
|
+
startDatetimePlaceholder: string;
|
|
69
|
+
endDatetimePlaceholder: string;
|
|
70
|
+
startMonthPlaceholder: string;
|
|
71
|
+
endMonthPlaceholder: string;
|
|
72
|
+
monthBeforeYear: boolean;
|
|
73
|
+
firstDayOfWeek: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
74
|
+
today: string;
|
|
75
|
+
};
|
|
76
|
+
DataTable: {
|
|
77
|
+
checkTableAll: string;
|
|
78
|
+
uncheckTableAll: string;
|
|
79
|
+
confirm: string;
|
|
80
|
+
clear: string;
|
|
81
|
+
};
|
|
82
|
+
LegacyTransfer: {
|
|
83
|
+
sourceTitle: string;
|
|
84
|
+
targetTitle: string;
|
|
85
|
+
};
|
|
86
|
+
Transfer: {
|
|
87
|
+
selectAll: string;
|
|
88
|
+
unselectAll: string;
|
|
89
|
+
clearAll: string;
|
|
90
|
+
total: (num: number) => string;
|
|
91
|
+
selected: (num: number) => string;
|
|
92
|
+
};
|
|
93
|
+
Empty: {
|
|
94
|
+
description: string;
|
|
95
|
+
};
|
|
96
|
+
Select: {
|
|
97
|
+
placeholder: string;
|
|
98
|
+
};
|
|
99
|
+
TimePicker: {
|
|
100
|
+
placeholder: string;
|
|
101
|
+
positiveText: string;
|
|
102
|
+
negativeText: string;
|
|
103
|
+
now: string;
|
|
104
|
+
clear: string;
|
|
105
|
+
};
|
|
106
|
+
Pagination: {
|
|
107
|
+
goto: string;
|
|
108
|
+
selectionSuffix: string;
|
|
109
|
+
};
|
|
110
|
+
DynamicTags: {
|
|
111
|
+
add: string;
|
|
112
|
+
};
|
|
113
|
+
Log: {
|
|
114
|
+
loading: string;
|
|
115
|
+
};
|
|
116
|
+
Input: {
|
|
117
|
+
placeholder: string;
|
|
118
|
+
};
|
|
119
|
+
InputNumber: {
|
|
120
|
+
placeholder: string;
|
|
121
|
+
};
|
|
122
|
+
DynamicInput: {
|
|
123
|
+
create: string;
|
|
124
|
+
};
|
|
125
|
+
ThemeEditor: {
|
|
126
|
+
title: string;
|
|
127
|
+
clearAllVars: string;
|
|
128
|
+
clearSearch: string;
|
|
129
|
+
filterCompName: string;
|
|
130
|
+
filterVarName: string;
|
|
131
|
+
import: string;
|
|
132
|
+
export: string;
|
|
133
|
+
restore: string;
|
|
134
|
+
};
|
|
135
|
+
Image: {
|
|
136
|
+
tipPrevious: string;
|
|
137
|
+
tipNext: string;
|
|
138
|
+
tipCounterclockwise: string;
|
|
139
|
+
tipClockwise: string;
|
|
140
|
+
tipZoomOut: string;
|
|
141
|
+
tipZoomIn: string;
|
|
142
|
+
tipDownload: string;
|
|
143
|
+
tipClose: string;
|
|
144
|
+
tipOriginalSize: string;
|
|
145
|
+
};
|
|
146
|
+
}>;
|
|
147
|
+
dateLocale: ComputedRef<NDateLocale>;
|
|
148
|
+
color: Ref<{
|
|
149
|
+
primary: string;
|
|
150
|
+
info: string;
|
|
151
|
+
success: string;
|
|
152
|
+
warning: string;
|
|
153
|
+
error: string;
|
|
154
|
+
}, Color | {
|
|
155
|
+
primary: string;
|
|
156
|
+
info: string;
|
|
157
|
+
success: string;
|
|
158
|
+
warning: string;
|
|
159
|
+
error: string;
|
|
160
|
+
}>;
|
|
161
|
+
setColor: (v: Color) => void;
|
|
162
|
+
};
|
|
163
|
+
type NaiveThemeReturns = ReturnType<typeof useNaiveTheme>;
|
|
164
|
+
//#endregion
|
|
165
|
+
export { NaiveThemeReturns, useNaiveTheme };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { computed, ref, toValue, watchEffect } from "vue";
|
|
2
|
+
import { colord } from "colord";
|
|
3
|
+
import { darkTheme, dateEnUS, dateZhCN, enUS, zhCN } from "naive-ui";
|
|
4
|
+
|
|
5
|
+
//#region src/composables/useNaiveTheme.ts
|
|
6
|
+
function getStatusColor(color = "#ff461f") {
|
|
7
|
+
return {
|
|
8
|
+
color,
|
|
9
|
+
hover: colord(color).lighten(.1).toHex(),
|
|
10
|
+
pressed: colord(color).darken(.1).toHex(),
|
|
11
|
+
suppl: colord(color).lighten(.1).toHex()
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const naiveLocaleMap = {
|
|
15
|
+
"zh-CN": {
|
|
16
|
+
name: "简体中文",
|
|
17
|
+
dateLocale: dateZhCN,
|
|
18
|
+
locale: zhCN
|
|
19
|
+
},
|
|
20
|
+
"en-US": {
|
|
21
|
+
name: "English",
|
|
22
|
+
dateLocale: dateEnUS,
|
|
23
|
+
locale: enUS
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
function getColors(color) {
|
|
27
|
+
const { primary, info, success, warning, error } = color;
|
|
28
|
+
return {
|
|
29
|
+
primary: getStatusColor(primary),
|
|
30
|
+
info: getStatusColor(info),
|
|
31
|
+
success: getStatusColor(success),
|
|
32
|
+
warning: getStatusColor(warning),
|
|
33
|
+
error: getStatusColor(error)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function useNaiveTheme(options) {
|
|
37
|
+
const { language, darkMode, color, globalThemeOverrides } = options ?? {};
|
|
38
|
+
const languageRef = ref(toValue(language));
|
|
39
|
+
watchEffect(() => {
|
|
40
|
+
languageRef.value = toValue(language);
|
|
41
|
+
});
|
|
42
|
+
const darkModeRef = ref(toValue(darkMode));
|
|
43
|
+
watchEffect(() => {
|
|
44
|
+
darkModeRef.value = toValue(darkMode);
|
|
45
|
+
});
|
|
46
|
+
const { common, Dialog,...extra } = globalThemeOverrides ?? {};
|
|
47
|
+
const colorRef = ref({
|
|
48
|
+
primary: "#64748B",
|
|
49
|
+
info: "#06b6d4",
|
|
50
|
+
success: "#10b981",
|
|
51
|
+
warning: "#fbbf24",
|
|
52
|
+
error: "#f43f5e",
|
|
53
|
+
...color
|
|
54
|
+
});
|
|
55
|
+
function setColor(v) {
|
|
56
|
+
colorRef.value = v;
|
|
57
|
+
}
|
|
58
|
+
const theme = computed(() => {
|
|
59
|
+
return darkModeRef?.value ? darkTheme : void 0;
|
|
60
|
+
});
|
|
61
|
+
const themeOverrides = computed(() => {
|
|
62
|
+
const { primary, info, success, warning, error } = getColors(colorRef.value);
|
|
63
|
+
return {
|
|
64
|
+
common: {
|
|
65
|
+
bodyColor: darkModeRef?.value ? "#1f1f1f" : "#f5f5f5",
|
|
66
|
+
primaryColor: primary.color,
|
|
67
|
+
primaryColorHover: primary.hover,
|
|
68
|
+
primaryColorPressed: primary.pressed,
|
|
69
|
+
primaryColorSuppl: primary.suppl,
|
|
70
|
+
infoColor: info.color,
|
|
71
|
+
infoColorHover: info.hover,
|
|
72
|
+
infoColorPressed: info.pressed,
|
|
73
|
+
infoColorSuppl: info.suppl,
|
|
74
|
+
successColor: success.color,
|
|
75
|
+
successColorHover: success.hover,
|
|
76
|
+
successColorPressed: success.pressed,
|
|
77
|
+
successColorSuppl: success.suppl,
|
|
78
|
+
warningColor: warning.color,
|
|
79
|
+
warningColorHover: warning.hover,
|
|
80
|
+
warningColorPressed: warning.pressed,
|
|
81
|
+
warningColorSuppl: warning.suppl,
|
|
82
|
+
errorColor: error.color,
|
|
83
|
+
errorColorHover: error.hover,
|
|
84
|
+
errorColorPressed: error.pressed,
|
|
85
|
+
errorColorSuppl: error.suppl,
|
|
86
|
+
borderRadius: "6px",
|
|
87
|
+
...common
|
|
88
|
+
},
|
|
89
|
+
Dialog: {
|
|
90
|
+
borderRadius: "12px",
|
|
91
|
+
padding: "20px",
|
|
92
|
+
closeMargin: "20px 20px 0 0",
|
|
93
|
+
...Dialog
|
|
94
|
+
},
|
|
95
|
+
...extra
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
const locale = computed(() => {
|
|
99
|
+
if (!languageRef?.value || !naiveLocaleMap[languageRef.value]) return naiveLocaleMap["zh-CN"].locale;
|
|
100
|
+
return naiveLocaleMap[languageRef.value].locale;
|
|
101
|
+
});
|
|
102
|
+
const dateLocale = computed(() => {
|
|
103
|
+
if (!languageRef?.value || !naiveLocaleMap[languageRef.value]) return naiveLocaleMap["zh-CN"].dateLocale;
|
|
104
|
+
return naiveLocaleMap[languageRef.value].dateLocale;
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
language: languageRef,
|
|
108
|
+
darkMode: darkModeRef,
|
|
109
|
+
theme,
|
|
110
|
+
themeOverrides,
|
|
111
|
+
locale,
|
|
112
|
+
dateLocale,
|
|
113
|
+
color: colorRef,
|
|
114
|
+
setColor
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
//#endregion
|
|
119
|
+
export { useNaiveTheme };
|