-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split the TimeFrameSelector into separate components and update the r…
…esponsive styles
- Loading branch information
1 parent
8681cbd
commit c3bd28e
Showing
7 changed files
with
137 additions
and
56 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
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,86 @@ | ||
import { useState, useEffect, forwardRef } from 'react' | ||
import { Button } from '@chakra-ui/react' | ||
import { DateRangePicker } from '../calendar' | ||
import './TimeframeMenu.scss' | ||
|
||
const chartConfig = { | ||
timespan: { | ||
defaultIndex: 3, | ||
values: [ | ||
{ | ||
label: '1 hour', | ||
range: '1h' | ||
}, | ||
{ | ||
label: '24 hours', | ||
range: '24h' | ||
}, | ||
{ | ||
label: '3 days', | ||
range: '3d' | ||
}, | ||
{ | ||
label: '1 week', | ||
range: '1w' | ||
} | ||
] | ||
} | ||
} | ||
|
||
const TimeframeMenu = forwardRef(function TimeframeMenu ({ config, isActive, changeCallback, openStateCallback, className }, ref) { | ||
const [timespan, setTimespan] = useState(chartConfig.timespan.values[chartConfig.timespan.defaultIndex]) | ||
const [menuIsOpen, setMenuIsOpen] = useState(false) | ||
|
||
const changeHandler = (value) => { | ||
setTimespan(value) | ||
if (typeof changeCallback === 'function') changeCallback(value) | ||
} | ||
|
||
useEffect(() => { | ||
if (!isActive) setMenuIsOpen(false) | ||
}, [isActive]) | ||
|
||
useEffect(() => { | ||
if (typeof openStateCallback === 'function') openStateCallback(menuIsOpen) | ||
}, [menuIsOpen]) | ||
|
||
const calendarHandler = (value) => {} | ||
|
||
return ( | ||
<div ref={ref} className={`TimeframeMenu ${className || ''}`}> | ||
<div className={'TimeframeMenu__ValuesContainer'}> | ||
<div className={'TimeframeMenu__ValuesTitle'}> | ||
Select a day, period or Timeframe: | ||
</div> | ||
|
||
<div className={'TimeframeMenu__Values'}> | ||
{config.timespan.values.map((iTimespan, i) => ( | ||
<Button | ||
className={`TimeframeMenu__ValueButton ${iTimespan.range === timespan.range ? 'TimeframeMenu__ValueButton--Active' : ''}`} | ||
onClick={() => { | ||
changeHandler(iTimespan) | ||
setMenuIsOpen(false) | ||
}} | ||
key={i} | ||
size={'xs'} | ||
> | ||
{iTimespan.label} | ||
</Button> | ||
))} | ||
</div> | ||
</div> | ||
|
||
<div className={'TimeframeMenu__Calendar TimeframeMenu__Calendar--Stub'}> | ||
<DateRangePicker | ||
disableFutureDates={true} | ||
monthsToShow={7} | ||
noTopNavigation={true} | ||
noWeekDay={true} | ||
changeHandler={calendarHandler} | ||
/> | ||
</div> | ||
</div> | ||
) | ||
}) | ||
|
||
export default TimeframeMenu |
4 changes: 2 additions & 2 deletions
4
...c/app/validator/[hash]/TimeframeMenu.scss → .../src/components/charts/TimeframeMenu.scss
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