Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
54 changes: 27 additions & 27 deletions src/components/calendar/calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import {

dayjs.extend(isoWeek)

const classPrefix = 'adm-calendar'

export type CalendarRef = {
jumpTo: (page: Page | ((page: Page) => Page)) => void
jumpToToday: () => void
Expand All @@ -50,6 +48,7 @@ export type CalendarProps = {
shouldDisableDate?: (date: Date) => boolean
minPage?: Page
maxPage?: Page
prefixCls?: string
} & (
| {
selectionMode?: undefined
Expand Down Expand Up @@ -85,7 +84,8 @@ const defaultProps = {
export const Calendar = forwardRef<CalendarRef, CalendarProps>((p, ref) => {
const today = dayjs()
const props = mergeProps(defaultProps, p)
const { locale } = useConfig()
const { locale, getPrefixCls } = useConfig()
const prefixCls = getPrefixCls('calendar', props.prefixCls)
const markItems = [...locale.Calendar.markItems]
if (props.weekStartsOn === 'Sunday') {
const item = markItems.pop()
Expand Down Expand Up @@ -157,10 +157,10 @@ export const Calendar = forwardRef<CalendarRef, CalendarProps>((p, ref) => {
}

const header = (
<div className={`${classPrefix}-header`}>
<div className={`${prefixCls}-header`}>
{props.prevYearButton !== null && (
<a
className={`${classPrefix}-arrow-button ${classPrefix}-arrow-button-year`}
className={`${prefixCls}-arrow-button ${prefixCls}-arrow-button-year`}
onClick={() => {
handlePageChange('subtract', 1, 'year')
}}
Expand All @@ -170,15 +170,15 @@ export const Calendar = forwardRef<CalendarRef, CalendarProps>((p, ref) => {
)}
{props.prevMonthButton !== null && (
<a
className={`${classPrefix}-arrow-button ${classPrefix}-arrow-button-month`}
className={`${prefixCls}-arrow-button ${prefixCls}-arrow-button-month`}
onClick={() => {
handlePageChange('subtract', 1, 'month')
}}
>
{props.prevMonthButton}
</a>
)}
<div className={`${classPrefix}-title`}>
<div className={`${prefixCls}-title`}>
{replaceMessage(locale.Calendar.yearAndMonth, {
year: current.year().toString(),
month: (current.month() + 1).toString(),
Expand All @@ -187,9 +187,9 @@ export const Calendar = forwardRef<CalendarRef, CalendarProps>((p, ref) => {
{props.nextMonthButton !== null && (
<a
className={classNames(
`${classPrefix}-arrow-button`,
`${classPrefix}-arrow-button-right`,
`${classPrefix}-arrow-button-right-month`
`${prefixCls}-arrow-button`,
`${prefixCls}-arrow-button-right`,
`${prefixCls}-arrow-button-right-month`
)}
onClick={() => {
handlePageChange('add', 1, 'month')
Expand All @@ -201,9 +201,9 @@ export const Calendar = forwardRef<CalendarRef, CalendarProps>((p, ref) => {
{props.nextYearButton !== null && (
<a
className={classNames(
`${classPrefix}-arrow-button`,
`${classPrefix}-arrow-button-right`,
`${classPrefix}-arrow-button-right-year`
`${prefixCls}-arrow-button`,
`${prefixCls}-arrow-button-right`,
`${prefixCls}-arrow-button-right-year`
)}
onClick={() => {
handlePageChange('add', 1, 'year')
Expand Down Expand Up @@ -258,15 +258,15 @@ export const Calendar = forwardRef<CalendarRef, CalendarProps>((p, ref) => {
<div
key={d.valueOf()}
className={classNames(
`${classPrefix}-cell`,
(disabled || !inThisMonth) && `${classPrefix}-cell-disabled`,
`${prefixCls}-cell`,
(disabled || !inThisMonth) && `${prefixCls}-cell-disabled`,
inThisMonth && {
[`${classPrefix}-cell-today`]: d.isSame(today, 'day'),
[`${classPrefix}-cell-selected`]: isSelect,
[`${classPrefix}-cell-selected-begin`]: isBegin,
[`${classPrefix}-cell-selected-end`]: isEnd,
[`${classPrefix}-cell-selected-row-begin`]: isSelectRowBegin,
[`${classPrefix}-cell-selected-row-end`]: isSelectRowEnd,
[`${prefixCls}-cell-today`]: d.isSame(today, 'day'),
[`${prefixCls}-cell-selected`]: isSelect,
[`${prefixCls}-cell-selected-begin`]: isBegin,
[`${prefixCls}-cell-selected-end`]: isEnd,
[`${prefixCls}-cell-selected-row-begin`]: isSelectRowBegin,
[`${prefixCls}-cell-selected-row-end`]: isSelectRowEnd,
}
)}
onClick={() => {
Expand Down Expand Up @@ -310,10 +310,10 @@ export const Calendar = forwardRef<CalendarRef, CalendarProps>((p, ref) => {
}
}}
>
<div className={`${classPrefix}-cell-top`}>
<div className={`${prefixCls}-cell-top`}>
{props.renderDate ? props.renderDate(d.toDate()) : d.date()}
</div>
<div className={`${classPrefix}-cell-bottom`}>
<div className={`${prefixCls}-cell-bottom`}>
{props.renderLabel?.(d.toDate())}
</div>
</div>
Expand All @@ -333,12 +333,12 @@ export const Calendar = forwardRef<CalendarRef, CalendarProps>((p, ref) => {
}
return cells
}
const body = <div className={`${classPrefix}-cells`}>{renderCells()}</div>
const body = <div className={`${prefixCls}-cells`}>{renderCells()}</div>

const mark = (
<div className={`${classPrefix}-mark`}>
<div className={`${prefixCls}-mark`}>
{markItems.map((item, index) => (
<div key={index} className={`${classPrefix}-mark-cell`}>
<div key={index} className={`${prefixCls}-mark-cell`}>
{item}
</div>
))}
Expand All @@ -357,7 +357,7 @@ export const Calendar = forwardRef<CalendarRef, CalendarProps>((p, ref) => {

return withNativeProps(
props,
<div className={classPrefix}>
<div className={prefixCls}>
{header}
{mark}
{body}
Expand Down
Loading
Loading