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

Addded class props for active and now tiles #949

Open
wants to merge 3 commits into
base: main
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
8 changes: 7 additions & 1 deletion packages/react-calendar/src/Calendar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { forwardRef, useCallback, useImperativeHandle, useState } from 'react';
import { forwardRef, useCallback, useEffect, useImperativeHandle, useState } from 'react';
import clsx from 'clsx';

import Navigation from './Calendar/Navigation.js';
Expand Down Expand Up @@ -392,6 +392,8 @@ export type CalendarProps = {
* @example ({ activeStartDate, date, view }) => view === 'month' && date.getDay() === 3 ? 'wednesday' : null
*/
tileClassName?: TileClassNameFunc | ClassName;
activeTileClassName?:string
nowTileClassName?:string
/**
* Allows to render custom content within a given calendar item (day on month view, month on year view and so on).
*
Expand Down Expand Up @@ -653,6 +655,8 @@ const Calendar: React.ForwardRefExoticComponent<CalendarProps & React.RefAttribu
showWeekNumbers,
tileClassName,
tileContent,
activeTileClassName,
nowTileClassName,
tileDisabled,
value: valueProps,
view: viewProps,
Expand Down Expand Up @@ -1020,6 +1024,8 @@ const Calendar: React.ForwardRefExoticComponent<CalendarProps & React.RefAttribu
onClick,
onMouseOver: selectRange ? onMouseOver : undefined,
tileClassName,
activeClassName:activeTileClassName,
nowClassName:nowTileClassName,
tileContent,
tileDisabled,
value,
Expand Down
4 changes: 4 additions & 0 deletions packages/react-calendar/src/MonthView/Days.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export default function Days(props: DaysProps): React.ReactElement {
showNeighboringMonth,
value,
valueType,
activeClassName,
nowClassName,
...otherProps
} = props;

Expand Down Expand Up @@ -103,6 +105,8 @@ export default function Days(props: DaysProps): React.ReactElement {
dateType="day"
hover={hover}
end={end}
activeClassName={activeClassName}
nowClassName={nowClassName}
renderTile={({ date, ...otherTileProps }) => (
<Day
key={date.getTime()}
Expand Down
2 changes: 2 additions & 0 deletions packages/react-calendar/src/Tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type TileProps = {
* @example ({ activeStartDate, date, view }) => view === 'month' && date.getDay() === 3 ? 'wednesday' : null
*/
tileClassName?: TileClassNameFunc | ClassName;
activeClassName?:string;
nowClassName?:string;
/**
* Allows to render custom content within a given calendar item (day on month view, month on year view and so on).
*
Expand Down
9 changes: 8 additions & 1 deletion packages/react-calendar/src/TileGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import Flex from './Flex.js';
import { getTileClasses } from './shared/utils.js';

import type { RangeType, Value } from './shared/types.js';
import { useEffect } from 'react';

type TileGroupProps = {
className?: string;
activeClassName?:string
nowClassName?:string
count?: number;
dateTransform: (point: number) => Date;
dateType: RangeType;
Expand All @@ -25,6 +28,8 @@ export default function TileGroup({
dateTransform,
dateType,
end,
activeClassName,
nowClassName,
hover,
offset,
renderTile,
Expand All @@ -36,7 +41,7 @@ export default function TileGroup({
const tiles = [];
for (let point = start; point <= end; point += step) {
const date = dateTransform(point);

console.log(nowClassName,activeClassName)
tiles.push(
renderTile({
classes: getTileClasses({
Expand All @@ -45,6 +50,8 @@ export default function TileGroup({
hover,
value,
valueType,
activeClassName,
nowClassName,
}),
date,
}),
Expand Down
7 changes: 7 additions & 0 deletions packages/react-calendar/src/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export function getTileClasses(args: {
dateType?: RangeType;
hover?: Date | null;
value?: Value;
activeClassName?:string;
nowClassName?:string;
valueType?: RangeType;
}): string[] {
if (!args) {
Expand Down Expand Up @@ -110,6 +112,7 @@ export function getTileClasses(args: {

if (isValueWithinRange(now, dateRange)) {
classes.push(`${className}--now`);
if(args.nowClassName) classes.push(args.nowClassName)
}

if (!value || !isCompleteValue(value)) {
Expand All @@ -132,10 +135,14 @@ export function getTileClasses(args: {

if (isRangeWithinRange(valueRange, dateRange)) {
classes.push(`${className}--active`);
if(args.activeClassName) classes.push(args.activeClassName)
} else if (doRangesOverlap(valueRange, dateRange)) {
classes.push(`${className}--hasActive`);
if(args.activeClassName) classes.push(args.activeClassName)
}

console.log(classes)

const valueRangeClassNames = getRangeClassNames(valueRange, dateRange, `${className}--range`);

classes.push(...valueRangeClassNames);
Expand Down