-
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.
feat(time-slider): highlight active ticks (#341)
- Loading branch information
Showing
5 changed files
with
146 additions
and
103 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/scripts/components/time-slider-range/time-slider-range.styl
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,35 @@ | ||
@require '../../../variables.styl' | ||
|
||
$range-height = 5px | ||
|
||
boxShadow() | ||
box-shadow: 0px 1px 5px rgba(0, 0, 0, 0.2), 0px 3px 4px rgba(0, 0, 0, 0.12), 0px 2px 4px rgba(0, 0, 0, 0.14) | ||
|
||
.track | ||
position: absolute | ||
top: $range-height | ||
width: 100% | ||
height: $range-height | ||
border-radius: emCalc(2px) | ||
background: $darkGrey4 | ||
|
||
&:not(:first-of-type) | ||
top: $range-height * 3 | ||
|
||
.range | ||
position: absolute | ||
top: 0 | ||
z-index: 1 | ||
display: flex | ||
height: $range-height | ||
border-radius: emCalc(2px) | ||
background: $main | ||
|
||
.tick | ||
position: absolute | ||
width: emCalc(5px) | ||
height: emCalc(5px) | ||
border-radius: 50% | ||
background-color: rgba($darkGrey4, 0.5) | ||
transition: 0.2s all ease-out | ||
transform: translateX(-50%) |
52 changes: 52 additions & 0 deletions
52
src/scripts/components/time-slider-range/time-slider-range.tsx
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,52 @@ | ||
import React, {FunctionComponent} from 'react'; | ||
import {TimeRange} from '../../types/time-range'; | ||
|
||
import styles from './time-slider-range.styl'; | ||
|
||
interface Props { | ||
range: TimeRange; | ||
combined: TimeRange; | ||
selectedTimeIndex: number; | ||
} | ||
|
||
const TimeSliderRange: FunctionComponent<Props> = ({ | ||
range, | ||
combined, | ||
selectedTimeIndex | ||
}) => { | ||
const totalRange = combined.max - combined.min; | ||
const left = Math.round(((range.min - combined.min) / totalRange) * 100); | ||
const right = | ||
100 - Math.round(((range.max - combined.min) / totalRange) * 100); | ||
const rangeStyle = { | ||
left: `${left}%`, | ||
right: `${right}%` | ||
}; | ||
|
||
const getTickStyle = (timestamp: string, isSelected: boolean) => { | ||
const tickPosition = | ||
((Date.parse(timestamp) - range.min) / (range.max - range.min)) * 100; | ||
|
||
return { | ||
left: `${tickPosition}%`, | ||
backgroundColor: isSelected ? 'white' : undefined, // eslint-disable-line no-undefined | ||
transform: isSelected ? 'translateX(-50%) scale(2)' : undefined // eslint-disable-line no-undefined | ||
}; | ||
}; | ||
|
||
return ( | ||
<div className={styles.track}> | ||
<div className={styles.range} style={rangeStyle}> | ||
{range.timestamps.map((timestamp, index) => ( | ||
<div | ||
key={timestamp} | ||
className={styles.tick} | ||
style={getTickStyle(timestamp, index === selectedTimeIndex)} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default TimeSliderRange; |
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