Prettier tooltips
This commit is contained in:
parent
3b86432c73
commit
ab7824aff7
|
|
@ -1,4 +1,4 @@
|
||||||
import { useState, useEffect, Fragment } from 'react';
|
import { useState, useEffect, useRef, Fragment } from 'react';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import localeData from 'dayjs/plugin/localeData';
|
import localeData from 'dayjs/plugin/localeData';
|
||||||
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
||||||
|
|
@ -8,6 +8,7 @@ import { useSettingsStore } from 'stores';
|
||||||
import { Legend, Center } from 'components';
|
import { Legend, Center } from 'components';
|
||||||
import {
|
import {
|
||||||
Wrapper,
|
Wrapper,
|
||||||
|
ScrollWrapper,
|
||||||
Container,
|
Container,
|
||||||
Date,
|
Date,
|
||||||
Times,
|
Times,
|
||||||
|
|
@ -19,6 +20,7 @@ import {
|
||||||
TooltipTitle,
|
TooltipTitle,
|
||||||
TooltipDate,
|
TooltipDate,
|
||||||
TooltipContent,
|
TooltipContent,
|
||||||
|
TooltipPerson,
|
||||||
TimeLabels,
|
TimeLabels,
|
||||||
TimeLabel,
|
TimeLabel,
|
||||||
TimeSpace,
|
TimeSpace,
|
||||||
|
|
@ -47,6 +49,8 @@ const AvailabilityViewer = ({
|
||||||
const [tempFocus, setTempFocus] = useState(null);
|
const [tempFocus, setTempFocus] = useState(null);
|
||||||
const [focusCount, setFocusCount] = useState(null);
|
const [focusCount, setFocusCount] = useState(null);
|
||||||
|
|
||||||
|
const wrapper = useRef();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setFilteredPeople(people.map(p => p.name));
|
setFilteredPeople(people.map(p => p.name));
|
||||||
setTouched(people.length <= 1);
|
setTouched(people.length <= 1);
|
||||||
|
|
@ -92,7 +96,8 @@ const AvailabilityViewer = ({
|
||||||
)}
|
)}
|
||||||
</StyledMain>
|
</StyledMain>
|
||||||
|
|
||||||
<Wrapper>
|
<Wrapper ref={wrapper}>
|
||||||
|
<ScrollWrapper>
|
||||||
<Container>
|
<Container>
|
||||||
<TimeLabels>
|
<TimeLabels>
|
||||||
{!!timeLabels.length && timeLabels.map((label, i) =>
|
{!!timeLabels.length && timeLabels.map((label, i) =>
|
||||||
|
|
@ -134,13 +139,14 @@ const AvailabilityViewer = ({
|
||||||
minPeople={tempFocus !== null ? 0 : Math.min(min, filteredPeople.length)}
|
minPeople={tempFocus !== null ? 0 : Math.min(min, filteredPeople.length)}
|
||||||
onMouseEnter={(e) => {
|
onMouseEnter={(e) => {
|
||||||
const cellBox = e.currentTarget.getBoundingClientRect();
|
const cellBox = e.currentTarget.getBoundingClientRect();
|
||||||
|
const wrapperBox = wrapper?.current?.getBoundingClientRect() ?? { x: 0, y: 0 };
|
||||||
const timeText = timeFormat === '12h' ? 'h:mma' : 'HH:mm';
|
const timeText = timeFormat === '12h' ? 'h:mma' : 'HH:mm';
|
||||||
setTooltip({
|
setTooltip({
|
||||||
x: Math.round(cellBox.x + cellBox.width/2),
|
x: Math.round(cellBox.x-wrapperBox.x + cellBox.width/2),
|
||||||
y: Math.round(cellBox.y + cellBox.height)+6,
|
y: Math.round(cellBox.y-wrapperBox.y + cellBox.height)+6,
|
||||||
available: `${peopleHere.length} / ${people.length} available`,
|
available: `${peopleHere.length} / ${people.length} available`,
|
||||||
date: parsedDate.hour(time.slice(0, 2)).minute(time.slice(2, 4)).format(isSpecificDates ? `${timeText} ddd, D MMM YYYY` : `${timeText} ddd`),
|
date: parsedDate.hour(time.slice(0, 2)).minute(time.slice(2, 4)).format(isSpecificDates ? `${timeText} ddd, D MMM YYYY` : `${timeText} ddd`),
|
||||||
people: peopleHere.join(', '),
|
people: peopleHere,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
onMouseLeave={() => {
|
onMouseLeave={() => {
|
||||||
|
|
@ -165,9 +171,19 @@ const AvailabilityViewer = ({
|
||||||
>
|
>
|
||||||
<TooltipTitle>{tooltip.available}</TooltipTitle>
|
<TooltipTitle>{tooltip.available}</TooltipTitle>
|
||||||
<TooltipDate>{tooltip.date}</TooltipDate>
|
<TooltipDate>{tooltip.date}</TooltipDate>
|
||||||
<TooltipContent>{tooltip.people}</TooltipContent>
|
{!!filteredPeople.length && (
|
||||||
|
<TooltipContent>
|
||||||
|
{tooltip.people.map(person =>
|
||||||
|
<TooltipPerson key={person}>{person}</TooltipPerson>
|
||||||
|
)}
|
||||||
|
{filteredPeople.filter(p => !tooltip.people.includes(p)).map(person =>
|
||||||
|
<TooltipPerson key={person} disabled>{person}</TooltipPerson>
|
||||||
|
)}
|
||||||
|
</TooltipContent>
|
||||||
|
)}
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
|
</ScrollWrapper>
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,13 @@
|
||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
|
|
||||||
export const Wrapper = styled.div`
|
export const Wrapper = styled.div`
|
||||||
overflow-x: auto;
|
overflow-y: visible;
|
||||||
margin: 20px 0;
|
margin: 20px 0;
|
||||||
|
position: relative;
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const ScrollWrapper = styled.div`
|
||||||
|
overflow-x: auto;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const Container = styled.div`
|
export const Container = styled.div`
|
||||||
|
|
@ -62,8 +67,8 @@ export const Time = styled.div`
|
||||||
`}
|
`}
|
||||||
|
|
||||||
background-image: linear-gradient(
|
background-image: linear-gradient(
|
||||||
${props => `${props.theme.primary}${Math.round(((props.peopleCount)/(props.maxPeople))*255).toString(16)}`},
|
${props => `${props.theme.primary}${Math.round((props.peopleCount/props.maxPeople)*255).toString(16)}`},
|
||||||
${props => `${props.theme.primary}${Math.round(((props.peopleCount)/(props.maxPeople))*255).toString(16)}`}
|
${props => `${props.theme.primary}${Math.round((props.peopleCount/props.maxPeople)*255).toString(16)}`}
|
||||||
);
|
);
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|
@ -73,7 +78,7 @@ export const Spacer = styled.div`
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const Tooltip = styled.div`
|
export const Tooltip = styled.div`
|
||||||
position: fixed;
|
position: absolute;
|
||||||
top: ${props => props.y}px;
|
top: ${props => props.y}px;
|
||||||
left: ${props => props.x}px;
|
left: ${props => props.x}px;
|
||||||
transform: translateX(-50%);
|
transform: translateX(-50%);
|
||||||
|
|
@ -83,6 +88,7 @@ export const Tooltip = styled.div`
|
||||||
background-color: ${props => props.theme.background}DD;
|
background-color: ${props => props.theme.background}DD;
|
||||||
max-width: 200px;
|
max-width: 200px;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
|
z-index: 100;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const TooltipTitle = styled.span`
|
export const TooltipTitle = styled.span`
|
||||||
|
|
@ -94,13 +100,26 @@ export const TooltipTitle = styled.span`
|
||||||
export const TooltipDate = styled.span`
|
export const TooltipDate = styled.span`
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
display: block;
|
display: block;
|
||||||
opacity: .7;
|
opacity: .8;
|
||||||
font-weight: 700;
|
font-weight: 600;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const TooltipContent = styled.span`
|
export const TooltipContent = styled.div`
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
display: block;
|
padding: 4px 0;
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const TooltipPerson = styled.span`
|
||||||
|
display: inline-block;
|
||||||
|
margin: 2px;
|
||||||
|
padding: 1px 4px;
|
||||||
|
border: 1px solid ${props => props.theme.primary};
|
||||||
|
border-radius: 3px;
|
||||||
|
|
||||||
|
${props => props.disabled && `
|
||||||
|
opacity: .5;
|
||||||
|
border-color: ${props.theme.text}
|
||||||
|
`}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const TimeLabels = styled.div`
|
export const TimeLabels = styled.div`
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue