File tree Expand file tree Collapse file tree 4 files changed +45
-0
lines changed
Expand file tree Collapse file tree 4 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { Segment } from 'semantic-ui-react';
44import Dayzed from 'dayzed' ;
55import Button from '../button' ;
66import CalendarCell from '../cell' ;
7+ import { getToday } from '../../utils' ;
78import { monthNamesShort , weekdayNamesShort } from '../../data' ;
89import 'semantic-ui-css/semantic.min.css' ;
910import './calendar.css' ;
@@ -13,6 +14,7 @@ const Calendar = ({
1314 onDateSelected,
1415 selected,
1516 selectedClassName,
17+ showToday,
1618 ...otherProps
1719} ) => (
1820 < Dayzed
@@ -77,6 +79,15 @@ const Calendar = ({
7779 ) ;
7880 } )
7981 ) }
82+ { showToday && (
83+ < CalendarCell
84+ fluid
85+ { ...getToday ( selected ) }
86+ { ...getDateProps ( { dateObj : getToday ( selected ) } ) }
87+ >
88+ Today
89+ </ CalendarCell >
90+ ) }
8091 </ div >
8192 </ Segment >
8293 ) )
@@ -89,10 +100,12 @@ Calendar.propTypes = {
89100 onDateSelected : PropTypes . func ,
90101 selected : PropTypes . instanceOf ( Date ) ,
91102 selectedClassName : PropTypes . string ,
103+ showToday : PropTypes . bool ,
92104} ;
93105
94106Calendar . defaultProps = {
95107 onDateSelected : ( ) => { } ,
108+ showToday : true ,
96109} ;
97110
98111export default Calendar ;
Original file line number Diff line number Diff line change 1818 background : # 4f4f4f ;
1919 color : # f2f2f2 ;
2020}
21+
22+ .clndr-cell-full {
23+ grid-column : 1 / -1 ;
24+ }
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import cn from 'classnames';
44import './cell.css' ;
55
66const CalendarCell = ( {
7+ fluid,
78 selectable,
89 selected,
910 selectedClassName,
@@ -12,6 +13,7 @@ const CalendarCell = ({
1213} ) => (
1314 < span
1415 className = { cn ( 'clndr-cell' , {
16+ 'clndr-cell-full' : fluid ,
1517 'clndr-cell-today' : today ,
1618 'clndr-cell-disabled' : ! selectable ,
1719 [ selectedClassName ] : selected ,
@@ -21,6 +23,7 @@ const CalendarCell = ({
2123) ;
2224
2325CalendarCell . propTypes = {
26+ fluid : PropTypes . bool ,
2427 selected : PropTypes . bool ,
2528 selectable : PropTypes . bool ,
2629 selectedClassName : PropTypes . string ,
Original file line number Diff line number Diff line change 1+ export const normalizeDate = date => {
2+ const newDate = new Date ( date . getTime ( ) ) ;
3+ newDate . setHours ( 0 , 0 , 0 , 0 ) ;
4+
5+ return newDate ;
6+ } ;
7+
8+ const isEqual = ( date , dateToCompare ) => {
9+ if ( ! date || ! dateToCompare ) {
10+ return false ;
11+ }
12+
13+ return (
14+ normalizeDate ( date ) . getTime ( ) === normalizeDate ( dateToCompare ) . getTime ( )
15+ ) ;
16+ } ;
17+
18+ export const getToday = selected => {
19+ return {
20+ date : normalizeDate ( new Date ( ) ) ,
21+ selectable : true ,
22+ selected : isEqual ( new Date ( ) , selected ) ,
23+ today : true ,
24+ } ;
25+ } ;
You can’t perform that action at this time.
0 commit comments