diff --git a/components/anchor/index.tsx b/components/anchor/index.tsx index 54d2aa82b..c6846752f 100644 --- a/components/anchor/index.tsx +++ b/components/anchor/index.tsx @@ -10,4 +10,6 @@ Anchor.install = function(app: App) { app.component(Anchor.Link.name, Anchor.Link); return app; }; -export default Anchor; +export default Anchor as typeof Anchor & { + readonly Link: typeof AnchorLink; +}; diff --git a/components/auto-complete/index.tsx b/components/auto-complete/index.tsx index 319186948..b3e0fba76 100644 --- a/components/auto-complete/index.tsx +++ b/components/auto-complete/index.tsx @@ -141,4 +141,7 @@ AutoComplete.install = function(app: App) { return app; }; -export default AutoComplete; +export default AutoComplete as typeof AutoComplete & { + readonly Option: typeof AutoComplete.Option; + readonly OptGroup: typeof AutoComplete.OptGroup; +}; diff --git a/components/breadcrumb/index.ts b/components/breadcrumb/index.ts index 5cefc878e..9f4ee79e1 100644 --- a/components/breadcrumb/index.ts +++ b/components/breadcrumb/index.ts @@ -14,4 +14,7 @@ Breadcrumb.install = function(app: App) { return app; }; -export default Breadcrumb; +export default Breadcrumb as typeof Breadcrumb & { + readonly Item: typeof BreadcrumbItem; + readonly Separator: typeof BreadcrumbSeparator; +}; diff --git a/components/button/index.ts b/components/button/index.ts index 2f5fa390a..ed0560229 100644 --- a/components/button/index.ts +++ b/components/button/index.ts @@ -11,4 +11,6 @@ Button.install = function(app: App) { return app; }; -export default Button; +export default Button as typeof Button & { + readonly Group: typeof ButtonGroup; +}; diff --git a/components/card/index.ts b/components/card/index.ts index 126674bed..63956219b 100644 --- a/components/card/index.ts +++ b/components/card/index.ts @@ -14,4 +14,7 @@ Card.install = function(app: App) { return app; }; -export default Card; +export default Card as typeof Card & { + readonly Meta: typeof Meta; + readonly Grid: typeof Grid; +}; diff --git a/components/checkbox/index.ts b/components/checkbox/index.ts index 307ec994e..07176cad2 100644 --- a/components/checkbox/index.ts +++ b/components/checkbox/index.ts @@ -11,4 +11,6 @@ Checkbox.install = function(app: App) { return app; }; -export default Checkbox; +export default Checkbox as typeof Checkbox & { + readonly Group: typeof CheckboxGroup; +}; diff --git a/components/collapse/index.js b/components/collapse/index.ts similarity index 61% rename from components/collapse/index.js rename to components/collapse/index.ts index a02659270..a55c8549b 100644 --- a/components/collapse/index.js +++ b/components/collapse/index.ts @@ -1,13 +1,16 @@ +import { App } from 'vue'; import Collapse from './Collapse'; import CollapsePanel from './CollapsePanel'; Collapse.Panel = CollapsePanel; /* istanbul ignore next */ -Collapse.install = function(app) { +Collapse.install = function(app: App) { app.component(Collapse.name, Collapse); app.component(CollapsePanel.name, CollapsePanel); return app; }; -export default Collapse; +export default Collapse as typeof Collapse & { + readonly Panel: typeof CollapsePanel; +}; diff --git a/components/descriptions/index.tsx b/components/descriptions/index.tsx index 9d93d67ef..3391e48e2 100644 --- a/components/descriptions/index.tsx +++ b/components/descriptions/index.tsx @@ -4,12 +4,7 @@ import ResponsiveObserve, { Breakpoint, responsiveArray } from '../_util/respons import { defaultConfigProvider } from '../config-provider'; import Col from './Col'; import PropTypes from '../_util/vue-types'; -import { - getOptionProps, - getComponent, - isValidElement, - getSlot, -} from '../_util/props-util'; +import { getOptionProps, getComponent, isValidElement, getSlot } from '../_util/props-util'; import BaseMixin from '../_util/BaseMixin'; import { tuple, VueNode } from '../_util/type'; @@ -57,7 +52,7 @@ export const DescriptionsProps = { title: PropTypes.VNodeChild, column: { type: [Number, Object] as PropType>>, - default: () => defaultColumnMap + default: () => defaultColumnMap, }, layout: PropTypes.oneOf(tuple('horizontal', 'vertical')), colon: PropTypes.looseBool, @@ -154,13 +149,9 @@ const Descriptions = defineComponent({ { prefixCls }: { prefixCls: string }, bordered: boolean, layout: 'horizontal' | 'vertical', - colon: boolean + colon: boolean, ) { - const renderCol = ( - colItem: VNode, - type: 'label' | 'content', - idx: number - ) => { + const renderCol = (colItem: VNode, type: 'label' | 'content', idx: number) => { return ( void; + disabled?: boolean; + size?: 'large' | 'small' | 'default'; + formatter?: (value: number | string | undefined) => string; + parser?: (displayValue: string | undefined) => number | string; + decimalSeparator?: string; + placeholder?: string; + name?: string; + id?: string; + precision?: number; + onPressEnter?: EventHandlerNonNull; + autofocus?: boolean; +} + +const InputNumberProps = { prefixCls: PropTypes.string, min: PropTypes.number, max: PropTypes.number, value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), - step: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), + step: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).def(1), defaultValue: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), tabindex: PropTypes.number, disabled: PropTypes.looseBool, - size: PropTypes.oneOf(['large', 'small', 'default']), + size: PropTypes.oneOf(tuple('large', 'small', 'default')), formatter: PropTypes.func, parser: PropTypes.func, decimalSeparator: PropTypes.string, @@ -27,44 +50,41 @@ export const InputNumberProps = { autofocus: PropTypes.looseBool, }; -const InputNumber = { +const InputNumber = defineComponent({ name: 'AInputNumber', inheritAttrs: false, - props: initDefaultProps(InputNumberProps, { - step: 1, - }), - setup() { + props: InputNumberProps as any, + setup(props) { + const inputNumberRef = ref(null); + const focus = () => { + inputNumberRef.value.focus(); + }; + const blur = () => { + inputNumberRef.value.blur(); + }; + onMounted(() => { + nextTick(() => { + if (process.env.NODE_ENV === 'test') { + if (props.autofocus && !props.disabled) { + focus(); + } + } + }); + }); return { configProvider: inject('configProvider', defaultConfigProvider), + inputNumberRef, + focus, + blur, }; }, - mounted() { - this.$nextTick(() => { - if (process.env.NODE_ENV === 'test') { - if (this.autofocus && !this.disabled) { - this.focus(); - } - } - }); - }, - methods: { - saveInputNumber(inputNumberRef) { - this.inputNumberRef = inputNumberRef; - }, - focus() { - this.inputNumberRef.focus(); - }, - blur() { - this.inputNumberRef.blur(); - }, - }, render() { const { prefixCls: customizePrefixCls, size, class: className, ...others } = { ...getOptionProps(this), ...this.$attrs, - }; - const getPrefixCls = this.configProvider.getPrefixCls; + } as any; + const getPrefixCls = (this as any).configProvider.getPrefixCls; const prefixCls = getPrefixCls('input-number', customizePrefixCls); const inputNumberClass = classNames( @@ -84,12 +104,12 @@ const InputNumber = { ...others, class: inputNumberClass, }; - return ; + return ; }, -}; +}); /* istanbul ignore next */ -InputNumber.install = function(app) { +InputNumber.install = function(app: App) { app.component(InputNumber.name, InputNumber); return app; }; diff --git a/components/input-number/style/index.js b/components/input-number/style/index.ts similarity index 100% rename from components/input-number/style/index.js rename to components/input-number/style/index.ts diff --git a/examples/App.tsx b/examples/App.tsx index c4a42fc49..6692ef905 100644 --- a/examples/App.tsx +++ b/examples/App.tsx @@ -1,4 +1,4 @@ -import Empty from '../components/date-picker'; +import Empty from '../components/input-number'; import '../components/empty/style'; export default {