Skip to content

Commit 4531564

Browse files
TinsFoxluo3house3lang3thinkasanyxiejun-net
authored
feat(Calendar): add horizontal feature (#592)
* feat(Calendar): add `horizontal` feature * feat: Fix Calendar/horizontal based on #592 (#612) * feat: `Stepper` 支持 ref 调用 `focus` `blur`方法 (#590) * chore: stepper types correct * Feat icons build (#593) * fix(Icon): target=es5 for icons build * chore: release icon dev * chore(icons): release 0.0.8 * chore: precommit lint * chore: release 3.0.3 * chore: release v3.0.4 * docs: optimization example (#596) * fix: add button type & optimize condition (#597) * chore: release icons * fix: issues/599 (#600) Co-authored-by: jeff.xie <jeff.xie@usmarthk.com> * chore: relase 3.0.5 ver * feat: dropdownMenu自定义选项的选中态勾选icon (#601) * fix: issues/599 * feat: dropdownMenu自定义选项的选中态勾选icon Co-authored-by: jeff.xie <jeff.xie@usmarthk.com> * chore: release 3.1.0 * fix: dropdownMenu自定义选项的选中态勾选icon非必填选项 (#602) Co-authored-by: jeff.xie <jeff.xie@usmarthk.com> * fix: tabs传入style(#595) (#603) * chore: release 3.1.1 * fix(collapse): fix bug in strict mode(#605) (#606) * fix: close #604 (#610) * fix: close #608 (#609) * chore: release 3.1.2 * fix(Calendar): prevent scroll update in horizontal Co-authored-by: 3lang <675483520@qq.com> Co-authored-by: thinkasany <117748716+thinkasany@users.noreply.github.com> Co-authored-by: 谢俊 <xiejun_ncu@qq.com> Co-authored-by: jeff.xie <jeff.xie@usmarthk.com> Co-authored-by: xiaogonggong-w <79799040+xiaogonggong-w@users.noreply.github.com> Co-authored-by: LZHD <brucefxq@gmail.com> Co-authored-by: TinsFox <fox@tinsfox.com> Co-authored-by: luo3house <96865086+luo3house@users.noreply.github.com> Co-authored-by: 3lang <675483520@qq.com> Co-authored-by: thinkasany <117748716+thinkasany@users.noreply.github.com> Co-authored-by: 谢俊 <xiejun_ncu@qq.com> Co-authored-by: jeff.xie <jeff.xie@usmarthk.com> Co-authored-by: xiaogonggong-w <79799040+xiaogonggong-w@users.noreply.github.com> Co-authored-by: LZHD <brucefxq@gmail.com>
1 parent 07912e3 commit 4531564

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

packages/react-vant/src/components/calendar/Calendar.tsx

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import useUpdateEffect from '../hooks/use-update-effect'
3333
import ConfigProviderContext from '../config-provider/ConfigProviderContext'
3434
import { usePropsValue } from '../hooks'
3535
import { PickerPopupActions } from '../picker/PropsType'
36+
import Swiper from '../swiper'
3637

3738
const [bem] = createNamespace('calendar')
3839

@@ -128,7 +129,6 @@ const Calendar = forwardRef<CalendarInstance, CalendarProps>(
128129
}, [value])
129130

130131
const [monthRefs, setMonthRefs] = useRefs()
131-
132132
const dayOffset = useMemo(
133133
() => (props.firstDayOfWeek ? +props.firstDayOfWeek % 7 : 0),
134134
[props.firstDayOfWeek, props.firstDayOfWeek]
@@ -213,7 +213,11 @@ const Calendar = forwardRef<CalendarInstance, CalendarProps>(
213213
})
214214

215215
/* istanbul ignore else */
216-
if (currentMonth && currentMonth.getTitle() !== state.subtitle) {
216+
if (
217+
currentMonth &&
218+
currentMonth.getTitle() !== state.subtitle &&
219+
!props.horizontal
220+
) {
217221
updateState({ subtitle: currentMonth.getTitle() })
218222
}
219223
}
@@ -381,7 +385,8 @@ const Calendar = forwardRef<CalendarInstance, CalendarProps>(
381385
}
382386

383387
const renderMonth = (date: Date, index: number) => {
384-
const showMonthTitle = index !== 0 || !props.showSubtitle
388+
const showMonthTitle =
389+
!props.horizontal && (index !== 0 || !props.showSubtitle)
385390
return (
386391
<CalendarMonth
387392
key={index}
@@ -461,9 +466,27 @@ const Calendar = forwardRef<CalendarInstance, CalendarProps>(
461466
props.onClickSubtitle?.(event)
462467
}}
463468
/>
464-
<div ref={bodyRef} className={cls(bem('body'))} onScroll={onScroll}>
465-
{months.map(renderMonth)}
466-
</div>
469+
{props.horizontal ? (
470+
<div ref={bodyRef} className={cls(bem('horizontal-body'))}>
471+
<Swiper
472+
indicator={() => null}
473+
onChange={index => {
474+
updateState({ subtitle: monthRefs[index].getTitle() })
475+
}}
476+
>
477+
{months.map((month, index) => (
478+
<Swiper.Item key={month}>
479+
{renderMonth(month, index)}
480+
</Swiper.Item>
481+
))}
482+
</Swiper>
483+
</div>
484+
) : (
485+
<div ref={bodyRef} className={cls(bem('body'))} onScroll={onScroll}>
486+
{months.map(renderMonth)}
487+
</div>
488+
)}
489+
467490
{renderFooter()}
468491
</div>
469492
)

packages/react-vant/src/components/calendar/PropsType.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export interface CalendarProps extends Omit<BaseTypeProps, 'children'> {
121121
firstDayOfWeek?: number | string
122122
showRangePrompt?: boolean
123123
footer?: React.ReactNode
124+
horizontal?: boolean
124125
topInfoRender?: (day: CalendarDayItem) => React.ReactNode
125126
bottomInfoRender?: (day: CalendarDayItem) => React.ReactNode
126127
onSelect?: (value: CalendarValue) => void

packages/react-vant/src/components/calendar/demo/custom.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ export default () => {
116116
/>
117117
)}
118118
</Calendar>
119+
<Calendar horizontal>
120+
{(val: Date, actions) => (
121+
<Cell
122+
isLink
123+
title='水平滑动'
124+
value={val ? val.toLocaleDateString() : '请选择日期'}
125+
onClick={() => actions.open()}
126+
/>
127+
)}
128+
</Calendar>
119129
</>
120130
)
121131
}

packages/react-vant/src/components/calendar/style/index.less

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@
9393
-webkit-overflow-scrolling: touch;
9494
}
9595

96+
&__horizontal-body {
97+
flex: 1;
98+
overflow-x: hidden;
99+
overflow-y: scroll;
100+
}
101+
96102
&__days {
97103
position: relative;
98104
display: flex;

0 commit comments

Comments
 (0)