-
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(hover-legend): add legend with hover values (#807)
* feat(hover-legend): add legend with hover values * refactor(legend): remove ternary operator * refactor(legend): rename to hoverLegendValues * refactor(layers): remove legendValues from interface * refactor(hoverLegend): add legend values to metadata, add legend component * refactor(styles): remove classnames
- Loading branch information
1 parent
124b76f
commit f972072
Showing
9 changed files
with
251 additions
and
9 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
73 changes: 73 additions & 0 deletions
73
src/scripts/components/layers/hover-legend/hover-legend.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,73 @@ | ||
@require '../../../../variables.styl' | ||
|
||
.hoverLegend | ||
position: absolute | ||
top: 50% | ||
left: emCalc(22px) | ||
z-index: 1 | ||
display: flex | ||
flex-direction: row | ||
height: 40% | ||
color: white | ||
transform: translateY(-50%) | ||
user-select: none | ||
|
||
.rightSided | ||
right: emCalc(22px) | ||
left: auto | ||
flex-direction: row-reverse | ||
|
||
.values | ||
padding-right: emCalc(8px, 14) | ||
padding-left: 0 | ||
text-align: right | ||
|
||
.color | ||
width: 8px | ||
height: 100% | ||
|
||
.values | ||
display: flex | ||
flex-direction: column | ||
justify-content: space-between | ||
padding-left: emCalc(8px, 14) | ||
text-shadow: 0px 0px 2px $plainBlack | ||
font-size: 14px | ||
font-family: 'NotesESA', 'Arial', sans-serif | ||
|
||
.hoverLegend | ||
display: flex | ||
flex-direction: column | ||
|
||
> :first-child | ||
.color | ||
border-top-left-radius: 5px | ||
border-top-right-radius: 5px | ||
|
||
> :last-child | ||
.color | ||
border-bottom-right-radius: 5px | ||
border-bottom-left-radius: 5px | ||
|
||
> :hover | ||
.color | ||
box-shadow: inset 0 0 0.1em $plainBlack | ||
|
||
.legendItem | ||
display: flex | ||
width: 100% | ||
height: 100% | ||
|
||
.hoverValue | ||
position: absolute | ||
display: block | ||
margin: 0 emCalc(15px) | ||
width: max-content | ||
text-shadow: 0px 0px 2px $plainBlack | ||
font-size: 14px | ||
font-family: 'NotesESA', 'Arial', sans-serif | ||
line-height: 50% | ||
|
||
.rightSided | ||
.legendItem | ||
flex-direction: row-reverse |
34 changes: 34 additions & 0 deletions
34
src/scripts/components/layers/hover-legend/hover-legend.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,34 @@ | ||
import React, {FunctionComponent, useState} from 'react'; | ||
import cx from 'classnames'; | ||
|
||
import {LegendValueColor} from '../../../types/legend-value-color'; | ||
|
||
import styles from './hover-legend.styl'; | ||
|
||
interface Props { | ||
values: LegendValueColor[]; | ||
isCompare?: boolean; | ||
} | ||
|
||
const HoverLegend: FunctionComponent<Props> = ({values, isCompare}) => { | ||
const [legendValue, setLegendValue] = useState(''); | ||
|
||
return ( | ||
<div className={cx(styles.hoverLegend, isCompare && styles.rightSided)}> | ||
{values.map((legendItem, index) => ( | ||
<div className={styles.legendItem} key={index}> | ||
<div | ||
className={styles.color} | ||
style={{backgroundColor: legendItem.color}} | ||
onMouseOver={() => setLegendValue(legendItem.value)} | ||
onMouseLeave={() => setLegendValue('')}></div> | ||
{legendValue === legendItem.value && ( | ||
<span className={styles.hoverValue}>{legendValue}</span> | ||
)} | ||
</div> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default HoverLegend; |
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,4 @@ | ||
export interface LegendValueColor { | ||
value: string; | ||
color: string; | ||
} |