mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat: add useToggle
This commit is contained in:
parent
1aa61f7142
commit
9f372af1ec
10
src/api/use-toggle.ts
Normal file
10
src/api/use-toggle.ts
Normal 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];
|
||||
}
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user