From 47c84cdbadae40ef6b642a5bc8e46f7577c8bffd Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Wed, 1 Feb 2023 22:16:23 +0800 Subject: [PATCH] refactor: dropdown --- components/_util/type.ts | 4 +- components/dropdown/dropdown-button.tsx | 32 +- components/dropdown/dropdown.tsx | 53 ++- components/dropdown/index.en-US.md | 20 +- components/dropdown/index.zh-CN.md | 16 +- components/dropdown/props.ts | 39 +- components/dropdown/style/button.ts | 26 ++ components/dropdown/style/index.less | 394 ------------------- components/dropdown/style/index.ts | 458 +++++++++++++++++++++++ components/dropdown/style/index.tsx | 5 - components/dropdown/style/rtl.less | 90 ----- components/dropdown/style/status.less | 14 - components/dropdown/style/status.ts | 25 ++ components/menu/src/Menu.tsx | 2 +- components/menu/src/OverrideContext.ts | 4 +- components/popconfirm/style/index.less | 8 - components/popconfirm/style/index.ts | 89 +++++ components/popconfirm/style/index.tsx | 8 - components/popover/style/index.less | 258 ------------- components/popover/style/index.ts | 183 +++++++++ components/popover/style/index.tsx | 5 - components/popover/style/rtl.less | 33 -- components/style.ts | 6 +- components/theme/interface/components.ts | 12 +- 24 files changed, 904 insertions(+), 880 deletions(-) create mode 100644 components/dropdown/style/button.ts delete mode 100644 components/dropdown/style/index.less create mode 100644 components/dropdown/style/index.ts delete mode 100644 components/dropdown/style/index.tsx delete mode 100644 components/dropdown/style/rtl.less delete mode 100644 components/dropdown/style/status.less create mode 100644 components/dropdown/style/status.ts delete mode 100644 components/popconfirm/style/index.less create mode 100644 components/popconfirm/style/index.ts delete mode 100644 components/popconfirm/style/index.tsx delete mode 100644 components/popover/style/index.less create mode 100644 components/popover/style/index.ts delete mode 100644 components/popover/style/index.tsx delete mode 100644 components/popover/style/rtl.less diff --git a/components/_util/type.ts b/components/_util/type.ts index 266c85398..86b366fe4 100644 --- a/components/_util/type.ts +++ b/components/_util/type.ts @@ -51,8 +51,8 @@ export function objectType(defaultVal?: any) { return { type: Object as PropType, default: defaultVal as T }; } -export function booleanType(defaultVal?: any) { - return { type: Boolean as PropType, default: defaultVal as T }; +export function booleanType(defaultVal?: any) { + return { type: Boolean, default: defaultVal as boolean }; } export function someType(types: any[], defaultVal?: any) { diff --git a/components/dropdown/dropdown-button.tsx b/components/dropdown/dropdown-button.tsx index fbfae9745..baa418647 100644 --- a/components/dropdown/dropdown-button.tsx +++ b/components/dropdown/dropdown-button.tsx @@ -1,12 +1,13 @@ import type { ExtractPropTypes, HTMLAttributes } from 'vue'; -import { defineComponent } from 'vue'; +import { computed, defineComponent } from 'vue'; import Button from '../button'; -import classNames from '../_util/classNames'; import Dropdown from './dropdown'; +import classNames from '../_util/classNames'; import { initDefaultProps } from '../_util/props-util'; import { dropdownButtonProps } from './props'; import EllipsisOutlined from '@ant-design/icons-vue/EllipsisOutlined'; import useConfigInject from '../config-provider/hooks/useConfigInject'; +import useStyle from './style'; const ButtonGroup = Button.Group; export type DropdownButtonProps = Partial>>; @@ -27,20 +28,25 @@ export default defineComponent({ const handleVisibleChange = (val: boolean) => { emit('update:visible', val); emit('visibleChange', val); + emit('update:open', val); + emit('openChange', val); }; - const { prefixCls, direction, getPopupContainer } = useConfigInject('dropdown-button', props); - + const { prefixCls, direction, getPopupContainer } = useConfigInject('dropdown', props); + const buttonPrefixCls = computed(() => `${prefixCls.value}-button`); + const [wrapSSR, hashId] = useStyle(prefixCls); return () => { const { type = 'default', disabled, + danger, loading, htmlType, class: className = '', overlay = slots.overlay?.(), trigger, align, + open, visible, onVisibleChange: _onVisibleChange, placement = direction.value === 'rtl' ? 'bottomLeft' : 'bottomRight', @@ -53,7 +59,7 @@ export default defineComponent({ overlayStyle, destroyPopupOnHide, onClick, - 'onUpdate:visible': _updateVisible, + 'onUpdate:open': _updateVisible, ...restProps } = { ...props, ...attrs } as DropdownButtonProps & HTMLAttributes; @@ -63,10 +69,10 @@ export default defineComponent({ trigger: disabled ? [] : trigger, placement, getPopupContainer: getPopupContainer?.value, - onVisibleChange: handleVisibleChange, + onOpenChange: handleVisibleChange, mouseEnterDelay, mouseLeaveDelay, - visible, + open: open ?? visible, overlayClassName, overlayStyle, destroyPopupOnHide, @@ -74,6 +80,7 @@ export default defineComponent({ const leftButton = ( ); - const rightButton =