Skip to content
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

feat: Customize by day of the week #2545

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
17 changes: 16 additions & 1 deletion src/calendar/day/basic/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ const BasicDay = (props: BasicDayProps) => {
const isMultiPeriod = markingType === Marking.markings.MULTI_PERIOD;
const isCustom = markingType === Marking.markings.CUSTOM;
const dateData = date ? xdateToData(date) : undefined;

const weekDayStyles = {
0: 'sunday',
1: 'monday',
2: 'tuesday',
3: 'wednesday',
4: 'thursday',
5: 'friday',
6: 'saturday',
};
const shouldDisableTouchEvent = () => {
const {disableTouchEvent} = _marking;
let disableTouch = false;
Expand All @@ -84,6 +92,8 @@ const BasicDay = (props: BasicDayProps) => {
}
} else if (isToday) {
styles.push(style.current.today);
} else if (typeof dateData?.weekDay === 'number' && weekDayStyles[dateData?.weekDay]) {
styles.push(style.current[weekDayStyles[dateData?.weekDay]]);
}

//Custom marking type
Expand Down Expand Up @@ -112,6 +122,11 @@ const BasicDay = (props: BasicDayProps) => {
styles.push(style.current.todayText);
} else if (isInactive) {
styles.push(style.current.inactiveText);
} else if (typeof dateData?.weekDay === 'number' && weekDayStyles[dateData?.weekDay]) {
const weekDayNumberTextStyle = `${weekDayStyles[dateData?.weekDay]}Text`;
if (style.current[weekDayNumberTextStyle]) {
styles.push(style.current[weekDayNumberTextStyle]);
}
}

//Custom marking type
Expand Down
14 changes: 14 additions & 0 deletions src/calendar/day/basic/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ export default function styleConstructor(theme: Theme = {}) {
selectedText: {
color: appStyle.selectedDayTextColor
},
sunday: {},
sundayText: {},
monday: {},
mondayText: {},
tuesday: {},
tuesdayText: {},
wednesday: {},
wednesdayText: {},
thursday: {},
thursdayText: {},
friday: {},
fridayText: {},
saturday: {},
saturdayText: {},
disabledText: {
color: appStyle.textDisabledColor
},
Expand Down
5 changes: 3 additions & 2 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export function xdateToData(date: XDate | string) {
month: d.getMonth() + 1,
day: d.getDate(),
timestamp: new XDate(dateString, true).getTime(),
dateString: dateString
dateString: dateString,
weekDay: d.getDay(),
};
}

Expand Down Expand Up @@ -51,4 +52,4 @@ export function toMarkingFormat(d: XDate) {
return year + '-' + doubleDigitMonth + '-' + doubleDigitDay;
}
return 'Invalid Date';
}
}