revert: useBreakpoint
parent
67939d3399
commit
3814fc8f4e
|
@ -0,0 +1,16 @@
|
||||||
|
import { watchEffect, shallowRef } from 'vue';
|
||||||
|
import type { ComputedRef } from 'vue';
|
||||||
|
export declare type ComputedGetter<T> = (...args: any[]) => T;
|
||||||
|
export default function eagerComputed<T>(fn: ComputedGetter<T>) {
|
||||||
|
const result = shallowRef<T>();
|
||||||
|
watchEffect(
|
||||||
|
() => {
|
||||||
|
result.value = fn();
|
||||||
|
},
|
||||||
|
{
|
||||||
|
flush: 'sync', // needed so updates are immediate.
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
return result as any as ComputedRef<T>;
|
||||||
|
}
|
|
@ -1,18 +1,14 @@
|
||||||
import type { Ref } from 'vue';
|
import type { Ref } from 'vue';
|
||||||
import { getCurrentInstance, onMounted, onUnmounted, ref } from 'vue';
|
import { onMounted, onUnmounted, ref } from 'vue';
|
||||||
import type { ScreenMap } from '../../_util/responsiveObserve';
|
import type { ScreenMap } from '../../_util/responsiveObserve';
|
||||||
import ResponsiveObserve from '../../_util/responsiveObserve';
|
import ResponsiveObserve from '../../_util/responsiveObserve';
|
||||||
|
|
||||||
function useBreakpoint(refreshOnChange = ref(true)): Ref<ScreenMap> {
|
function useBreakpoint(): Ref<ScreenMap> {
|
||||||
const screens = ref<ScreenMap>({});
|
const screens = ref<ScreenMap>({});
|
||||||
let token = null;
|
let token = null;
|
||||||
const instance = getCurrentInstance();
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
token = ResponsiveObserve.subscribe(supportScreens => {
|
token = ResponsiveObserve.subscribe(supportScreens => {
|
||||||
screens.value = supportScreens;
|
screens.value = supportScreens;
|
||||||
if (refreshOnChange?.value) {
|
|
||||||
instance.update();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { responsiveArray } from '../_util/responsiveObserve';
|
||||||
import useConfigInject from '../_util/hooks/useConfigInject';
|
import useConfigInject from '../_util/hooks/useConfigInject';
|
||||||
import ResizeObserver from '../vc-resize-observer';
|
import ResizeObserver from '../vc-resize-observer';
|
||||||
import { useInjectSize } from '../_util/hooks/useSize';
|
import { useInjectSize } from '../_util/hooks/useSize';
|
||||||
|
import eagerComputed from '../_util/eagerComputed';
|
||||||
|
|
||||||
export type AvatarSize = 'large' | 'small' | 'default' | number | ScreenSizeMap;
|
export type AvatarSize = 'large' | 'small' | 'default' | number | ScreenSizeMap;
|
||||||
|
|
||||||
|
@ -54,13 +55,8 @@ const Avatar = defineComponent({
|
||||||
const size = computed(() => {
|
const size = computed(() => {
|
||||||
return props.size === 'default' ? groupSize.value : props.size;
|
return props.size === 'default' ? groupSize.value : props.size;
|
||||||
});
|
});
|
||||||
const needResponsive = computed(() =>
|
const screens = useBreakpoint();
|
||||||
Object.keys(typeof size.value === 'object' ? size.value || {} : {}).some(key =>
|
const responsiveSize = eagerComputed(() => {
|
||||||
['xs', 'sm', 'md', 'lg', 'xl', 'xxl'].includes(key),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
const screens = useBreakpoint(needResponsive);
|
|
||||||
const responsiveSize = computed(() => {
|
|
||||||
if (typeof props.size !== 'object') {
|
if (typeof props.size !== 'object') {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
import Row from './Row';
|
import Row from './Row';
|
||||||
import Col from './Col';
|
import Col from './Col';
|
||||||
import useInternalBreakpoint from '../_util/hooks/useBreakpoint';
|
import useBreakpoint from '../_util/hooks/useBreakpoint';
|
||||||
|
|
||||||
// Do not export params
|
|
||||||
function useBreakpoint() {
|
|
||||||
return useInternalBreakpoint();
|
|
||||||
}
|
|
||||||
export type { RowProps } from './Row';
|
export type { RowProps } from './Row';
|
||||||
|
|
||||||
export type { ColProps, ColSize } from './Col';
|
export type { ColProps, ColSize } from './Col';
|
||||||
|
|
|
@ -17,6 +17,7 @@ import useConfigInject from '../_util/hooks/useConfigInject';
|
||||||
import useBreakpoint from '../_util/hooks/useBreakpoint';
|
import useBreakpoint from '../_util/hooks/useBreakpoint';
|
||||||
import type { Breakpoint } from '../_util/responsiveObserve';
|
import type { Breakpoint } from '../_util/responsiveObserve';
|
||||||
import { responsiveArray } from '../_util/responsiveObserve';
|
import { responsiveArray } from '../_util/responsiveObserve';
|
||||||
|
import eagerComputed from '../_util/eagerComputed';
|
||||||
|
|
||||||
export { ListItemProps } from './Item';
|
export { ListItemProps } from './Item';
|
||||||
export type { ListItemMetaProps } from './ItemMeta';
|
export type { ListItemMetaProps } from './ItemMeta';
|
||||||
|
@ -43,7 +44,7 @@ export const listProps = () => ({
|
||||||
bordered: PropTypes.looseBool,
|
bordered: PropTypes.looseBool,
|
||||||
dataSource: PropTypes.array,
|
dataSource: PropTypes.array,
|
||||||
extra: PropTypes.any,
|
extra: PropTypes.any,
|
||||||
grid: { type: Object as PropType<ListGridType>, default: undefined },
|
grid: { type: Object as PropType<ListGridType>, default: undefined as ListGridType },
|
||||||
itemLayout: String as PropType<ListItemLayout>,
|
itemLayout: String as PropType<ListItemLayout>,
|
||||||
loading: {
|
loading: {
|
||||||
type: [Boolean, Object] as PropType<boolean | (SpinProps & HTMLAttributes)>,
|
type: [Boolean, Object] as PropType<boolean | (SpinProps & HTMLAttributes)>,
|
||||||
|
@ -200,14 +201,9 @@ const List = defineComponent({
|
||||||
return dd;
|
return dd;
|
||||||
});
|
});
|
||||||
|
|
||||||
const needResponsive = computed(() =>
|
const screens = useBreakpoint();
|
||||||
Object.keys(props.grid || {}).some(key =>
|
|
||||||
['xs', 'sm', 'md', 'lg', 'xl', 'xxl'].includes(key),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
const screens = useBreakpoint(needResponsive);
|
|
||||||
|
|
||||||
const currentBreakpoint = computed(() => {
|
const currentBreakpoint = eagerComputed(() => {
|
||||||
for (let i = 0; i < responsiveArray.length; i += 1) {
|
for (let i = 0; i < responsiveArray.length; i += 1) {
|
||||||
const breakpoint: Breakpoint = responsiveArray[i];
|
const breakpoint: Breakpoint = responsiveArray[i];
|
||||||
if (screens.value[breakpoint]) {
|
if (screens.value[breakpoint]) {
|
||||||
|
|
Loading…
Reference in New Issue