Skip to content

Commit

Permalink
Merge pull request #282 from hackforla/175-FRONT-HoverOverInfo
Browse files Browse the repository at this point in the history
Closes #175 
added HoverOverInfo component
  • Loading branch information
adamkendis authored Feb 23, 2020
2 parents 9d819b4 + 2ecad4b commit 3571bea
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"react-leaflet-choropleth": "^2.0.0",
"react-redux": "^7.1.3",
"react-test-renderer": "^16.12.0",
"react-tooltip": "^4.0.3",
"react-vis": "^1.11.7",
"redux": "^4.0.4",
"redux-devtools-extension": "^2.13.8",
Expand Down
2 changes: 2 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { connect } from 'react-redux';
import Header from './components/main/header/Header';
import Body from './components/main/body/Body';
import Footer from './components/main/footer/Footer';
import Tooltip from './components/main/tooltip/Tooltip';

const App = () => {
useEffect(() => {
Expand All @@ -15,6 +16,7 @@ const App = () => {
<Header />
<Body />
<Footer />
<Tooltip />
</div>
);
};
Expand Down
28 changes: 28 additions & 0 deletions src/components/common/HoverOverInfo.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import PropTypes from 'proptypes';

const HoverOverInfo = ({
title,
text,
position,
children
}) => (
<span
data-for="react-tooltip"
data-tip={JSON.stringify({ title, text })}
data-place={position}>
{ children }
</span>
);

export default HoverOverInfo;

HoverOverInfo.propTypes = {
title: PropTypes.string,
text: PropTypes.string,
position: PropTypes.oneOf(['top', 'bottom', 'left', 'right']),
};

HoverOverInfo.defaultProps = {
position: 'right'
};
15 changes: 14 additions & 1 deletion src/components/main/menu/DateSelector/DateSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
import Dropdown from '../../../common/Dropdown';
import Modal from '../../../common/Modal';
import DateRangePicker from './DateRangePicker';
import Icon from '../../../common/Icon';
import HoverOverInfo from '../../../common/HoverOverInfo';

import COLORS from '../../../../styles/COLORS';

Expand Down Expand Up @@ -88,9 +90,20 @@ const DateSelector = ({
}}
>
<div className="date-selector-title">
<span className="has-text-weight-bold is-size-6">
<span
className="has-text-weight-bold is-size-6"
style={{ paddingRight: '10px' }}>
Date Range Selection
</span>
<HoverOverInfo
title="Date Range Selection"
text="This filter allows the user to choose a date range for 311 data.">
<Icon
id="type-selector-info-icon"
icon="info-circle"
size="small"
/>
</HoverOverInfo>
</div>
<div className="date-selector-dates" style={{ padding: '15px 0 10px' }}>
<span className="has-text-weight-normal">
Expand Down
13 changes: 12 additions & 1 deletion src/components/main/menu/NCSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { updateNC } from '../../../redux/reducers/data';

import { COUNCILS } from '../../common/CONSTANTS';
import Checkbox from '../../common/Checkbox';
import Icon from '../../common/Icon';
import HoverOverInfo from '../../common/HoverOverInfo';

const NCSelector = ({
updateNCList,
Expand Down Expand Up @@ -68,9 +70,18 @@ const NCSelector = ({
<div className="nc-selector" style={{ width: '349px' }}>
<div className="nc-title">
<p className="is-size-6" style={{ padding: '15px 0' }}>
<strong>
<strong style={{ paddingRight: '10px' }}>
Neighborhood Council (NC) Selection
</strong>
<HoverOverInfo
title="Neighborhood Council (NC) Selection"
text="This filter allows the user to select specific neighborhood councils.">
<Icon
id="type-selector-info-icon"
icon="info-circle"
size="small"
/>
</HoverOverInfo>
</p>
</div>

Expand Down
15 changes: 10 additions & 5 deletions src/components/main/menu/RequestTypeSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {

import Checkbox from '../../common/Checkbox';
import Icon from '../../common/Icon';
import HoverOverInfo from '../../common/HoverOverInfo';

import { REQUEST_TYPES } from '../../common/CONSTANTS';
import COLORS from '../../../styles/COLORS';
Expand Down Expand Up @@ -105,11 +106,15 @@ const RequestTypeSelector = ({
>
Request Type Selection
</span>
<Icon
id="type-selector-info-icon"
icon="info-circle"
size="small"
/>
<HoverOverInfo
title="Request Type Selection"
text="This filter allows the user to choose specific 311 data types.">
<Icon
id="type-selector-info-icon"
icon="info-circle"
size="small"
/>
</HoverOverInfo>
</div>
<div className="columns is-0" style={{ width: '475px' }}>
<div className="column" style={{ paddingRight: '8px' }}>
Expand Down
42 changes: 42 additions & 0 deletions src/components/main/tooltip/Tooltip.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import ReactTooltip from 'react-tooltip';
import Icon from '../../common/Icon';
import COLORS from '../../../styles/COLORS';
import './styles.scss';

const Tooltip = () => (
<div className="tooltip">
<ReactTooltip
id="react-tooltip"
effect="solid"
getContent={data => {
if (!data) return null;
let { text, title } = JSON.parse(data);
if (!text && !title) return null;

return (
<div style={{ color: COLORS.BRAND.MAIN }}>
{ title &&
<div className="has-text-weight-bold is-size-6">
<Icon
id="react-tooltip-icon"
icon="info-circle"
size="small"
style={{ marginRight: '6px' }}
/>
{ title }
</div>
}
{ text &&
<div className="tooltip-text is-size-6">
{ text }
</div>
}
</div>
);
}}
/>
</div>
);

export default Tooltip;
24 changes: 24 additions & 0 deletions src/components/main/tooltip/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.tooltip {
position: absolute;
z-index: 1101; // must exceed z-index of the side menu (1100)

$bg-color: rgb(200, 200, 200);

#react-tooltip {
background-color: $bg-color;
max-width: 200px;
padding: 8px 12px;
word-break: break-word;
line-height: 20px;
opacity: 1.0;

&.place-right:after { border-right-color: $bg-color; }
&.place-top:after { border-top-color: $bg-color; }
&.place-left:after { border-left-color: $bg-color; }
&.place-bottom:after { border-bottom-color: $bg-color; }

.tooltip-text {
margin-top: 6px;
}
}
}

0 comments on commit 3571bea

Please sign in to comment.