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 }) { setup(props, { slots }) {
const instance = getCurrentInstance(); const instance = getCurrentInstance();
const { prefixCls } = useConfigInject('wave', props); const { prefixCls, wave } = useConfigInject('wave', props);
// ============================== Style =============================== // ============================== Style ===============================
const [, hashId] = useStyle(prefixCls); const [, hashId] = useStyle(prefixCls);
@ -35,6 +35,7 @@ export default defineComponent({
const showWave = useWave( const showWave = useWave(
instance, instance,
computed(() => classNames(prefixCls.value, hashId.value)), computed(() => classNames(prefixCls.value, hashId.value)),
wave,
); );
let onClick: (e: MouseEvent) => void; let onClick: (e: MouseEvent) => void;
const clear = () => { 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 { findDOMNode } from '../props-util';
import showWaveEffect from './WaveEffect'; import showWaveEffect from './WaveEffect';
export default function useWave( export default function useWave(
instance: ComponentInternalInstance | null, instance: ComponentInternalInstance | null,
className: Ref<string>, className: Ref<string>,
wave: ComputedRef<{ disabled?: boolean }>,
): VoidFunction { ): VoidFunction {
function showWave() { function showWave() {
const node = findDOMNode(instance); const node = findDOMNode(instance);
if (wave.value?.disabled || !node) {
return;
}
showWaveEffect(node, className.value); showWaveEffect(node, className.value);
} }

View File

@ -105,6 +105,9 @@ export const configProviderProps = () => ({
select: objectType<{ select: objectType<{
showSearch?: boolean; showSearch?: boolean;
}>(), }>(),
wave: objectType<{
disabled?: boolean;
}>(),
}); });
export type ConfigProviderProps = Partial<ExtractPropTypes<ReturnType<typeof configProviderProps>>>; export type ConfigProviderProps = Partial<ExtractPropTypes<ReturnType<typeof configProviderProps>>>;
@ -145,6 +148,9 @@ export interface ConfigProviderInnerProps {
componentSize?: ComputedRef<SizeType>; componentSize?: ComputedRef<SizeType>;
componentDisabled?: ComputedRef<boolean>; componentDisabled?: ComputedRef<boolean>;
transformCellText?: ComputedRef<(tableProps: TransformCellTextProps) => any>; transformCellText?: ComputedRef<(tableProps: TransformCellTextProps) => any>;
wave?: ComputedRef<{
disabled?: boolean;
}>;
} }
export const configProviderKey: InjectionKey<ConfigProviderInnerProps> = Symbol('configProvider'); 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 disabled = computed<boolean>(() => props.disabled ?? disabledContext.value);
const csp = computed(() => props.csp ?? configProvider.csp); const csp = computed(() => props.csp ?? configProvider.csp);
const wave = computed<{
disabled?: boolean;
}>(() => props.wave ?? configProvider.wave.value);
return { return {
configProvider, configProvider,
prefixCls, prefixCls,
@ -63,5 +67,6 @@ export default (name: string, props: Record<any, any>) => {
iconPrefixCls, iconPrefixCls,
disabled, disabled,
select: configProvider.select, select: configProvider.select,
wave,
}; };
}; };

View File

@ -197,6 +197,7 @@ const ConfigProvider = defineComponent({
); );
const componentSize = computed(() => props.componentSize); const componentSize = computed(() => props.componentSize);
const componentDisabled = computed(() => props.componentDisabled); const componentDisabled = computed(() => props.componentDisabled);
const wave = computed(() => props.wave ?? parentContext.wave?.value);
const configProvider: ConfigProviderInnerProps = { const configProvider: ConfigProviderInnerProps = {
csp, csp,
autoInsertSpaceInButton, autoInsertSpaceInButton,
@ -221,6 +222,7 @@ const ConfigProvider = defineComponent({
componentSize, componentSize,
componentDisabled, componentDisabled,
transformCellText: computed(() => props.transformCellText), transformCellText: computed(() => props.transformCellText),
wave,
}; };
// ================================ Dynamic theme ================================ // ================================ Dynamic theme ================================