From d71df4b3ba1c500a2a3ff8cf09f63c5631c56c81 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Mon, 3 Jan 2022 22:23:24 +0800 Subject: [PATCH] fix: component ts type --- components/checkbox/Checkbox.tsx | 9 +- components/checkbox/interface.ts | 1 + components/components.ts | 2 +- components/input-number/src/InputNumber.tsx | 2 + components/menu/demo/switch-mode.vue | 5 +- components/menu/demo/theme.vue | 3 +- components/menu/demo/vertical.vue | 11 +- components/menu/index.en-US.md | 2 +- components/menu/index.tsx | 4 +- components/menu/index.zh-CN.md | 2 +- components/menu/src/Menu.tsx | 21 +-- components/radio/Radio.tsx | 10 +- components/vc-overflow/RawItem.tsx | 5 + components/vc-pagination/Pager.tsx | 6 + components/vc-slider/src/Handle.tsx | 132 ++---------------- components/vc-slider/src/Range.tsx | 19 +-- components/vc-slider/src/Slider.tsx | 10 +- .../vc-slider/src/common/createSlider.tsx | 5 +- components/vc-tree/props.ts | 1 + typings/vue-tsx-shim.d.ts | 58 ++++---- 20 files changed, 111 insertions(+), 197 deletions(-) diff --git a/components/checkbox/Checkbox.tsx b/components/checkbox/Checkbox.tsx index f08ce38f2..83a85d930 100644 --- a/components/checkbox/Checkbox.tsx +++ b/components/checkbox/Checkbox.tsx @@ -59,7 +59,13 @@ export default defineComponent({ }); return () => { const children = flattenChildren(slots.default?.()); - const { indeterminate, skipGroup, id = formItemContext.id.value, ...restProps } = props; + const { + indeterminate, + skipGroup, + id = formItemContext.id.value, + onClick, + ...restProps + } = props; const { onMouseenter, onMouseleave, onInput, class: className, style, ...restAttrs } = attrs; const checkboxProps: CheckboxProps = { ...restProps, @@ -97,6 +103,7 @@ export default defineComponent({ style={style} onMouseenter={onMouseenter as EventHandler} onMouseleave={onMouseleave as EventHandler} + onClick={onClick} > {children.length ? {children} : null} diff --git a/components/checkbox/interface.ts b/components/checkbox/interface.ts index 9d3c4beb8..ee84ee635 100644 --- a/components/checkbox/interface.ts +++ b/components/checkbox/interface.ts @@ -53,6 +53,7 @@ export const abstractCheckboxProps = () => { autofocus: { type: Boolean, default: undefined }, onChange: PropTypes.func, 'onUpdate:checked': PropTypes.func, + onClick: PropTypes.func, skipGroup: { type: Boolean, default: false }, }; }; diff --git a/components/components.ts b/components/components.ts index 45a9c4ab7..ce45ecc6a 100644 --- a/components/components.ts +++ b/components/components.ts @@ -102,7 +102,7 @@ export { default as List, ListItem, ListItemMeta } from './list'; export type { MessageArgsProps } from './message'; export { default as message } from './message'; -export type { MenuProps, MenuTheme, SubMenuProps, MenuItemProps } from './menu'; +export type { MenuProps, MenuTheme, SubMenuProps, MenuItemProps, MenuMode } from './menu'; export { default as Menu, MenuDivider, MenuItem, MenuItemGroup, SubMenu } from './menu'; export type { MentionsProps } from './mentions'; diff --git a/components/input-number/src/InputNumber.tsx b/components/input-number/src/InputNumber.tsx index e72f79341..35ee512ef 100644 --- a/components/input-number/src/InputNumber.tsx +++ b/components/input-number/src/InputNumber.tsx @@ -74,6 +74,8 @@ export const inputNumberProps = { (value: ValueType, info: { offset: ValueType; type: 'up' | 'down' }) => void >, }, + onBlur: { type: Function as PropType<(e: InputEvent) => void> }, + onFocus: { type: Function as PropType<(e: InputEvent) => void> }, }; export default defineComponent({ diff --git a/components/menu/demo/switch-mode.vue b/components/menu/demo/switch-mode.vue index 8cb69fd10..60f1774b7 100644 --- a/components/menu/demo/switch-mode.vue +++ b/components/menu/demo/switch-mode.vue @@ -78,6 +78,7 @@ import { AppstoreOutlined, SettingOutlined, } from '@ant-design/icons-vue'; +import type { MenuMode, MenuTheme } from 'ant-design-vue'; export default defineComponent({ components: { MailOutlined, @@ -87,8 +88,8 @@ export default defineComponent({ }, setup() { const state = reactive({ - mode: 'inline', - theme: 'light', + mode: 'inline' as MenuMode, + theme: 'light' as MenuTheme, selectedKeys: ['1'], openKeys: ['sub1'], }); diff --git a/components/menu/demo/theme.vue b/components/menu/demo/theme.vue index 1d21fdc72..14e1a40d0 100644 --- a/components/menu/demo/theme.vue +++ b/components/menu/demo/theme.vue @@ -78,6 +78,7 @@ import { AppstoreOutlined, SettingOutlined, } from '@ant-design/icons-vue'; +import type { MenuTheme } from 'ant-design-vue'; export default defineComponent({ components: { MailOutlined, @@ -87,7 +88,7 @@ export default defineComponent({ }, setup() { const state = reactive({ - theme: 'dark', + theme: 'dark' as MenuTheme, selectedKeys: ['1'], openKeys: ['sub1'], }); diff --git a/components/menu/demo/vertical.vue b/components/menu/demo/vertical.vue index 87c5dfb7b..6fd2ffa2e 100644 --- a/components/menu/demo/vertical.vue +++ b/components/menu/demo/vertical.vue @@ -68,13 +68,8 @@ import { AppstoreOutlined, SettingOutlined, } from '@ant-design/icons-vue'; +import type { MenuProps } from 'ant-design-vue'; -interface MenuInfo { - key: string; - keyPath: string[]; - item: any; - domEvent: MouseEvent; -} export default defineComponent({ components: { MailOutlined, @@ -87,8 +82,8 @@ export default defineComponent({ selectedKeys: [], openKeys: [], }); - const handleClick = (e: MenuInfo) => { - console.log('click ', e); + const handleClick: MenuProps['onClick'] = menuInfo => { + console.log('click ', menuInfo); }; return { ...toRefs(state), diff --git a/components/menu/index.en-US.md b/components/menu/index.en-US.md index f60ded861..797fb43dd 100644 --- a/components/menu/index.en-US.md +++ b/components/menu/index.en-US.md @@ -34,7 +34,7 @@ More layouts with navigation: [Layout](/components/layout). | forceSubMenuRender | render submenu into DOM before it shows | boolean | false | | inlineCollapsed | specifies the collapsed status when menu is inline mode | boolean | - | | inlineIndent | indent px of inline menu item on each level | number | 24 | -| mode | type of the menu; `vertical`, `horizontal`, and `inline` modes are supported | string: `vertical` \| `vertical-right` \| `horizontal` \| `inline` | `vertical` | +| mode | type of the menu; `vertical`, `horizontal`, and `inline` modes are supported | `vertical` \| `horizontal` \| `inline` | `vertical` | | multiple | Allow selection of multiple items | boolean | false | | openKeys(v-model) | array with the keys of currently opened sub menus | string\[] | | | selectable | allow selecting menu items | boolean | true | diff --git a/components/menu/index.tsx b/components/menu/index.tsx index 59979bb28..6987cc85d 100644 --- a/components/menu/index.tsx +++ b/components/menu/index.tsx @@ -8,7 +8,7 @@ import type { MenuItemGroupProps } from './src/ItemGroup'; import ItemGroup from './src/ItemGroup'; import Divider from './src/Divider'; import type { App, Plugin } from 'vue'; -import type { MenuTheme } from './src/interface'; +import type { MenuTheme, MenuMode } from './src/interface'; /* istanbul ignore next */ Menu.install = function (app: App) { app.component(Menu.name, Menu); @@ -23,7 +23,7 @@ Menu.Item = MenuItem; Menu.Divider = Divider; Menu.SubMenu = SubMenu; Menu.ItemGroup = ItemGroup; -export type { MenuProps, SubMenuProps, MenuItemProps, MenuItemGroupProps, MenuTheme }; +export type { MenuProps, SubMenuProps, MenuItemProps, MenuItemGroupProps, MenuTheme, MenuMode }; export { SubMenu, MenuItem as Item, diff --git a/components/menu/index.zh-CN.md b/components/menu/index.zh-CN.md index c29423731..cc632796e 100644 --- a/components/menu/index.zh-CN.md +++ b/components/menu/index.zh-CN.md @@ -35,7 +35,7 @@ cover: https://gw.alipayobjects.com/zos/alicdn/3XZcjGpvK/Menu.svg | forceSubMenuRender | 在子菜单展示之前就渲染进 DOM | boolean | false | | inlineCollapsed | inline 时菜单是否收起状态 | boolean | - | | inlineIndent | inline 模式的菜单缩进宽度 | number | 24 | -| mode | 菜单类型,现在支持垂直、水平、和内嵌模式三种 | string: `vertical` `vertical-right` `horizontal` `inline` | `vertical` | +| mode | 菜单类型,现在支持垂直、水平、和内嵌模式三种 | `vertical` \| `horizontal` \| `inline` | `vertical` | | multiple | 是否允许多选 | boolean | false | | openKeys(v-model) | 当前展开的 SubMenu 菜单项 key 数组 | string\[] | | | selectable | 是否允许选中 | boolean | true | diff --git a/components/menu/src/Menu.tsx b/components/menu/src/Menu.tsx index ca3650e7a..bac54e7a8 100644 --- a/components/menu/src/Menu.tsx +++ b/components/menu/src/Menu.tsx @@ -12,6 +12,8 @@ import type { TriggerSubMenuAction, MenuInfo, SelectInfo, + MenuClickEventHandler, + SelectEventHandler, } from './interface'; import devWarning from '../../vc-util/devWarning'; import type { CSSMotionProps } from '../../_util/transition'; @@ -25,6 +27,7 @@ import SubMenu from './SubMenu'; import EllipsisOutlined from '@ant-design/icons-vue/EllipsisOutlined'; import { cloneElement } from '../../_util/vnode'; import { OVERFLOW_KEY, PathContext } from './hooks/useKeyPath'; +import type { FocusEventHandler } from '../../_util/EventInterface'; export const menuProps = { id: String, @@ -55,6 +58,15 @@ export const menuProps = { getPopupContainer: Function as PropType<(node: HTMLElement) => HTMLElement>, expandIcon: Function as PropType<(p?: { isOpen: boolean; [key: string]: any }) => any>, + onOpenChange: Function as PropType<(keys: Key[]) => void>, + onSelect: Function as PropType, + onDeselect: Function as PropType, + onClick: Function as PropType, + onFocus: Function as PropType, + onBlur: Function as PropType, + 'onUpdate:openKeys': Function as PropType<(keys: Key[]) => void>, + 'onUpdate:selectedKeys': Function as PropType<(keys: Key[]) => void>, + 'onUpdate:activeKey': Function as PropType<(key: Key) => void>, }; export type MenuProps = Partial>; @@ -64,15 +76,6 @@ export default defineComponent({ name: 'AMenu', inheritAttrs: false, props: menuProps, - emits: [ - 'update:openKeys', - 'openChange', - 'select', - 'deselect', - 'update:selectedKeys', - 'click', - 'update:activeKey', - ], slots: ['expandIcon', 'overflowedIndicator'], setup(props, { slots, emit, attrs }) { const { prefixCls, direction, getPrefixCls } = useConfigInject('menu', props); diff --git a/components/radio/Radio.tsx b/components/radio/Radio.tsx index 6eeaf1064..4c02209c3 100644 --- a/components/radio/Radio.tsx +++ b/components/radio/Radio.tsx @@ -20,6 +20,7 @@ export const radioProps = { onChange: PropTypes.func, onFocus: PropTypes.func, onBlur: PropTypes.func, + onClick: PropTypes.func, }; export type RadioProps = Partial>; @@ -61,7 +62,12 @@ export default defineComponent({ return () => { const radioGroup = radioGroupContext; - const { prefixCls: customizePrefixCls, id = formItemContext.id.value, ...restProps } = props; + const { + prefixCls: customizePrefixCls, + id = formItemContext.id.value, + onClick, + ...restProps + } = props; const rProps: RadioProps = { prefixCls: prefixCls.value, @@ -85,7 +91,7 @@ export default defineComponent({ }); return ( -