You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
912 B
31 lines
912 B
import type { ComputedRef } from 'vue';
|
|
import { computed } from 'vue';
|
|
|
|
import warning from '../../vc-util/warning';
|
|
import type { PresetDate } from '../interface';
|
|
|
|
export default function usePresets<T>(
|
|
presets?: ComputedRef<PresetDate<T>[]>,
|
|
legacyRanges?: ComputedRef<Record<string, T | (() => T)>>,
|
|
): ComputedRef<PresetDate<T>[]> {
|
|
return computed(() => {
|
|
if (presets?.value) {
|
|
return presets.value;
|
|
}
|
|
if (legacyRanges?.value) {
|
|
warning(false, '`ranges` is deprecated. Please use `presets` instead.');
|
|
|
|
const rangeLabels = Object.keys(legacyRanges.value);
|
|
return rangeLabels.map(label => {
|
|
const range = legacyRanges.value[label];
|
|
const newValues = typeof range === 'function' ? (range as any)() : range;
|
|
return {
|
|
label,
|
|
value: newValues,
|
|
};
|
|
});
|
|
}
|
|
return [] as unknown as PresetDate<T>[];
|
|
});
|
|
}
|