Skip to content

feat(calendar): add viewmode #2985

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d4a51a0
refactor: calendar
xiaoyatong Feb 11, 2025
99c272b
refactor: calendar h5
xiaoyatong Feb 11, 2025
635f37b
refactor: calendar h5
xiaoyatong Feb 11, 2025
eb12eda
feat(calendar): 初始创建viewmode模式
xiaoyatong Feb 11, 2025
831fb9e
feat: quarters
xiaoyatong Feb 11, 2025
19f7397
feat: quarters
xiaoyatong Feb 11, 2025
ca536a4
fix: quarter calculating
xiaoyatong Feb 12, 2025
0b781ef
perf: 提炼代码
xiaoyatong Feb 12, 2025
4a0f2f2
feat: weeks
xiaoyatong Feb 12, 2025
6715bdc
feat: add click event
xiaoyatong Feb 12, 2025
2fb671a
perf: 清理代码添加demo
xiaoyatong Feb 12, 2025
403c7fb
feat: 添加周号
xiaoyatong Feb 12, 2025
348672a
fix: 增加默认值处理,修订参数
xiaoyatong Feb 13, 2025
119688b
feat: taro 版本支持
xiaoyatong Feb 13, 2025
8e8a72d
fix: 类型
xiaoyatong Feb 13, 2025
04ed29a
fix: 修订类型,兼容日面板,增加文档
xiaoyatong Feb 13, 2025
0fdd3e7
fix: merge
xiaoyatong Feb 13, 2025
14b86d8
fix: 修改方法
xiaoyatong Feb 13, 2025
d8a0a6c
test: 增加单测
xiaoyatong Feb 13, 2025
52a73d2
Merge branch 'next' into feat_calendar_0211
xiaoyatong Feb 17, 2025
ae32866
fix: merge next
xiaoyatong Feb 20, 2025
a1c2ee8
fix: ai fixed
xiaoyatong Feb 20, 2025
3c320d6
feat: 周号
xiaoyatong Feb 20, 2025
f2491db
fix: 默认值为空时异常
xiaoyatong Feb 24, 2025
94d65a2
fix: merge next
xiaoyatong Feb 26, 2025
5968bc8
feat: 已提供默认值时,定位到默认值位置
xiaoyatong Feb 27, 2025
d342e08
fix: 修复多语言
xiaoyatong Mar 12, 2025
3b0d503
fix: remove unused cls and refactor data
xiaoyatong Mar 13, 2025
19ea50e
refactor: renderpanel
xiaoyatong Mar 13, 2025
7818ab4
refactor: 构造数据
xiaoyatong Mar 13, 2025
258424e
refactor: 充足date公用方法
xiaoyatong Mar 13, 2025
f2a2f1b
fix: taro h5 下点击事件后页面滚动问题修复
xiaoyatong Mar 13, 2025
294d725
test: fixed
xiaoyatong Mar 13, 2025
993f1bb
fix: 删除无用代码
xiaoyatong Mar 13, 2025
34b97a5
fix: 删除无用代码
xiaoyatong Mar 13, 2025
7d44b51
fix: type
xiaoyatong Mar 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/locales/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export interface BaseLang {
start: string
confirm: string
title: string
week: string
month: string
year: string
quarter: string
// eslint-disable-next-line @typescript-eslint/ban-types
monthTitle: Function
today: string
Expand Down
4 changes: 4 additions & 0 deletions src/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const enUS: BaseLang = {
start: 'Start',
confirm: 'Confirm',
title: 'Calendar',
week: 'W',
month: 'M',
year: 'Y',
quarter: 'Q',
monthTitle: (year: number, month: number) =>
`${year}/${Number(month) < 10 ? `0${Number(month)}` : month}`,
today: 'Today',
Expand Down
4 changes: 4 additions & 0 deletions src/locales/id-ID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const idID: BaseLang = {
start: 'Mulai',
confirm: 'Mengonfirmasi',
title: 'Kalender',
week: 'Mg',
month: 'Bl',
year: 'Th',
quarter: 'Kt',
monthTitle: (year: number, month: number) =>
`${year}/${Number(month) < 10 ? `0${Number(month)}` : month}`,
today: 'Hari ini',
Expand Down
4 changes: 4 additions & 0 deletions src/locales/tr-TR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ const trTR: BaseLang = {
start: 'Başlangıç',
confirm: 'Onayla',
title: 'Takvim seçimi',
week: 'H',
month: 'A',
year: 'Y',
quarter: 'Ç',
monthTitle: (year: number, month: number) =>
`${year}/${Number(month) < 10 ? `0${Number(month)}` : month}`,
today: 'Bugün',
Expand Down
4 changes: 4 additions & 0 deletions src/locales/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const zhCN: BaseLang = {
start: '开始',
confirm: '确认',
title: '日历选择',
week: '周',
month: '月',
year: '年',
quarter: '季度',
monthTitle: (year: number, month: number) =>
`${year}年${Number(month) < 10 ? `0${Number(month)}` : month}月`,
today: '今天',
Expand Down
4 changes: 4 additions & 0 deletions src/locales/zh-TW.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const zhCN: BaseLang = {
start: '開始',
confirm: '確認',
title: '日歷選擇',
week: '周',
month: '月',
year: '年',
quarter: '季度',
monthTitle: (year: number, month: number) =>
`${year}年${Number(month) < 10 ? `0${Number(month)}` : month}月`,
today: '今天',
Expand Down
4 changes: 4 additions & 0 deletions src/locales/zh-UG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const zhUG: BaseLang = {
start: 'بېشى',
confirm: 'جەزملەشتۈرۈڭ',
title: 'تاللاڭ',
week: 'ھە',
month: 'ئا',
year: 'ي',
quarter: 'پە',
monthTitle: (year: number, month: number) =>
`${year} يىلى ${Number(month) < 10 ? `0${Number(month)}` : month} ئاي`,
today: 'بۈگۈن',
Expand Down

Large diffs are not rendered by default.

86 changes: 79 additions & 7 deletions src/packages/calendar/__tests__/calendar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ test('week prop', async () => {
firstDayOfWeek={1}
/>
)
const viewArea = container.querySelector('.viewArea') as HTMLElement
// expect(viewArea.innerHTML).toMatchSnapshot()
const viewArea = container.querySelector(
'.nut-calendar-pannel'
) as HTMLElement
expect(viewArea.innerHTML).toMatchSnapshot()
})

test('range prop', async () => {
Expand All @@ -80,8 +82,76 @@ test('range prop', async () => {
firstDayOfWeek={1}
/>
)
const viewArea = container.querySelector('.viewArea') as HTMLElement
// expect(viewArea.innerHTML).toMatchSnapshot()
const viewArea = container.querySelector(
'.nut-calendar-pannel'
) as HTMLElement
expect(viewArea.innerHTML).toMatchSnapshot()
})

test('viewmode prop', async () => {
const onItemClick = vi.fn()
const { container } = render(
<Calendar
viewMode="quarter"
defaultValue="2025-Q1"
startDate="2025-01-01"
endDate="2025-3-31"
onItemClick={onItemClick}
/>
)
const viewArea = container.querySelector(
'.nut-calendar-viewmode-pannel'
) as HTMLElement
expect(viewArea.innerHTML).toMatchSnapshot()
})

test('should render calendar in quarter view with extended date range', async () => {
const { container } = render(
<Calendar
viewMode="quarter"
defaultValue="2025-Q1"
startDate="2025-01-01"
endDate="2027-3-31"
/>
)
const viewArea = container.querySelector(
'.nut-calendar-viewmode-pannel'
) as HTMLElement
expect(viewArea.innerHTML).toMatchSnapshot()
})

test('should render calendar in month view with onItemClick', async () => {
const onItemClick = vi.fn()
const { container } = render(
<Calendar
viewMode="month"
defaultValue="2025-01"
startDate="2025-01-01"
endDate="2025-3-31"
onItemClick={onItemClick}
/>
)
const viewArea = container.querySelector(
'.nut-calendar-viewmode-pannel'
) as HTMLElement
expect(viewArea.innerHTML).toMatchSnapshot()
})

test('should render calendar in month view with extended date range', async () => {
const onItemClick = vi.fn()
const { container } = render(
<Calendar
viewMode="month"
defaultValue="2025-01"
startDate="2025-01-01"
endDate="2027-3-31"
onItemClick={onItemClick}
/>
)
const viewArea = container.querySelector(
'.nut-calendar-viewmode-pannel'
) as HTMLElement
expect(viewArea.innerHTML).toMatchSnapshot()
})

test('popup prop', async () => {
Expand Down Expand Up @@ -121,7 +191,9 @@ test('should render slot correctly', async () => {
const topSlot = container.querySelector(
'.nut-calendar-header-buttons'
) as HTMLElement
const viewArea = container.querySelector('.viewArea') as HTMLElement
const viewArea = container.querySelector(
'.nut-calendar-pannel'
) as HTMLElement
expect(topSlot.innerHTML).toContain('<div class="d_div"> 最近七天</div>')
expect(viewArea.innerHTML).toMatchSnapshot()
})
Expand Down Expand Up @@ -217,13 +289,13 @@ test('range select event when click item', () => {
const start = container.querySelectorAll(
'.nut-calendar-day-active .nut-calendar-day-day'
)[0]
expect(start.innerHTML).toBe('13')
expect(start.innerHTML).toBe('10')

const calendarMonthDay2 = container.querySelectorAll('.nut-calendar-day')[20]
fireEvent.click(calendarMonthDay2)
expect(onDayClick).toBeCalled()
const next = container.querySelectorAll(
'.nut-calendar-day-choose .nut-calendar-day-day'
)[0]
expect(next.innerHTML).toBe('14')
expect(next.innerHTML).toBe('11')
})
25 changes: 25 additions & 0 deletions src/packages/calendar/calendar.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@import '../popup/popup.scss';
@import './calendarviewmode.scss';

.nut-calendar {
position: relative;
Expand Down Expand Up @@ -62,6 +63,10 @@
height: 36px;
border-radius: 0px 0px 12px 12px;
box-shadow: 0px 4px 10px 0px rgba($color: #000000, $alpha: 0.06);

&-shrink {
padding-left: 17%;
}
}

&-week-item {
Expand Down Expand Up @@ -111,6 +116,22 @@
margin: 8px 0;
}

&-weeknumber {
width: 35%;
&-index {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
position: relative;
height: $calendar-day-height;
font-weight: $font-weight;
font-size: $font-size-base;
margin-bottom: 4px;
color: $color-text-help;
}
}

&-days {
overflow: hidden;
}
Expand Down Expand Up @@ -205,6 +226,10 @@
}
}

.shrink {
display: flex;
}

// 底部导航
&-footer {
display: flex;
Expand Down
Loading
Loading