From e70a6d977a7e90c4846290cfdf3cd380d5e9795a Mon Sep 17 00:00:00 2001 From: 07akioni <07akioni2@gmail.com> Date: Sat, 17 Apr 2021 23:27:12 +0800 Subject: [PATCH] feat(tooltip, popconfirm): export props type --- src/popconfirm/index.ts | 2 +- src/popconfirm/src/Popconfirm.ts | 49 ++++++++++++++------------ src/popconfirm/src/PopconfirmPanel.tsx | 11 +++--- src/popconfirm/src/interface.ts | 6 +++- src/tooltip/index.ts | 1 + src/tooltip/src/Tooltip.ts | 13 ++++--- 6 files changed, 49 insertions(+), 33 deletions(-) diff --git a/src/popconfirm/index.ts b/src/popconfirm/index.ts index ccfbcf859..6683c5a33 100644 --- a/src/popconfirm/index.ts +++ b/src/popconfirm/index.ts @@ -1,2 +1,2 @@ -/* istanbul ignore file */ export { default as NPopconfirm } from './src/Popconfirm' +export type { PopconfirmProps } from './src/Popconfirm' diff --git a/src/popconfirm/src/Popconfirm.ts b/src/popconfirm/src/Popconfirm.ts index 10f641e1c..d82f47d27 100644 --- a/src/popconfirm/src/Popconfirm.ts +++ b/src/popconfirm/src/Popconfirm.ts @@ -2,36 +2,41 @@ import { h, ref, defineComponent, provide, PropType } from 'vue' import { NPopover, PopoverInst, PopoverTrigger } from '../../popover' import { popoverBaseProps } from '../../popover/src/Popover' import { omit, keep, call } from '../../_utils' +import type { ExtractPublicPropTypes } from '../../_utils' import { useConfig, useTheme } from '../../_mixins' import type { ThemeProps } from '../../_mixins' import { popconfirmLight } from '../styles' import type { PopconfirmTheme } from '../styles' import PopconfirmPanel, { panelPropKeys } from './PopconfirmPanel' import style from './styles/index.cssr' -import type { PopconfirmInjection } from './interface' +import { popconfirmInjectionKey } from './interface' + +const popconfirmProps = { + ...(useTheme.props as ThemeProps), + ...popoverBaseProps, + positiveText: String, + negativeText: String, + showIcon: { + type: Boolean, + default: true + }, + trigger: { + type: String as PropType, + default: 'click' + }, + onPositiveClick: Function as PropType< + (e: MouseEvent) => Promise | boolean | any + >, + onNegativeClick: Function as PropType< + (e: MouseEvent) => Promise | boolean | any + > +} + +export type PopconfirmProps = ExtractPublicPropTypes export default defineComponent({ name: 'Popconfirm', - props: { - ...(useTheme.props as ThemeProps), - ...popoverBaseProps, - positiveText: String, - negativeText: String, - showIcon: { - type: Boolean, - default: true - }, - trigger: { - type: String as PropType, - default: 'click' - }, - onPositiveClick: Function as PropType< - (e: MouseEvent) => Promise | boolean | any - >, - onNegativeClick: Function as PropType< - (e: MouseEvent) => Promise | boolean | any - > - }, + props: popconfirmProps, setup (props) { const { mergedClsPrefix } = useConfig() const themeRef = useTheme( @@ -63,7 +68,7 @@ export default defineComponent({ } ) } - provide('NPopconfirm', { + provide(popconfirmInjectionKey, { mergedThemeRef: themeRef, mergedClsPrefixRef: mergedClsPrefix }) diff --git a/src/popconfirm/src/PopconfirmPanel.tsx b/src/popconfirm/src/PopconfirmPanel.tsx index dc29e8ef0..6e38c5f13 100644 --- a/src/popconfirm/src/PopconfirmPanel.tsx +++ b/src/popconfirm/src/PopconfirmPanel.tsx @@ -12,7 +12,7 @@ import { NBaseIcon } from '../../_internal' import { WarningIcon } from '../../_internal/icons' import { useLocale } from '../../_mixins' import { keysOf } from '../../_utils' -import type { PopconfirmInjection } from './interface' +import { popconfirmInjectionKey } from './interface' export const panelProps = { positiveText: String, @@ -38,9 +38,8 @@ export default defineComponent({ props: panelProps, setup (props) { const { locale: localeRef } = useLocale('Popconfirm') - const NPopconfirm = inject( - 'NPopconfirm' - ) as PopconfirmInjection + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const NPopconfirm = inject(popconfirmInjectionKey)! return { ...useLocale('Popconfirm'), cPrefix: NPopconfirm.mergedClsPrefixRef, @@ -78,7 +77,9 @@ export default defineComponent({ {this.showIcon ? (
- {{ default: () => }} + + {{ default: () => }} +
) : null} diff --git a/src/popconfirm/src/interface.ts b/src/popconfirm/src/interface.ts index 1539de7fb..4316e386b 100644 --- a/src/popconfirm/src/interface.ts +++ b/src/popconfirm/src/interface.ts @@ -1,4 +1,4 @@ -import { Ref } from 'vue' +import { InjectionKey, Ref } from 'vue' import type { MergedTheme } from '../../_mixins' import type { PopconfirmTheme } from '../styles' @@ -6,3 +6,7 @@ export interface PopconfirmInjection { mergedThemeRef: Ref> mergedClsPrefixRef: Ref } + +export const popconfirmInjectionKey: InjectionKey = Symbol( + 'popconfirm' +) diff --git a/src/tooltip/index.ts b/src/tooltip/index.ts index 71a1a57a9..69e39e869 100644 --- a/src/tooltip/index.ts +++ b/src/tooltip/index.ts @@ -1 +1,2 @@ export { default as NTooltip } from './src/Tooltip' +export type { TooltipProps } from './src/Tooltip' diff --git a/src/tooltip/src/Tooltip.ts b/src/tooltip/src/Tooltip.ts index 20e076364..dc52a409e 100644 --- a/src/tooltip/src/Tooltip.ts +++ b/src/tooltip/src/Tooltip.ts @@ -7,15 +7,20 @@ import { useTheme } from '../../_mixins' import type { ThemeProps } from '../../_mixins' import { tooltipLight } from '../styles' import type { TooltipTheme } from '../styles' +import type { ExtractPublicPropTypes } from '../../_utils' export type TooltipInst = PopoverInst +const tooltipProps = { + ...popoverBaseProps, + ...(useTheme.props as ThemeProps) +} + +export type TooltipProps = ExtractPublicPropTypes + export default defineComponent({ name: 'Tooltip', - props: { - ...popoverBaseProps, - ...(useTheme.props as ThemeProps) - }, + props: tooltipProps, setup (props) { const themeRef = useTheme( 'Tooltip',