-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat(date-picker): #2610
- Loading branch information
Showing
9 changed files
with
192 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hi-ui/hiui": patch | ||
--- | ||
|
||
DatePicker feat: add cellRender api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hi-ui/date-picker": minor | ||
--- | ||
|
||
feat: add cellRender api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
packages/ui/date-picker/stories/cell-render.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import React from 'react' | ||
import DatePicker from '../src' | ||
|
||
/** | ||
* @title 自定义单元格内容 | ||
*/ | ||
export const CellRender = () => { | ||
return ( | ||
<> | ||
<h1>CellRender</h1> | ||
<div className="date-picker-ymw__wrap"> | ||
<h2>年份</h2> | ||
<DatePicker | ||
style={{ width: 238 }} | ||
type="year" | ||
cellRender={(info) => { | ||
const { type, text } = info | ||
|
||
return type === 'today' ? <strong>{text}</strong> : text | ||
}} | ||
onChange={(date, dateStr) => { | ||
console.log('onChange', date, dateStr) | ||
}} | ||
/> | ||
<h2>月份</h2> | ||
<DatePicker | ||
style={{ width: 238 }} | ||
type="month" | ||
cellRender={(info) => { | ||
const { type, text } = info | ||
return type === 'today' ? <strong>{text}</strong> : text | ||
}} | ||
onChange={(date, dateStr) => { | ||
console.log('onChange', date, dateStr) | ||
}} | ||
/> | ||
|
||
<h2>周</h2> | ||
<DatePicker | ||
style={{ width: 238 }} | ||
type="week" | ||
defaultValue={new Date()} | ||
cellRender={(info) => { | ||
const { value, weekNum } = info | ||
|
||
return weekNum ? weekNum + 'W' : value | ||
}} | ||
onChange={(date, dateStr) => { | ||
console.log('onChange', date, dateStr) | ||
}} | ||
/> | ||
<h2>周范围</h2> | ||
<DatePicker | ||
style={{ width: 560 }} | ||
type="weekrange" | ||
defaultValue={new Date()} | ||
format={`YYYY年第w周`} | ||
cellRender={(cellInfo) => { | ||
// console.log('cellInfo', cellInfo) | ||
|
||
const { value, weekNum } = cellInfo | ||
|
||
if (weekNum) { | ||
// weekStartDate 周一日期 | ||
// renderDate 当前月日期 | ||
const { weekStartDate, renderDate } = cellInfo | ||
// 当前周最后一天 | ||
const weekEndDate = weekStartDate?.clone().add(6, 'day') | ||
|
||
if ( | ||
weekEndDate && | ||
renderDate && | ||
(weekEndDate?.month() > renderDate?.month() || | ||
weekEndDate?.year() > renderDate?.year()) && | ||
weekStartDate?.month() === renderDate?.month() | ||
) { | ||
return weekNum + 'A' | ||
} | ||
|
||
if ( | ||
weekStartDate && | ||
renderDate && | ||
(weekStartDate?.month() < renderDate?.month() || | ||
weekStartDate?.year() < renderDate?.year()) && | ||
weekEndDate?.month() === renderDate?.month() | ||
) { | ||
return weekNum + 'B' | ||
} | ||
|
||
return weekNum | ||
} else { | ||
return value | ||
} | ||
}} | ||
onChange={(date, dateStr) => { | ||
console.log('onChange', date, dateStr) | ||
}} | ||
/> | ||
</div> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters