feat: add useToggle

This commit is contained in:
chenjiahan 2020-08-26 10:36:07 +08:00
parent 1aa61f7142
commit 9f372af1ec
2 changed files with 13 additions and 6 deletions

10
src/api/use-toggle.ts Normal file
View File

@ -0,0 +1,10 @@
import { ref } from 'vue';
export function useToggle(defaultValue = false) {
const state = ref(defaultValue);
const setState = (value: boolean) => {
state.value = value;
};
return [state, setState];
}

View File

@ -11,6 +11,7 @@ import {
getNextDay,
formatMonthTitle,
} from '../utils';
import { useToggle } from '../../api/use-toggle';
import { getMonthEndDay } from '../../datetime-picker/utils';
import Day from './Day';
@ -37,7 +38,7 @@ export default createComponent({
emits: ['click'],
setup(props, { emit }) {
const visible = ref(false);
const [visible, setVisible] = useToggle();
const daysRef = ref(null);
const monthRef = ref(null);
@ -82,10 +83,6 @@ export default createComponent({
return height;
};
const setVisible = (value) => {
visible.value = value;
};
const getDate = () => props.data;
const getTitle = () => title.value;
@ -141,7 +138,7 @@ export default createComponent({
const compareToEnd = compareDay(day, endDay);
if (compareToStart === 0 && compareToEnd === 0 && props.allowSameDay) {
if (props.allowSameDay && compareToStart === 0 && compareToEnd === 0) {
return 'start-end';
}
if (compareToStart === 0) {