From bdd569f0197fa1744e35f00d7659f8e7f81dc364 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Mon, 19 Oct 2020 22:19:33 +0800 Subject: [PATCH] refactor: pagination by ts --- components/calendar/Header.tsx | 38 +++++++++---------- .../{MiniSelect.jsx => MiniSelect.tsx} | 11 +++--- .../{Pagination.jsx => Pagination.tsx} | 13 ++++--- components/pagination/{index.js => index.ts} | 3 +- .../pagination/style/{index.js => index.ts} | 0 components/vc-select/generate.tsx | 2 +- package.json | 1 - 7 files changed, 33 insertions(+), 35 deletions(-) rename components/pagination/{MiniSelect.jsx => MiniSelect.tsx} (74%) rename components/pagination/{Pagination.jsx => Pagination.tsx} (93%) rename components/pagination/{index.js => index.ts} (76%) rename components/pagination/style/{index.js => index.ts} (100%) diff --git a/components/calendar/Header.tsx b/components/calendar/Header.tsx index a3f38d00e..4d0649c26 100644 --- a/components/calendar/Header.tsx +++ b/components/calendar/Header.tsx @@ -5,9 +5,7 @@ import PropTypes from '../_util/vue-types'; import { defaultConfigProvider } from '../config-provider'; import { VueNode } from '../_util/type'; -const { Option } = Select; - -function getMonthsLocale(value: moment.Moment) { +function getMonthsLocale(value: moment.Moment): string[] { const current = value.clone(); const localeData = value.localeData(); const months = []; @@ -66,29 +64,26 @@ export default defineComponent({ start = validRange[0].get('year'); end = validRange[1].get('year') + 1; } - const suffix = locale.year === '年' ? '年' : ''; - - const options = []; + const suffix = locale && locale.year === '年' ? '年' : ''; + const options: { label: string; value: number }[] = []; for (let index = start; index < end; index++) { - options.push(); + options.push({ label: `${index}${suffix}`, value: index }); } return ( + > ); }, - getMonthSelectElement(prefixCls: string, month: number, months: number[]) { + getMonthSelectElement(prefixCls: string, month: number, months: string[]) { const { fullscreen, validRange, value } = this; - const options = []; let start = 0; let end = 12; if (validRange) { @@ -101,21 +96,24 @@ export default defineComponent({ start = rangeStart.get('month'); } } - for (let index = start; index < end; index++) { - options.push(); + const options: { label: string; value: number }[] = []; + for (let index = start; index <= end; index += 1) { + options.push({ + label: months[index], + value: index, + }); } return ( + > ); }, diff --git a/components/pagination/MiniSelect.jsx b/components/pagination/MiniSelect.tsx similarity index 74% rename from components/pagination/MiniSelect.jsx rename to components/pagination/MiniSelect.tsx index ec79f8981..d02c7febf 100644 --- a/components/pagination/MiniSelect.jsx +++ b/components/pagination/MiniSelect.tsx @@ -1,19 +1,18 @@ +import { defineComponent } from 'vue'; import VcSelect, { SelectProps } from '../select'; import { getOptionProps, getSlot } from '../_util/props-util'; -export default { +export default defineComponent({ inheritAttrs: false, - props: { - ...SelectProps(), - }, + props: SelectProps(), Option: VcSelect.Option, render() { const selectOptionsProps = getOptionProps(this); - const selelctProps = { + const selelctProps: any = { ...selectOptionsProps, size: 'small', ...this.$attrs, }; return {getSlot(this)}; }, -}; +}); diff --git a/components/pagination/Pagination.jsx b/components/pagination/Pagination.tsx similarity index 93% rename from components/pagination/Pagination.jsx rename to components/pagination/Pagination.tsx index 10b19ab1b..1eadf67ec 100644 --- a/components/pagination/Pagination.jsx +++ b/components/pagination/Pagination.tsx @@ -10,8 +10,9 @@ import RightOutlined from '@ant-design/icons-vue/RightOutlined'; import DoubleLeftOutlined from '@ant-design/icons-vue/DoubleLeftOutlined'; import DoubleRightOutlined from '@ant-design/icons-vue/DoubleRightOutlined'; import { defaultConfigProvider } from '../config-provider'; -import { inject } from 'vue'; +import { defineComponent, inject } from 'vue'; import classNames from '../_util/classNames'; +import { tuple } from '../_util/type'; export const PaginationProps = () => ({ total: PropTypes.number, @@ -39,10 +40,10 @@ export const PaginationProps = () => ({ export const PaginationConfig = () => ({ ...PaginationProps(), - position: PropTypes.oneOf(['top', 'bottom', 'both']), + position: PropTypes.oneOf(tuple('top', 'bottom', 'both')), }); -export default { +export default defineComponent({ name: 'APagination', inheritAttrs: false, props: { @@ -56,7 +57,7 @@ export default { }, methods: { - getIconsProps(prefixCls) { + getIconsProps(prefixCls: string) { const prevIcon = ( @@ -92,7 +93,7 @@ export default { jumpNextIcon, }; }, - renderPagination(contextLocale) { + renderPagination(contextLocale: object) { const { prefixCls: customizePrefixCls, selectPrefixCls: customizeSelectPrefixCls, @@ -131,4 +132,4 @@ export default { > ); }, -}; +}); diff --git a/components/pagination/index.js b/components/pagination/index.ts similarity index 76% rename from components/pagination/index.js rename to components/pagination/index.ts index e8338024d..334745233 100644 --- a/components/pagination/index.js +++ b/components/pagination/index.ts @@ -1,9 +1,10 @@ +import { App } from 'vue'; import Pagination from './Pagination'; export { PaginationProps, PaginationConfig } from './Pagination'; /* istanbul ignore next */ -Pagination.install = function(app) { +Pagination.install = function(app: App) { app.component(Pagination.name, Pagination); return app; }; diff --git a/components/pagination/style/index.js b/components/pagination/style/index.ts similarity index 100% rename from components/pagination/style/index.js rename to components/pagination/style/index.ts diff --git a/components/vc-select/generate.tsx b/components/vc-select/generate.tsx index e36d182a3..c9d3b8015 100644 --- a/components/vc-select/generate.tsx +++ b/components/vc-select/generate.tsx @@ -175,7 +175,7 @@ export interface SelectProps { // Options options?: OptionsType; - children?: VNode[] | JSX.Element[]; + children?: any[]; mode?: Mode; // Value diff --git a/package.json b/package.json index d6d043e21..4937f7751 100644 --- a/package.json +++ b/package.json @@ -95,7 +95,6 @@ "@vue/compiler-sfc": "^3.0.0", "@vue/eslint-config-prettier": "^6.0.0", "@vue/eslint-config-typescript": "^5.1.0", - "@vue/server-test-utils": "1.0.0-beta.16", "@vue/test-utils": "^2.0.0-beta.2", "acorn": "^7.0.0", "autoprefixer": "^9.6.0",