Skip to content

Commit 1a61cc2

Browse files
authored
feat: calendarcard adaptation (#2732)
* feat: calendarcard adaption * fix: review * fix: review
1 parent 1222cb6 commit 1a61cc2

File tree

5 files changed

+101
-58
lines changed

5 files changed

+101
-58
lines changed

src/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@
437437
"author": "szg2008"
438438
},
439439
{
440-
"version": "2.0.0",
440+
"version": "3.0.0",
441441
"name": "CalendarCard",
442442
"type": "component",
443443
"cName": "日历卡片",

src/packages/calendarcard/calendarcard.scss

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555

5656
&-top,
5757
&-bottom {
58+
display: flex;
59+
align-items: center;
60+
justify-content: center;
5861
width: 100%;
5962
height: 12px;
6063
font-size: 12px;
@@ -67,14 +70,22 @@
6770

6871
&.active {
6972
background-color: $calendar-active-background-color;
70-
color: $color-primary-text;
7173
border-radius: $calendar-day-active-border-radius;
74+
.nut-calendarcard-day-top,
75+
.nut-calendarcard-day-inner,
76+
.nut-calendarcard-day-bottom {
77+
color: $color-primary-text;
78+
}
7279
}
7380

7481
&.start,
7582
&.end {
7683
background-color: $calendar-active-background-color;
77-
color: $color-primary-text;
84+
.nut-calendarcard-day-top,
85+
.nut-calendarcard-day-inner,
86+
.nut-calendarcard-day-bottom {
87+
color: $color-primary-text;
88+
}
7889
}
7990

8091
&.start {
@@ -89,7 +100,11 @@
89100

90101
&.mid {
91102
background-color: $calendar-choose-background-color;
92-
color: $calendar-choose-color;
103+
.nut-calendarcard-day-top,
104+
.nut-calendarcard-day-inner,
105+
.nut-calendarcard-day-bottom {
106+
color: $calendar-choose-color;
107+
}
93108
}
94109

95110
.nut-calendar-day-info {
@@ -100,7 +115,11 @@
100115
&.prev,
101116
&.next,
102117
&.disabled {
103-
color: $calendar-disable-color;
118+
.nut-calendarcard-day-top,
119+
.nut-calendarcard-day-inner,
120+
.nut-calendarcard-day-bottom {
121+
color: $calendar-disable-color;
122+
}
104123
cursor: not-allowed;
105124
}
106125
}
@@ -128,11 +147,13 @@
128147
}
129148
}
130149
}
150+
131151
&-day {
132152
&.start,
133153
&.end {
134154
border-radius: 0;
135155
}
156+
136157
&.start {
137158
border-top-right-radius: $calendar-day-active-border-radius;
138159
border-bottom-right-radius: $calendar-day-active-border-radius;

src/packages/calendarcard/calendarcard.taro.tsx

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect, ReactNode } from 'react'
1+
import React, { ReactNode, useCallback, useEffect, useState } from 'react'
22
import classNames from 'classnames'
33
import { View } from '@tarojs/components'
44
import { ArrowLeft, ArrowRight, DoubleLeft, DoubleRight } from './icon.taro'
@@ -35,6 +35,7 @@ export interface CalendarCardProps extends BasicComponent {
3535
onPageChange: (data: CalendarCardMonth) => void
3636
onChange: (value: CalendarCardValue) => void
3737
}
38+
3839
const defaultProps = {
3940
...ComponentDefaults,
4041
type: 'single',
@@ -123,33 +124,36 @@ export const CalendarCard = React.forwardRef<
123124
}
124125
}
125126

126-
const getDays = (month: CalendarCardMonth) => {
127-
const y = month.year
128-
const m = month.month
129-
const days = [
130-
...getPrevMonthDays(y, m, firstDayOfWeek),
131-
...getCurrentMonthDays(y, m),
132-
] as CalendarCardDay[]
133-
const size = days.length
134-
const yearOfNextMonth = month.month === 12 ? month.year + 1 : month.year
135-
const monthOfNextMonth = month.month === 12 ? 1 : month.month + 1
136-
// 补全 6 行 7 列视图
137-
for (let i = 1; i <= 42 - size; i++) {
138-
days.push({
139-
type: 'next',
140-
year: yearOfNextMonth,
141-
month: monthOfNextMonth,
142-
date: i,
143-
})
144-
}
145-
return days
146-
}
127+
const getDays = useCallback(
128+
(month: CalendarCardMonth) => {
129+
const y = month.year
130+
const m = month.month
131+
const days = [
132+
...getPrevMonthDays(y, m, firstDayOfWeek),
133+
...getCurrentMonthDays(y, m),
134+
] as CalendarCardDay[]
135+
const size = days.length
136+
const yearOfNextMonth = month.month === 12 ? month.year + 1 : month.year
137+
const monthOfNextMonth = month.month === 12 ? 1 : month.month + 1
138+
// 补全 6 行 7 列视图
139+
for (let i = 1; i <= 42 - size; i++) {
140+
days.push({
141+
type: 'next',
142+
year: yearOfNextMonth,
143+
month: monthOfNextMonth,
144+
date: i,
145+
})
146+
}
147+
return days
148+
},
149+
[firstDayOfWeek]
150+
)
147151

