feat(config-provider ): wave config (#7036)

This commit is contained in:
Konv Suu 2023-10-22 21:15:56 -05:00 committed by GitHub
parent 82f407d396
commit 6c39bec277
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 2 deletions

View File

@ -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 = () => {

View File

@ -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<string>,
wave: ComputedRef<{ disabled?: boolean }>,
): VoidFunction {
function showWave() {
const node = findDOMNode(instance);
if (wave.value?.disabled || !node) {
return;
}
showWaveEffect(node, className.value);
}

View File

@ -105,6 +105,9 @@ export const configProviderProps = () => ({
select: objectType<{
showSearch?: boolean;
}>(),
wave: objectType<{
disabled?: boolean;
}>(),
});
export type ConfigProviderProps = Partial<ExtractPropTypes<ReturnType<typeof configProviderProps>>>;
@ -145,6 +148,9 @@ export interface ConfigProviderInnerProps {
componentSize?: ComputedRef<SizeType>;
componentDisabled?: ComputedRef<boolean>;
transformCellText?: ComputedRef<(tableProps: TransformCellTextProps) => any>;
wave?: ComputedRef<{
disabled?: boolean;
}>;
}
export const configProviderKey: InjectionKey<ConfigProviderInnerProps> = Symbol('configProvider');

View File

@ -42,6 +42,10 @@ export default (name: string, props: Record<any, any>) => {
);
const disabled = computed<boolean>(() => 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<any, any>) => {
iconPrefixCls,
disabled,
select: configProvider.select,
wave,
};
};

View File

@ -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 ================================