2021-06-07 17:35:03 +08:00
|
|
|
import {
|
|
|
|
computed,
|
|
|
|
ComputedRef,
|
|
|
|
defineComponent,
|
|
|
|
inject,
|
|
|
|
InjectionKey,
|
|
|
|
PropType,
|
|
|
|
provide,
|
|
|
|
} from 'vue';
|
|
|
|
import { Key } from '../_util/type';
|
|
|
|
|
|
|
|
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),
|
|
|
|
);
|
|
|
|
};
|