148152
useEffect(() => {
149153
const newDays = getDays(month)
150154
setDays(newDays)
151155
onPageChange?.(month)
152-
}, [month])
156+
}, [month, getDays, onPageChange, firstDayOfWeek])
153157

154158
const isSameDay = (day1: CalendarCardDay, day2: CalendarCardDay) => {
155159
return (

src/packages/calendarcard/calendarcard.tsx

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect, ReactNode } from 'react'
1+
import React, { ReactNode, useEffect, useState, useCallback } from 'react'
22
import classNames from 'classnames'
33
import { ArrowLeft, ArrowRight, DoubleLeft, DoubleRight } from './icon'
44
import { BasicComponent, ComponentDefaults } from '@/utils/typings'
@@ -34,6 +34,7 @@ export interface CalendarCardProps extends BasicComponent {
3434
onPageChange: (data: CalendarCardMonth) => void
3535
onChange: (value: CalendarCardValue) => void
3636
}
37+
3738
const defaultProps = {
3839
...ComponentDefaults,
3940
type: 'single',
@@ -122,33 +123,36 @@ export const CalendarCard = React.forwardRef<
122123
}
123124
}
124125

125-
const getDays = (month: CalendarCardMonth) => {
126-
const y = month.year
127-
const m = month.month
128-
const days = [
129-
...getPrevMonthDays(y, m, firstDayOfWeek),
130-
...getCurrentMonthDays(y, m),
131-
] as CalendarCardDay[]
132-
const size = days.length
133-
const yearOfNextMonth = month.month === 12 ? month.year + 1 : month.year
134-
const monthOfNextMonth = month.month === 12 ? 1 : month.month + 1
135-
// 补全 6 行 7 列视图
136-
for (let i = 1; i <= 42 - size; i++) {
137-
days.push({
138-
type: 'next',
139-
year: yearOfNextMonth,
140-
month: monthOfNextMonth,
141-
date: i,
142-
})
143-
}
144-
return days
145-
}
126+
const getDays = useCallback(
127+
(month: CalendarCardMonth) => {
128+
const y = month.year
129+
const m = month.month
130+
const days = [
131+
...getPrevMonthDays(y, m, firstDayOfWeek),
132+
...getCurrentMonthDays(y, m),
133+
] as CalendarCardDay[]
134+
const size = days.length
135+
const yearOfNextMonth = month.month === 12 ? month.year + 1 : month.year
136+
const monthOfNextMonth = month.month === 12 ? 1 : month.month + 1
137+
// 补全 6 行 7 列视图
138+
for (let i = 1; i <= 42 - size; i++) {
139+
days.push({
140+
type: 'next',
141+
year: yearOfNextMonth,
142+
month: monthOfNextMonth,
143+
date: i,
144+
})
145+
}
146+
return days
147+
},
148+
[firstDayOfWeek]
149+
)
146150

147151
useEffect(() => {
148152
const newDays = getDays(month)
149153
setDays(newDays)
150154
onPageChange?.(month)
151-
}, [month])
155+
}, [month, getDays, onPageChange, firstDayOfWeek])
152156

