From 99c997fcb10b02e6c527f6541fbcc6155c55ff27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Thu, 19 Oct 2023 15:48:53 +0800 Subject: [PATCH 1/5] chore: mv --- config/components.ts | 3 +- .../arrow-left-double.tsx | 0 .../arrow-left.tsx | 0 .../calendar-view.en.md | 0 .../calendar-view.less | 0 .../calendar-view.tsx | 0 .../calendar-view.zh.md | 0 .../convert.ts | 0 .../demos/demo1.tsx | 0 .../index.ts | 0 .../__snapshots__/calendar-view.test.tsx.snap | 0 .../tests/calendar-view.test.tsx | 0 src/components/calendar-picker/calendar.en.md | 79 + src/components/calendar-picker/calendar.tsx | 123 + src/components/calendar-picker/calendar.zh.md | 79 + .../calendar-picker/demos/demo1.tsx | 73 + .../calendar-picker/demos/demo2.tsx | 73 + .../demos/demo3.less | 0 .../calendar-picker/demos/demo3.tsx | 111 + .../calendar-picker/demos/demo4.tsx | 48 + src/components/calendar-picker/index.ts | 5 + .../__snapshots__/calendar.test.tsx.snap | 9 + .../calendar-picker/tests/calendar.test.tsx | 39 + src/components/calendar/arrow-left-double.tsx | 23 + src/components/calendar/arrow-left.tsx | 22 + src/components/calendar/calendar.en.md | 24 +- src/components/calendar/calendar.less | 111 + src/components/calendar/calendar.tsx | 392 +- src/components/calendar/calendar.zh.md | 26 +- src/components/calendar/convert.ts | 20 + src/components/calendar/demos/demo1.tsx | 83 +- src/components/calendar/demos/demo2.tsx | 80 +- src/components/calendar/demos/demo3.tsx | 137 +- src/components/calendar/demos/demo4.less | 86 + src/components/calendar/demos/demo4.tsx | 61 +- src/components/calendar/demos/demo5.less | 13 + src/components/calendar/demos/demo5.tsx | 30 + src/components/calendar/index.ts | 1 + .../__snapshots__/calendar.test.tsx.snap | 5121 ++++++++++++++++- .../calendar/tests/calendar.test.tsx | 158 +- src/index.ts | 4 +- 41 files changed, 6643 insertions(+), 391 deletions(-) rename src/components/{calendar-view => calendar-picker-view}/arrow-left-double.tsx (100%) rename src/components/{calendar-view => calendar-picker-view}/arrow-left.tsx (100%) rename src/components/{calendar-view => calendar-picker-view}/calendar-view.en.md (100%) rename src/components/{calendar-view => calendar-picker-view}/calendar-view.less (100%) rename src/components/{calendar-view => calendar-picker-view}/calendar-view.tsx (100%) rename src/components/{calendar-view => calendar-picker-view}/calendar-view.zh.md (100%) rename src/components/{calendar-view => calendar-picker-view}/convert.ts (100%) rename src/components/{calendar-view => calendar-picker-view}/demos/demo1.tsx (100%) rename src/components/{calendar-view => calendar-picker-view}/index.ts (100%) rename src/components/{calendar-view => calendar-picker-view}/tests/__snapshots__/calendar-view.test.tsx.snap (100%) rename src/components/{calendar-view => calendar-picker-view}/tests/calendar-view.test.tsx (100%) create mode 100644 src/components/calendar-picker/calendar.en.md create mode 100644 src/components/calendar-picker/calendar.tsx create mode 100644 src/components/calendar-picker/calendar.zh.md create mode 100644 src/components/calendar-picker/demos/demo1.tsx create mode 100644 src/components/calendar-picker/demos/demo2.tsx rename src/components/{calendar => calendar-picker}/demos/demo3.less (100%) create mode 100644 src/components/calendar-picker/demos/demo3.tsx create mode 100644 src/components/calendar-picker/demos/demo4.tsx create mode 100644 src/components/calendar-picker/index.ts create mode 100644 src/components/calendar-picker/tests/__snapshots__/calendar.test.tsx.snap create mode 100644 src/components/calendar-picker/tests/calendar.test.tsx create mode 100644 src/components/calendar/arrow-left-double.tsx create mode 100644 src/components/calendar/arrow-left.tsx create mode 100644 src/components/calendar/calendar.less create mode 100644 src/components/calendar/convert.ts create mode 100644 src/components/calendar/demos/demo4.less create mode 100644 src/components/calendar/demos/demo5.less create mode 100644 src/components/calendar/demos/demo5.tsx diff --git a/config/components.ts b/config/components.ts index 8f737d4763..534e13e71a 100644 --- a/config/components.ts +++ b/config/components.ts @@ -74,7 +74,8 @@ export const components = { experimental: [ '/guide/what-is-experimental', '/components/calendar', - '/components/calendar-view', + '/components/calendar-picker', + '/components/calendar-picker-view', '/components/dropdown', '/components/floating-bubble', '/components/image-uploader', diff --git a/src/components/calendar-view/arrow-left-double.tsx b/src/components/calendar-picker-view/arrow-left-double.tsx similarity index 100% rename from src/components/calendar-view/arrow-left-double.tsx rename to src/components/calendar-picker-view/arrow-left-double.tsx diff --git a/src/components/calendar-view/arrow-left.tsx b/src/components/calendar-picker-view/arrow-left.tsx similarity index 100% rename from src/components/calendar-view/arrow-left.tsx rename to src/components/calendar-picker-view/arrow-left.tsx diff --git a/src/components/calendar-view/calendar-view.en.md b/src/components/calendar-picker-view/calendar-view.en.md similarity index 100% rename from src/components/calendar-view/calendar-view.en.md rename to src/components/calendar-picker-view/calendar-view.en.md diff --git a/src/components/calendar-view/calendar-view.less b/src/components/calendar-picker-view/calendar-view.less similarity index 100% rename from src/components/calendar-view/calendar-view.less rename to src/components/calendar-picker-view/calendar-view.less diff --git a/src/components/calendar-view/calendar-view.tsx b/src/components/calendar-picker-view/calendar-view.tsx similarity index 100% rename from src/components/calendar-view/calendar-view.tsx rename to src/components/calendar-picker-view/calendar-view.tsx diff --git a/src/components/calendar-view/calendar-view.zh.md b/src/components/calendar-picker-view/calendar-view.zh.md similarity index 100% rename from src/components/calendar-view/calendar-view.zh.md rename to src/components/calendar-picker-view/calendar-view.zh.md diff --git a/src/components/calendar-view/convert.ts b/src/components/calendar-picker-view/convert.ts similarity index 100% rename from src/components/calendar-view/convert.ts rename to src/components/calendar-picker-view/convert.ts diff --git a/src/components/calendar-view/demos/demo1.tsx b/src/components/calendar-picker-view/demos/demo1.tsx similarity index 100% rename from src/components/calendar-view/demos/demo1.tsx rename to src/components/calendar-picker-view/demos/demo1.tsx diff --git a/src/components/calendar-view/index.ts b/src/components/calendar-picker-view/index.ts similarity index 100% rename from src/components/calendar-view/index.ts rename to src/components/calendar-picker-view/index.ts diff --git a/src/components/calendar-view/tests/__snapshots__/calendar-view.test.tsx.snap b/src/components/calendar-picker-view/tests/__snapshots__/calendar-view.test.tsx.snap similarity index 100% rename from src/components/calendar-view/tests/__snapshots__/calendar-view.test.tsx.snap rename to src/components/calendar-picker-view/tests/__snapshots__/calendar-view.test.tsx.snap diff --git a/src/components/calendar-view/tests/calendar-view.test.tsx b/src/components/calendar-picker-view/tests/calendar-view.test.tsx similarity index 100% rename from src/components/calendar-view/tests/calendar-view.test.tsx rename to src/components/calendar-picker-view/tests/calendar-view.test.tsx diff --git a/src/components/calendar-picker/calendar.en.md b/src/components/calendar-picker/calendar.en.md new file mode 100644 index 0000000000..41320924b0 --- /dev/null +++ b/src/components/calendar-picker/calendar.en.md @@ -0,0 +1,79 @@ +# Calendar + +Used to select a date or date range. + +## When to Use + +When the user needs to enter a date, he can select it in the pop-up date panel. + +## Demos + + + + + + + + + +## Calendar + +### Props + +| Name | Description | Type | Default | Version | +| --- | --- | --- | --- | --- | +| visible | To show or hide the Cclendar | `boolean` | `true` | +| confirmText | The text of confirm button | `string` | `Confirm` | +| popupClassName | The custom class name of the popup | `string` | - | +| popupStyle | The custom style of the popup | `React.CSSProperties` | - | +| popupBodyStyle | The custom style of the popup body | `React.CSSProperties` | - | +| forceRender | Render content forcely,When ref is passed,always be true | `boolean` | `false` | +| closeOnMaskClick | Whether to close after clicking the mask layer | `boolean` | `true` | +| onClose | Triggered when closed | `() => void` | - | +| onMaskClick | Triggered when the mask is clicked | `() => void` | - | +| allowClear | Whether to allow clearing after another click. | `boolean` | `true` | +| defaultValue | The default selected date or date range. | Same as `value` prop. | - | +| max | Maximum value of a selectable range. | `Date` | - | +| min | Minimum value of a selectable range. | `Date` | - | - | +| onChange | Trigger when selected date changes. | `(val: Date \| null) => void` when selection mode is "single". `(val: [Date, Date] \| null) => void` when selection mode is "range". | - | +| onConfirm | Trigger when confirm button is clicked. | `(val: Date \| null) => void` when selection mode is "single",`(val: [Date, Date] \| null) => void` when selection mode is "range" | - | +| renderTop | The top information of date render function. | `(date: Date) => ReactNode \| null \| undefined` | - | +| renderBottom | The bottom information of date render function. | `(date: Date) => ReactNode \| null \| undefined` | - | +| selectionMode | The selection mode. Disable selection when this prop is not set. | `'single' \| 'range'` | - | +| shouldDisableDate | Set whether the date is disable selection. The min and max Settings are ignored | `(date: Date) => boolean` | - | +| title | The title of calendar | `React.ReactNode` | `Date selection` | +| value | The selected date or date range. | `Date \| null` when selection mode is "single". `[Date, Date] \| null` when selection mode is "range" | - | +| weekStartsOn | Week starts on which day. | `'Monday' \| 'Sunday'` | `'Sunday'` | +| renderDate | Custom date rendering. | `(date: Date) => ReactNode` | - | 5.28.0 | + +### CSS Variables + +Not supported yet. + +### Ref + +| Name | Description | Type | +| --- | --- | --- | +| jumpTo | Jump to specified page | `(page: Page \| ((page: Page) => Page)) => void` | +| jumpToToday | Jump to today's page | `() => void` | +| getDateRange | get date | `[Date, Date]` | + +```ts +type Page = { month: number; year: number } +``` + +You can manually control the page turning of the calendar through Ref, for example: + +```ts +// Jump to today's page +ref.current.jumpToToday() + +// Jump to the specified year and month +ref.current.jumpTo({ year: 2021, month: 1 }) + +// Jump to three years later +ref.current.jumpTo(page => ({ + year: page.year + 3, + month: page.month, +})) +``` diff --git a/src/components/calendar-picker/calendar.tsx b/src/components/calendar-picker/calendar.tsx new file mode 100644 index 0000000000..ab585b4ce7 --- /dev/null +++ b/src/components/calendar-picker/calendar.tsx @@ -0,0 +1,123 @@ +import React, { forwardRef, useRef } from 'react' +import { withNativeProps } from '../../utils/native-props' +import classNames from 'classnames' +import Button from '../button' +import Divider from '../divider' +import Popup from '../popup' +import { mergeProps } from '../../utils/with-default-props' +import { useConfig } from '../config-provider' +import CalendarView, { + CalendarViewProps, + CalendarViewRef, +} from '../calendar-picker-view' + +const classPrefix = 'adm-calendar' + +export type CalendarRef = CalendarViewRef + +export type CalendarProps = CalendarViewProps & { + visible?: boolean + confirmText?: string + popupClassName?: string + popupStyle?: React.CSSProperties + popupBodyStyle?: React.CSSProperties + forceRender?: true + closeOnMaskClick?: boolean + onClose?: () => void + onMaskClick?: () => void +} & ( + | { + selectionMode?: undefined + onConfirm?: undefined + } + | { + selectionMode: 'single' + onConfirm?: (val: Date | null) => void + } + | { + selectionMode: 'range' + onConfirm?: (val: [Date, Date] | null) => void + } + ) + +const defaultProps = { + weekStartsOn: 'Sunday', + defaultValue: null, + allowClear: true, + usePopup: true, + selectionMode: 'single', +} + +export const Calendar = forwardRef((p, ref) => { + const props = mergeProps(defaultProps, p) + const { locale } = useConfig() + const calendarRef = (ref ?? + useRef(null)) as React.RefObject + + const { + visible, + confirmText, + popupClassName, + popupStyle, + popupBodyStyle, + forceRender, + closeOnMaskClick, + onClose, + onConfirm, + onMaskClick, + ...calendarViewProps + } = props + + const footer = ( +
+ +
+ +
+
+ ) + + return withNativeProps( + props, +
+ { + onMaskClick?.() + if (closeOnMaskClick) { + onClose?.() + } + }} + > + + {footer} + +
+ ) +}) diff --git a/src/components/calendar-picker/calendar.zh.md b/src/components/calendar-picker/calendar.zh.md new file mode 100644 index 0000000000..9fe79f0ba2 --- /dev/null +++ b/src/components/calendar-picker/calendar.zh.md @@ -0,0 +1,79 @@ +# Calendar 日历 + +用于选择日期或日期区间。 + +## 何时使用 + +当用户需要输入一个日期,可以在弹出的日期面板进行选择。 + +## 示例 + + + + + + + + + +## Calendar + +### 属性 + +| 属性 | 说明 | 类型 | 默认值 | 版本 | +| --- | --- | --- | --- | --- | +| visible | 显示隐藏 | `boolean` | `true` | +| confirmText | 确认按钮文案 | `string` | `确认` | +| popupClassName | 弹出层类名 | `string` | - | +| popupStyle | 弹层容器的自定义样式 | `React.CSSProperties` | - | +| popupBodyStyle | 容器内部自定义样式 | `React.CSSProperties` | - | +| forceRender | 强制渲染内容,当传递 ref 时,会强制设为 true | `boolean` | `false` | +| closeOnMaskClick | 点击背景蒙层后是否关闭 | `boolean` | `true` | +| onClose | 关闭时触发 | `() => void` | - | +| onMaskClick | 点击背景蒙层时触发 | `() => void` | - | +| allowClear | 是否允许再次点击后清除 | `boolean` | `true` | +| defaultValue | 默认选择的日期 | 同 `value` 属性 | - | +| max | 可选择范围的最大值 | `Date` | - | +| min | 可选择范围的最小值 | `Date` | - | +| onChange | 选择日期变化时触发 | 单选模式下为 `(val: Date \| null) => void`,多选模式下为 `(val: [Date, Date] \| null) => void` | - | +| onConfirm | 点击确认按钮时触发 | 单选模式下为 `(val: Date \| null) => void`,多选模式下为 `(val: [Date, Date] \| null) => void` | - | +| renderTop | 日期顶部信息的渲染函数 | `(date: Date) => ReactNode \| null \| undefined` | - | +| renderBottom | 日期底部信息的渲染函数 | `(date: Date) => ReactNode \| null \| undefined` | - | +| selectionMode | 选择模式,不设置的话表示不支持选择 | `'single' \| 'range'` | - | +| shouldDisableDate | 判断日期是否可选,使用后会忽略 min 和 max 设置 | `(date: Date) => boolean` | - | +| title | 日期选择器的标题 | `React.ReactNode` | `日期选择` | +| value | 选择的日期 | 单选模式下为 `Date \| null`,多选模式下为 `[Date, Date] \| null` | - | +| weekStartsOn | 每周以周几作为第一天 | `'Monday' \| 'Sunday'` | `'Sunday'` | +| renderDate | 自定义日期渲染 | `(date: Date) => ReactNode` | - | 5.28.0 | + +### CSS 变量 + +暂无 + +### Ref + +| 属性 | 说明 | 类型 | +| --- | --- | --- | +| jumpTo | 跳转至指定日期的区间 | `(page: Page \| ((page: Page) => Page)) => void` | +| jumpToToday | 跳转至今日 | `() => void` | +| getDateRange | 获取日期 | `[Date, Date]` | + +```ts +type Page = { month: number; year: number } +``` + +你可以通过 Ref 手动控制日历的翻页,例如: + +```ts +// 跳回当月 +ref.current.jumpToToday() + +// 跳转至指定年月 +ref.current.jumpTo({ year: 2021, month: 1 }) + +// 跳转到三年之后 +ref.current.jumpTo(page => ({ + year: page.year + 3, + month: page.month, +})) +``` diff --git a/src/components/calendar-picker/demos/demo1.tsx b/src/components/calendar-picker/demos/demo1.tsx new file mode 100644 index 0000000000..528bc15b59 --- /dev/null +++ b/src/components/calendar-picker/demos/demo1.tsx @@ -0,0 +1,73 @@ +import dayjs from 'dayjs' +import React, { useState } from 'react' +import { Calendar, List } from 'antd-mobile' + +const defaultRange: [Date, Date] = [ + dayjs().toDate(), + dayjs().add(2, 'day').toDate(), +] + +export default () => { + const [val, setVal] = useState<[Date, Date] | null>(() => [ + dayjs().subtract(2, 'day').toDate(), + dayjs().add(2, 'day').toDate(), + ]) + const [visible1, setVisible1] = useState(false) + const [visible2, setVisible2] = useState(false) + const [visible3, setVisible3] = useState(false) + + const singleDate: Date = new Date('2023-06-03') + + return ( + + { + setVisible1(true) + }} + > + 选择单个日期 + setVisible1(false)} + onMaskClick={() => setVisible1(false)} + /> + + { + setVisible2(true) + }} + > + 选择日期范围 + setVisible2(false)} + onMaskClick={() => setVisible2(false)} + onChange={val => { + console.log(val) + }} + /> + + { + setVisible3(true) + }} + > + 受控日期选择 + setVisible3(false)} + onMaskClick={() => setVisible3(false)} + onChange={val => { + setVal(val) + }} + /> + + + ) +} diff --git a/src/components/calendar-picker/demos/demo2.tsx b/src/components/calendar-picker/demos/demo2.tsx new file mode 100644 index 0000000000..d9f7c7d9c0 --- /dev/null +++ b/src/components/calendar-picker/demos/demo2.tsx @@ -0,0 +1,73 @@ +import React, { useState } from 'react' +import { Calendar, List } from 'antd-mobile' + +const min = new Date() +min.setDate(5) +const max = new Date() +max.setDate(20) + +export default () => { + const [visible1, setVisible1] = useState(false) + const [visible2, setVisible2] = useState(false) + const [visible3, setVisible3] = useState(false) + const [visible4, setVisible4] = useState(false) + + return ( + + { + setVisible1(true) + }} + > + 自定义标题 + setVisible1(false)} + onMaskClick={() => setVisible1(false)} + /> + + { + setVisible2(true) + }} + > + 自定义确认文案 + setVisible2(false)} + onMaskClick={() => setVisible2(false)} + /> + + { + setVisible3(true) + }} + > + 周一作为每周的第一天 + setVisible3(false)} + onMaskClick={() => setVisible3(false)} + /> + + { + setVisible4(true) + }} + > + 限制日期范围 + setVisible4(false)} + onMaskClick={() => setVisible4(false)} + /> + + + ) +} diff --git a/src/components/calendar/demos/demo3.less b/src/components/calendar-picker/demos/demo3.less similarity index 100% rename from src/components/calendar/demos/demo3.less rename to src/components/calendar-picker/demos/demo3.less diff --git a/src/components/calendar-picker/demos/demo3.tsx b/src/components/calendar-picker/demos/demo3.tsx new file mode 100644 index 0000000000..7a1a7697e7 --- /dev/null +++ b/src/components/calendar-picker/demos/demo3.tsx @@ -0,0 +1,111 @@ +import classnames from 'classnames' +import dayjs from 'dayjs' +import React, { useState } from 'react' +import { Calendar, List } from 'antd-mobile' +import './demo3.less' + +export default () => { + const today = dayjs() + const [val, setVal] = useState<[Date, Date] | null>(() => [ + today.subtract(2, 'day').toDate(), + today.add(2, 'day').toDate(), + ]) + + const [visible1, setVisible1] = useState(false) + const [visible2, setVisible2] = useState(false) + const [visible3, setVisible3] = useState(false) + const [visible4, setVisible4] = useState(false) + + return ( + + { + setVisible1(true) + }} + > + 自定义日期顶部信息 + setVisible1(false)} + onMaskClick={() => setVisible1(false)} + renderTop={date => { + const map = { + 1: '初一', + 2: '初二', + 3: '初三', + } + const dates = [1, 2, 3] + const d = dayjs(date).date() as keyof typeof map + + if (dates.includes(d)) { + return map[d] + } + }} + /> + + { + setVisible2(true) + }} + > + 自定义日期底部信息 + setVisible2(false)} + onMaskClick={() => setVisible2(false)} + renderBottom={date => { + const dates = [16, 17, 18, 19] + const d = dayjs(date).date() + + if (dates.includes(d)) { + return '¥100' + } + }} + /> + + { + setVisible3(true) + }} + > + 自定义日期渲染 + setVisible3(false)} + onMaskClick={() => setVisible3(false)} + renderDate={date => { + const dates = [16, 17, 18, 19] + const d = dayjs(date).date() + return ( +
+ {d} +
+ ) + }} + /> +
+ { + setVisible4(true) + }} + > + 高级自定义样式 + { + setVal(val) + }} + visible={visible4} + onClose={() => setVisible4(false)} + onMaskClick={() => setVisible4(false)} + /> + +
+ ) +} diff --git a/src/components/calendar-picker/demos/demo4.tsx b/src/components/calendar-picker/demos/demo4.tsx new file mode 100644 index 0000000000..82ee73197f --- /dev/null +++ b/src/components/calendar-picker/demos/demo4.tsx @@ -0,0 +1,48 @@ +import React, { useState, useRef } from 'react' +import { Calendar, List, CalendarRef } from 'antd-mobile' + +export default () => { + const ref1 = useRef(null) + const ref2 = useRef(null) + const [visible1, setVisible1] = useState(false) + const [visible2, setVisible2] = useState(false) + + return ( + + { + setVisible1(true) + ref1.current?.jumpTo(page => ({ + year: page.year, + month: page.month + 3, + })) + }} + > + 跳转到 3 月后 + setVisible1(false)} + onMaskClick={() => setVisible1(false)} + /> + + { + setVisible2(true) + ref2.current?.jumpTo(page => ({ + year: page.year + 3, + month: page.month, + })) + }} + > + 跳转到 3 年后 + setVisible2(false)} + onMaskClick={() => setVisible2(false)} + /> + + + ) +} diff --git a/src/components/calendar-picker/index.ts b/src/components/calendar-picker/index.ts new file mode 100644 index 0000000000..7cf42a25f9 --- /dev/null +++ b/src/components/calendar-picker/index.ts @@ -0,0 +1,5 @@ +import { Calendar } from './calendar' + +export type { CalendarProps, CalendarRef } from './calendar' + +export default Calendar diff --git a/src/components/calendar-picker/tests/__snapshots__/calendar.test.tsx.snap b/src/components/calendar-picker/tests/__snapshots__/calendar.test.tsx.snap new file mode 100644 index 0000000000..a3644cc699 --- /dev/null +++ b/src/components/calendar-picker/tests/__snapshots__/calendar.test.tsx.snap @@ -0,0 +1,9 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Calendar single mode 1`] = ` +
+
+
+`; diff --git a/src/components/calendar-picker/tests/calendar.test.tsx b/src/components/calendar-picker/tests/calendar.test.tsx new file mode 100644 index 0000000000..fa43a79f95 --- /dev/null +++ b/src/components/calendar-picker/tests/calendar.test.tsx @@ -0,0 +1,39 @@ +import React from 'react' +import { render, testA11y, fireEvent } from 'testing' +import Calendar from '..' +import MockDate from 'mockdate' + +const classPrefix = `adm-calendar-view` + +// mock today +MockDate.set(new Date('2023-05-22')) + +const mixDate: Date = new Date('2023-05-01') +const maxDate: Date = new Date('2023-05-31') +const singleDate: Date = new Date('2023-05-03') + +describe('Calendar', () => { + test('a11y', async () => { + await testA11y() + }) + + test('single mode', async () => { + const fn = jest.fn() + const { container, getAllByText } = render( + + ) + + expect(container).toMatchSnapshot() + const dateEl = getAllByText(15)[0] + fireEvent.click(dateEl) + expect(dateEl.parentElement).toHaveClass(`${classPrefix}-cell-selected`) + expect(fn).toBeCalled() + }) +}) diff --git a/src/components/calendar/arrow-left-double.tsx b/src/components/calendar/arrow-left-double.tsx new file mode 100644 index 0000000000..e47a37737d --- /dev/null +++ b/src/components/calendar/arrow-left-double.tsx @@ -0,0 +1,23 @@ +import React, { FC } from 'react' + +export const ArrowLeftDouble: FC = () => { + return ( + + + + + + + + + + + + + + ) +} diff --git a/src/components/calendar/arrow-left.tsx b/src/components/calendar/arrow-left.tsx new file mode 100644 index 0000000000..52bb688201 --- /dev/null +++ b/src/components/calendar/arrow-left.tsx @@ -0,0 +1,22 @@ +import React, { FC } from 'react' + +export const ArrowLeft: FC = () => { + return ( + + + + + + + + + + + + + ) +} diff --git a/src/components/calendar/calendar.en.md b/src/components/calendar/calendar.en.md index 41320924b0..b5d4c4974e 100644 --- a/src/components/calendar/calendar.en.md +++ b/src/components/calendar/calendar.en.md @@ -16,32 +16,29 @@ When the user needs to enter a date, he can select it in the pop-up date panel. + + ## Calendar ### Props | Name | Description | Type | Default | Version | | --- | --- | --- | --- | --- | -| visible | To show or hide the Cclendar | `boolean` | `true` | -| confirmText | The text of confirm button | `string` | `Confirm` | -| popupClassName | The custom class name of the popup | `string` | - | -| popupStyle | The custom style of the popup | `React.CSSProperties` | - | -| popupBodyStyle | The custom style of the popup body | `React.CSSProperties` | - | -| forceRender | Render content forcely,When ref is passed,always be true | `boolean` | `false` | -| closeOnMaskClick | Whether to close after clicking the mask layer | `boolean` | `true` | -| onClose | Triggered when closed | `() => void` | - | -| onMaskClick | Triggered when the mask is clicked | `() => void` | - | | allowClear | Whether to allow clearing after another click. | `boolean` | `true` | | defaultValue | The default selected date or date range. | Same as `value` prop. | - | | max | Maximum value of a selectable range. | `Date` | - | | min | Minimum value of a selectable range. | `Date` | - | - | +| maxPage | Maximum visible page of date. | `Page` | +| minPage | Minimum visible page of date. | `Page` | - | +| nextMonthButton | Contents of the Next Month button on the navigation pane | `React.ReactNode` | `>` | +| nextYearButton | Contents of the next Year button on the navigation pane | `React.ReactNode` | `>>` | | onChange | Trigger when selected date changes. | `(val: Date \| null) => void` when selection mode is "single". `(val: [Date, Date] \| null) => void` when selection mode is "range". | - | -| onConfirm | Trigger when confirm button is clicked. | `(val: Date \| null) => void` when selection mode is "single",`(val: [Date, Date] \| null) => void` when selection mode is "range" | - | -| renderTop | The top information of date render function. | `(date: Date) => ReactNode \| null \| undefined` | - | -| renderBottom | The bottom information of date render function. | `(date: Date) => ReactNode \| null \| undefined` | - | +| onPageChange | Trigger when changed year or month. | `(year: number, month: number) => void` | - | +| prevMonthButton | Contents of the Last Month button on the navigation pane | `React.ReactNode` | `<` | +| prevYearButton | Contents of the Last year button on the navigation pane | `React.ReactNode` | `<<` | +| renderLabel | The label render function. | `(date: Date) => ReactNode \| null \| undefined` | - | | selectionMode | The selection mode. Disable selection when this prop is not set. | `'single' \| 'range'` | - | | shouldDisableDate | Set whether the date is disable selection. The min and max Settings are ignored | `(date: Date) => boolean` | - | -| title | The title of calendar | `React.ReactNode` | `Date selection` | | value | The selected date or date range. | `Date \| null` when selection mode is "single". `[Date, Date] \| null` when selection mode is "range" | - | | weekStartsOn | Week starts on which day. | `'Monday' \| 'Sunday'` | `'Sunday'` | | renderDate | Custom date rendering. | `(date: Date) => ReactNode` | - | 5.28.0 | @@ -56,7 +53,6 @@ Not supported yet. | --- | --- | --- | | jumpTo | Jump to specified page | `(page: Page \| ((page: Page) => Page)) => void` | | jumpToToday | Jump to today's page | `() => void` | -| getDateRange | get date | `[Date, Date]` | ```ts type Page = { month: number; year: number } diff --git a/src/components/calendar/calendar.less b/src/components/calendar/calendar.less new file mode 100644 index 0000000000..aaaf8d2e58 --- /dev/null +++ b/src/components/calendar/calendar.less @@ -0,0 +1,111 @@ +.adm-calendar { + & &-header { + display: flex; + flex-direction: row; + align-items: center; + justify-content: space-between; + padding-top: 4px; + a.adm-calendar-arrow-button { + padding: 4px 8px; + display: block; + flex: none; + svg { + height: 22px; + } + &.adm-calendar-arrow-button-right { + svg { + transform: rotate(180deg); + } + } + } + .adm-calendar-title { + font-size: var(--adm-font-size-10); + flex: auto; + text-align: center; + } + } + & &-body { + display: flex; + flex-wrap: wrap; + } + &-cells { + display: flex; + flex-direction: row; + flex-wrap: wrap; + justify-content: flex-start; + align-items: stretch; + padding: 8px 8px 4px; + } + &-cell { + flex: none; + box-sizing: border-box; + width: calc(100% / 7); + height: 48px; + margin-bottom: 4px; + padding: 2px; + color: var(--adm-color-text); + cursor: pointer; + &&-today { + color: var(--adm-color-primary); + } + &&-disabled { + color: var(--adm-color-light); + .adm-calendar-cell-bottom { + color: var(--adm-color-light); + } + } + &&-selected { + && { + background: var(--adm-color-primary); + color: var(--adm-color-white); + } + & .adm-calendar-cell-bottom { + color: var(--adm-color-white); + } + &&-begin { + border-top-left-radius: 4px; + border-bottom-left-radius: 4px; + } + &&-end { + border-top-right-radius: 4px; + border-bottom-right-radius: 4px; + } + } + + &&-disabled&&-selected { + color: var(--adm-color-light); + } + + display: flex; + flex-direction: column; + align-items: center; + justify-content: flex-end; + & &-top { + flex: none; + font-size: var(--adm-font-size-10); + } + & &-bottom { + flex: none; + font-size: var(--adm-font-size-4); + height: 12px; + line-height: 12px; + color: var(--adm-color-weak); + } + } + + &-mark { + display: flex; + flex-direction: row; + justify-content: flex-start; + align-items: center; + border-bottom: solid 1px var(--adm-color-border); + height: 45px; + box-sizing: border-box; + font-size: var(--adm-font-size-7); + padding: 0 8px; + & &-cell { + flex: 1; + text-align: center; + } + } +} diff --git a/src/components/calendar/calendar.tsx b/src/components/calendar/calendar.tsx index 057dabb8d1..e05e57b6de 100644 --- a/src/components/calendar/calendar.tsx +++ b/src/components/calendar/calendar.tsx @@ -1,123 +1,333 @@ -import React, { forwardRef, useRef } from 'react' -import { withNativeProps } from '../../utils/native-props' +import React, { + forwardRef, + ReactNode, + useState, + useImperativeHandle, + useMemo, +} from 'react' +import { NativeProps, withNativeProps } from '../../utils/native-props' +import dayjs from 'dayjs' import classNames from 'classnames' -import Button from '../button' -import Divider from '../divider' -import Popup from '../popup' import { mergeProps } from '../../utils/with-default-props' +import { ArrowLeft } from './arrow-left' +import { ArrowLeftDouble } from './arrow-left-double' import { useConfig } from '../config-provider' -import CalendarView, { - CalendarViewProps, - CalendarViewRef, -} from '../calendar-view' +import isoWeek from 'dayjs/plugin/isoWeek' +import { useUpdateEffect } from 'ahooks' +import { usePropsValue } from '../../utils/use-props-value' +import { replaceMessage } from '../../utils/replace-message' +import { + convertValueToRange, + convertPageToDayjs, + DateRange, + Page, +} from './convert' + +dayjs.extend(isoWeek) const classPrefix = 'adm-calendar' -export type CalendarRef = CalendarViewRef - -export type CalendarProps = CalendarViewProps & { - visible?: boolean - confirmText?: string - popupClassName?: string - popupStyle?: React.CSSProperties - popupBodyStyle?: React.CSSProperties - forceRender?: true - closeOnMaskClick?: boolean - onClose?: () => void - onMaskClick?: () => void +export type CalendarRef = { + jumpTo: (page: Page | ((page: Page) => Page)) => void + jumpToToday: () => void +} + +export type CalendarProps = { + prevMonthButton?: React.ReactNode + prevYearButton?: React.ReactNode + nextMonthButton?: React.ReactNode + nextYearButton?: React.ReactNode + onPageChange?: (year: number, month: number) => void + weekStartsOn?: 'Monday' | 'Sunday' + renderLabel?: (date: Date) => React.ReactNode + renderDate?: (date: Date) => React.ReactNode + allowClear?: boolean + max?: Date + min?: Date + shouldDisableDate?: (date: Date) => boolean + minPage?: Page + maxPage?: Page } & ( - | { - selectionMode?: undefined - onConfirm?: undefined - } - | { - selectionMode: 'single' - onConfirm?: (val: Date | null) => void - } - | { - selectionMode: 'range' - onConfirm?: (val: [Date, Date] | null) => void - } - ) + | { + selectionMode?: undefined + value?: undefined + defaultValue?: undefined + onChange?: undefined + } + | { + selectionMode: 'single' + value?: Date | null + defaultValue?: Date | null + onChange?: (val: Date | null) => void + } + | { + selectionMode: 'range' + value?: [Date, Date] | null + defaultValue?: [Date, Date] | null + onChange?: (val: [Date, Date] | null) => void + } +) & + NativeProps const defaultProps = { weekStartsOn: 'Sunday', defaultValue: null, allowClear: true, - usePopup: true, - selectionMode: 'single', + prevMonthButton: , + prevYearButton: , + nextMonthButton: , + nextYearButton: , } export const Calendar = forwardRef((p, ref) => { + const today = dayjs() const props = mergeProps(defaultProps, p) const { locale } = useConfig() - const calendarRef = (ref ?? - useRef(null)) as React.RefObject - - const { - visible, - confirmText, - popupClassName, - popupStyle, - popupBodyStyle, - forceRender, - closeOnMaskClick, - onClose, - onConfirm, - onMaskClick, - ...calendarViewProps - } = props - - const footer = ( -
- -
- -
+
+ {props.renderDate ? props.renderDate(d.toDate()) : d.date()} +
+
+ {props.renderLabel?.(d.toDate())} +
+
+ ) + iterator = iterator.add(1, 'day') + } + return cells + } + const body =
{renderCells()}
+ + const mark = ( +
+ {markItems.map((item, index) => ( +
+ {item} +
+ ))}
) return withNativeProps( props,
- { - onMaskClick?.() - if (closeOnMaskClick) { - onClose?.() - } - }} - > - - {footer} - + {header} + {mark} + {body}
) }) diff --git a/src/components/calendar/calendar.zh.md b/src/components/calendar/calendar.zh.md index 9fe79f0ba2..ed01567c4a 100644 --- a/src/components/calendar/calendar.zh.md +++ b/src/components/calendar/calendar.zh.md @@ -16,32 +16,29 @@ + + ## Calendar ### 属性 | 属性 | 说明 | 类型 | 默认值 | 版本 | | --- | --- | --- | --- | --- | -| visible | 显示隐藏 | `boolean` | `true` | -| confirmText | 确认按钮文案 | `string` | `确认` | -| popupClassName | 弹出层类名 | `string` | - | -| popupStyle | 弹层容器的自定义样式 | `React.CSSProperties` | - | -| popupBodyStyle | 容器内部自定义样式 | `React.CSSProperties` | - | -| forceRender | 强制渲染内容,当传递 ref 时,会强制设为 true | `boolean` | `false` | -| closeOnMaskClick | 点击背景蒙层后是否关闭 | `boolean` | `true` | -| onClose | 关闭时触发 | `() => void` | - | -| onMaskClick | 点击背景蒙层时触发 | `() => void` | - | | allowClear | 是否允许再次点击后清除 | `boolean` | `true` | | defaultValue | 默认选择的日期 | 同 `value` 属性 | - | | max | 可选择范围的最大值 | `Date` | - | | min | 可选择范围的最小值 | `Date` | - | +| maxPage | 可切换到的最晚日期 | `Page` | - | +| minPage | 可切换到的最早日期 | `Page` | - | +| nextMonthButton | 导航窗格上的“下一月”按钮的内容 | `React.ReactNode` | `>` | +| nextYearButton | 导航窗格上的“下一年”按钮的内容 | `React.ReactNode` | `>>` | | onChange | 选择日期变化时触发 | 单选模式下为 `(val: Date \| null) => void`,多选模式下为 `(val: [Date, Date] \| null) => void` | - | -| onConfirm | 点击确认按钮时触发 | 单选模式下为 `(val: Date \| null) => void`,多选模式下为 `(val: [Date, Date] \| null) => void` | - | -| renderTop | 日期顶部信息的渲染函数 | `(date: Date) => ReactNode \| null \| undefined` | - | -| renderBottom | 日期底部信息的渲染函数 | `(date: Date) => ReactNode \| null \| undefined` | - | +| onPageChange | 切换月或年时触发 | `(year: number, month: number) => void` | - | +| prevMonthButton | 导航窗格上的“上一月”按钮的内容 | `React.ReactNode` | `<` | +| prevYearButton | 导航窗格上的“上一年”按钮的内容 | `React.ReactNode` | `<<` | +| renderLabel | 标注信息的渲染函数 | `(date: Date) => ReactNode \| null \| undefined` | - | | selectionMode | 选择模式,不设置的话表示不支持选择 | `'single' \| 'range'` | - | | shouldDisableDate | 判断日期是否可选,使用后会忽略 min 和 max 设置 | `(date: Date) => boolean` | - | -| title | 日期选择器的标题 | `React.ReactNode` | `日期选择` | | value | 选择的日期 | 单选模式下为 `Date \| null`,多选模式下为 `[Date, Date] \| null` | - | | weekStartsOn | 每周以周几作为第一天 | `'Monday' \| 'Sunday'` | `'Sunday'` | | renderDate | 自定义日期渲染 | `(date: Date) => ReactNode` | - | 5.28.0 | @@ -54,9 +51,8 @@ | 属性 | 说明 | 类型 | | --- | --- | --- | -| jumpTo | 跳转至指定日期的区间 | `(page: Page \| ((page: Page) => Page)) => void` | +| jumpTo | 跳转至指定日期的页面 | `(page: Page \| ((page: Page) => Page)) => void` | | jumpToToday | 跳转至今日 | `() => void` | -| getDateRange | 获取日期 | `[Date, Date]` | ```ts type Page = { month: number; year: number } diff --git a/src/components/calendar/convert.ts b/src/components/calendar/convert.ts new file mode 100644 index 0000000000..11c6eea7d3 --- /dev/null +++ b/src/components/calendar/convert.ts @@ -0,0 +1,20 @@ +import dayjs from 'dayjs' +export type DateRange = [Date, Date] | null +export type Page = { month: number; year: number } +export function convertValueToRange( + selectionMode: 'single' | 'range' | undefined, + value: Date | [Date, Date] | null +): DateRange { + if (selectionMode === undefined || value === null) return null + + if (Array.isArray(value)) { + return value + } + return [value, value] +} +export function convertPageToDayjs(page: Page) { + return dayjs() + .year(page.year) + .month(page.month - 1) + .date(1) +} diff --git a/src/components/calendar/demos/demo1.tsx b/src/components/calendar/demos/demo1.tsx index 528bc15b59..19d00b9aeb 100644 --- a/src/components/calendar/demos/demo1.tsx +++ b/src/components/calendar/demos/demo1.tsx @@ -1,73 +1,50 @@ -import dayjs from 'dayjs' -import React, { useState } from 'react' -import { Calendar, List } from 'antd-mobile' +import React from 'react' +import { Calendar } from 'antd-mobile' +import { DemoBlock, DemoDescription } from 'demos' +const defaultSingle = new Date('2022-03-09') const defaultRange: [Date, Date] = [ - dayjs().toDate(), - dayjs().add(2, 'day').toDate(), + new Date('2022-03-09'), + new Date('2022-03-21'), ] export default () => { - const [val, setVal] = useState<[Date, Date] | null>(() => [ - dayjs().subtract(2, 'day').toDate(), - dayjs().add(2, 'day').toDate(), - ]) - const [visible1, setVisible1] = useState(false) - const [visible2, setVisible2] = useState(false) - const [visible3, setVisible3] = useState(false) - - const singleDate: Date = new Date('2023-06-03') - return ( - - { - setVisible1(true) - }} - > - 选择单个日期 + <> + + + + 如果你不设置 selectionMode 属性,那么日历默认是不支持进行选择操作的 + + + + setVisible1(false)} - onMaskClick={() => setVisible1(false)} + prevMonthButton={上一月} + nextMonthButton={下一月} + prevYearButton={上一年} + nextYearButton={下一年} /> - - { - setVisible2(true) - }} - > - 选择日期范围 + + + setVisible2(false)} - onMaskClick={() => setVisible2(false)} + selectionMode='single' + defaultValue={defaultSingle} onChange={val => { console.log(val) }} /> - - { - setVisible3(true) - }} - > - 受控日期选择 + + setVisible3(false)} - onMaskClick={() => setVisible3(false)} onChange={val => { - setVal(val) + console.log(val) }} /> - - + + ) } diff --git a/src/components/calendar/demos/demo2.tsx b/src/components/calendar/demos/demo2.tsx index d9f7c7d9c0..9c4027e352 100644 --- a/src/components/calendar/demos/demo2.tsx +++ b/src/components/calendar/demos/demo2.tsx @@ -1,73 +1,25 @@ +import dayjs from 'dayjs' import React, { useState } from 'react' -import { Calendar, List } from 'antd-mobile' - -const min = new Date() -min.setDate(5) -const max = new Date() -max.setDate(20) +import { Calendar } from 'antd-mobile' +import { DemoBlock } from 'demos' export default () => { - const [visible1, setVisible1] = useState(false) - const [visible2, setVisible2] = useState(false) - const [visible3, setVisible3] = useState(false) - const [visible4, setVisible4] = useState(false) - + const today = dayjs() + const [val, setVal] = useState<[Date, Date] | null>(() => [ + today.subtract(2, 'day').toDate(), + today.add(2, 'day').toDate(), + ]) return ( - - { - setVisible1(true) - }} - > - 自定义标题 - setVisible1(false)} - onMaskClick={() => setVisible1(false)} - /> - - { - setVisible2(true) - }} - > - 自定义确认文案 - setVisible2(false)} - onMaskClick={() => setVisible2(false)} - /> - - { - setVisible3(true) - }} - > - 周一作为每周的第一天 - setVisible3(false)} - onMaskClick={() => setVisible3(false)} - /> - - { - setVisible4(true) - }} - > - 限制日期范围 + <> + setVisible4(false)} - onMaskClick={() => setVisible4(false)} + value={val} + onChange={val => { + setVal(val) + }} /> - - + + ) } diff --git a/src/components/calendar/demos/demo3.tsx b/src/components/calendar/demos/demo3.tsx index 7a1a7697e7..0a82f6ffd4 100644 --- a/src/components/calendar/demos/demo3.tsx +++ b/src/components/calendar/demos/demo3.tsx @@ -1,111 +1,52 @@ -import classnames from 'classnames' import dayjs from 'dayjs' -import React, { useState } from 'react' -import { Calendar, List } from 'antd-mobile' -import './demo3.less' +import React, { useEffect, useRef } from 'react' +import { Calendar } from 'antd-mobile' +import { DemoBlock } from 'demos' +import { CalendarRef } from 'antd-mobile/es/components/calendar' + +const min = new Date() +min.setDate(5) +const max = new Date() +max.setDate(20) export default () => { const today = dayjs() - const [val, setVal] = useState<[Date, Date] | null>(() => [ - today.subtract(2, 'day').toDate(), - today.add(2, 'day').toDate(), - ]) - - const [visible1, setVisible1] = useState(false) - const [visible2, setVisible2] = useState(false) - const [visible3, setVisible3] = useState(false) - const [visible4, setVisible4] = useState(false) - + const calendarRef = useRef(null) + useEffect(() => { + if (calendarRef.current) { + calendarRef.current.jumpTo({ + year: 2022, + month: 4, + }) + } + }, []) return ( - - { - setVisible1(true) - }} - > - 自定义日期顶部信息 - setVisible1(false)} - onMaskClick={() => setVisible1(false)} - renderTop={date => { - const map = { - 1: '初一', - 2: '初二', - 3: '初三', - } - const dates = [1, 2, 3] - const d = dayjs(date).date() as keyof typeof map - - if (dates.includes(d)) { - return map[d] - } - }} - /> - - { - setVisible2(true) - }} - > - 自定义日期底部信息 + <> + + + + setVisible2(false)} - onMaskClick={() => setVisible2(false)} - renderBottom={date => { - const dates = [16, 17, 18, 19] - const d = dayjs(date).date() - - if (dates.includes(d)) { - return '¥100' + renderLabel={date => { + if (dayjs(date).isSame(today, 'day')) return '今天' + if (date.getDay() === 0 || date.getDay() === 6) { + return '周末' } }} /> - - { - setVisible3(true) - }} - > - 自定义日期渲染 + + + + + setVisible3(false)} - onMaskClick={() => setVisible3(false)} - renderDate={date => { - const dates = [16, 17, 18, 19] - const d = dayjs(date).date() - return ( -
- {d} -
- ) - }} - /> -
- { - setVisible4(true) - }} - > - 高级自定义样式 - { - setVal(val) - }} - visible={visible4} - onClose={() => setVisible4(false)} - onMaskClick={() => setVisible4(false)} + minPage={{ year: 2022, month: 8 }} + maxPage={{ year: 2022, month: 12 }} /> - -
+ + + + + ) } diff --git a/src/components/calendar/demos/demo4.less b/src/components/calendar/demos/demo4.less new file mode 100644 index 0000000000..f0bc9bdd99 --- /dev/null +++ b/src/components/calendar/demos/demo4.less @@ -0,0 +1,86 @@ +@prefix: ~'adm-calendar'; + +.calendar-custom { + .@{prefix}-cell { + justify-content: center; + height: 38px; + + &-bottom { + display: none; + } + + &.@{prefix}-cell-selected.@{prefix}-cell.@{prefix}-cell-selected { + background: rgba(229, 242, 250, 1); + + .@{prefix}-cell-top { + height: 38px; + width: 38px; + border-radius: 99px; + display: flex; + justify-content: center; + align-items: center; + background: rgba(229, 242, 250, 1); + color: var(--adm-color-primary); + } + + &.@{prefix}-cell-selected-begin { + background: linear-gradient( + to right, + var(--adm-color-white) 50%, + #e5f2fa 51%, + #e5f2fa + ); + .@{prefix}-cell-top { + height: 38px; + width: 38px; + border-radius: 99px; + display: flex; + justify-content: center; + align-items: center; + background: var(--adm-color-primary); + color: var(--adm-color-white); + } + + &.@{prefix}-cell-selected-row-end { + background: transparent; + } + } + + &.@{prefix}-cell-selected-begin.@{prefix}-cell-selected-end { + background: var(--adm-color-white); + } + + &.@{prefix}-cell-selected-end { + background: linear-gradient( + to right, + #e5f2fa 50%, + var(--adm-color-white) 51%, + var(--adm-color-white) + ); + .@{prefix}-cell-top { + height: 38px; + width: 38px; + border-radius: 99px; + display: flex; + justify-content: center; + align-items: center; + background: var(--adm-color-primary); + color: var(--adm-color-white); + } + + &.@{prefix}-cell-selected-row-start { + background: transparent; + } + } + + &.@{prefix}-cell-selected-row-begin { + border-top-left-radius: 99px; + border-bottom-left-radius: 99px; + } + &.@{prefix}-cell-selected-row-end { + border-top-right-radius: 99px; + border-bottom-right-radius: 99px; + } + } + } +} diff --git a/src/components/calendar/demos/demo4.tsx b/src/components/calendar/demos/demo4.tsx index 82ee73197f..93adfc363d 100644 --- a/src/components/calendar/demos/demo4.tsx +++ b/src/components/calendar/demos/demo4.tsx @@ -1,48 +1,27 @@ -import React, { useState, useRef } from 'react' -import { Calendar, List, CalendarRef } from 'antd-mobile' +import dayjs from 'dayjs' +import React, { useState } from 'react' +import { Calendar } from 'antd-mobile' +import { DemoBlock } from 'demos' +import './demo4.less' export default () => { - const ref1 = useRef(null) - const ref2 = useRef(null) - const [visible1, setVisible1] = useState(false) - const [visible2, setVisible2] = useState(false) - + const today = dayjs() + const [val, setVal] = useState<[Date, Date] | null>(() => [ + today.subtract(2, 'day').toDate(), + today.add(2, 'day').toDate(), + ]) return ( - - { - setVisible1(true) - ref1.current?.jumpTo(page => ({ - year: page.year, - month: page.month + 3, - })) - }} - > - 跳转到 3 月后 - setVisible1(false)} - onMaskClick={() => setVisible1(false)} - /> - - { - setVisible2(true) - ref2.current?.jumpTo(page => ({ - year: page.year + 3, - month: page.month, - })) - }} - > - 跳转到 3 年后 + <> + setVisible2(false)} - onMaskClick={() => setVisible2(false)} + className='calendar-custom' + selectionMode='range' + value={val} + onChange={val => { + setVal(val) + }} /> - - + + ) } diff --git a/src/components/calendar/demos/demo5.less b/src/components/calendar/demos/demo5.less new file mode 100644 index 0000000000..3286137d79 --- /dev/null +++ b/src/components/calendar/demos/demo5.less @@ -0,0 +1,13 @@ +.custom-cell { + width: 38px; + height: 38px; + border-radius: 50%; + display: flex; + justify-content: center; + align-items: center; + + &-selected { + background: var(--adm-color-primary); + color: #fff; + } +} diff --git a/src/components/calendar/demos/demo5.tsx b/src/components/calendar/demos/demo5.tsx new file mode 100644 index 0000000000..7f614be14e --- /dev/null +++ b/src/components/calendar/demos/demo5.tsx @@ -0,0 +1,30 @@ +import dayjs from 'dayjs' +import React from 'react' +import { Calendar } from 'antd-mobile' +import { DemoBlock } from 'demos' +import classNames from 'classnames' +import './demo5.less' + +export default () => { + return ( + <> + + { + const dates = [16, 17, 18, 19] + const d = dayjs(date).date() + return ( +
+ {d} +
+ ) + }} + /> +
+ + ) +} diff --git a/src/components/calendar/index.ts b/src/components/calendar/index.ts index 7cf42a25f9..cff7d5a2ec 100644 --- a/src/components/calendar/index.ts +++ b/src/components/calendar/index.ts @@ -1,3 +1,4 @@ +import './calendar.less' import { Calendar } from './calendar' export type { CalendarProps, CalendarRef } from './calendar' diff --git a/src/components/calendar/tests/__snapshots__/calendar.test.tsx.snap b/src/components/calendar/tests/__snapshots__/calendar.test.tsx.snap index a3644cc699..c33e4205dd 100644 --- a/src/components/calendar/tests/__snapshots__/calendar.test.tsx.snap +++ b/src/components/calendar/tests/__snapshots__/calendar.test.tsx.snap @@ -1,9 +1,5128 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Calendar controlled mode 1`] = ` +
+
+ +
+
+ 日 +
+
+ 一 +
+
+ 二 +
+
+ 三 +
+
+ 四 +
+
+ 五 +
+
+ 六 +
+
+
+
+
+ 27 +
+
+
+
+
+ 28 +
+
+
+
+
+ 29 +
+
+
+
+
+ 30 +
+
+
+
+
+ 31 +
+
+
+
+
+ 1 +
+
+
+
+
+ 2 +
+
+
+
+
+ 3 +
+
+
+
+
+ 4 +
+
+
+
+
+ 5 +
+
+
+
+
+ 6 +
+
+
+
+
+ 7 +
+
+
+
+
+ 8 +
+
+
+
+
+ 9 +
+
+
+
+
+ 10 +
+
+
+
+
+ 11 +
+
+
+
+
+ 12 +
+
+
+
+
+ 13 +
+
+
+
+
+ 14 +
+
+
+
+
+ 15 +
+
+
+
+
+ 16 +
+
+
+
+
+ 17 +
+
+
+
+
+ 18 +
+
+
+
+
+ 19 +
+
+
+
+
+ 20 +
+
+
+
+
+ 21 +
+
+
+
+
+ 22 +
+
+
+
+
+ 23 +
+
+
+
+
+ 24 +
+
+
+
+
+ 25 +
+
+
+
+
+ 26 +
+
+
+
+
+ 27 +
+
+
+
+
+ 28 +
+
+
+
+
+ 29 +
+
+
+
+
+ 30 +
+
+
+
+
+ 1 +
+
+
+
+
+ 2 +
+
+
+
+
+ 3 +
+
+
+
+
+ 4 +
+
+
+
+
+ 5 +
+
+
+
+
+ 6 +
+
+
+
+
+ 7 +
+
+
+
+
+
+`; + +exports[`Calendar custom label 1`] = ` +
+
+ +
+
+ 日 +
+
+ 一 +
+
+ 二 +
+
+ 三 +
+
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+
+
+
+ 19 +
+
+
+
+
+ 20 +
+
+
+
+
+ 21 +
+
+
+
+
+ 22 +
+
+
+
+
+ 23 +
+
+
+
+
+ 24 +
+
+
+
+
+ 25 +
+
+
+
+
+ 26 +
+
+
+
+
+ 27 +
+
+
+
+
+ 28 +
+
+
+
+
+ 29 +
+
+
+
+
+ 30 +
+
+
+
+
+ 31 +
+
+
+
+
+ 1 +
+
+
+
+
+ 2 +
+
+
+
+
+ 3 +
+
+
+
+
+ 4 +
+
+
+
+
+ 5 +
+
+
+
+
+ 6 +
+
+
+
+
+ 7 +
+
+
+
+
+ 8 +
+
+
+
+
+ 9 +
+
+
+
+
+ 10 +
+
+
+
+
`; diff --git a/src/components/calendar/tests/calendar.test.tsx b/src/components/calendar/tests/calendar.test.tsx index fa43a79f95..231c3640d4 100644 --- a/src/components/calendar/tests/calendar.test.tsx +++ b/src/components/calendar/tests/calendar.test.tsx @@ -1,16 +1,16 @@ -import React from 'react' +import React, { useState, useRef } from 'react' import { render, testA11y, fireEvent } from 'testing' -import Calendar from '..' +import Calendar, { CalendarRef } from '..' +import dayjs from 'dayjs' import MockDate from 'mockdate' -const classPrefix = `adm-calendar-view` +const classPrefix = `adm-calendar` // mock today -MockDate.set(new Date('2023-05-22')) +MockDate.set(new Date('2022-03-22')) -const mixDate: Date = new Date('2023-05-01') -const maxDate: Date = new Date('2023-05-31') -const singleDate: Date = new Date('2023-05-03') +const singleDate: Date = new Date('2022-03-09') +const rangeDate: [Date, Date] = [new Date('2022-03-09'), new Date('2022-03-21')] describe('Calendar', () => { test('a11y', async () => { @@ -19,21 +19,155 @@ describe('Calendar', () => { test('single mode', async () => { const fn = jest.fn() - const { container, getAllByText } = render( + const { container, getByText } = render( ) expect(container).toMatchSnapshot() - const dateEl = getAllByText(15)[0] + const dateEl = getByText(15) fireEvent.click(dateEl) expect(dateEl.parentElement).toHaveClass(`${classPrefix}-cell-selected`) expect(fn).toBeCalled() }) + + test('range mode', async () => { + const fn = jest.fn() + const { container, getByText } = render( + + ) + + expect(container).toMatchSnapshot() + const [startEl, endEl] = [getByText(20), getByText(26)] + fireEvent.click(startEl) + fireEvent.click(endEl) + expect( + document.querySelectorAll(`.${classPrefix}-cell-selected`).length + ).toBe(7) + expect(fn.mock.calls[1][0].map((d: Date) => d.toDateString())).toEqual([ + 'Sun Mar 20 2022', + 'Sat Mar 26 2022', + ]) + }) + + test('controlled mode', async () => { + const today = dayjs('2022-05-01') + + const App = () => { + const [val, setVal] = useState<[Date, Date] | null>(() => [ + today.subtract(2, 'day').toDate(), + today.add(2, 'day').toDate(), + ]) + + return ( + { + setVal(val) + }} + /> + ) + } + + const { container, getByText } = render() + const [startEl, endEl] = [getByText(8), getByText(15)] + fireEvent.click(startEl) + fireEvent.click(endEl) + expect(container).toMatchSnapshot() + }) + + test('page change', async () => { + const fn = jest.fn() + render() + + const btns = document.querySelectorAll(`.${classPrefix}-arrow-button-right`) + const titleEl = document.querySelector(`.${classPrefix}-title`) + // month + fireEvent.click(btns[0]) + expect(titleEl?.innerHTML).toContain('4月') + expect(fn.mock.calls[0]).toEqual([2022, 4]) + + // year + fireEvent.click(btns[1]) + expect(titleEl?.innerHTML).toContain('2023') + expect(fn.mock.calls[1]).toEqual([2023, 4]) + }) + + test('jump to a day', async () => { + const App = () => { + const ref = useRef(null) + return ( + <> + + + + + ) + } + const { container, getByText } = render() + + fireEvent.click(getByText('jumpTo')) + expect(container).toMatchSnapshot() + + fireEvent.click(getByText('jumpToToday')) + expect(container).toMatchSnapshot() + }) + + test('week start on Monday', async () => { + const { container } = render() + expect(container).toMatchSnapshot() + }) + + test(`can't allow to clear`, async () => { + const { getByText } = render( + + ) + + const dateEl = getByText(16) + fireEvent.click(dateEl) + fireEvent.click(dateEl) + expect(dateEl.parentElement).toHaveClass(`${classPrefix}-cell-selected`) + }) + + test('custom label', async () => { + const today = dayjs() + const { container } = render( + { + if (dayjs(date).isSame(today, 'day')) return '今天' + if (date.getDay() === 0 || date.getDay() === 6) { + return '周末' + } + }} + /> + ) + expect(container).toMatchSnapshot() + }) + + test('custom date render', () => { + render( + { + return
{dayjs(date).date()}
+ }} + /> + ) + expect(document.getElementsByClassName('custom-cell').length).toBe(42) + }) }) diff --git a/src/index.ts b/src/index.ts index 6995d510ee..cc7b42478b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,7 +14,9 @@ export { default as Button } from './components/button' export type { ButtonProps, ButtonRef } from './components/button' export { default as Calendar } from './components/calendar' export type { CalendarProps, CalendarRef } from './components/calendar' -export { default as CalendarView } from './components/calendar-view' +export { default as CalendarPicker } from './components/calendar-picker' +export type { CalendarProps, CalendarRef } from './components/calendar-picker' +export { default as CalendarView } from './components/calendar-picker-view' export type { CalendarViewProps, CalendarViewRef, From 1e06d1b8d28f2a54d50d6e96d9ff0119fdddeb2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Thu, 19 Oct 2023 15:55:11 +0800 Subject: [PATCH 2/5] chore: rename --- .../{calendar.en.md => calendar-picker.en.md} | 0 .../{calendar.tsx => calendar-picker.tsx} | 11 +++++++---- .../{calendar.zh.md => calendar-picker.zh.md} | 0 src/components/calendar-picker/index.ts | 6 +++--- src/index.ts | 5 ++++- 5 files changed, 14 insertions(+), 8 deletions(-) rename src/components/calendar-picker/{calendar.en.md => calendar-picker.en.md} (100%) rename src/components/calendar-picker/{calendar.tsx => calendar-picker.tsx} (91%) rename src/components/calendar-picker/{calendar.zh.md => calendar-picker.zh.md} (100%) diff --git a/src/components/calendar-picker/calendar.en.md b/src/components/calendar-picker/calendar-picker.en.md similarity index 100% rename from src/components/calendar-picker/calendar.en.md rename to src/components/calendar-picker/calendar-picker.en.md diff --git a/src/components/calendar-picker/calendar.tsx b/src/components/calendar-picker/calendar-picker.tsx similarity index 91% rename from src/components/calendar-picker/calendar.tsx rename to src/components/calendar-picker/calendar-picker.tsx index ab585b4ce7..c0d06e4a04 100644 --- a/src/components/calendar-picker/calendar.tsx +++ b/src/components/calendar-picker/calendar-picker.tsx @@ -13,9 +13,9 @@ import CalendarView, { const classPrefix = 'adm-calendar' -export type CalendarRef = CalendarViewRef +export type CalendarPickerRef = CalendarViewRef -export type CalendarProps = CalendarViewProps & { +export type CalendarPickerProps = CalendarViewProps & { visible?: boolean confirmText?: string popupClassName?: string @@ -48,11 +48,14 @@ const defaultProps = { selectionMode: 'single', } -export const Calendar = forwardRef((p, ref) => { +export const CalendarPicker = forwardRef< + CalendarPickerRef, + CalendarPickerProps +>((p, ref) => { const props = mergeProps(defaultProps, p) const { locale } = useConfig() const calendarRef = (ref ?? - useRef(null)) as React.RefObject + useRef(null)) as React.RefObject const { visible, diff --git a/src/components/calendar-picker/calendar.zh.md b/src/components/calendar-picker/calendar-picker.zh.md similarity index 100% rename from src/components/calendar-picker/calendar.zh.md rename to src/components/calendar-picker/calendar-picker.zh.md diff --git a/src/components/calendar-picker/index.ts b/src/components/calendar-picker/index.ts index 7cf42a25f9..27591887e7 100644 --- a/src/components/calendar-picker/index.ts +++ b/src/components/calendar-picker/index.ts @@ -1,5 +1,5 @@ -import { Calendar } from './calendar' +import { CalendarPicker } from './calendar-picker' -export type { CalendarProps, CalendarRef } from './calendar' +export type { CalendarPickerProps, CalendarPickerRef } from './calendar-picker' -export default Calendar +export default CalendarPicker diff --git a/src/index.ts b/src/index.ts index cc7b42478b..2d7fc1840a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,10 @@ export type { ButtonProps, ButtonRef } from './components/button' export { default as Calendar } from './components/calendar' export type { CalendarProps, CalendarRef } from './components/calendar' export { default as CalendarPicker } from './components/calendar-picker' -export type { CalendarProps, CalendarRef } from './components/calendar-picker' +export type { + CalendarPickerProps, + CalendarPickerRef, +} from './components/calendar-picker' export { default as CalendarView } from './components/calendar-picker-view' export type { CalendarViewProps, From 3041d8c53b8b3a2515468affb6e61703f6aaec92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Thu, 19 Oct 2023 16:30:20 +0800 Subject: [PATCH 3/5] chore: move it --- ...-view.en.md => calendar-picker-view.en.md} | 8 +- ...ar-view.less => calendar-picker-view.less} | 18 +- .../calendar-picker-view.tsx | 329 +++++++++++++++++ ...-view.zh.md => calendar-picker-view.zh.md} | 8 +- .../calendar-picker-view/calendar-view.tsx | 332 ------------------ .../calendar-picker-view/demos/demo1.tsx | 4 +- src/components/calendar-picker-view/index.ts | 11 +- .../tests/calendar-view.test.tsx | 20 +- .../calendar-picker/calendar-picker.en.md | 4 +- .../calendar-picker/calendar-picker.tsx | 14 +- .../calendar-picker/calendar-picker.zh.md | 4 +- .../calendar-picker/demos/demo1.tsx | 8 +- .../calendar-picker/demos/demo2.tsx | 10 +- .../calendar-picker/demos/demo3.tsx | 10 +- .../calendar-picker/demos/demo4.tsx | 10 +- src/components/calendar/calendar.en.md | 4 + src/components/calendar/calendar.tsx | 12 + src/components/calendar/calendar.zh.md | 4 + src/index.ts | 8 +- 19 files changed, 419 insertions(+), 399 deletions(-) rename src/components/calendar-picker-view/{calendar-view.en.md => calendar-picker-view.en.md} (90%) rename src/components/calendar-picker-view/{calendar-view.less => calendar-picker-view.less} (88%) create mode 100644 src/components/calendar-picker-view/calendar-picker-view.tsx rename src/components/calendar-picker-view/{calendar-view.zh.md => calendar-picker-view.zh.md} (89%) delete mode 100644 src/components/calendar-picker-view/calendar-view.tsx diff --git a/src/components/calendar-picker-view/calendar-view.en.md b/src/components/calendar-picker-view/calendar-picker-view.en.md similarity index 90% rename from src/components/calendar-picker-view/calendar-view.en.md rename to src/components/calendar-picker-view/calendar-picker-view.en.md index 65262130c0..101399cd95 100644 --- a/src/components/calendar-picker-view/calendar-view.en.md +++ b/src/components/calendar-picker-view/calendar-picker-view.en.md @@ -1,16 +1,16 @@ -# CalendarView +# CalendarPickerView Used to select a date or date range. -CalendarView is the content area of [Calendar](/components/calendar). +CalendarPickerView is the content area of [CalendarPicker](/components/calendar-picker). ## Demos -Only the simplest content area is shown here, and other more usages can be consulted [Calendar](/zh/components/calendar) +Only the simplest content area is shown here, and other more usages can be consulted [CalendarPicker](/components/calendar-picker) -## CalendarView +## CalendarPickerView ### Props diff --git a/src/components/calendar-picker-view/calendar-view.less b/src/components/calendar-picker-view/calendar-picker-view.less similarity index 88% rename from src/components/calendar-picker-view/calendar-view.less rename to src/components/calendar-picker-view/calendar-picker-view.less index ce675711dd..510089885d 100644 --- a/src/components/calendar-picker-view/calendar-view.less +++ b/src/components/calendar-picker-view/calendar-picker-view.less @@ -1,6 +1,6 @@ -.adm-calendar, -.adm-calendar-view, -.adm-calendar-popup { +.adm-calendar-picker, +.adm-calendar-picker-view, +.adm-calendar-picker-popup { & &-title { flex: auto; font-size: var(--adm-font-size-10); @@ -10,7 +10,7 @@ padding: 12px; border-bottom: 1px solid var(--adm-color-border); - .adm-calendar-view-title { + .adm-calendar-picker-view-title { text-align: center; } } @@ -23,7 +23,7 @@ display: none; } - .adm-calendar-view-title { + .adm-calendar-picker-view-title { position: sticky; top: 0; padding: 8px 20px; @@ -71,8 +71,8 @@ &&-disabled { color: var(--adm-color-light); - .adm-calendar-view-cell-top, - .adm-calendar-view-cell-bottom { + .adm-calendar-picker-view-cell-top, + .adm-calendar-picker-view-cell-bottom { color: var(--adm-color-light); } } @@ -83,8 +83,8 @@ color: var(--adm-color-text); } - & .adm-calendar-view-cell-top, - & .adm-calendar-view-cell-bottom { + & .adm-calendar-picker-view-cell-top, + & .adm-calendar-picker-view-cell-bottom { color: var(--adm-color-white); } diff --git a/src/components/calendar-picker-view/calendar-picker-view.tsx b/src/components/calendar-picker-view/calendar-picker-view.tsx new file mode 100644 index 0000000000..65643da8db --- /dev/null +++ b/src/components/calendar-picker-view/calendar-picker-view.tsx @@ -0,0 +1,329 @@ +import React, { + forwardRef, + useState, + useImperativeHandle, + useMemo, +} from 'react' +import type { ReactNode } from 'react' +import { NativeProps, withNativeProps } from '../../utils/native-props' +import dayjs from 'dayjs' +import classNames from 'classnames' +import { mergeProps } from '../../utils/with-default-props' +import { useConfig } from '../config-provider' +import isoWeek from 'dayjs/plugin/isoWeek' +import isSameOrBefore from 'dayjs/plugin/isSameOrBefore' +import { usePropsValue } from '../../utils/use-props-value' +import { + convertValueToRange, + convertPageToDayjs, + DateRange, + Page, +} from './convert' + +dayjs.extend(isoWeek) +dayjs.extend(isSameOrBefore) + +const classPrefix = 'adm-calendar-picker-view' + +export type CalendarPickerViewRef = { + jumpTo: (page: Page | ((page: Page) => Page)) => void + jumpToToday: () => void + getDateRange: () => DateRange +} + +export type CalendarPickerViewProps = { + title?: React.ReactNode + confirmText?: string + weekStartsOn?: 'Monday' | 'Sunday' + renderTop?: (date: Date) => React.ReactNode + renderDate?: (date: Date) => React.ReactNode + renderBottom?: (date: Date) => React.ReactNode + allowClear?: boolean + max?: Date + min?: Date + shouldDisableDate?: (date: Date) => boolean +} & ( + | { + selectionMode?: undefined + value?: undefined + defaultValue?: undefined + onChange?: undefined + } + | { + selectionMode: 'single' + value?: Date | null + defaultValue?: Date | null + onChange?: (val: Date | null) => void + } + | { + selectionMode: 'range' + value?: [Date, Date] | null + defaultValue?: [Date, Date] | null + onChange?: (val: [Date, Date] | null) => void + } +) & + NativeProps + +const defaultProps = { + weekStartsOn: 'Sunday', + defaultValue: null, + allowClear: true, + usePopup: true, + selectionMode: 'single', +} + +export const CalendarPickerView = forwardRef< + CalendarPickerViewRef, + CalendarPickerViewProps +>((p, ref) => { + const today = dayjs() + const props = mergeProps(defaultProps, p) + const { locale } = useConfig() + const markItems = [...locale.Calendar.markItems] + if (props.weekStartsOn === 'Sunday') { + const item = markItems.pop() + if (item) markItems.unshift(item) + } + + const [dateRange, setDateRange] = usePropsValue({ + value: + props.value === undefined + ? undefined + : convertValueToRange(props.selectionMode, props.value), + defaultValue: convertValueToRange(props.selectionMode, props.defaultValue), + onChange: v => { + if (props.selectionMode === 'single') { + props.onChange?.(v ? v[0] : null) + } else if (props.selectionMode === 'range') { + props.onChange?.(v) + } + }, + }) + + const [intermediate, setIntermediate] = useState(false) + + const [current, setCurrent] = useState(() => + dayjs(dateRange ? dateRange[0] : today).date(1) + ) + + useImperativeHandle(ref, () => ({ + jumpTo: pageOrPageGenerator => { + let page: Page + if (typeof pageOrPageGenerator === 'function') { + page = pageOrPageGenerator({ + year: current.year(), + month: current.month() + 1, + }) + } else { + page = pageOrPageGenerator + } + setCurrent(convertPageToDayjs(page)) + }, + jumpToToday: () => { + setCurrent(dayjs().date(1)) + }, + getDateRange: () => dateRange, + })) + + const header = ( +
+
+ {props.title ?? locale.Calendar.title} +
+
+ ) + + const maxDay = useMemo( + () => (props.max ? dayjs(props.max) : current.add(6, 'month')), + [props.max, current] + ) + const minDay = useMemo( + () => (props.min ? dayjs(props.min) : current), + [props.min, current] + ) + + function renderBody() { + const cells: ReactNode[] = [] + let monthIterator = minDay + // 遍历月份 + while (monthIterator.isSameOrBefore(maxDay, 'month')) { + const year = monthIterator.year() + const month = monthIterator.month() + const renderMap = { + year, + month: month + 1, + } + + cells.push( +
+
+ {locale.Calendar.yearAndMonth?.replace( + /\${(.*?)}/g, + (_, variable: keyof typeof renderMap) => { + return renderMap[variable]?.toString() + } + )} +
+
+ {/* 空格填充 */} + {Array( + props.weekStartsOn === 'Monday' + ? monthIterator.date(1).isoWeekday() - 1 + : monthIterator.date(1).isoWeekday() + ) + .fill(null) + .map((_, index) => ( +
+ ))} + {/* 遍历每月 */} + {Array(monthIterator.daysInMonth()) + .fill(null) + .map((_, index) => { + const d = monthIterator.date(index + 1) + let isSelect = false + let isBegin = false + let isEnd = false + let isSelectRowBegin = false + let isSelectRowEnd = false + if (dateRange) { + const [begin, end] = dateRange + isBegin = d.isSame(begin, 'day') + isEnd = d.isSame(end, 'day') + isSelect = + isBegin || + isEnd || + (d.isAfter(begin, 'day') && d.isBefore(end, 'day')) + if (isSelect) { + isSelectRowBegin = + (cells.length % 7 === 0 || + d.isSame(d.startOf('month'), 'day')) && + !isBegin + isSelectRowEnd = + (cells.length % 7 === 6 || + d.isSame(d.endOf('month'), 'day')) && + !isEnd + } + } + const disabled = props.shouldDisableDate + ? props.shouldDisableDate(d.toDate()) + : (maxDay && d.isAfter(maxDay, 'day')) || + (minDay && d.isBefore(minDay, 'day')) + + const renderTop = () => { + const top = props.renderTop?.(d.toDate()) + + if (top) { + return top + } + + if (props.selectionMode === 'range') { + if (isBegin) { + return locale.Calendar.start + } + + if (isEnd) { + return locale.Calendar.end + } + } + + if (d.isSame(today, 'day') && !isSelect) { + return locale.Calendar.today + } + } + return ( +
{ + if (!props.selectionMode) return + if (disabled) return + const date = d.toDate() + function shouldClear() { + if (!props.allowClear) return false + if (!dateRange) return false + const [begin, end] = dateRange + return d.isSame(begin, 'date') && d.isSame(end, 'day') + } + if (props.selectionMode === 'single') { + if (props.allowClear && shouldClear()) { + setDateRange(null) + return + } + setDateRange([date, date]) + } else if (props.selectionMode === 'range') { + if (!dateRange) { + setDateRange([date, date]) + setIntermediate(true) + return + } + if (shouldClear()) { + setDateRange(null) + setIntermediate(false) + return + } + if (intermediate) { + const another = dateRange[0] + setDateRange( + another > date ? [date, another] : [another, date] + ) + setIntermediate(false) + } else { + setDateRange([date, date]) + setIntermediate(true) + } + } + }} + > +
+ {renderTop()} +
+
+ {props.renderDate + ? props.renderDate(d.toDate()) + : d.date()} +
+
+ {props.renderBottom?.(d.toDate())} +
+
+ ) + })} +
+
+ ) + + monthIterator = monthIterator.add(1, 'month') + } + + return cells + } + const body =
{renderBody()}
+ + const mark = ( +
+ {markItems.map((item, index) => ( +
+ {item} +
+ ))} +
+ ) + + return withNativeProps( + props, +
+ {header} + {mark} + {body} +
+ ) +}) diff --git a/src/components/calendar-picker-view/calendar-view.zh.md b/src/components/calendar-picker-view/calendar-picker-view.zh.md similarity index 89% rename from src/components/calendar-picker-view/calendar-view.zh.md rename to src/components/calendar-picker-view/calendar-picker-view.zh.md index 621dc08365..69a5d06446 100644 --- a/src/components/calendar-picker-view/calendar-view.zh.md +++ b/src/components/calendar-picker-view/calendar-picker-view.zh.md @@ -1,16 +1,16 @@ -# CalendarView 日历 +# CalendarPickerView 日历选择器视图 用于选择日期或日期区间。 -CalendarView 是 [Calendar](/zh/components/calendar) 的内容区域。 +CalendarPickerView 是 [CalendarPicker](/zh/components/calendar-picker) 的内容区域。 ## 示例 -此处只展示了最简单的内容区域,其他更多用法可以参考 [Calendar](/zh/components/calendar) +此处只展示了最简单的内容区域,其他更多用法可以参考 [CalendarPicker](/zh/components/calendar-picker) -## CalendarView +## CalendarPickerView ### 属性 diff --git a/src/components/calendar-picker-view/calendar-view.tsx b/src/components/calendar-picker-view/calendar-view.tsx deleted file mode 100644 index 6ed42221bb..0000000000 --- a/src/components/calendar-picker-view/calendar-view.tsx +++ /dev/null @@ -1,332 +0,0 @@ -import React, { - forwardRef, - useState, - useImperativeHandle, - useMemo, -} from 'react' -import type { ReactNode } from 'react' -import { NativeProps, withNativeProps } from '../../utils/native-props' -import dayjs from 'dayjs' -import classNames from 'classnames' -import { mergeProps } from '../../utils/with-default-props' -import { useConfig } from '../config-provider' -import isoWeek from 'dayjs/plugin/isoWeek' -import isSameOrBefore from 'dayjs/plugin/isSameOrBefore' -import { usePropsValue } from '../../utils/use-props-value' -import { - convertValueToRange, - convertPageToDayjs, - DateRange, - Page, -} from './convert' - -dayjs.extend(isoWeek) -dayjs.extend(isSameOrBefore) - -const classPrefix = 'adm-calendar-view' - -export type CalendarViewRef = { - jumpTo: (page: Page | ((page: Page) => Page)) => void - jumpToToday: () => void - getDateRange: () => DateRange -} - -export type CalendarViewProps = { - title?: React.ReactNode - confirmText?: string - weekStartsOn?: 'Monday' | 'Sunday' - renderTop?: (date: Date) => React.ReactNode - renderDate?: (date: Date) => React.ReactNode - renderBottom?: (date: Date) => React.ReactNode - allowClear?: boolean - max?: Date - min?: Date - shouldDisableDate?: (date: Date) => boolean -} & ( - | { - selectionMode?: undefined - value?: undefined - defaultValue?: undefined - onChange?: undefined - } - | { - selectionMode: 'single' - value?: Date | null - defaultValue?: Date | null - onChange?: (val: Date | null) => void - } - | { - selectionMode: 'range' - value?: [Date, Date] | null - defaultValue?: [Date, Date] | null - onChange?: (val: [Date, Date] | null) => void - } -) & - NativeProps - -const defaultProps = { - weekStartsOn: 'Sunday', - defaultValue: null, - allowClear: true, - usePopup: true, - selectionMode: 'single', -} - -export const CalendarView = forwardRef( - (p, ref) => { - const today = dayjs() - const props = mergeProps(defaultProps, p) - const { locale } = useConfig() - const markItems = [...locale.Calendar.markItems] - if (props.weekStartsOn === 'Sunday') { - const item = markItems.pop() - if (item) markItems.unshift(item) - } - - const [dateRange, setDateRange] = usePropsValue({ - value: - props.value === undefined - ? undefined - : convertValueToRange(props.selectionMode, props.value), - defaultValue: convertValueToRange( - props.selectionMode, - props.defaultValue - ), - onChange: v => { - if (props.selectionMode === 'single') { - props.onChange?.(v ? v[0] : null) - } else if (props.selectionMode === 'range') { - props.onChange?.(v) - } - }, - }) - - const [intermediate, setIntermediate] = useState(false) - - const [current, setCurrent] = useState(() => - dayjs(dateRange ? dateRange[0] : today).date(1) - ) - - useImperativeHandle(ref, () => ({ - jumpTo: pageOrPageGenerator => { - let page: Page - if (typeof pageOrPageGenerator === 'function') { - page = pageOrPageGenerator({ - year: current.year(), - month: current.month() + 1, - }) - } else { - page = pageOrPageGenerator - } - setCurrent(convertPageToDayjs(page)) - }, - jumpToToday: () => { - setCurrent(dayjs().date(1)) - }, - getDateRange: () => dateRange, - })) - - const header = ( -
-
- {props.title ?? locale.Calendar.title} -
-
- ) - - const maxDay = useMemo( - () => (props.max ? dayjs(props.max) : current.add(6, 'month')), - [props.max, current] - ) - const minDay = useMemo( - () => (props.min ? dayjs(props.min) : current), - [props.min, current] - ) - - function renderBody() { - const cells: ReactNode[] = [] - let monthIterator = minDay - // 遍历月份 - while (monthIterator.isSameOrBefore(maxDay, 'month')) { - const year = monthIterator.year() - const month = monthIterator.month() - const renderMap = { - year, - month: month + 1, - } - - cells.push( -
-
- {locale.Calendar.yearAndMonth?.replace( - /\${(.*?)}/g, - (_, variable: keyof typeof renderMap) => { - return renderMap[variable]?.toString() - } - )} -
-
- {/* 空格填充 */} - {Array( - props.weekStartsOn === 'Monday' - ? monthIterator.date(1).isoWeekday() - 1 - : monthIterator.date(1).isoWeekday() - ) - .fill(null) - .map((_, index) => ( -
- ))} - {/* 遍历每月 */} - {Array(monthIterator.daysInMonth()) - .fill(null) - .map((_, index) => { - const d = monthIterator.date(index + 1) - let isSelect = false - let isBegin = false - let isEnd = false - let isSelectRowBegin = false - let isSelectRowEnd = false - if (dateRange) { - const [begin, end] = dateRange - isBegin = d.isSame(begin, 'day') - isEnd = d.isSame(end, 'day') - isSelect = - isBegin || - isEnd || - (d.isAfter(begin, 'day') && d.isBefore(end, 'day')) - if (isSelect) { - isSelectRowBegin = - (cells.length % 7 === 0 || - d.isSame(d.startOf('month'), 'day')) && - !isBegin - isSelectRowEnd = - (cells.length % 7 === 6 || - d.isSame(d.endOf('month'), 'day')) && - !isEnd - } - } - const disabled = props.shouldDisableDate - ? props.shouldDisableDate(d.toDate()) - : (maxDay && d.isAfter(maxDay, 'day')) || - (minDay && d.isBefore(minDay, 'day')) - - const renderTop = () => { - const top = props.renderTop?.(d.toDate()) - - if (top) { - return top - } - - if (props.selectionMode === 'range') { - if (isBegin) { - return locale.Calendar.start - } - - if (isEnd) { - return locale.Calendar.end - } - } - - if (d.isSame(today, 'day') && !isSelect) { - return locale.Calendar.today - } - } - return ( -
{ - if (!props.selectionMode) return - if (disabled) return - const date = d.toDate() - function shouldClear() { - if (!props.allowClear) return false - if (!dateRange) return false - const [begin, end] = dateRange - return d.isSame(begin, 'date') && d.isSame(end, 'day') - } - if (props.selectionMode === 'single') { - if (props.allowClear && shouldClear()) { - setDateRange(null) - return - } - setDateRange([date, date]) - } else if (props.selectionMode === 'range') { - if (!dateRange) { - setDateRange([date, date]) - setIntermediate(true) - return - } - if (shouldClear()) { - setDateRange(null) - setIntermediate(false) - return - } - if (intermediate) { - const another = dateRange[0] - setDateRange( - another > date ? [date, another] : [another, date] - ) - setIntermediate(false) - } else { - setDateRange([date, date]) - setIntermediate(true) - } - } - }} - > -
- {renderTop()} -
-
- {props.renderDate - ? props.renderDate(d.toDate()) - : d.date()} -
-
- {props.renderBottom?.(d.toDate())} -
-
- ) - })} -
-
- ) - - monthIterator = monthIterator.add(1, 'month') - } - - return cells - } - const body =
{renderBody()}
- - const mark = ( -
- {markItems.map((item, index) => ( -
- {item} -
- ))} -
- ) - - return withNativeProps( - props, -
- {header} - {mark} - {body} -
- ) - } -) diff --git a/src/components/calendar-picker-view/demos/demo1.tsx b/src/components/calendar-picker-view/demos/demo1.tsx index eab94397bd..6d3c30933b 100644 --- a/src/components/calendar-picker-view/demos/demo1.tsx +++ b/src/components/calendar-picker-view/demos/demo1.tsx @@ -1,11 +1,11 @@ import React from 'react' -import { CalendarView } from 'antd-mobile' +import { CalendarPickerView } from 'antd-mobile' import { DemoBlock } from 'demos' export default () => { return ( - + ) } diff --git a/src/components/calendar-picker-view/index.ts b/src/components/calendar-picker-view/index.ts index f7f5369f3a..4f32243fa2 100644 --- a/src/components/calendar-picker-view/index.ts +++ b/src/components/calendar-picker-view/index.ts @@ -1,6 +1,9 @@ -import './calendar-view.less' -import { CalendarView } from './calendar-view' +import './calendar-picker-view.less' +import { CalendarPickerView } from './calendar-picker-view' -export type { CalendarViewProps, CalendarViewRef } from './calendar-view' +export type { + CalendarPickerViewProps, + CalendarPickerViewRef, +} from './calendar-picker-view' -export default CalendarView +export default CalendarPickerView diff --git a/src/components/calendar-picker-view/tests/calendar-view.test.tsx b/src/components/calendar-picker-view/tests/calendar-view.test.tsx index c91e57f2fc..240ea16cd0 100644 --- a/src/components/calendar-picker-view/tests/calendar-view.test.tsx +++ b/src/components/calendar-picker-view/tests/calendar-view.test.tsx @@ -1,6 +1,6 @@ import React, { useRef } from 'react' import { render, testA11y, fireEvent } from 'testing' -import CalendarView, { CalendarViewRef } from '..' +import CalendarPickerView, { CalendarViewRef } from '..' import dayjs from 'dayjs' import MockDate from 'mockdate' @@ -16,13 +16,13 @@ const rangeDate: [Date, Date] = [new Date('2023-05-04'), new Date('2023-05-07')] describe('Calendar', () => { test('a11y', async () => { - await testA11y() + await testA11y() }) test('single mode', async () => { const fn = jest.fn() const { container, getAllByText } = render( - { test('range mode', async () => { const fn = jest.fn() const { container, getByText } = render( - { > jumpToToday - + ) } @@ -97,14 +97,14 @@ describe('Calendar', () => { test('week start on Monday', async () => { const { container } = render( - + ) expect(container).toMatchSnapshot() }) test(`can't allow to clear`, async () => { const { getByText } = render( - { test('custom top', async () => { const today = dayjs() const { container } = render( - { @@ -137,7 +137,7 @@ describe('Calendar', () => { test('custom date', () => { render( - { @@ -150,7 +150,7 @@ describe('Calendar', () => { test('custom bottom', () => { render( - { diff --git a/src/components/calendar-picker/calendar-picker.en.md b/src/components/calendar-picker/calendar-picker.en.md index 41320924b0..9ecb697a2f 100644 --- a/src/components/calendar-picker/calendar-picker.en.md +++ b/src/components/calendar-picker/calendar-picker.en.md @@ -1,4 +1,4 @@ -# Calendar +# CalendarPicker Used to select a date or date range. @@ -16,7 +16,7 @@ When the user needs to enter a date, he can select it in the pop-up date panel. -## Calendar +## CalendarPicker ### Props diff --git a/src/components/calendar-picker/calendar-picker.tsx b/src/components/calendar-picker/calendar-picker.tsx index c0d06e4a04..808e408bdd 100644 --- a/src/components/calendar-picker/calendar-picker.tsx +++ b/src/components/calendar-picker/calendar-picker.tsx @@ -6,16 +6,16 @@ import Divider from '../divider' import Popup from '../popup' import { mergeProps } from '../../utils/with-default-props' import { useConfig } from '../config-provider' -import CalendarView, { - CalendarViewProps, - CalendarViewRef, +import CalendarPickerView, { + CalendarPickerViewProps, + CalendarPickerViewRef, } from '../calendar-picker-view' -const classPrefix = 'adm-calendar' +const classPrefix = 'adm-calendar-picker' -export type CalendarPickerRef = CalendarViewRef +export type CalendarPickerRef = CalendarPickerViewRef -export type CalendarPickerProps = CalendarViewProps & { +export type CalendarPickerProps = CalendarPickerViewProps & { visible?: boolean confirmText?: string popupClassName?: string @@ -118,7 +118,7 @@ export const CalendarPicker = forwardRef< } }} > - + {footer}
diff --git a/src/components/calendar-picker/calendar-picker.zh.md b/src/components/calendar-picker/calendar-picker.zh.md index 9fe79f0ba2..5b19f55524 100644 --- a/src/components/calendar-picker/calendar-picker.zh.md +++ b/src/components/calendar-picker/calendar-picker.zh.md @@ -1,4 +1,4 @@ -# Calendar 日历 +# CalendarPicker 日历选择器 用于选择日期或日期区间。 @@ -16,7 +16,7 @@ -## Calendar +## CalendarPicker ### 属性 diff --git a/src/components/calendar-picker/demos/demo1.tsx b/src/components/calendar-picker/demos/demo1.tsx index 528bc15b59..82284fdaaa 100644 --- a/src/components/calendar-picker/demos/demo1.tsx +++ b/src/components/calendar-picker/demos/demo1.tsx @@ -1,6 +1,6 @@ import dayjs from 'dayjs' import React, { useState } from 'react' -import { Calendar, List } from 'antd-mobile' +import { CalendarPicker, List } from 'antd-mobile' const defaultRange: [Date, Date] = [ dayjs().toDate(), @@ -26,7 +26,7 @@ export default () => { }} > 选择单个日期 - { }} > 选择日期范围 - { }} > 受控日期选择 - { }} > 自定义标题 - setVisible1(false)} @@ -33,7 +33,7 @@ export default () => { }} > 自定义确认文案 - setVisible2(false)} @@ -46,7 +46,7 @@ export default () => { }} > 周一作为每周的第一天 - setVisible3(false)} @@ -59,7 +59,7 @@ export default () => { }} > 限制日期范围 - { @@ -24,7 +24,7 @@ export default () => { }} > 自定义日期顶部信息 - setVisible1(false)} onMaskClick={() => setVisible1(false)} @@ -49,7 +49,7 @@ export default () => { }} > 自定义日期底部信息 - setVisible2(false)} onMaskClick={() => setVisible2(false)} @@ -69,7 +69,7 @@ export default () => { }} > 自定义日期渲染 - setVisible3(false)} onMaskClick={() => setVisible3(false)} @@ -94,7 +94,7 @@ export default () => { }} > 高级自定义样式 - { - const ref1 = useRef(null) - const ref2 = useRef(null) + const ref1 = useRef(null) + const ref2 = useRef(null) const [visible1, setVisible1] = useState(false) const [visible2, setVisible2] = useState(false) @@ -19,7 +19,7 @@ export default () => { }} > 跳转到 3 月后 - setVisible1(false)} @@ -36,7 +36,7 @@ export default () => { }} > 跳转到 3 年后 - setVisible2(false)} diff --git a/src/components/calendar/calendar.en.md b/src/components/calendar/calendar.en.md index b5d4c4974e..d6f92ad067 100644 --- a/src/components/calendar/calendar.en.md +++ b/src/components/calendar/calendar.en.md @@ -1,5 +1,9 @@ # Calendar + + Calendar will be removed due to design updates. Please use the CalendarPickerView component instead. + + Used to select a date or date range. ## When to Use diff --git a/src/components/calendar/calendar.tsx b/src/components/calendar/calendar.tsx index e05e57b6de..9e8afcc4ac 100644 --- a/src/components/calendar/calendar.tsx +++ b/src/components/calendar/calendar.tsx @@ -4,6 +4,7 @@ import React, { useState, useImperativeHandle, useMemo, + useEffect, } from 'react' import { NativeProps, withNativeProps } from '../../utils/native-props' import dayjs from 'dayjs' @@ -16,6 +17,7 @@ import isoWeek from 'dayjs/plugin/isoWeek' import { useUpdateEffect } from 'ahooks' import { usePropsValue } from '../../utils/use-props-value' import { replaceMessage } from '../../utils/replace-message' +import { devWarning } from '../../utils/dev-log' import { convertValueToRange, convertPageToDayjs, @@ -322,6 +324,16 @@ export const Calendar = forwardRef((p, ref) => {
) + // Dev only warning + if (process.env.NODE_ENV !== 'production') { + useEffect(() => { + devWarning( + 'Calendar', + 'Calendar will be removed in the future, please use CalendarPickerView instead.' + ) + }, []) + } + return withNativeProps( props,
diff --git a/src/components/calendar/calendar.zh.md b/src/components/calendar/calendar.zh.md index ed01567c4a..26ce96a670 100644 --- a/src/components/calendar/calendar.zh.md +++ b/src/components/calendar/calendar.zh.md @@ -1,5 +1,9 @@ # Calendar 日历 + + 由于设计更新,Calendar 组件将被移除。请使用 CalendarPickerView 组件。 + + 用于选择日期或日期区间。 ## 何时使用 diff --git a/src/index.ts b/src/index.ts index 2d7fc1840a..7f26c66a25 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,11 +19,11 @@ export type { CalendarPickerProps, CalendarPickerRef, } from './components/calendar-picker' -export { default as CalendarView } from './components/calendar-picker-view' +export { default as CalendarPickerView } from './components/calendar-picker-view' export type { - CalendarViewProps, - CalendarViewRef, -} from './components/calendar-view' + CalendarPickerViewProps, + CalendarPickerViewRef, +} from './components/calendar-picker-view' export { default as CapsuleTabs } from './components/capsule-tabs' export type { CapsuleTabsProps, From f962539cfc26afbb430f433a946f20b421d09c4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Thu, 19 Oct 2023 16:32:51 +0800 Subject: [PATCH 4/5] chore: clean up --- .../calendar-picker-view.test.tsx.snap | 9019 +++++++++++++++++ .../__snapshots__/calendar-view.test.tsx.snap | 9019 ----------------- ...test.tsx => calendar-picker-view.test.tsx} | 4 +- ...tsx.snap => calendar-picker.test.tsx.snap} | 2 +- ...ndar.test.tsx => calendar-picker.test.tsx} | 6 +- .../tests/config-provider.test.tsx | 4 +- 6 files changed, 9027 insertions(+), 9027 deletions(-) create mode 100644 src/components/calendar-picker-view/tests/__snapshots__/calendar-picker-view.test.tsx.snap delete mode 100644 src/components/calendar-picker-view/tests/__snapshots__/calendar-view.test.tsx.snap rename src/components/calendar-picker-view/tests/{calendar-view.test.tsx => calendar-picker-view.test.tsx} (97%) rename src/components/calendar-picker/tests/__snapshots__/{calendar.test.tsx.snap => calendar-picker.test.tsx.snap} (77%) rename src/components/calendar-picker/tests/{calendar.test.tsx => calendar-picker.test.tsx} (90%) diff --git a/src/components/calendar-picker-view/tests/__snapshots__/calendar-picker-view.test.tsx.snap b/src/components/calendar-picker-view/tests/__snapshots__/calendar-picker-view.test.tsx.snap new file mode 100644 index 0000000000..b0fa98624c --- /dev/null +++ b/src/components/calendar-picker-view/tests/__snapshots__/calendar-picker-view.test.tsx.snap @@ -0,0 +1,9019 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Calendar custom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+
+ 8 +
+
+
+
+
+
+ 9 +
+
+
+
+
+
+ 10 +
+
+
+
+
+
+ 11 +
+
+
+
+
+
+ 12 +
+
+
+
+
+
+ 13 +
+
+
+
+
+
+ 14 +
+
+
+
+
+
+ 15 +
+
+
+
+
+
+ 16 +
+
+
+
+
+
+ 17 +
+
+
+
+
+
+ 18 +
+
+
+
+
+
+ 19 +
+
+
+
+
+
+ 20 +
+
+
+
+
+
+ 21 +
+
+
+
+
+ 今日 +
+
+ 22 +
+
+
+
+
+
+ 23 +
+
+
+
+
+
+ 24 +
+
+
+
+
+
+ 25 +
+
+
+
+
+
+ 26 +
+
+
+
+
+
+ 27 +
+
+
+
+
+
+ 28 +
+
+
+
+
+
+ 29 +
+
+
+
+
+
+ 30 +
+
+
+
+
+
+ 31 +
+
+
+
+
+
+
+
+`; diff --git a/src/components/calendar-picker-view/tests/__snapshots__/calendar-view.test.tsx.snap b/src/components/calendar-picker-view/tests/__snapshots__/calendar-view.test.tsx.snap deleted file mode 100644 index 0cbe7a9e29..0000000000 --- a/src/components/calendar-picker-view/tests/__snapshots__/calendar-view.test.tsx.snap +++ /dev/null @@ -1,9019 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Calendar custom top 1`] = ` -
-
-
-
- 日期选择 -
-
-
-
- 日 -
-
- 一 -
-
- 二 -
-
- 三 -
-
- 四 -
-
- 五 -
-
- 六 -
-
-
-
-
- 2023年5月 -
-
-
-
-
-
- 1 -
-
-
-
-
-
- 2 -
-
-
-
-
-
- 3 -
-
-
-
-
-
- 4 -
-
-
-
-
-
- 5 -
-
-
-
-
- 周末 -
-
- 6 -
-
-
-
-
- 周末 -
-
- 7 -
-
-
-
-
-
- 8 -
-
-
-
-
-
- 9 -
-
-
-
-
-
- 10 -
-
-
-
-
-
- 11 -
-
-
-
-
-
- 12 -
-
-
-
-
- 周末 -
-
- 13 -
-
-
-
-
- 周末 -
-
- 14 -
-
-
-
-
-
- 15 -
-
-
-
-
-
- 16 -
-
-
-
-
-
- 17 -
-
-
-
-
-
- 18 -
-
-
-
-
-
- 19 -
-
-
-
-
- 周末 -
-
- 20 -
-
-
-
-
- 周末 -
-
- 21 -
-
-
-
-
- 今天 -
-
- 22 -
-
-
-
-
-
- 23 -
-
-
-
-
-
- 24 -
-
-
-
-
-
- 25 -
-
-
-
-
-
- 26 -
-
-
-
-
- 周末 -
-
- 27 -
-
-
-
-
- 周末 -
-
- 28 -
-
-
-
-
-
- 29 -
-
-
-
-
-
- 30 -
-
-
-
-
-
- 31 -
-
-
-
-
-
-
-
-`; - -exports[`Calendar jump to a day 1`] = ` -
- - -
-
-
- 日期选择 -
-
-
-
- 日 -
-
- 一 -
-
- 二 -
-
- 三 -
-
- 四 -
-
- 五 -
-
- 六 -
-
-
-
-
- 2021年1月 -
-
-
-
-
-
-
-
-
-
- 1 -
-
-
-
-
-
- 2 -
-
-
-
-
-
- 3 -
-
-
-
-
-
- 4 -
-
-
-
-
-
- 5 -
-
-
-
-
-
- 6 -
-
-
-
-
-
- 7 -
-
-
-
-
-
- 8 -
-
-
-
-
-
- 9 -
-
-
-
-
-
- 10 -
-
-
-
-
-
- 11 -
-
-
-
-
-
- 12 -
-
-
-
-
-
- 13 -
-
-
-
-
-
- 14 -
-
-
-
-
-
- 15 -
-
-
-
-
-
- 16 -
-
-
-
-
-
- 17 -
-
-
-
-
-
- 18 -
-
-
-
-
-
- 19 -
-
-
-
-
-
- 20 -
-
-
-
-
-
- 21 -
-
-
-
-
-
- 22 -
-
-
-
-
-
- 23 -
-
-
-
-
-
- 24 -
-
-
-
-
-
- 25 -
-
-
-
-
-
- 26 -
-
-
-
-
-
- 27 -
-
-
-
-
-
- 28 -
-
-
-
-
-
- 29 -
-
-
-
-
-
- 30 -
-
-
-
-
-
- 31 -
-
-
-
-
-
-
- 2021年2月 -
-
-
-
-
-
- 1 -
-
-
-
-
-
- 2 -
-
-
-
-
-
- 3 -
-
-
-
-
-
- 4 -
-
-
-
-
-
- 5 -
-
-
-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-
-
-
-
- 今日 -
-
- 22 -
-
-
-
-
-
- 23 -
-
-
-
-
-
- 24 -
-
-
-
-
-
- 25 -
-
-
-
-
-
- 26 -
-
-
-
-
-
- 27 -
-
-
-
-
-
- 28 -
-
-
-
-
-
- 29 -
-
-
-
-
-
- 30 -
-
-
-
-
-
- 31 -
-
-
-
-
-
-
-
-`; - -exports[`Calendar single mode 1`] = ` -
-
-
-
- 日期选择 -
-
-
-
- 日 -
-
- 一 -
-
- 二 -
-
- 三 -
-
- 四 -
-
- 五 -
-
- 六 -
-
-
-
-
- 2023年5月 -
-
-
-
-
-
- 1 -
-
-
-
-
-
- 2 -
-
-
-
-
-
- 3 -
-
-
-
-
-
- 4 -
-
-
-
-
-
- 5 -
-
-
-
-
-
- 6 -
-
-
-
-
-
- 7 -
-
-
-
-
-
- 8 -
-
-
-
-
-
- 9 -
-
-
-
-
-
- 10 -
-
-
-
-
-
- 11 -
-
-
-
-
-
- 12 -
-
-
-
-
-
- 13 -
-
-
-
-
-
- 14 -
-
-
-
-
-
- 15 -
-
-
-
-
-
- 16 -
-
-
-
-
-
- 17 -
-
-
-
-
-
- 18 -
-
-
-
-
-
- 19 -
-
-
-
-
-
- 20 -
-
-
-
-
-
- 21 -
-
-
-
-
- 今日 -
-
- 22 -
-
-
-
-
-
- 23 -
-
-
-
-
-
- 24 -
-
-
-
-
-
- 25 -
-
-
-
-
-
- 26 -
-
-
-
-
-
- 27 -
-
-
-
-
-
- 28 -
-
-
-
-
-
- 29 -
-
-
-
-
-
- 30 -
-
-
-
-
-
- 31 -
-
-
-
-
-
-
-
-`; - -exports[`Calendar week start on Monday 1`] = ` -
-
-
-
- 日期选择 -
-
-
-
- 一 -
-
- 二 -
-
- 三 -
-
- 四 -
-
- 五 -
-
- 六 -
-
- 日 -
-
-
-
-
- 2023年5月 -
-
-
-
-
- 1 -
-
-
-
-
-
- 2 -
-
-
-
-
-
- 3 -
-
-
-
-
-
- 4 -
-
-
-
-
-
- 5 -
-
-
-
-
-
- 6 -
-
-
-
-
-
- 7 -
-
-
-
-
-
- 8 -
-
-
-
-
-
- 9 -
-
-
-
-
-
- 10 -
-
-
-
-
-
- 11 -
-
-
-
-
-
- 12 -
-
-
-
-
-
- 13 -
-
-
-
-
-
- 14 -
-
-
-
-
-
- 15 -
-
-
-
-
-
- 16 -
-
-
-
-
-
- 17 -
-
-
-
-
-
- 18 -
-
-
-
-
-
- 19 -
-
-
-
-
-
- 20 -
-
-
-
-
-
- 21 -
-
-
-
-
- 今日 -
-
- 22 -
-
-
-
-
-
- 23 -
-
-
-
-
-
- 24 -
-
-
-
-
-
- 25 -
-
-
-
-
-
- 26 -
-
-
-
-
-
- 27 -
-
-
-
-
-
- 28 -
-
-
-
-
-
- 29 -
-
-
-
-
-
- 30 -
-
-
-
-
-
- 31 -
-
-
-
-
-
-
-
-`; diff --git a/src/components/calendar-picker-view/tests/calendar-view.test.tsx b/src/components/calendar-picker-view/tests/calendar-picker-view.test.tsx similarity index 97% rename from src/components/calendar-picker-view/tests/calendar-view.test.tsx rename to src/components/calendar-picker-view/tests/calendar-picker-view.test.tsx index 240ea16cd0..9bd19cd8bf 100644 --- a/src/components/calendar-picker-view/tests/calendar-view.test.tsx +++ b/src/components/calendar-picker-view/tests/calendar-picker-view.test.tsx @@ -1,6 +1,6 @@ import React, { useRef } from 'react' import { render, testA11y, fireEvent } from 'testing' -import CalendarPickerView, { CalendarViewRef } from '..' +import CalendarPickerView, { CalendarPickerViewRef } from '..' import dayjs from 'dayjs' import MockDate from 'mockdate' @@ -65,7 +65,7 @@ describe('Calendar', () => { test('jump to a day', async () => { const App = () => { - const ref = useRef(null) + const ref = useRef(null) return ( <>