-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/dev' into dev
- Loading branch information
Showing
25 changed files
with
196 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { useRef, useState } from 'react'; | ||
import { Text, Icon, CalendarMonthSelect, CalendarYearSelect, Button } from 'react-basics'; | ||
import { startOfMonth, endOfMonth } from 'date-fns'; | ||
import Icons from 'components/icons'; | ||
import { useLocale } from 'hooks'; | ||
import { formatDate } from 'lib/date'; | ||
import { getDateLocale } from 'lib/lang'; | ||
import styles from './MonthSelect.module.css'; | ||
|
||
const MONTH = 'month'; | ||
const YEAR = 'year'; | ||
|
||
export function MonthSelect({ date = new Date(), onChange }) { | ||
const { locale } = useLocale(); | ||
const [select, setSelect] = useState(null); | ||
const month = formatDate(date, 'MMMM', locale); | ||
const year = date.getFullYear(); | ||
const ref = useRef(); | ||
|
||
const handleSelect = value => { | ||
setSelect(state => (state !== value ? value : null)); | ||
}; | ||
|
||
const handleChange = date => { | ||
onChange(`range:${startOfMonth(date).getTime()}:${endOfMonth(date).getTime()}`); | ||
setSelect(null); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div ref={ref} className={styles.container}> | ||
<Button className={styles.input} variant="quiet" onClick={() => handleSelect(MONTH)}> | ||
<Text>{month}</Text> | ||
<Icon size="sm">{select === MONTH ? <Icons.Close /> : <Icons.ChevronDown />}</Icon> | ||
</Button> | ||
<Button className={styles.input} variant="quiet" onClick={() => handleSelect(YEAR)}> | ||
<Text>{year}</Text> | ||
<Icon size="sm">{select === YEAR ? <Icons.Close /> : <Icons.ChevronDown />}</Icon> | ||
</Button> | ||
</div> | ||
{select === MONTH && ( | ||
<CalendarMonthSelect date={date} locale={getDateLocale(locale)} onSelect={handleChange} /> | ||
)} | ||
{select === YEAR && ( | ||
<CalendarYearSelect date={date} locale={getDateLocale(locale)} onSelect={handleChange} /> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
export default MonthSelect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.container { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.input { | ||
display: flex; | ||
align-items: center; | ||
gap: 10px; | ||
cursor: pointer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
display: flex; | ||
flex-direction: column; | ||
padding-top: 40px; | ||
padding-right: 20px; | ||
} | ||
|
||
.content { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.