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';
4
4
import Dayzed from 'dayzed' ;
5
5
import Button from '../button' ;
6
6
import CalendarCell from '../cell' ;
7
+ import { getToday } from '../../utils' ;
7
8
import { monthNamesShort , weekdayNamesShort } from '../../data' ;
8
9
import 'semantic-ui-css/semantic.min.css' ;
9
10
import './calendar.css' ;
@@ -13,6 +14,7 @@ const Calendar = ({
13
14
onDateSelected,
14
15
selected,
15
16
selectedClassName,
17
+ showToday,
16
18
...otherProps
17
19
} ) => (
18
20
< Dayzed
@@ -77,6 +79,15 @@ const Calendar = ({
77
79
) ;
78
80
} )
79
81
) }
82
+ { showToday && (
83
+ < CalendarCell
84
+ fluid
85
+ { ...getToday ( selected ) }
86
+ { ...getDateProps ( { dateObj : getToday ( selected ) } ) }
87
+ >
88
+ Today
89
+ </ CalendarCell >
90
+ ) }
80
91
</ div >
81
92
</ Segment >
82
93
) )
@@ -89,10 +100,12 @@ Calendar.propTypes = {
89
100
onDateSelected : PropTypes . func ,
90
101
selected : PropTypes . instanceOf ( Date ) ,
91
102
selectedClassName : PropTypes . string ,
103
+ showToday : PropTypes . bool ,
92
104
} ;
93
105
94
106
Calendar . defaultProps = {
95
107
onDateSelected : ( ) => { } ,
108
+ showToday : true ,
96
109
} ;
97
110
98
111
export default Calendar ;
Original file line number Diff line number Diff line change 18
18
background : # 4f4f4f ;
19
19
color : # f2f2f2 ;
20
20
}
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';
4
4
import './cell.css' ;
5
5
6
6
const CalendarCell = ( {
7
+ fluid,
7
8
selectable,
8
9
selected,
9
10
selectedClassName,
@@ -12,6 +13,7 @@ const CalendarCell = ({
12
13
} ) => (
13
14
< span
14
15
className = { cn ( 'clndr-cell' , {
16
+ 'clndr-cell-full' : fluid ,
15
17
'clndr-cell-today' : today ,
16
18
'clndr-cell-disabled' : ! selectable ,
17
19
[ selectedClassName ] : selected ,
@@ -21,6 +23,7 @@ const CalendarCell = ({
21
23
) ;
22
24
23
25
CalendarCell . propTypes = {
26
+ fluid : PropTypes . bool ,
24
27
selected : PropTypes . bool ,
25
28
selectable : PropTypes . bool ,
26
29
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