feat: support vue 3.3 slot type

pull/6584/head
tangjinzhou 2023-05-18 22:53:21 +08:00
parent b4258dc23d
commit 144bb2e6d5
9 changed files with 90 additions and 62 deletions

View File

@ -46,7 +46,7 @@ const AutoComplete = defineComponent({
props: autoCompleteProps(), props: autoCompleteProps(),
// emits: ['change', 'select', 'focus', 'blur'], // emits: ['change', 'select', 'focus', 'blur'],
slots: Object as CustomSlotsType<{ slots: Object as CustomSlotsType<{
option: any; options: any;
default: any; default: any;
notFoundContent: any; notFoundContent: any;
dataSource: any; dataSource: any;

View File

@ -37,7 +37,7 @@ Customize Calendar header content.
:value="String(current.year())" :value="String(current.year())"
@change=" @change="
newYear => { newYear => {
onChange(current.year(newYear)); onChange(current.year(+newYear));
} }
" "
> >

View File

@ -12,7 +12,7 @@ import { useLocaleReceiver } from '../locale-provider/LocaleReceiver';
import enUS from './locale/en_US'; import enUS from './locale/en_US';
import CalendarHeader from './Header'; import CalendarHeader from './Header';
import type { CustomSlotsType, VueNode } from '../_util/type'; import type { CustomSlotsType, VueNode } from '../_util/type';
import type { App } from 'vue'; import type { App, PropType } from 'vue';
import { computed, defineComponent, toRef } from 'vue'; import { computed, defineComponent, toRef } from 'vue';
import useConfigInject from '../_util/hooks/useConfigInject'; import useConfigInject from '../_util/hooks/useConfigInject';
import classNames from '../_util/classNames'; import classNames from '../_util/classNames';
@ -86,28 +86,41 @@ function generateCalendar<
); );
} }
const Calendar = defineComponent<Props>({ const Calendar = defineComponent({
name: 'ACalendar', name: 'ACalendar',
inheritAttrs: false, inheritAttrs: false,
props: [ props: {
'prefixCls', prefixCls: String,
'locale', locale: { type: Object as PropType<Props['locale']>, default: undefined as Props['locale'] },
'validRange', validRange: { type: Array as PropType<DateType[]>, default: undefined },
'disabledDate', disabledDate: { type: Function as PropType<Props['disabledDate']>, default: undefined },
'dateFullCellRender', dateFullCellRender: {
'dateCellRender', type: Function as PropType<Props['dateFullCellRender']>,
'monthFullCellRender', default: undefined,
'monthCellRender', },
'headerRender', dateCellRender: { type: Function as PropType<Props['dateCellRender']>, default: undefined },
'value', monthFullCellRender: {
'defaultValue', type: Function as PropType<Props['monthFullCellRender']>,
'mode', default: undefined,
'fullscreen', },
'onChange', monthCellRender: { type: Function as PropType<Props['monthCellRender']>, default: undefined },
'onPanelChange', headerRender: { type: Function as PropType<Props['headerRender']>, default: undefined },
'onSelect', value: {
'valueFormat', type: [Object, String] as PropType<Props['value']>,
] as any, default: undefined as Props['value'],
},
defaultValue: {
type: [Object, String] as PropType<Props['defaultValue']>,
default: undefined as Props['defaultValue'],
},
mode: { type: String as PropType<Props['mode']>, default: undefined },
fullscreen: { type: Boolean as PropType<Props['fullscreen']>, default: undefined },
onChange: { type: Function as PropType<Props['onChange']>, default: undefined },
'onUpdate:value': { type: Function as PropType<Props['onUpdate:value']>, default: undefined },
onPanelChange: { type: Function as PropType<Props['onPanelChange']>, default: undefined },
onSelect: { type: Function as PropType<Props['onSelect']>, default: undefined },
valueFormat: { type: String, default: undefined },
},
slots: Object as CustomSlotsType<{ slots: Object as CustomSlotsType<{
dateFullCellRender?: { current: DateType }; dateFullCellRender?: { current: DateType };
dateCellRender?: { current: DateType }; dateCellRender?: { current: DateType };
@ -121,7 +134,8 @@ function generateCalendar<
}; };
default: any; default: any;
}>, }>,
setup(props, { emit, slots, attrs }) { setup(p, { emit, slots, attrs }) {
const props = p as unknown as Props;
const { prefixCls, direction } = useConfigInject('picker', props); const { prefixCls, direction } = useConfigInject('picker', props);
const calendarPrefixCls = computed(() => `${prefixCls.value}-calendar`); const calendarPrefixCls = computed(() => `${prefixCls.value}-calendar`);
const maybeToString = (date: DateType) => { const maybeToString = (date: DateType) => {

View File

@ -76,6 +76,7 @@ const Popconfirm = defineComponent({
content?: any; content?: any;
okText?: any; okText?: any;
icon?: any; icon?: any;
cancel?: any;
cancelText?: any; cancelText?: any;
cancelButton?: any; cancelButton?: any;
okButton?: any; okButton?: any;

View File

@ -68,7 +68,7 @@ const Result = defineComponent({
subTitle?: any; subTitle?: any;
icon?: any; icon?: any;
extra?: any; extra?: any;
dfault?: any; default?: any;
}>, }>,
setup(props, { slots }) { setup(props, { slots }) {
const { prefixCls, direction } = useConfigInject('result', props); const { prefixCls, direction } = useConfigInject('result', props);

View File

@ -224,38 +224,27 @@ export const tableProps = () => {
type: [Boolean, Object] as PropType<boolean | TooltipProps>, type: [Boolean, Object] as PropType<boolean | TooltipProps>,
default: true, default: true,
}, },
contextSlots: {
type: Object as PropType<ContextSlots>,
},
transformCellText: { transformCellText: {
type: Function as PropType<TableProps['transformCellText']>, type: Function as PropType<TableProps['transformCellText']>,
}, },
}; };
}; };
const InteralTable = defineComponent< const InteralTable = defineComponent({
TableProps & {
contextSlots: ContextSlots;
}
>({
name: 'InteralTable', name: 'InteralTable',
inheritAttrs: false, inheritAttrs: false,
props: initDefaultProps(tableProps(), { props: initDefaultProps(
{
...tableProps(),
contextSlots: {
type: Object as PropType<ContextSlots>,
},
},
{
rowKey: 'key', rowKey: 'key',
}) as any, },
slots: Object as CustomSlotsType<{ ),
emptyText?: any;
expandIcon?: RenderExpandIconProps<any>;
title?: any;
footer?: any;
summary?: any;
expandedRowRender?: any;
bodyCell?: any;
headerCell?: any;
customFilterIcon?: any;
customFilterDropdown?: any;
default: any;
}>,
setup(props, { attrs, slots, expose, emit }) { setup(props, { attrs, slots, expose, emit }) {
devWarning( devWarning(
!(typeof props.rowKey === 'function' && props.rowKey.length > 1), !(typeof props.rowKey === 'function' && props.rowKey.length > 1),
@ -684,9 +673,34 @@ const InteralTable = defineComponent<
}, },
}); });
const Table = defineComponent<TableProps>({ const Table = defineComponent({
name: 'ATable', name: 'ATable',
inheritAttrs: false, inheritAttrs: false,
props: initDefaultProps(tableProps(), {
rowKey: 'key',
}),
slots: Object as CustomSlotsType<{
emptyText?: any;
expandIcon?: RenderExpandIconProps<any>;
title?: any;
footer?: any;
summary?: any;
expandedRowRender?: any;
bodyCell?: {
text: any;
value: any;
record: Record<string, any>;
index: number;
column: ColumnType;
};
headerCell?: {
title: any;
column: ColumnType;
};
customFilterIcon?: any;
customFilterDropdown?: any;
default: any;
}>,
setup(_props, { attrs, slots, expose }) { setup(_props, { attrs, slots, expose }) {
const table = ref(); const table = ref();
expose({ expose({

View File

@ -85,7 +85,7 @@ function createTimePicker<
}); });
const { TimePicker: InternalTimePicker, RangePicker: InternalRangePicker } = DatePicker as any; const { TimePicker: InternalTimePicker, RangePicker: InternalRangePicker } = DatePicker as any;
const TimePicker = defineComponent<DTimePickerProps>({ const TimePicker = defineComponent({
name: 'ATimePicker', name: 'ATimePicker',
inheritAttrs: false, inheritAttrs: false,
props: { props: {
@ -93,7 +93,7 @@ function createTimePicker<
...datePickerProps<DateType>(), ...datePickerProps<DateType>(),
...timePickerProps(), ...timePickerProps(),
addon: { type: Function }, addon: { type: Function },
} as any, },
slots: Object as CustomSlotsType<{ slots: Object as CustomSlotsType<{
addon?: any; addon?: any;
renderExtraFooter?: any; renderExtraFooter?: any;
@ -101,7 +101,8 @@ function createTimePicker<
clearIcon?: any; clearIcon?: any;
default: any; default: any;
}>, }>,
setup(props, { slots, expose, emit, attrs }) { setup(p, { slots, expose, emit, attrs }) {
const props = p as unknown as DTimePickerProps;
const formItemContext = useInjectFormItemContext(); const formItemContext = useInjectFormItemContext();
devWarning( devWarning(
!(slots.addon || props.addon), !(slots.addon || props.addon),
@ -162,7 +163,7 @@ function createTimePicker<
}, },
}); });
const TimeRangePicker = defineComponent<DTimeRangePickerProps>({ const TimeRangePicker = defineComponent({
name: 'ATimeRangePicker', name: 'ATimeRangePicker',
inheritAttrs: false, inheritAttrs: false,
props: { props: {
@ -170,14 +171,15 @@ function createTimePicker<
...rangePickerProps<DateType>(), ...rangePickerProps<DateType>(),
...timePickerProps(), ...timePickerProps(),
order: { type: Boolean, default: true }, order: { type: Boolean, default: true },
} as any, },
slots: Object as CustomSlotsType<{ slots: Object as CustomSlotsType<{
renderExtraFooter?: any; renderExtraFooter?: any;
suffixIcon?: any; suffixIcon?: any;
clearIcon?: any; clearIcon?: any;
default: any; default: any;
}>, }>,
setup(props, { slots, expose, emit, attrs }) { setup(p, { slots, expose, emit, attrs }) {
const props = p as unknown as DTimeRangePickerProps;
const pickerRef = ref(); const pickerRef = ref();
const formItemContext = useInjectFormItemContext(); const formItemContext = useInjectFormItemContext();
expose({ expose({

View File

@ -18,28 +18,27 @@ export const typographyProps = () => ({
// Form Internal use // Form Internal use
component: String, component: String,
}); });
const Typography = defineComponent<InternalTypographyProps>({ const Typography = defineComponent({
name: 'ATypography', name: 'ATypography',
inheritAttrs: false, inheritAttrs: false,
props: typographyProps() as any, props: typographyProps(),
setup(props, { slots, attrs }) { setup(props, { slots, attrs }) {
const { prefixCls, direction } = useConfigInject('typography', props); const { prefixCls, direction } = useConfigInject('typography', props);
return () => { return () => {
const { const {
prefixCls: _prefixCls, prefixCls: _prefixCls,
class: _className,
direction: _direction, direction: _direction,
component: Component = 'article' as any, component: Component = 'article' as any,
...restProps ...restProps
} = { ...props, ...attrs }; } = { ...props, ...attrs };
return ( return (
<Component <Component
{...restProps}
class={classNames( class={classNames(
prefixCls.value, prefixCls.value,
{ [`${prefixCls.value}-rtl`]: direction.value === 'rtl' }, { [`${prefixCls.value}-rtl`]: direction.value === 'rtl' },
attrs.class, attrs.class,
)} )}
{...restProps}
> >
{slots.default?.()} {slots.default?.()}
</Component> </Component>

View File

@ -251,7 +251,6 @@
"url-loader": "^3.0.0", "url-loader": "^3.0.0",
"vite": "^3.0.0", "vite": "^3.0.0",
"vue": "^3.2.0", "vue": "^3.2.0",
"vue-antd-md-loader": "^1.2.1-beta.1",
"vue-clipboard2": "0.3.3", "vue-clipboard2": "0.3.3",
"vue-drag-resize": "^2.0.3", "vue-drag-resize": "^2.0.3",
"vue-eslint-parser": "^8.0.0", "vue-eslint-parser": "^8.0.0",
@ -260,7 +259,6 @@
"vue-loader": "^17.0.0", "vue-loader": "^17.0.0",
"vue-request": "^1.0.2", "vue-request": "^1.0.2",
"vue-router": "^4.0.0", "vue-router": "^4.0.0",
"vue-server-renderer": "^2.6.11",
"vue-style-loader": "^4.1.2", "vue-style-loader": "^4.1.2",
"vue-tsc": "^1.0.6", "vue-tsc": "^1.0.6",
"vuex": "^4.0.0", "vuex": "^4.0.0",