153157
const isSameDay = (day1: CalendarCardDay, day2: CalendarCardDay) => {
154158
return (

src/packages/calendarcard/icon.taro.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
11
import React, { FC } from 'react'
2-
import { View } from '@tarojs/components'
2+
import { Image, View } from '@tarojs/components'
33

4-
const left =
4+
let left =
55
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxOCIgaGVpZ2h0PSIxOCIgdmlld0JveD0iMCAwIDE4IDE4Ij48cGF0aCBkPSJNNi42MDUgOS40OWEuNzcxLjc3MSAwIDAgMSAwLS45OGwzLjYtNC4zNzJhLjc3MS43NzEgMCAwIDEgMS4xOS45ODFMOC4yIDlsMy4xOTcgMy44ODFhLjc3MS43NzEgMCAxIDEtMS4xOTEuOThsLTMuNi00LjM3eiIvPjwvc3ZnPg=='
66

7-
const right =
7+
let right =
88
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxOCIgaGVpZ2h0PSIxOCIgdmlld0JveD0iMCAwIDE4IDE4Ij48cGF0aCBkPSJNMTEuMzk2IDkuNDlhLjc3MS43NzEgMCAwIDAgMC0uOThsLTMuNi00LjM3MmEuNzcxLjc3MSAwIDAgMC0xLjE5MS45ODFMOS44IDlsLTMuMTk2IDMuODgxYS43NzEuNzcxIDAgMCAwIDEuMTkuOThsMy42LTQuMzd6Ii8+PC9zdmc+'
99

10-
const doubleLeft =
10+
let doubleLeft =
1111
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxOCIgaGVpZ2h0PSIxOCIgdmlld0JveD0iMCAwIDE4IDE4Ij48cGF0aCBkPSJNMTMuODUzIDQuMDI2YS43NzEuNzcxIDAgMCAxIC4xMiAxLjA4NUwxMC44NjQgOWwzLjExIDMuODg5YS43NzEuNzcxIDAgMSAxLTEuMjA0Ljk2M2wtMy40OTgtNC4zN2EuNzcxLjc3MSAwIDAgMSAwLS45NjRsMy40OTctNC4zNzFhLjc3MS43NzEgMCAwIDEgMS4wODQtLjEyem0tNS4yNDUgMGEuNzcxLjc3MSAwIDAgMSAuMTIgMS4wODVMNS42MTcgOWwzLjExMSAzLjg4OWEuNzcxLjc3MSAwIDAgMS0xLjIwNS45NjNsLTMuNDk3LTQuMzdhLjc3MS43NzEgMCAwIDEgMC0uOTY0bDMuNDk3LTQuMzcxYS43NzEuNzcxIDAgMCAxIDEuMDg1LS4xMnoiLz48L3N2Zz4='
1212

13-
const doubleRight =
13+
let doubleRight =
1414
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxOCIgaGVpZ2h0PSIxOCIgdmlld0JveD0iMCAwIDE4IDE4Ij48cGF0aCBkPSJNNC4xNDcgMTMuOTc0YS43NzEuNzcxIDAgMCAxLS4xMi0xLjA4NUw3LjEzNiA5IDQuMDI4IDUuMTFhLjc3MS43NzEgMCAxIDEgMS4yMDQtLjk2M2wzLjQ5NyA0LjM3MWEuNzcxLjc3MSAwIDAgMSAwIC45NjRsLTMuNDk3IDQuMzcxYS43NzEuNzcxIDAgMCAxLTEuMDg0LjEyem01LjI0NSAwYS43NzEuNzcxIDAgMCAxLS4xMi0xLjA4NUwxMi4zODMgOSA5LjI3MiA1LjExYS43NzEuNzcxIDAgMSAxIDEuMjA1LS45NjNsMy40OTcgNC4zNzFhLjc3MS43NzEgMCAwIDEgMCAuOTY0bC0zLjQ5NyA0LjM3MWEuNzcxLjc3MSAwIDAgMS0xLjA4NS4xMnoiLz48L3N2Zz4='
1515

1616
interface IconProps {
1717
url: string
1818
}
1919

20+
if (process.env.TARO_ENV === 'jdharmony_cpp') {
21+
left =
22+
'https://img11.360buyimg.com/imagetools/jfs/t1/187031/35/51586/196/6731c464F9b9f8f00/5506e32bf15e29dc.png'
23+
right =
24+
'https://img12.360buyimg.com/imagetools/jfs/t1/181006/25/51824/185/6731c452F9e252322/7493147dd6b4a88d.png'
25+
doubleLeft =
26+
'https://img13.360buyimg.com/imagetools/jfs/t1/221244/29/45876/259/6731c6bdF515df0a2/624e8eee3c8494a2.png'
27+
doubleRight =
28+
'https://img11.360buyimg.com/imagetools/jfs/t1/238382/25/24000/235/6731c6bdF0153286c/4a57e60b6e889af3.png'
29+
}
30+
2031
const Icon: FC<IconProps> = ({ url }) => {
2132
const style = {
2233
background: `url('${url}') no-repeat center`,
2334
backgroundSize: '100% 100%',
24-
width: '18px',
25-
height: '18px',
35+
width: 18,
36+
height: 18,
37+
}
38+
if (process.env.TARO_ENV === 'jdharmony_cpp') {
39+
return <Image src={url} style={style} />
2640
}
2741
return <View style={style} />
2842
}

0 commit comments

Comments
 (0)