Skip to content

feat(config-provider): wave config #7036

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion components/_util/wave/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 = () => {
Expand Down
7 changes: 6 additions & 1 deletion components/_util/wave/useWave.ts
Original file line number Diff line number Diff line change
@@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions components/config-provider/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ export const configProviderProps = () => ({
select: objectType<{
showSearch?: boolean;
}>(),
wave: objectType<{
disabled?: boolean;
}>(),
});

export type ConfigProviderProps = Partial<ExtractPropTypes<ReturnType<typeof configProviderProps>>>;
Expand Down Expand Up @@ -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');
Expand Down
5 changes: 5 additions & 0 deletions components/config-provider/hooks/useConfigInject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -63,5 +67,6 @@ export default (name: string, props: Record<any, any>) => {
iconPrefixCls,
disabled,
select: configProvider.select,
wave,
};
};
2 changes: 2 additions & 0 deletions components/config-provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -221,6 +222,7 @@ const ConfigProvider = defineComponent({
componentSize,
componentDisabled,
transformCellText: computed(() => props.transformCellText),
wave,
};

// ================================ Dynamic theme ================================
Expand Down