Skip to content

Commit 313a320

Browse files
authored
Improvement/dpr style (#315)
* improve the Date Range Picker aesthetics/UX
1 parent bfd19c6 commit 313a320

File tree

7 files changed

+141
-49
lines changed

7 files changed

+141
-49
lines changed

.eslintrc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
"react/jsx-one-expression-per-line": ["warn"],
2020
"jsx-a11y/mouse-events-have-key-events": ["warn"],
2121
"jsx-a11y/click-events-have-key-events": ["warn"],
22-
"jsx-a11y/no-static-element-interactions": ["warn"]
22+
"jsx-a11y/no-static-element-interactions": ["warn"],
23+
"jsx-a11y/label-has-associated-control": [ "error", {
24+
"required": {
25+
"some": [ "nesting", "id" ]
26+
}
27+
}]
2328
},
2429
"env": {
2530
"browser": true,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from "react";
2+
3+
// https://www.svgrepo.com/vectors/check/
4+
export default function CheckIcon() {
5+
return (
6+
<svg
7+
version="1.1"
8+
id="Capa_1"
9+
xmlns="http://www.w3.org/2000/svg"
10+
x="0px"
11+
y="0px"
12+
width="12px"
13+
height="12px"
14+
viewBox="0 0 405.272 405.272"
15+
>
16+
<g>
17+
<path
18+
d="M393.401,124.425L179.603,338.208c-15.832,15.835-41.514,15.835-57.361,0L11.878,227.836
19+
20+
c-15.838-15.835-15.838-41.52,0-57.358c15.841-15.841,41.521-15.841,57.355-0.006l81.698,81.699L336.037,67.064
21+
22+
c15.841-15.841,41.523-15.829,57.358,0C409.23,82.902,409.23,108.578,393.401,124.425z"
23+
/>
24+
</g>
25+
</svg>
26+
);
27+
}

webapp/javascript/components/CustomDatePicker.jsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ function CustomDatePicker({ setRange, dispatch, setDateRange }) {
3636
}, [from, until]);
3737

