2021-06-26 09:35:40 +08:00
|
|
|
import type { ComputedRef, InjectionKey, PropType } from 'vue';
|
|
|
|
import { computed, defineComponent, inject, provide } from 'vue';
|
|
|
|
import type { Key } from '../_util/type';
|
2021-06-07 17:35:03 +08:00
|
|
|
|
|
|
|
export interface OverflowContextProviderValueType {
|
|
|
|
prefixCls: string;
|
|
|
|
responsive: boolean;
|
|
|
|
order: number;
|
|
|
|
registerSize: (key: Key, width: number | null) => void;
|
|
|
|
display: boolean;
|
|
|
|
|
|
|
|
invalidate: boolean;
|
|
|
|
|
|
|
|
// Item Usage
|
|
|
|
item?: any;
|
|
|
|
itemKey?: Key;
|
|
|
|
|
|
|
|
// Rest Usage
|
|
|
|
className?: string;
|
|
|
|
}
|
|
|
|
|
2021-06-23 23:08:16 +08:00
|
|
|
const OverflowContextProviderKey: InjectionKey<
|
|
|
|
ComputedRef<OverflowContextProviderValueType | null>
|
|
|
|
> = Symbol('OverflowContextProviderKey');
|
2021-06-07 17:35:03 +08:00
|
|
|
|
|
|
|
export const OverflowContextProvider = defineComponent({
|
|
|
|
name: 'OverflowContextProvider',
|
|
|
|
inheritAttrs: false,
|
|
|
|
props: {
|
|
|
|
value: { type: Object as PropType<OverflowContextProviderValueType> },
|
|
|
|
},
|
|
|
|
setup(props, { slots }) {
|
|
|
|
provide(
|
|
|
|
OverflowContextProviderKey,
|
|
|
|
computed(() => props.value),
|
|
|
|
);
|
|
|
|
return () => slots.default?.();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-06-23 23:08:16 +08:00
|
|
|
export const useInjectOverflowContext =
|
|
|
|
(): ComputedRef<OverflowContextProviderValueType | null> => {
|
|
|
|
return inject(
|
|
|
|
OverflowContextProviderKey,
|
|
|
|
computed(() => null),
|
|
|
|
);
|
|
|
|
};
|