Skip to content

Commit a4af119

Browse files
author
刘欢
committed
feat(Calendar): unified provision of custom prefixCls
1 parent 2742629 commit a4af119

File tree

5 files changed

+1503
-27
lines changed

5 files changed

+1503
-27
lines changed

src/components/calendar/calendar.tsx

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import {
2727

2828
dayjs.extend(isoWeek)
2929

30-
const classPrefix = 'adm-calendar'
31-
3230
export type CalendarRef = {
3331
jumpTo: (page: Page | ((page: Page) => Page)) => void
3432
jumpToToday: () => void
@@ -50,6 +48,7 @@ export type CalendarProps = {
5048
shouldDisableDate?: (date: Date) => boolean
5149
minPage?: Page
5250
maxPage?: Page
51+
prefixCls?: string
5352
} & (
5453
| {
5554
selectionMode?: undefined
@@ -85,7 +84,8 @@ const defaultProps = {
8584
export const Calendar = forwardRef<CalendarRef, CalendarProps>((p, ref) => {
8685
const today = dayjs()
8786
const props = mergeProps(defaultProps, p)
88-
const { locale } = useConfig()
87+
const { locale, getPrefixCls } = useConfig()
88+
const prefixCls = getPrefixCls('calendar', props.prefixCls)
8989
const markItems = [...locale.Calendar.markItems]
9090
if (props.weekStartsOn === 'Sunday') {
9191
const item = markItems.pop()
@@ -157,10 +157,10 @@ export const Calendar = forwardRef<CalendarRef, CalendarProps>((p, ref) => {
157157
}
158158

159159
const header = (
160-
<div className={`${classPrefix}-header`}>
160+
<div className={`${prefixCls}-header`}>
161161
{props.prevYearButton !== null && (
162162
<a
163-
className={`${classPrefix}-arrow-button ${classPrefix}-arrow-button-year`}
163+
className={`${prefixCls}-arrow-button ${prefixCls}-arrow-button-year`}
164164
onClick={() => {
165165
handlePageChange('subtract', 1, 'year')
166166
}}
@@ -170,15 +170,15 @@ export const Calendar = forwardRef<CalendarRef, CalendarProps>((p, ref) => {
170170
)}
171171
{props.prevMonthButton !== null && (
172172
<a
173-
className={`${classPrefix}-arrow-button ${classPrefix}-arrow-button-month`}
173+
className={`${prefixCls}-arrow-button ${prefixCls}-arrow-button-month`}
174174
onClick={() => {
175175
handlePageChange('subtract', 1, 'month')
176176
}}
177177
>
178178
{props.prevMonthButton}
179179
</a>
180180
)}
181-
<div className={`${classPrefix}-title`}>
181+
<div className={`${prefixCls}-title`}>
182182
{replaceMessage(locale.Calendar.yearAndMonth, {
183183
year: current.year().toString(),
184184
month: (current.month() + 1).toString(),
@@ -187,9 +187,9 @@ export const Calendar = forwardRef<CalendarRef, CalendarProps>((p, ref) => {
187187
{props.nextMonthButton !== null && (
188188
<a
189189
className={classNames(
190-
`${classPrefix}-arrow-button`,
191-
`${classPrefix}-arrow-button-right`,
192-
`${classPrefix}-arrow-button-right-month`
190+
`${prefixCls}-arrow-button`,
191+
`${prefixCls}-arrow-button-right`,
192+
`${prefixCls}-arrow-button-right-month`
193193
)}
194194
onClick={() => {
195195
handlePageChange('add', 1, 'month')
@@ -201,9 +201,9 @@ export const Calendar = forwardRef<CalendarRef, CalendarProps>((p, ref) => {
201201
{props.nextYearButton !== null && (
202202
<a
203203
className={classNames(
204-
`${classPrefix}-arrow-button`,
205-
`${classPrefix}-arrow-button-right`,
206-
`${classPrefix}-arrow-button-right-year`
204+
`${prefixCls}-arrow-button`,
205+
`${prefixCls}-arrow-button-right`,
206+
`${prefixCls}-arrow-button-right-year`
207207
)}
208208
onClick={() => {
209209
handlePageChange('add', 1, 'year')
@@ -258,15 +258,15 @@ export const Calendar = forwardRef<CalendarRef, CalendarProps>((p, ref) => {
258258
<div
259259
key={d.valueOf()}
260260
className={classNames(
261-
`${classPrefix}-cell`,
262-
(disabled || !inThisMonth) && `${classPrefix}-cell-disabled`,
261+
`${prefixCls}-cell`,
262+
(disabled || !inThisMonth) && `${prefixCls}-cell-disabled`,
263263
inThisMonth && {
264-
[`${classPrefix}-cell-today`]: d.isSame(today, 'day'),
265-
[`${classPrefix}-cell-selected`]: isSelect,
266-
[`${classPrefix}-cell-selected-begin`]: isBegin,
267-
[`${classPrefix}-cell-selected-end`]: isEnd,
268-
[`${classPrefix}-cell-selected-row-begin`]: isSelectRowBegin,
269-
[`${classPrefix}-cell-selected-row-end`]: isSelectRowEnd,
264+
[`${prefixCls}-cell-today`]: d.isSame(today, 'day'),
265+
[`${prefixCls}-cell-selected`]: isSelect,
266+
[`${prefixCls}-cell-selected-begin`]: isBegin,
267+
[`${prefixCls}-cell-selected-end`]: isEnd,
268+
[`${prefixCls}-cell-selected-row-begin`]: isSelectRowBegin,
269+
[`${prefixCls}-cell-selected-row-end`]: isSelectRowEnd,
270270
}
271271
)}
272272
onClick={() => {
@@ -310,10 +310,10 @@ export const Calendar = forwardRef<CalendarRef, CalendarProps>((p, ref) => {
310310
}
311311
}}
312312
>
313-
<div className={`${classPrefix}-cell-top`}>
313+
<div className={`${prefixCls}-cell-top`}>
314314
{props.renderDate ? props.renderDate(d.toDate()) : d.date()}
315315
</div>
316-
<div className={`${classPrefix}-cell-bottom`}>
316+
<div className={`${prefixCls}-cell-bottom`}>
317317
{props.renderLabel?.(d.toDate())}
318318
</div>
319319
</div>
@@ -333,12 +333,12 @@ export const Calendar = forwardRef<CalendarRef, CalendarProps>((p, ref) => {
333333
}
334334
return cells
335335
}
336-
const body = <div className={`${classPrefix}-cells`}>{renderCells()}</div>
336+
const body = <div className={`${prefixCls}-cells`}>{renderCells()}</div>
337337

338338
const mark = (
339-
<div className={`${classPrefix}-mark`}>
339+
<div className={`${prefixCls}-mark`}>
340340
{markItems.map((item, index) => (
341-
<div key={index} className={`${classPrefix}-mark-cell`}>
341+
<div key={index} className={`${prefixCls}-mark-cell`}>
342342
{item}
343343
</div>
344344
))}
@@ -357,7 +357,7 @@ export const Calendar = forwardRef<CalendarRef, CalendarProps>((p, ref) => {
357357

358358
return withNativeProps(
359359
props,
360-
<div className={classPrefix}>
360+
<div className={prefixCls}>
361361
{header}
362362
{mark}
363363
{body}

0 commit comments

Comments
 (0)