3838
return (
39-
<div>
39+
<div className="drp-custom">
4040
<h4>Custom Date Range</h4>
41-
<div className="form">
42-
<p style={{ marginBottom: "10px", color: "white" }}>From: </p>
41+
<div className="from">
42+
<label htmlFor="datepicker-from">From: </label>
4343
<DatePicker
44+
id="datepicker-from"
4445
selected={selectedDate.from}
4546
onChange={(date) => {
4647
setSelectedDate({ ...selectedDate, from: date });
@@ -52,8 +53,9 @@ function CustomDatePicker({ setRange, dispatch, setDateRange }) {
5253
/>
5354
</div>
5455
<div className="until">
55-
<p style={{ marginBottom: "10px", color: "white" }}>Until: </p>
56+
<label htmlFor="datepicker-until">Until: </label>
5657
<DatePicker
58+
id="datepicker-until"
5759
selected={selectedDate.until}
5860
onChange={(date) => {
5961
setSelectedDate({ ...selectedDate, until: date });
@@ -69,13 +71,8 @@ function CustomDatePicker({ setRange, dispatch, setDateRange }) {
6971
{warning && <p style={{ color: "red" }}>Warning: invalid date Range</p>}
7072

7173
<button
72-
style={{
73-
marginTop: "20px",
74-
backgroundColor: "#2ECC40",
75-
color: "white",
76-
}}
7774
type="submit"
78-
className="btn"
75+
className="btn primary"
7976
onClick={() => updateDateRange()}
8077
>
8178
Apply range

webapp/javascript/components/DateRangePicker.jsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { faClock } from "@fortawesome/free-solid-svg-icons";
66
import OutsideClickHandler from "react-outside-click-handler";
77
import CustomDatePicker from "./CustomDatePicker";
88
import { setDateRange } from "../redux/actions";
9+
import CheckIcon from "./CheckIcon";
910

1011
const defaultPresets = [
1112
[
@@ -60,24 +61,27 @@ function DateRangePicker() {
6061
<span>{range}</span>
6162
</button>
6263
<div className="drp-dropdown">
63-
<h4>Quick Presets</h4>
64-
<div className="drp-presets">
65-
{defaultPresets.map((arr, i) => (
66-
<div key={`preset-${i + 1}`} className="drp-preset-column">
67-
{arr.map((x) => (
68-
<button
69-
type="button"
70-
className={`drp-preset ${
71-
x.label === range ? "active" : ""
72-
}`}
73-
key={x.label}
74-
onClick={() => selectPreset(x)}
75-
>
76-
{x.label}
77-
</button>
78-
))}
79-
</div>
80-
))}
64+
<div className="drp-quick-presets">
65+
<h4>Quick Presets</h4>
66+
<div className="drp-presets">
67+
{defaultPresets.map((arr, i) => (
68+
<div key={`preset-${i + 1}`} className="drp-preset-column">
69+
{arr.map((x) => (
70+
<button
71+
type="button"
72+
className={`drp-preset ${
73+
x.label === range ? "active" : ""
74+
}`}
75+
key={x.label}
76+
onClick={() => selectPreset(x)}
77+
>
78+
{x.label}
79+
{x.label === range ? <CheckIcon /> : false}
80+
</button>
81+
))}
82+
</div>
83+
))}
84+
</div>
8185
</div>
8286
<CustomDatePicker
8387
setRange={setRange}

webapp/sass/components/button.scss

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
@use "../variables"as *;
2+
@use "../mixins/outline"as *;
3+
4+
.btn {
5+
@include outline;
6+
7+
white-space: nowrap;
8+
overflow: hidden;
9+
text-overflow: ellipsis;
10+
11+
cursor: pointer;
12+
13+
border: 1px solid $btn-border-color;
14+
border-radius: 4px;
15+
background: $btn-color;
16+
17+
&:hover {
18+
background: $btn-hover-color;
19+
}
20+
}
21+
22+
// inspired by .viz-switch .btn
23+
.btn.primary {
24+
$active-color: #269f34;
25+
26+
background-color: $active-color;
27+
border-left-color: $active-color;
28+
border-right-color: $active-color;
29+
border-top-color: $active-color;
30+
border-bottom-color: $active-color;
31+
transition: 0.3s cubic-bezier(.17,.67,.83,.67);
32+
font-weight: 600;
33+
34+
&:hover {
35+
background-color: #2ecc40;
36+
}
37+
}

webapp/sass/components/daterangepicker.scss

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
.drp-presets {
5050
display: flex;
5151
flex-direction: row;
52+
53+
// cancel the padding from drp-container
54+
// so that it spams the whole row
55+
margin-left: -20px;
56+
margin-right: -20px;
57+
5258
.drp-preset-column {
5359
flex: 1;
5460
display: flex;
@@ -57,17 +63,35 @@
5763
}
5864
}
5965

66+
.drp-custom {
67+
margin-top: 20px;
68+
}
69+
6070
.drp-preset {
6171
@include outline;
6272

73+
6374
border: none;
6475
text-align: left;
6576
padding: 2px 0;
77+
// compensates for the negative margin in .drp-presets
78+
padding-left: 20px;
6679
color: rgba(255, 255, 255, 0.66);
6780

81+
// give some room between the text and the icon
82+
// https://web.dev/learn/css/logical-properties/#solving-the-icon-issue
83+
svg {
84+
margin-inline-start: 0.5em;
85+
}
86+
6887
&:hover,
6988
&.active {
7089
color: rgba(255, 255, 255, 1);
90+
background: $btn-hover-color;
91+
}
92+
93+
&:hover{
94+
cursor: pointer;
7195
}
7296
}
7397

@@ -84,6 +108,23 @@
84108
}
85109
}
86110

111+
// Custom Date Range block
112+
.drp-custom {
113+
// label should be on its own line
114+
label {
115+
display: block;
116+
}
117+
118+
.until {
119+
margin-top: 10px;
120+
}
121+
122+
// submit button
123+
button {
124+
margin-top: 20px;
125+
}
126+
}
127+
87128
// range picker custom styles
88129
.react-datepicker__day--in-range {
89130
background-color: #216ba5 !important;

webapp/sass/profile.scss

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
@use "components/daterangepicker";
44
@use "components/labels";
55
@use "components/exportdata";
6+
@use "components/button";
67

78
@import "~sanitize.css";
89
@import "~sanitize.css/forms.css";
@@ -85,26 +86,6 @@ tt {
8586
flex: 1;
8687
}
8788

88-
.btn {
89-
@include outline;
90-
91-
white-space: nowrap;
92-
overflow: hidden;
93-
text-overflow: ellipsis;
94-
95-
cursor: pointer;
96-
97-
// height: 30px;
98-
// line-height: 30px;
99-
border: 1px solid $btn-border-color;
100-
border-radius: 4px;
101-
background: $btn-color;
102-
103-
&:hover {
104-
background: $btn-hover-color;
105-
}
106-
}
107-
10889
select {
10990
@include outline;
11091
display: inline-block;

0 commit comments

Comments
 (0)