Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
51 changes: 7 additions & 44 deletions src/packages/calendarcard/calendarcard.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect, useState, useRef, useMemo } from 'react'
import React, { useCallback, useEffect, useState, useRef } from 'react'
import classNames from 'classnames'
import { View } from '@tarojs/components'
import { ArrowLeft, ArrowRight, DoubleLeft, DoubleRight } from './icon.taro'
Expand All @@ -24,7 +24,6 @@ const defaultProps = {
...ComponentDefaults,
type: 'single',
firstDayOfWeek: 0,
weekdays: [],
}

const prefixCls = 'nut-calendarcard'
Expand All @@ -48,7 +47,6 @@ export const CalendarCard = React.forwardRef<
renderDay,
renderDayTop,
renderDayBottom,
weekdays,
onDayClick,
onPageChange,
onChange,
Expand Down Expand Up @@ -237,36 +235,6 @@ export const CalendarCard = React.forwardRef<
return d === 0 || d === 6
}

const isToday = (day: CalendarCardDay) => {
const today = new Date()
return (
day.year === today.getFullYear() &&
day.month === today.getMonth() + 1 &&
day.date === today.getDate()
)
}

// 日期无障碍朗读
const getAriaLabel = (day: CalendarCardDay) => {
const today = isToday(day)
// 日期选定时,朗读="已选定 1号 按钮"
if (isActive(day)) {
return today
? `已选定今日${day.month}月${day.date}号`
: `已选定${day.month}月${day.date}号`
}
// 若不可选中,朗读=“3号 按钮 变暗”
if (isDisable(day)) {
return today
? `${day.month}月${day.date}号今日按钮变暗`
: `${day.month}月${day.date}号按钮变暗`
}
// 未选定时,朗读=“2号 按钮”
return today
? `${day.month}月${day.date}号今日`
: `${day.month}月${day.date}号`
}

const getClasses = (day: CalendarCardDay) => {
/**
* active: single、multiple 激活日期
Expand Down Expand Up @@ -429,20 +397,18 @@ export const CalendarCard = React.forwardRef<
)
}

const weekHeader = useMemo(() => {
const weekdaysList =
weekdays.length > 0 ? weekdays : locale.calendaritem.weekdays
const weekdaysData = weekdaysList.map((day, index) => {
const [weekHeader] = useState(() => {
const weekdays = locale.calendaritem.weekdays.map((day, index) => {
return {
name: day,
key: index,
}
})
return [
...weekdaysData.slice(firstDayOfWeek, 7),
...weekdaysData.slice(0, firstDayOfWeek),
...weekdays.slice(firstDayOfWeek, 7),
...weekdays.slice(0, firstDayOfWeek),
]
}, [weekdays, firstDayOfWeek, locale.calendaritem.weekdays])
})

const renderContent = () => {
return (
Expand Down Expand Up @@ -471,14 +437,11 @@ export const CalendarCard = React.forwardRef<
)}
key={`${day.year}-${day.month}-${day.date}`}
onClick={() => handleDayClick(day)}
ariaLabel={getAriaLabel(day)}
ariaRole="button"
>
<View className={`${prefixCls}-day-top`}>
{renderDayTop ? renderDayTop(day) : ''}
</View>
{/* @ts-ignore */}
<View className={`${prefixCls}-day-inner`} ariaHidden>
<View className={`${prefixCls}-day-inner`}>
{renderDay ? renderDay(day) : day.date}
</View>
<View className={`${prefixCls}-day-bottom`}>
Expand Down
6 changes: 0 additions & 6 deletions src/packages/calendarcard/demo.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Demo9 from './demos/taro/demo9'
import Demo10 from './demos/taro/demo10'
import Demo11 from './demos/taro/demo11'
import Demo12 from './demos/taro/demo12'
import Demo13 from './demos/taro/demo13'

const CalendarDemo = () => {
const [translated] = useTranslate({
Expand All @@ -35,7 +34,6 @@ const CalendarDemo = () => {
confirm: '确定',
ref: '使用 Ref 上的方法',
title: '搭配 Ref 使用自定义头',
customWeekdays: '自定义周几',
},
'zh-TW': {
single: '選擇單個日期',
Expand All @@ -52,7 +50,6 @@ const CalendarDemo = () => {
confirm: '確定',
ref: '使用 Ref 上的方法',
title: '搭配 Ref 使用自定義头',
customWeekdays: '自定義周几',
},
'en-US': {
single: 'Select a single date',
Expand All @@ -69,7 +66,6 @@ const CalendarDemo = () => {
confirm: 'Confirm',
ref: 'Use ref',
title: 'Custom title',
customWeekdays: 'Custom weekdays',
},
})

Expand Down Expand Up @@ -101,8 +97,6 @@ const CalendarDemo = () => {
<Demo11 />
<View className="h2">{translated.title}</View>
<Demo12 />
<View className="h2">{translated.customWeekdays}</View>
<Demo13 />
</ScrollView>
</>
)
Expand Down
24 changes: 0 additions & 24 deletions src/packages/calendarcard/demos/taro/demo13.tsx

This file was deleted.

1 change: 0 additions & 1 deletion src/types/spec/calendarcard/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export interface BaseCalendarCard extends BaseProps {
firstDayOfWeek: number // 0-6
startDate: Date
endDate: Date
weekdays?: string[]
disableDay: (day: CalendarCardDay) => boolean
renderDay: (day: CalendarCardDay) => ReactNode
renderDayTop: (day: CalendarCardDay) => ReactNode
Expand Down
Loading