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

Render TileGroup using css grid, fixes #222 #454

Open
wants to merge 1 commit 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
10 changes: 10 additions & 0 deletions src/Calendar.less
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
}

&__days {
display: grid;
grid-template-columns: repeat(7, 1fr);

&__day {
&--weekend {
color: rgb(209, 0, 0);
Expand All @@ -103,6 +106,13 @@
}
}

&__year-view__months,
&__decade-view__years,
&__century-view__decades {
display: grid;
grid-template-columns: repeat(3, 1fr);
}

&__tile {
max-width: 100%;
text-align: center;
Expand Down
1 change: 0 additions & 1 deletion src/MonthView/Days.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export default function Days(props) {
<TileGroup
{...otherProps}
className="react-calendar__month-view__days"
count={7}
currentMonthIndex={monthIndex}
dateTransform={(day) => {
const date = new Date();
Expand Down
15 changes: 5 additions & 10 deletions src/TileGroup.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import React from 'react';
import PropTypes from 'prop-types';

import Flex from './Flex';

import { getTileClasses } from './shared/utils';
import { tileGroupProps } from './shared/propTypes';

export default function TileGroup({
className,
count = 3,
dateTransform,
dateType,
end,
Expand All @@ -22,8 +19,9 @@ export default function TileGroup({
...tileProps
}) {
const tiles = [];
for (let point = start; point <= end; point += step) {
for (let point = start, i = 0; point <= end; point += step, i++) {
const date = dateTransform(point);
const style = i === 0 && offset ? { gridColumn: offset + 1 } : null;

tiles.push(
<Tile
Expand All @@ -33,27 +31,24 @@ export default function TileGroup({
})}
date={date}
point={point}
style={style}
{...tileProps}
/>,
);
}

return (
<Flex
<div
className={className}
count={count}
offset={offset}
wrap
>
{tiles}
</Flex>
</div>
);
}

TileGroup.propTypes = {
...tileGroupProps,
activeStartDate: PropTypes.instanceOf(Date),
count: PropTypes.number,
dateTransform: PropTypes.func.isRequired,
offset: PropTypes.number,
step: PropTypes.number,
Expand Down
28 changes: 28 additions & 0 deletions src/TileGroup.spec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { shallow } from 'enzyme';

import TileGroup from './TileGroup';

describe('<TileGroup /> component', () => {
const defaultProps = {
start: -5,
end: 36,
value: new Date(),
valueType: 'day',
date: new Date(),
dateType: 'day',
hover: null,
tile: () => null,
dateTransform: () => new Date(),
};

it('add style of offset if given', () => {
const offset = 2;
const component = shallow(
<TileGroup {...defaultProps} offset={offset} />,
);
const tiles = component.find('div').prop('children');

expect(tiles[0].props).toHaveProperty('style', { gridColumn: offset + 1 });
});
});