@antdv-next1/pro-card 1.0.0
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/LICENSE +21 -0
- package/dist/ProCard.d.ts +82 -0
- package/dist/ProCard.js +456 -0
- package/dist/components/CheckCard/CheckCard.d.ts +46 -0
- package/dist/components/CheckCard/CheckCard.js +265 -0
- package/dist/components/CheckCard/Group.d.ts +154 -0
- package/dist/components/CheckCard/Group.js +183 -0
- package/dist/components/CheckCard/index.d.ts +3 -0
- package/dist/components/CheckCard/index.js +3 -0
- package/dist/components/CheckCard/style/group.d.ts +13 -0
- package/dist/components/CheckCard/style/group.js +32 -0
- package/dist/components/CheckCard/style/index.d.ts +13 -0
- package/dist/components/CheckCard/style/index.js +165 -0
- package/dist/components/Statistic/index.d.ts +26 -0
- package/dist/components/Statistic/index.js +185 -0
- package/dist/components/Statistic/style/index.d.ts +11 -0
- package/dist/components/Statistic/style/index.js +64 -0
- package/dist/components/StatisticCard/index.d.ts +30 -0
- package/dist/components/StatisticCard/index.js +228 -0
- package/dist/components/StatisticCard/style/index.d.ts +11 -0
- package/dist/components/StatisticCard/style/index.js +47 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/pro-card.esm.js +24585 -0
- package/dist/pro-card.js +169 -0
- package/dist/style/index.d.ts +7 -0
- package/dist/style/index.js +107 -0
- package/dist/typing.d.ts +6 -0
- package/dist/typing.js +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import ProCard from "../../ProCard.js";
|
|
2
|
+
import ProCheckCardGroup, { useCheckCardGroupContextInject } from "./Group.js";
|
|
3
|
+
import { useStyle } from "./style/index.js";
|
|
4
|
+
import { Fragment, computed, createVNode, defineComponent, isVNode, mergeProps, reactive, ref, toRef } from "vue";
|
|
5
|
+
import { isNil, useEffect, useMountMergeState } from "@antdv-next1/pro-utils";
|
|
6
|
+
import { classNames } from "@v-c/util";
|
|
7
|
+
import { Avatar, CardMeta } from "antdv-next";
|
|
8
|
+
import { useConfig } from "antdv-next/dist/config-provider/context";
|
|
9
|
+
//#region src/components/CheckCard/CheckCard.tsx
|
|
10
|
+
function getSizeCls(size) {
|
|
11
|
+
if (size === "large") return "lg";
|
|
12
|
+
if (size === "small") return "sm";
|
|
13
|
+
return "";
|
|
14
|
+
}
|
|
15
|
+
const ProCheckCard = /* @__PURE__ */ defineComponent((props, { slots, attrs }) => {
|
|
16
|
+
const config = useConfig();
|
|
17
|
+
const prefixCls = computed(() => props.prefixCls || config.value.getPrefixCls("pro"));
|
|
18
|
+
const baseClassName = computed(() => `${prefixCls.value}-checkcard`);
|
|
19
|
+
const multiple = ref(false);
|
|
20
|
+
const checkCardGroupProvide = useCheckCardGroupContextInject();
|
|
21
|
+
const { wrapSSR, hashId } = useStyle(baseClassName);
|
|
22
|
+
const checkCardProps = reactive({});
|
|
23
|
+
const [stateChecked, setStateChecked] = useMountMergeState(props.defaultChecked || false, {
|
|
24
|
+
value: toRef(() => props.checked),
|
|
25
|
+
onChange: (checked) => {
|
|
26
|
+
props["onUpdate:checked"]?.(checked);
|
|
27
|
+
props.onChange?.(checked);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
checkCardProps.checked = stateChecked.value;
|
|
32
|
+
if (checkCardGroupProvide.value) {
|
|
33
|
+
checkCardProps.disabled = props.disabled || checkCardGroupProvide.value.disabled;
|
|
34
|
+
checkCardProps.loading = props.loading || checkCardGroupProvide.value.loading;
|
|
35
|
+
checkCardProps.bordered = props.bordered || checkCardGroupProvide.value.bordered;
|
|
36
|
+
multiple.value = checkCardGroupProvide.value.multiple;
|
|
37
|
+
const isChecked = checkCardGroupProvide.value.multiple ? checkCardGroupProvide.value.value?.includes(props.value) : checkCardGroupProvide.value.value === props.value;
|
|
38
|
+
checkCardProps.checked = checkCardProps.loading ? false : isChecked;
|
|
39
|
+
checkCardProps.size = props.size || checkCardGroupProvide.value.size;
|
|
40
|
+
}
|
|
41
|
+
}, [checkCardGroupProvide, stateChecked]);
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
checkCardGroupProvide.value?.registerValue?.(props.value);
|
|
44
|
+
return () => checkCardGroupProvide.value?.cancelValue?.(props.value);
|
|
45
|
+
}, [() => props.value]);
|
|
46
|
+
const handleClick = (e) => {
|
|
47
|
+
props?.onClick?.(e);
|
|
48
|
+
const newChecked = !stateChecked.value;
|
|
49
|
+
if (checkCardGroupProvide.value && checkCardGroupProvide.value.value === props.value && !checkCardGroupProvide.value.multiple) return;
|
|
50
|
+
checkCardGroupProvide.value?.toggleOption?.({ value: props.value });
|
|
51
|
+
setStateChecked?.(newChecked);
|
|
52
|
+
};
|
|
53
|
+
return () => {
|
|
54
|
+
const { title, avatar, prefixCls, onChange, value, disabled: propsDisabled, defaultChecked, checked, "onUpdate:checked": onUpdateChecked, "onUpdate:value": onUpdateValue, description, borderBeam, size: propsSize, onClick, ...rest } = props;
|
|
55
|
+
Object.keys(rest).forEach((key) => {
|
|
56
|
+
checkCardProps[key] = rest[key];
|
|
57
|
+
});
|
|
58
|
+
const { disabled = propsDisabled || false, loading: cardLoading, bordered = true, size, checked: propsChecked = checked, cover, extra, ...restCardProps } = checkCardProps;
|
|
59
|
+
const sizeCls = getSizeCls(size || propsSize);
|
|
60
|
+
const avatarDom = isVNode(avatar) ? avatar : slots.avatar?.() || avatar && createVNode(Avatar, {
|
|
61
|
+
"size": 48,
|
|
62
|
+
"shape": "square",
|
|
63
|
+
"src": avatar
|
|
64
|
+
}, null);
|
|
65
|
+
const headerDom = isNil((slots.title?.() || title) ?? (slots.extra?.() || extra)) ? null : !(slots.extra?.() || extra) ? slots.title?.() || title : createVNode(Fragment, null, [createVNode("div", { "class": classNames(`${baseClassName.value}-meta-title-left`, hashId.value) }, [createVNode("div", { "class": classNames(`${baseClassName.value}-meta-title-left-text`, hashId.value) }, [slots.title?.() || title])]), createVNode("div", { "class": classNames(`${baseClassName.value}-meta-title-extra`, hashId.value) }, [slots.extra?.() || extra])]);
|
|
66
|
+
const descriptionDom = slots.description?.() || description;
|
|
67
|
+
const coverDom = cover || slots.cover?.();
|
|
68
|
+
return wrapSSR(createVNode(ProCard, mergeProps({
|
|
69
|
+
"style": attrs.style,
|
|
70
|
+
"class": classNames(baseClassName.value, attrs.class, hashId.value, {
|
|
71
|
+
[`${baseClassName.value}-checked`]: propsChecked,
|
|
72
|
+
[`${baseClassName.value}-multiple`]: checkCardProps.multiple,
|
|
73
|
+
[`${baseClassName.value}-disabled`]: disabled,
|
|
74
|
+
[`${baseClassName.value}-${sizeCls}`]: sizeCls
|
|
75
|
+
}),
|
|
76
|
+
"borderBeam": !propsChecked && borderBeam ? borderBeam : void 0,
|
|
77
|
+
"disabled": disabled
|
|
78
|
+
}, restCardProps, {
|
|
79
|
+
"loading": cardLoading,
|
|
80
|
+
"onClick": (e) => {
|
|
81
|
+
if (!cardLoading && !disabled) handleClick(e);
|
|
82
|
+
}
|
|
83
|
+
}), {
|
|
84
|
+
...coverDom && { cover: () => typeof coverDom === "string" ? createVNode("img", {
|
|
85
|
+
"src": coverDom,
|
|
86
|
+
"alt": "checkcard"
|
|
87
|
+
}, null) : coverDom },
|
|
88
|
+
...headerDom || avatarDom || descriptionDom || cardLoading ? { default: () => createVNode(CardMeta, {
|
|
89
|
+
"title": headerDom,
|
|
90
|
+
"description": descriptionDom,
|
|
91
|
+
"class": classNames(`${baseClassName.value}-meta`, hashId.value, {
|
|
92
|
+
[`${baseClassName.value}-meta-avatar-header`]: avatarDom && headerDom && !descriptionDom,
|
|
93
|
+
[`${baseClassName.value}-meta-extra-header`]: !isNil(slots.extra?.() || extra)
|
|
94
|
+
}),
|
|
95
|
+
"avatar": avatarDom
|
|
96
|
+
}, null) } : {}
|
|
97
|
+
}));
|
|
98
|
+
};
|
|
99
|
+
}, {
|
|
100
|
+
props: {
|
|
101
|
+
prefixCls: {
|
|
102
|
+
type: String,
|
|
103
|
+
required: false
|
|
104
|
+
},
|
|
105
|
+
avatar: {
|
|
106
|
+
type: [
|
|
107
|
+
Function,
|
|
108
|
+
String,
|
|
109
|
+
Number,
|
|
110
|
+
null,
|
|
111
|
+
Object,
|
|
112
|
+
Boolean
|
|
113
|
+
],
|
|
114
|
+
required: false,
|
|
115
|
+
default: void 0
|
|
116
|
+
},
|
|
117
|
+
title: {
|
|
118
|
+
type: [
|
|
119
|
+
Function,
|
|
120
|
+
String,
|
|
121
|
+
Number,
|
|
122
|
+
null,
|
|
123
|
+
Object,
|
|
124
|
+
Boolean
|
|
125
|
+
],
|
|
126
|
+
required: false,
|
|
127
|
+
default: void 0
|
|
128
|
+
},
|
|
129
|
+
description: {
|
|
130
|
+
type: [
|
|
131
|
+
Function,
|
|
132
|
+
String,
|
|
133
|
+
Number,
|
|
134
|
+
null,
|
|
135
|
+
Object,
|
|
136
|
+
Boolean
|
|
137
|
+
],
|
|
138
|
+
required: false,
|
|
139
|
+
default: void 0
|
|
140
|
+
},
|
|
141
|
+
classes: {
|
|
142
|
+
type: [Object, Function],
|
|
143
|
+
required: false
|
|
144
|
+
},
|
|
145
|
+
styles: {
|
|
146
|
+
type: [Object, Function],
|
|
147
|
+
required: false
|
|
148
|
+
},
|
|
149
|
+
extra: {
|
|
150
|
+
type: [
|
|
151
|
+
Function,
|
|
152
|
+
String,
|
|
153
|
+
Number,
|
|
154
|
+
null,
|
|
155
|
+
Object,
|
|
156
|
+
Boolean
|
|
157
|
+
],
|
|
158
|
+
required: false,
|
|
159
|
+
default: void 0
|
|
160
|
+
},
|
|
161
|
+
bordered: {
|
|
162
|
+
type: Boolean,
|
|
163
|
+
required: false,
|
|
164
|
+
default: void 0
|
|
165
|
+
},
|
|
166
|
+
loading: {
|
|
167
|
+
type: Boolean,
|
|
168
|
+
required: false,
|
|
169
|
+
default: void 0
|
|
170
|
+
},
|
|
171
|
+
hoverable: {
|
|
172
|
+
type: Boolean,
|
|
173
|
+
required: false,
|
|
174
|
+
default: void 0
|
|
175
|
+
},
|
|
176
|
+
id: {
|
|
177
|
+
type: String,
|
|
178
|
+
required: false
|
|
179
|
+
},
|
|
180
|
+
cover: {
|
|
181
|
+
type: [
|
|
182
|
+
Function,
|
|
183
|
+
String,
|
|
184
|
+
Number,
|
|
185
|
+
null,
|
|
186
|
+
Object,
|
|
187
|
+
Boolean
|
|
188
|
+
],
|
|
189
|
+
required: false,
|
|
190
|
+
default: void 0
|
|
191
|
+
},
|
|
192
|
+
actions: {
|
|
193
|
+
type: Array,
|
|
194
|
+
required: false
|
|
195
|
+
},
|
|
196
|
+
tabProps: {
|
|
197
|
+
type: Object,
|
|
198
|
+
required: false
|
|
199
|
+
},
|
|
200
|
+
variant: {
|
|
201
|
+
type: String,
|
|
202
|
+
required: false
|
|
203
|
+
},
|
|
204
|
+
rootClass: {
|
|
205
|
+
type: String,
|
|
206
|
+
required: false
|
|
207
|
+
},
|
|
208
|
+
"onUpdate:activeTabKey": {
|
|
209
|
+
type: Function,
|
|
210
|
+
required: false
|
|
211
|
+
},
|
|
212
|
+
borderBeam: {
|
|
213
|
+
type: [Object, Boolean],
|
|
214
|
+
required: false,
|
|
215
|
+
default: void 0
|
|
216
|
+
},
|
|
217
|
+
size: { required: false },
|
|
218
|
+
checked: {
|
|
219
|
+
type: Boolean,
|
|
220
|
+
required: false,
|
|
221
|
+
default: void 0
|
|
222
|
+
},
|
|
223
|
+
value: {
|
|
224
|
+
type: [
|
|
225
|
+
String,
|
|
226
|
+
Number,
|
|
227
|
+
Boolean
|
|
228
|
+
],
|
|
229
|
+
required: false,
|
|
230
|
+
default: void 0
|
|
231
|
+
},
|
|
232
|
+
"onUpdate:value": {
|
|
233
|
+
type: Function,
|
|
234
|
+
required: false
|
|
235
|
+
},
|
|
236
|
+
disabled: {
|
|
237
|
+
type: Boolean,
|
|
238
|
+
required: false,
|
|
239
|
+
default: void 0
|
|
240
|
+
},
|
|
241
|
+
"onUpdate:checked": {
|
|
242
|
+
type: Function,
|
|
243
|
+
required: false
|
|
244
|
+
},
|
|
245
|
+
onChange: {
|
|
246
|
+
type: Function,
|
|
247
|
+
required: false
|
|
248
|
+
},
|
|
249
|
+
defaultChecked: {
|
|
250
|
+
type: Boolean,
|
|
251
|
+
required: false,
|
|
252
|
+
default: void 0
|
|
253
|
+
},
|
|
254
|
+
onClick: {
|
|
255
|
+
type: Function,
|
|
256
|
+
required: false
|
|
257
|
+
},
|
|
258
|
+
collapsible: { required: false }
|
|
259
|
+
},
|
|
260
|
+
name: "ProCheckCard",
|
|
261
|
+
inheritAttrs: false
|
|
262
|
+
});
|
|
263
|
+
ProCheckCard.Group = ProCheckCardGroup;
|
|
264
|
+
//#endregion
|
|
265
|
+
export { ProCheckCard as default };
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { ComputedRef, FunctionalComponent, InjectionKey } from "vue";
|
|
2
|
+
import { Key, VueNode } from "@antdv-next1/pro-utils";
|
|
3
|
+
|
|
4
|
+
//#region src/components/CheckCard/Group.d.ts
|
|
5
|
+
type CheckCardValueType = string | number | boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Represents the possible value types for a CheckGroup.
|
|
8
|
+
* It can be an array of CheckCardValueTypes, a single CheckCardValueType, or undefined.
|
|
9
|
+
*/
|
|
10
|
+
type CheckGroupValueType = CheckCardValueType[] | CheckCardValueType | undefined;
|
|
11
|
+
/**
|
|
12
|
+
* Represents an option for a CheckCard component.
|
|
13
|
+
*/
|
|
14
|
+
interface CheckCardItemType {
|
|
15
|
+
key?: Key;
|
|
16
|
+
/**
|
|
17
|
+
* The title to be displayed.
|
|
18
|
+
*
|
|
19
|
+
* @title Title
|
|
20
|
+
*/
|
|
21
|
+
title?: VueNode;
|
|
22
|
+
/**
|
|
23
|
+
* The value of the option.
|
|
24
|
+
*
|
|
25
|
+
* @title Value
|
|
26
|
+
*/
|
|
27
|
+
value: CheckCardValueType;
|
|
28
|
+
/**
|
|
29
|
+
* The description to be displayed.
|
|
30
|
+
*
|
|
31
|
+
* @title Description
|
|
32
|
+
*/
|
|
33
|
+
description?: VueNode;
|
|
34
|
+
/**
|
|
35
|
+
* The size of the component. Supports three default sizes: 'large', 'default', 'small'.
|
|
36
|
+
* Users can also customize the width and height.
|
|
37
|
+
*
|
|
38
|
+
* @default default
|
|
39
|
+
* @title Component Size
|
|
40
|
+
*/
|
|
41
|
+
size?: 'large' | 'default' | 'small';
|
|
42
|
+
/**
|
|
43
|
+
* The avatar to be displayed on the left side. Can be a link or a ReactNode.
|
|
44
|
+
*
|
|
45
|
+
* @title Left Avatar Area
|
|
46
|
+
*/
|
|
47
|
+
avatar?: VueNode;
|
|
48
|
+
/**
|
|
49
|
+
* The cover image. In this mode, other display values are ignored.
|
|
50
|
+
*
|
|
51
|
+
* @title Cover Image
|
|
52
|
+
*/
|
|
53
|
+
cover?: VueNode;
|
|
54
|
+
/**
|
|
55
|
+
* Specifies if the option is disabled.
|
|
56
|
+
*
|
|
57
|
+
* @default false
|
|
58
|
+
* @title Disabled
|
|
59
|
+
*/
|
|
60
|
+
disabled?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Change callback function.
|
|
63
|
+
*
|
|
64
|
+
* @param checked - Indicates whether the option is checked or not.
|
|
65
|
+
* @title Change Callback
|
|
66
|
+
*/
|
|
67
|
+
onChange?: (checked: boolean) => void;
|
|
68
|
+
}
|
|
69
|
+
interface CheckCardItemGroupType {
|
|
70
|
+
title?: string;
|
|
71
|
+
key?: Key;
|
|
72
|
+
/**
|
|
73
|
+
* Child options.
|
|
74
|
+
*/
|
|
75
|
+
children: CheckCardItemType[];
|
|
76
|
+
}
|
|
77
|
+
type CheckCardOptionType = string | CheckCardItemType | CheckCardItemGroupType;
|
|
78
|
+
/**
|
|
79
|
+
* Represents the props for the CheckCardGroup component.
|
|
80
|
+
*/
|
|
81
|
+
interface CheckCardGroupContextType {
|
|
82
|
+
/**
|
|
83
|
+
* A function to toggle the selected option.
|
|
84
|
+
* @param option - The option to toggle.
|
|
85
|
+
*/
|
|
86
|
+
toggleOption?: (option: CheckCardItemType) => void;
|
|
87
|
+
/**
|
|
88
|
+
* The currently selected value.
|
|
89
|
+
*/
|
|
90
|
+
value?: any;
|
|
91
|
+
/**
|
|
92
|
+
* Specifies whether the component is disabled.
|
|
93
|
+
*/
|
|
94
|
+
disabled?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* The size of the component.
|
|
97
|
+
*/
|
|
98
|
+
size?: any;
|
|
99
|
+
/**
|
|
100
|
+
* Specifies whether the component is in a loading state.
|
|
101
|
+
*/
|
|
102
|
+
loading?: any;
|
|
103
|
+
/**
|
|
104
|
+
* Specifies whether the component has a border.
|
|
105
|
+
*/
|
|
106
|
+
bordered?: any;
|
|
107
|
+
/**
|
|
108
|
+
* Specifies whether multiple options can be selected.
|
|
109
|
+
*/
|
|
110
|
+
multiple?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* A function to register a value.
|
|
113
|
+
* @param value - The value to register.
|
|
114
|
+
*/
|
|
115
|
+
registerValue?: (value: any) => void;
|
|
116
|
+
/**
|
|
117
|
+
* A function to cancel a value.
|
|
118
|
+
* @param value - The value to cancel.
|
|
119
|
+
*/
|
|
120
|
+
cancelValue?: (value: any) => void;
|
|
121
|
+
}
|
|
122
|
+
declare const checkCardGroupContextKey: InjectionKey<ComputedRef<CheckCardGroupContextType>>;
|
|
123
|
+
declare function useCheckCardGroupContextProvider(props: ComputedRef<CheckCardGroupContextType>): void;
|
|
124
|
+
declare function useCheckCardGroupContextInject(): ComputedRef<CheckCardGroupContextType>;
|
|
125
|
+
interface ProCheckCardGroupProps {
|
|
126
|
+
prefixCls?: string;
|
|
127
|
+
disabled?: boolean;
|
|
128
|
+
/**
|
|
129
|
+
* 是否多选
|
|
130
|
+
*
|
|
131
|
+
* @title 是否多选
|
|
132
|
+
*/
|
|
133
|
+
multiple?: boolean;
|
|
134
|
+
/**
|
|
135
|
+
* 默认选中的选项
|
|
136
|
+
*
|
|
137
|
+
* @title 默认选中的选项
|
|
138
|
+
*/
|
|
139
|
+
defaultValue?: CheckGroupValueType;
|
|
140
|
+
/**
|
|
141
|
+
* 指定选中的选项
|
|
142
|
+
*
|
|
143
|
+
* @title 指定选中的选项
|
|
144
|
+
*/
|
|
145
|
+
value?: CheckGroupValueType;
|
|
146
|
+
'onUpdate:value'?: (value: CheckGroupValueType) => void;
|
|
147
|
+
onChange?: (value: CheckGroupValueType) => void;
|
|
148
|
+
options?: CheckCardOptionType[];
|
|
149
|
+
loading?: boolean;
|
|
150
|
+
size?: 'large' | 'default' | 'small';
|
|
151
|
+
}
|
|
152
|
+
declare const ProCheckCardGroup: FunctionalComponent<ProCheckCardGroupProps>;
|
|
153
|
+
//#endregion
|
|
154
|
+
export { CheckCardGroupContextType, CheckCardItemGroupType, CheckCardItemType, CheckCardOptionType, CheckCardValueType, CheckGroupValueType, ProCheckCardGroupProps, checkCardGroupContextKey, ProCheckCardGroup as default, useCheckCardGroupContextInject, useCheckCardGroupContextProvider };
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import ProCard from "../../ProCard.js";
|
|
2
|
+
import { useStyle as useStyle$1 } from "./style/group.js";
|
|
3
|
+
import ProCheckCard from "./CheckCard.js";
|
|
4
|
+
import { computed, createVNode, defineComponent, inject, provide, shallowRef, toRef } from "vue";
|
|
5
|
+
import { childrenToArray, isSpecialNode, useMountMergeState } from "@antdv-next1/pro-utils";
|
|
6
|
+
import { classNames } from "@v-c/util";
|
|
7
|
+
import { useConfig } from "antdv-next/dist/config-provider/context";
|
|
8
|
+
import { ProConfigProvider } from "@antdv-next1/pro-provider";
|
|
9
|
+
//#region src/components/CheckCard/Group.tsx
|
|
10
|
+
/**
|
|
11
|
+
* Represents the possible value types for a CheckGroup.
|
|
12
|
+
* It can be an array of CheckCardValueTypes, a single CheckCardValueType, or undefined.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Represents an option for a CheckCard component.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Represents the props for the CheckCardGroup component.
|
|
19
|
+
*/
|
|
20
|
+
const checkCardGroupContextKey = Symbol("checkCardGroupContext");
|
|
21
|
+
function useCheckCardGroupContextProvider(props) {
|
|
22
|
+
return provide(checkCardGroupContextKey, props);
|
|
23
|
+
}
|
|
24
|
+
function useCheckCardGroupContextInject() {
|
|
25
|
+
return inject(checkCardGroupContextKey, computed(() => void 0));
|
|
26
|
+
}
|
|
27
|
+
const InternalCheckCardGroup = /* @__PURE__ */ defineComponent((props, { slots, attrs }) => {
|
|
28
|
+
const config = useConfig();
|
|
29
|
+
const prefixCls = computed(() => props.prefixCls || config.value.getPrefixCls("pro"));
|
|
30
|
+
const baseClassName = computed(() => `${prefixCls.value}-checkcard-group`);
|
|
31
|
+
const registerValueMap = shallowRef(/* @__PURE__ */ new Map());
|
|
32
|
+
const { wrapSSR, hashId } = useStyle$1(baseClassName);
|
|
33
|
+
const [stateValue, setStateValue] = useMountMergeState(props.defaultValue, {
|
|
34
|
+
value: toRef(() => props.value),
|
|
35
|
+
onChange: (value) => {
|
|
36
|
+
props.onChange?.(value);
|
|
37
|
+
props["onUpdate:value"]?.(value);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const registerValue = (value) => registerValueMap.value?.set(value, true);
|
|
41
|
+
const cancelValue = (value) => registerValueMap.value?.delete(value);
|
|
42
|
+
const getOptions = (options = []) => options.map((option) => {
|
|
43
|
+
if (typeof option === "string") return {
|
|
44
|
+
title: option,
|
|
45
|
+
value: option
|
|
46
|
+
};
|
|
47
|
+
return option;
|
|
48
|
+
});
|
|
49
|
+
const children = computed(() => {
|
|
50
|
+
if (props.loading) return Array.from({ length: props.options?.length || childrenToArray(slots.default?.()).filter((vnode) => !isSpecialNode(vnode)).length || 1 }).fill(0).map((_, index) => createVNode(ProCheckCard, {
|
|
51
|
+
"key": index,
|
|
52
|
+
"loading": true
|
|
53
|
+
}, null));
|
|
54
|
+
if (getOptions(props.options) && getOptions(props.options).length > 0) {
|
|
55
|
+
const optionValue = stateValue.value;
|
|
56
|
+
const renderOptions = (list) => {
|
|
57
|
+
return list.map((option, index) => {
|
|
58
|
+
if (option?.children && option?.children.length > 0) return createVNode(ProCard, {
|
|
59
|
+
"collapsible": true,
|
|
60
|
+
"key": option.title?.toString() || index.toString(),
|
|
61
|
+
"title": option.title,
|
|
62
|
+
"style": { flex: "0 0 100%" }
|
|
63
|
+
}, { default: () => renderOptions(option?.children) });
|
|
64
|
+
return createVNode(ProCheckCard, {
|
|
65
|
+
"key": option.value.toString(),
|
|
66
|
+
"disabled": option.disabled,
|
|
67
|
+
"size": option.size ?? props.size,
|
|
68
|
+
"value": option.value,
|
|
69
|
+
"checked": props.multiple ? optionValue?.includes(option.value) : optionValue === option.value,
|
|
70
|
+
"onChange": option.onChange,
|
|
71
|
+
"title": option.title,
|
|
72
|
+
"avatar": option.avatar,
|
|
73
|
+
"description": option.description,
|
|
74
|
+
"cover": option.cover
|
|
75
|
+
}, null);
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
return renderOptions(getOptions(props.options));
|
|
79
|
+
}
|
|
80
|
+
return slots.default?.();
|
|
81
|
+
});
|
|
82
|
+
const toggleOption = (option) => {
|
|
83
|
+
if (!props.multiple) {
|
|
84
|
+
let changeValue;
|
|
85
|
+
changeValue = stateValue.value;
|
|
86
|
+
if (changeValue === option.value) changeValue = void 0;
|
|
87
|
+
else changeValue = option.value;
|
|
88
|
+
setStateValue?.(changeValue);
|
|
89
|
+
}
|
|
90
|
+
if (props.multiple) {
|
|
91
|
+
let changeValue = [];
|
|
92
|
+
const stateValues = stateValue.value;
|
|
93
|
+
const hasOption = stateValues?.includes(option.value);
|
|
94
|
+
changeValue = [...stateValues || []];
|
|
95
|
+
if (!hasOption) changeValue.push(option.value);
|
|
96
|
+
if (hasOption) changeValue = changeValue.filter((itemValue) => itemValue !== option.value);
|
|
97
|
+
const newOptions = getOptions(props.options);
|
|
98
|
+
const newValue = changeValue?.filter((val) => registerValueMap.value.has(val))?.sort((a, b) => {
|
|
99
|
+
return newOptions.findIndex((opt) => opt.value === a) - newOptions.findIndex((opt) => opt.value === b);
|
|
100
|
+
});
|
|
101
|
+
setStateValue(newValue);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
useCheckCardGroupContextProvider(computed(() => ({
|
|
105
|
+
toggleOption,
|
|
106
|
+
value: stateValue.value,
|
|
107
|
+
disabled: props.disabled,
|
|
108
|
+
size: props.size,
|
|
109
|
+
loading: props.loading,
|
|
110
|
+
multiple: props.multiple,
|
|
111
|
+
registerValue,
|
|
112
|
+
cancelValue
|
|
113
|
+
})));
|
|
114
|
+
return () => wrapSSR(createVNode("div", {
|
|
115
|
+
"class": classNames(baseClassName.value, hashId.value),
|
|
116
|
+
"style": attrs.style
|
|
117
|
+
}, [children.value]));
|
|
118
|
+
}, {
|
|
119
|
+
props: {
|
|
120
|
+
prefixCls: {
|
|
121
|
+
type: String,
|
|
122
|
+
required: false
|
|
123
|
+
},
|
|
124
|
+
disabled: {
|
|
125
|
+
type: Boolean,
|
|
126
|
+
required: false,
|
|
127
|
+
default: void 0
|
|
128
|
+
},
|
|
129
|
+
multiple: {
|
|
130
|
+
type: Boolean,
|
|
131
|
+
required: false,
|
|
132
|
+
default: void 0
|
|
133
|
+
},
|
|
134
|
+
defaultValue: {
|
|
135
|
+
type: [
|
|
136
|
+
Array,
|
|
137
|
+
String,
|
|
138
|
+
Number,
|
|
139
|
+
Boolean,
|
|
140
|
+
null
|
|
141
|
+
],
|
|
142
|
+
required: false,
|
|
143
|
+
default: void 0
|
|
144
|
+
},
|
|
145
|
+
value: {
|
|
146
|
+
type: [
|
|
147
|
+
Array,
|
|
148
|
+
String,
|
|
149
|
+
Number,
|
|
150
|
+
Boolean,
|
|
151
|
+
null
|
|
152
|
+
],
|
|
153
|
+
required: false,
|
|
154
|
+
default: void 0
|
|
155
|
+
},
|
|
156
|
+
"onUpdate:value": {
|
|
157
|
+
type: Function,
|
|
158
|
+
required: false
|
|
159
|
+
},
|
|
160
|
+
onChange: {
|
|
161
|
+
type: Function,
|
|
162
|
+
required: false
|
|
163
|
+
},
|
|
164
|
+
options: {
|
|
165
|
+
type: Array,
|
|
166
|
+
required: false
|
|
167
|
+
},
|
|
168
|
+
loading: {
|
|
169
|
+
type: Boolean,
|
|
170
|
+
required: false,
|
|
171
|
+
default: void 0
|
|
172
|
+
},
|
|
173
|
+
size: {
|
|
174
|
+
type: String,
|
|
175
|
+
required: false
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
name: "InternalCheckCardGroup",
|
|
179
|
+
inheritAttrs: false
|
|
180
|
+
});
|
|
181
|
+
const ProCheckCardGroup = (props, { slots }) => createVNode(ProConfigProvider, { "needDeps": true }, { default: () => [createVNode(InternalCheckCardGroup, props, slots)] });
|
|
182
|
+
//#endregion
|
|
183
|
+
export { checkCardGroupContextKey, ProCheckCardGroup as default, useCheckCardGroupContextInject, useCheckCardGroupContextProvider };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ComputedRef } from "vue";
|
|
2
|
+
import * as _$_antdv_next1_pro_provider0 from "@antdv-next1/pro-provider";
|
|
3
|
+
import { ProAliasToken } from "@antdv-next1/pro-provider";
|
|
4
|
+
import { Keyframes } from "@antdv-next/cssinjs";
|
|
5
|
+
|
|
6
|
+
//#region src/components/CheckCard/style/group.d.ts
|
|
7
|
+
interface ProCheckCardGroupToken extends ProAliasToken {
|
|
8
|
+
componentCls: string;
|
|
9
|
+
}
|
|
10
|
+
declare const cardLoading: Keyframes;
|
|
11
|
+
declare function useStyle(prefixCls: ComputedRef<string>): _$_antdv_next1_pro_provider0.UseStyleResult;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { ProCheckCardGroupToken, cardLoading, useStyle };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useStyle as useStyle$1 } from "@antdv-next1/pro-provider";
|
|
2
|
+
import { Keyframes } from "@antdv-next/cssinjs";
|
|
3
|
+
//#region src/components/CheckCard/style/group.ts
|
|
4
|
+
const cardLoading = new Keyframes("card-loading", {
|
|
5
|
+
"0%": { backgroundPosition: "0 50%" },
|
|
6
|
+
"50%": { backgroundPosition: "100% 50%" },
|
|
7
|
+
"100%": { backgroundPosition: "0 50%" }
|
|
8
|
+
});
|
|
9
|
+
const genProCheckCardGroupStyle = (token) => {
|
|
10
|
+
return { [token.componentCls]: {
|
|
11
|
+
display: "inline-flex",
|
|
12
|
+
flexWrap: "wrap",
|
|
13
|
+
columnGap: token.margin,
|
|
14
|
+
rowGap: token.margin,
|
|
15
|
+
position: "relative",
|
|
16
|
+
[`${token.antCls}-row`]: { width: "100%" },
|
|
17
|
+
[`${token.proComponentsCls}-card${token.proComponentsCls}-checkcard`]: {
|
|
18
|
+
marginInlineEnd: 0,
|
|
19
|
+
marginBlockEnd: 0
|
|
20
|
+
}
|
|
21
|
+
} };
|
|
22
|
+
};
|
|
23
|
+
function useStyle(prefixCls) {
|
|
24
|
+
return useStyle$1("ProCheckCardGroup", (token) => {
|
|
25
|
+
return [genProCheckCardGroupStyle({
|
|
26
|
+
...token,
|
|
27
|
+
componentCls: `.${prefixCls.value}`
|
|
28
|
+
})];
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { cardLoading, useStyle };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ComputedRef } from "vue";
|
|
2
|
+
import * as _$_antdv_next1_pro_provider0 from "@antdv-next1/pro-provider";
|
|
3
|
+
import { ProAliasToken } from "@antdv-next1/pro-provider";
|
|
4
|
+
import { Keyframes } from "@antdv-next/cssinjs";
|
|
5
|
+
|
|
6
|
+
//#region src/components/CheckCard/style/index.d.ts
|
|
7
|
+
interface ProCheckCardToken extends ProAliasToken {
|
|
8
|
+
componentCls: string;
|
|
9
|
+
}
|
|
10
|
+
declare const cardLoading: Keyframes;
|
|
11
|
+
declare function useStyle(prefixCls: ComputedRef<string>): _$_antdv_next1_pro_provider0.UseStyleResult;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { ProCheckCardToken, cardLoading, useStyle };
|