Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: calendar #2983

Merged
merged 5 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/packages/calendar/calendar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,18 @@
}
}

&-choose-disabled {
background-color: $calendar-choose-disable-background-color;
color: $calendar-disable-color !important;

.nut-calendar-day-info-curr {
display: none;
}
}

&-choose {
background-color: $calendar-choose-background-color;
color: $calendar-choose-color;

&-disabled {
background-color: $calendar-choose-disable-background-color;
color: $calendar-disable-color !important;

.nut-calendar-day-info-curr {
display: none;
}
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/packages/calendar/calendar.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useRef, ReactNode } from 'react'
import Popup from '@/packages/popup/index.taro'
import CalendarItem from '@/packages/calendaritem/index.taro'
import { Utils } from '@/utils/date'
import { getDay } from '@/utils/date'
import { useConfig } from '@/packages/configprovider/configprovider.taro'
import type { CalendarDay, CalendarType, CalendarRef } from './types'
import { ComponentDefaults } from '@/utils/typings'
Expand Down Expand Up @@ -44,8 +44,8 @@ const defaultProps = {
visible: false,
title: '',
defaultValue: '',
startDate: Utils.getDay(0),
endDate: Utils.getDay(365),
startDate: getDay(0),
endDate: getDay(365),
showToday: true,
startText: '',
endText: '',
Expand Down
6 changes: 3 additions & 3 deletions src/packages/calendar/calendar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useRef, ReactNode } from 'react'
import Popup from '@/packages/popup'
import CalendarItem from '@/packages/calendaritem'
import { Utils } from '@/utils/date'
import { getDay } from '@/utils/date'
import { useConfig } from '@/packages/configprovider'
import type { CalendarDay, CalendarType, CalendarRef } from './types'
import { ComponentDefaults } from '@/utils/typings'
Expand Down Expand Up @@ -44,8 +44,8 @@ const defaultProps = {
visible: false,
title: '',
defaultValue: '',
startDate: Utils.getDay(0),
endDate: Utils.getDay(365),
startDate: getDay(0),
endDate: getDay(365),
showToday: true,
startText: '',
endText: '',
Expand Down
3 changes: 0 additions & 3 deletions src/packages/calendar/demos/taro/demo1.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useState } from 'react'
import { Cell, Calendar } from '@nutui/nutui-react-taro'
import { Star } from '@nutui/icons-react-taro'

const Demo1 = () => {
const d = new Date()
Expand Down Expand Up @@ -35,12 +34,10 @@ const Demo1 = () => {
/>
<Calendar
visible={isVisible}
showTitle={false}
defaultValue={date}
onClose={closeSwitch}
onConfirm={setChooseValue}
onDayClick={select}
closeIcon={<Star />}
/>
</>
)
Expand Down
16 changes: 7 additions & 9 deletions src/packages/calendar/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Utils } from '@/utils/date'
import { isEqual, date2Str, getNumTwoBit } from '@/utils/date'
import { CalendarDay, CalendarMonthInfo } from './types'

export const splitDate = (date: string) => {
Expand All @@ -9,32 +9,30 @@
export const isMultiple = (day: string, days: string[]) => {
if (days.length > 0) {
return days.some((item: string) => {
return Utils.isEqual(item, day)
return isEqual(item, day)

Check warning on line 12 in src/packages/calendar/utils.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/calendar/utils.tsx#L12

Added line #L12 was not covered by tests
})
}
return false
}

export const isCurrDay = (month: CalendarMonthInfo, day: string | number) => {
const date = `${month.curData[0]}/${month.curData[1]}/${day}`
return Utils.isEqual(date, Utils.date2Str(new Date(), '/'))
return isEqual(date, date2Str(new Date(), '/'))
}

export const getCurrDate = (day: CalendarDay, month: CalendarMonthInfo) => {
return `${month.curData[0]}/${month.curData[1]}/${Utils.getNumTwoBit(
+day.day
)}`
return `${month.curData[0]}/${month.curData[1]}/${getNumTwoBit(+day.day)}`
}

export const isStart = (day: string, days: string[]) => {
return Utils.isEqual(days[0], day)
return isEqual(days[0], day)

Check warning on line 28 in src/packages/calendar/utils.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/calendar/utils.tsx#L28

Added line #L28 was not covered by tests
}

export const isEnd = (day: string, days: string[]) => {
return Utils.isEqual(days[1], day)
return isEqual(days[1], day)

Check warning on line 32 in src/packages/calendar/utils.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/calendar/utils.tsx#L32

Added line #L32 was not covered by tests
}

// 开始结束时间是否相等
export const isStartAndEnd = (days: string[]) => {
return days.length >= 2 && Utils.isEqual(days[0], days[1])
return days.length >= 2 && isEqual(days[0], days[1])

Check warning on line 37 in src/packages/calendar/utils.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/calendar/utils.tsx#L37

Added line #L37 was not covered by tests
}
8 changes: 4 additions & 4 deletions src/packages/calendarcard/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Utils } from '@/utils/date'
import { getMonthPreDay, getMonthDays } from '@/utils/date'
import { CalendarCardDay } from './types'

export const convertDateToDay = (date: Date) => {
Expand Down Expand Up @@ -29,13 +29,13 @@ export const getPrevMonthDays = (
prevMonth = 12
prevYear -= 1
}
let days = Utils.getMonthPreDay(year, month)
let days = getMonthPreDay(year, month)
days -= firstDayOfWeek
if (days >= 7) {
days -= 7
}

const preDates = Utils.getMonthDays(`${prevYear}`, `${prevMonth}`)
const preDates = getMonthDays(`${prevYear}`, `${prevMonth}`)
const months = Array.from(Array(preDates), (_, k) => {
return {
type: 'prev',
Expand All @@ -51,7 +51,7 @@ export const getPrevMonthDays = (
* 获取当前月的日期数据
*/
export const getCurrentMonthDays = (year: number, month: number) => {
const days = Utils.getMonthDays(`${year}`, `${month}`)
const days = getMonthDays(`${year}`, `${month}`)
return Array.from(Array(days), (_, k) => {
return {
type: 'current',
Expand Down
Loading
Loading