Skip to content

Commit 7d4a556

Browse files
sunshineLixunsendya
authored andcommitted
feat: add ProSelect
1 parent fc607b3 commit 7d4a556

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

packages/pro-field/src/components/Select/SearchSelect/index.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import { searchSelectProps } from './types';
44

55
const SearchSelect = defineComponent({
66
props: searchSelectProps,
7-
setup(props) {
7+
slots: ['option'],
8+
setup(props, { slots }) {
89
return () => {
910
return (
1011
<Select
12+
{...props}
1113
v-slots={{
12-
option: props.option,
14+
option: props.option || slots.option,
1315
}}
14-
{...props}
1516
allowClear
1617
/>
1718
);

packages/pro-field/src/components/Select/SearchSelect/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import type { ExtractPropTypes, PropType } from 'vue';
22
import { selectProps, type DefaultOptionType } from 'ant-design-vue/es/select';
3+
import type { VueNode } from '@ant-design-vue/pro-utils';
34

45
const omitSelectProps = selectProps();
56

67
export const searchSelectProps = {
78
...omitSelectProps,
89
option: {
9-
type: Function as PropType<(props: DefaultOptionType) => void>,
10+
type: Function as PropType<(props: DefaultOptionType) => VueNode>,
1011
},
1112
};
1213

packages/pro-field/src/components/Select/index.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { defineComponent, type App, DefineComponent, Plugin, PropType, ExtractPropTypes } from 'vue';
22
import type { SelectProps } from 'ant-design-vue';
33
import SearchSelect from './SearchSelect';
4+
import type { SearchSelectProps } from './SearchSelect/types';
45
import { proFieldFC } from '../typings';
56

67
export const fieldSelectProps = {
78
...proFieldFC,
89
fieldProps: {
9-
type: Object as PropType<SelectProps>,
10+
type: Object as PropType<SelectProps & { option: SearchSelectProps['option'] }>,
1011
},
1112
};
1213
export type FieldSelectProps = Partial<ExtractPropTypes<typeof fieldSelectProps>>;
1314

1415
const FieldSelect = defineComponent({
1516
props: fieldSelectProps,
17+
slots: ['option'],
1618
setup(props) {
1719
const children = () => {
1820
if (props.mode === 'read') {

packages/pro-form/examples/views/ProForm.vue

+8-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@
9494
}"
9595
required
9696
/>
97-
<pro-form-select name="gender" label="性别" :options="sex" required />
97+
<pro-form-select name="gender" label="性别" :options="sex" required>
98+
<template #option="{ value: val, label, icon }">
99+
<span role="img" :aria-label="val">{{ icon }}</span>
100+
&nbsp;&nbsp;{{ label }}
101+
</template>
102+
</pro-form-select>
98103
</pro-form>
99104
</template>
100105

@@ -122,10 +127,12 @@ const sex = ref([
122127
{
123128
value: '',
124129
label: '',
130+
icon: '🇨🇳',
125131
},
126132
{
127133
value: '',
128134
label: '',
135+
icon: '🇺🇸',
129136
},
130137
]);
131138

packages/pro-form/src/components/Select/index.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { defineComponent, type App, DefineComponent, Plugin, PropType, ExtractPropTypes } from 'vue';
2+
import type { VueNode } from '@ant-design-vue/pro-utils';
23
import { omit, pick } from 'lodash-es';
34
import { proFieldProps } from '@ant-design-vue/pro-field';
4-
import type { SelectProps } from 'ant-design-vue/es/select';
5+
import type { SelectProps, DefaultOptionType } from 'ant-design-vue/es/select';
56
import ProFormField from '../Field';
67
import { proFormGridConfig, extendsProps } from '../../typings';
78
import { proFormItemProps } from '../FormItem';
@@ -17,6 +18,9 @@ const props = {
1718
options: {
1819
type: Array as PropType<SelectProps['options']>,
1920
},
21+
option: {
22+
type: Function as PropType<(props: DefaultOptionType) => VueNode>,
23+
},
2024
};
2125

2226
export type ProFormSelectProps = Partial<ExtractPropTypes<typeof props>>;
@@ -26,7 +30,7 @@ export const ProFormSelect = defineComponent({
2630
inheritAttrs: false,
2731
props,
2832
slots: ['option'],
29-
setup(props) {
33+
setup(props, { slots }) {
3034
const formItemProps = {
3135
...props.formItemProps,
3236
...pick(props, Object.keys(proFormItemProps)),
@@ -38,6 +42,7 @@ export const ProFormSelect = defineComponent({
3842
fieldProps={{
3943
...props.fieldProps,
4044
options: props.options,
45+
option: props.option || slots.option,
4146
}}
4247
filedConfig={{ valueType: 'select' }}
4348
colProps={props.colProps}

0 commit comments

Comments
 (0)