gonito-frontend/src/components/elements/IconLabel.js

103 lines
2.8 KiB
JavaScript
Raw Normal View History

2022-07-07 15:45:29 +02:00
import React from "react";
import {FlexRow, Svg} from "../../utils/containers";
2022-07-08 11:55:15 +02:00
import {Body, Medium} from "../../utils/fonts";
import metricIco from '../../assets/metric_ico.svg';
import coinsIco from '../../assets/coins_ico.svg';
import baselineIco from '../../assets/baseline_ico.svg';
import clockIco from '../../assets/clock_ico.svg';
import cupIco from '../../assets/cup_ico.svg';
import styled from "styled-components";
import textIco from '../../assets/text_ico.svg';
import tabularIco from '../../assets/tabular_ico.svg';
import imageIco from '../../assets/image_ico.svg';
2022-07-08 11:55:15 +02:00
const HoverLabel = styled(Body)`
position: absolute;
top: -32px;
left: ${({type}) => (type === 'text' || type === 'image' || type === 'tabular') ? '-32px' : 0};
width: 100px;
2022-07-08 11:55:15 +02:00
display: none;
justify-content: center;
align-items: center;
border-radius: 6px;
padding: 4px 12px;
background-color: ${({theme}) => theme.colors.green};
color: ${({theme}) => theme.colors.white};
`;
const renderHoverLabel = (type) => {
const hoverLabel = (label) =>
<HoverLabel className='HoverLabel' type={type}>
{label}
</HoverLabel>;
2022-07-08 11:55:15 +02:00
switch (type) {
case 'metric':
return hoverLabel('metric');
2022-07-08 11:55:15 +02:00
case 'prize':
return hoverLabel('prize');
2022-07-08 11:55:15 +02:00
case 'baseline':
return hoverLabel('baseline');
case 'deadline':
return hoverLabel('deadline');
2022-07-08 11:55:15 +02:00
case 'bestScore':
return hoverLabel('best score');
case 'text':
return hoverLabel('text data');
case 'image':
return hoverLabel('image data');
case 'tabular':
return hoverLabel('tabular data');
default:
return '';
2022-07-08 11:55:15 +02:00
}
}
const renderIco = (type) => {
switch (type) {
case 'metric':
return metricIco;
case 'prize':
return coinsIco;
case 'baseline':
return baselineIco;
case 'deadline':
2022-07-08 11:55:15 +02:00
return clockIco;
case 'bestScore':
return cupIco;
case 'text':
return textIco;
case 'image':
return imageIco;
case 'tabular':
return tabularIco;
default:
return '';
2022-07-08 11:55:15 +02:00
}
}
const IconLabelStyle = styled(FlexRow)`
position: relative;
&:hover {
.HoverLabel {
display: flex;
}
}
`
2022-07-07 15:45:29 +02:00
const IconLabel = (props) => {
return (
2022-07-08 11:55:15 +02:00
<IconLabelStyle gap={props.gap}>
<Svg width={props.size} height={props.size}
2022-07-08 11:55:15 +02:00
src={renderIco(props.type)}/>
{props.children ?
<Medium as='p'>
{props.children}
</Medium> : ''}
2022-07-08 11:55:15 +02:00
{renderHoverLabel(props.type)}
</IconLabelStyle>
2022-07-07 15:45:29 +02:00
);
}
export default IconLabel;