Skip to content

Commit

Permalink
Remove code duplication (#277)
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj authored Nov 16, 2019
1 parent 25e80e2 commit fd95418
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Calendar/Navigation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export default function Navigation({
</button>
<button
aria-label={navigationAriaLabel}
className="react-calendar__navigation__label"
className={`${className}__label`}
disabled={!drillUpAvailable}
onClick={drillUp}
style={{ flexGrow: 1 }}
Expand Down
27 changes: 15 additions & 12 deletions src/MonthView/WeekNumber.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,31 @@ export default function WeekNumber({
onClickWeekNumber,
weekNumber,
}) {
const props = {
className: 'react-calendar__tile',
style: { flexGrow: 1 },
};

const children = (
<span>
{weekNumber}
</span>
);

return (
onClickWeekNumber
? (
<button
className="react-calendar__tile"
{...props}
onClick={() => onClickWeekNumber(weekNumber, date)}
style={{ flexGrow: 1 }}
type="button"
>
<span>
{weekNumber}
</span>
{children}
</button>
)
: (
<div
className="react-calendar__tile"
style={{ flexGrow: 1 }}
>
<span>
{weekNumber}
</span>
<div {...props}>
{children}
</div>
)
);
Expand Down
6 changes: 4 additions & 2 deletions src/MonthView/Weekdays.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { getDayOfWeek } from '../shared/dates';
import { formatWeekday, formatShortWeekday as defaultFormatShortWeekday } from '../shared/dateFormatter';
import { isCalendarType } from '../shared/propTypes';

const className = 'react-calendar__month-view__weekdays';

export default function Weekdays(props) {
const {
calendarType,
Expand All @@ -37,7 +39,7 @@ export default function Weekdays(props) {
weekdays.push(
<div
key={weekday}
className="react-calendar__month-view__weekdays__weekday"
className={`${className}__weekday`}
>
<abbr aria-label={abbr} title={abbr}>
{formatShortWeekday(locale, weekdayDate).replace('.', '')}
Expand All @@ -48,7 +50,7 @@ export default function Weekdays(props) {

return (
<Flex
className="react-calendar__month-view__weekdays"
className={className}
count={7}
onFocus={onMouseLeave}
onMouseOver={onMouseLeave}
Expand Down

0 comments on commit fd95418

Please sign in to comment.