From 6c39bec277d1fa0687a86e1f0d119a5cad128a4f Mon Sep 17 00:00:00 2001 From: Konv Suu <2583695112@qq.com> Date: Sun, 22 Oct 2023 21:15:56 -0500 Subject: [PATCH] feat(config-provider ): wave config (#7036) --- components/_util/wave/index.tsx | 3 ++- components/_util/wave/useWave.ts | 7 ++++++- components/config-provider/context.ts | 6 ++++++ components/config-provider/hooks/useConfigInject.ts | 5 +++++ components/config-provider/index.tsx | 2 ++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/components/_util/wave/index.tsx b/components/_util/wave/index.tsx index 81fc6f325..26ac1aff5 100644 --- a/components/_util/wave/index.tsx +++ b/components/_util/wave/index.tsx @@ -26,7 +26,7 @@ export default defineComponent({ }, setup(props, { slots }) { const instance = getCurrentInstance(); - const { prefixCls } = useConfigInject('wave', props); + const { prefixCls, wave } = useConfigInject('wave', props); // ============================== Style =============================== const [, hashId] = useStyle(prefixCls); @@ -35,6 +35,7 @@ export default defineComponent({ const showWave = useWave( instance, computed(() => classNames(prefixCls.value, hashId.value)), + wave, ); let onClick: (e: MouseEvent) => void; const clear = () => { diff --git a/components/_util/wave/useWave.ts b/components/_util/wave/useWave.ts index 7a2c23188..7c5a24f22 100644 --- a/components/_util/wave/useWave.ts +++ b/components/_util/wave/useWave.ts @@ -1,14 +1,19 @@ -import type { ComponentInternalInstance, Ref } from 'vue'; +import type { ComponentInternalInstance, ComputedRef, Ref } from 'vue'; import { findDOMNode } from '../props-util'; import showWaveEffect from './WaveEffect'; export default function useWave( instance: ComponentInternalInstance | null, className: Ref, + wave: ComputedRef<{ disabled?: boolean }>, ): VoidFunction { function showWave() { const node = findDOMNode(instance); + if (wave.value?.disabled || !node) { + return; + } + showWaveEffect(node, className.value); } diff --git a/components/config-provider/context.ts b/components/config-provider/context.ts index 2fd2ced3d..c90426c61 100644 --- a/components/config-provider/context.ts +++ b/components/config-provider/context.ts @@ -105,6 +105,9 @@ export const configProviderProps = () => ({ select: objectType<{ showSearch?: boolean; }>(), + wave: objectType<{ + disabled?: boolean; + }>(), }); export type ConfigProviderProps = Partial>>; @@ -145,6 +148,9 @@ export interface ConfigProviderInnerProps { componentSize?: ComputedRef; componentDisabled?: ComputedRef; transformCellText?: ComputedRef<(tableProps: TransformCellTextProps) => any>; + wave?: ComputedRef<{ + disabled?: boolean; + }>; } export const configProviderKey: InjectionKey = Symbol('configProvider'); diff --git a/components/config-provider/hooks/useConfigInject.ts b/components/config-provider/hooks/useConfigInject.ts index 9e2dfa544..0c781d0f5 100644 --- a/components/config-provider/hooks/useConfigInject.ts +++ b/components/config-provider/hooks/useConfigInject.ts @@ -42,6 +42,10 @@ export default (name: string, props: Record) => { ); const disabled = computed(() => props.disabled ?? disabledContext.value); const csp = computed(() => props.csp ?? configProvider.csp); + const wave = computed<{ + disabled?: boolean; + }>(() => props.wave ?? configProvider.wave.value); + return { configProvider, prefixCls, @@ -63,5 +67,6 @@ export default (name: string, props: Record) => { iconPrefixCls, disabled, select: configProvider.select, + wave, }; }; diff --git a/components/config-provider/index.tsx b/components/config-provider/index.tsx index 506a31092..143d51c5d 100644 --- a/components/config-provider/index.tsx +++ b/components/config-provider/index.tsx @@ -197,6 +197,7 @@ const ConfigProvider = defineComponent({ ); const componentSize = computed(() => props.componentSize); const componentDisabled = computed(() => props.componentDisabled); + const wave = computed(() => props.wave ?? parentContext.wave?.value); const configProvider: ConfigProviderInnerProps = { csp, autoInsertSpaceInButton, @@ -221,6 +222,7 @@ const ConfigProvider = defineComponent({ componentSize, componentDisabled, transformCellText: computed(() => props.transformCellText), + wave, }; // ================================ Dynamic theme ================================