Skip to content

Commit

Permalink
fix: disabled days style
Browse files Browse the repository at this point in the history
  • Loading branch information
farhoudshapouran committed Feb 3, 2025
1 parent d1b0a4d commit 9e86ad8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 8 deletions.
3 changes: 2 additions & 1 deletion example/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import 'dayjs/locale/de';
import 'dayjs/locale/es';
import 'dayjs/locale/fr';
import 'dayjs/locale/tr';
import 'dayjs/locale/fa';

const Themes: ITheme[] = [
{ mainColor: '#0047FF', activeTextColor: '#fff' },
Expand Down Expand Up @@ -193,7 +194,7 @@ export default function MainPage() {
//maxDate={dayjs().add(3, 'day').endOf('day')}
//disabledDates={[dayjs(), dayjs().add(1, 'day')]}
//disabledDates={(date) => [0, 6].includes(dayjs(date).day())} // disable weekends
//firstDayOfWeek={1}
//firstDayOfWeek={6}
displayFullDays
timePicker={timePicker}
onChange={onChange}
Expand Down
2 changes: 1 addition & 1 deletion example/components/LocaleSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { memo } from 'react';
import { StyleSheet, View, Text, Pressable } from 'react-native';

const Locales = ['en', 'de', 'es', 'fr', 'tr'];
const Locales = ['en', 'de', 'es', 'fr', 'tr', 'fa'];

type Props = {
locale: string;
Expand Down
12 changes: 10 additions & 2 deletions src/components/Day.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,21 @@ function Day({
borderColor: selectedItemColor,
backgroundColor: selectedItemColor,
},
disabled && style.disabledDay,
]);

const textStyle = StyleSheet.flatten([
isSelected
? { color: '#fff', ...selectedTextStyle }
? {
color: '#fff',
...selectedTextStyle,
}
: isToday
? { ...calendarTextStyle, color: selectedItemColor, ...todayTextStyle }
? {
...calendarTextStyle,
color: selectedItemColor,
...todayTextStyle,
}
: calendarTextStyle,
]);

Expand Down
3 changes: 2 additions & 1 deletion src/components/DaySelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const DaySelector = () => {
firstDayOfWeek,
theme,
height,
locale,
} = useCalendarContext();

const { year, month, hour, minute } = getParsedDate(currentDate);
Expand Down Expand Up @@ -181,7 +182,7 @@ const DaySelector = () => {

return (
<View style={styles.container} testID="day-selector">
<WeekDays firstDayOfWeek={firstDayOfWeek} theme={theme} />
<WeekDays locale={locale} firstDayOfWeek={firstDayOfWeek} theme={theme} />
<View style={styles.daysContainer} testID="days">
{daysGrid?.map((day, index) => {
return day ? (
Expand Down
5 changes: 3 additions & 2 deletions src/components/WeekDays.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import { getWeekdaysMin } from '../utils';
import { CalendarThemeProps } from '../types';

type WeekDaysProps = {
locale: string | ILocale;
firstDayOfWeek: number;
theme: CalendarThemeProps;
};

const WeekDays = ({ firstDayOfWeek, theme }: WeekDaysProps) => {
const WeekDays = ({ locale, firstDayOfWeek, theme }: WeekDaysProps) => {
return (
<View
style={[styles.weekDaysContainer, theme?.weekDaysContainerStyle]}
testID="week-days"
>
{getWeekdaysMin(firstDayOfWeek)?.map((item, index) => (
{getWeekdaysMin(locale, firstDayOfWeek)?.map((item, index) => (
<View key={index} style={styles.weekDayCell}>
<Text style={theme?.weekDaysTextStyle}>{item}</Text>
</View>
Expand Down
6 changes: 5 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export const getWeekdays = () => dayjs.weekdays();

export const getWeekdaysShort = () => dayjs.weekdaysShort();

export const getWeekdaysMin = (firstDayOfWeek: number) => {
export const getWeekdaysMin = (
locale: string | ILocale,
firstDayOfWeek: number
) => {
dayjs().locale(locale);
let days = dayjs.weekdaysMin();
if (firstDayOfWeek > 0) {
days = [
Expand Down

0 comments on commit 9e86ad8

Please sign in to comment.