Skip to content

Commit c4d50c2

Browse files
chore: css improvements
Signed-off-by: Henry Gressmann <[email protected]>
1 parent 1f89af3 commit c4d50c2

File tree

9 files changed

+156
-72
lines changed

9 files changed

+156
-72
lines changed

web/src/components/card.module.css

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
a.card {
2+
all: unset;
3+
cursor: pointer;
4+
5+
position: relative;
6+
box-sizing: border-box;
7+
user-select: none;
8+
z-index: 0;
9+
display: inline-flex;
10+
align-items: center;
11+
gap: 0.4rem;
12+
13+
margin: 0;
14+
padding: 0.3rem 0.4rem 0.3rem 0.5rem;
15+
16+
transition: background-color 0.2s ease;
17+
border-radius: var(--pico-border-radius);
18+
19+
&::before {
20+
content: "";
21+
position: absolute;
22+
z-index: -1;
23+
top: 0;
24+
left: 0;
25+
right: 0;
26+
bottom: 0;
27+
border-radius: var(--pico-border-radius);
28+
background-color: var(--pico-card-background-color);
29+
box-shadow: var(--pico-card-box-shadow);
30+
opacity: 0.8;
31+
transition: opacity 0.2s ease;
32+
}
33+
34+
&:hover {
35+
&::before {
36+
opacity: 1;
37+
}
38+
}
39+
}
40+
41+
button.card {
42+
all: unset;
43+
cursor: pointer;
44+
45+
position: relative;
46+
box-sizing: border-box;
47+
user-select: none;
48+
z-index: 0;
49+
50+
margin: 0;
51+
padding: 0.5rem 0.5rem 0.3rem 0.5rem;
52+
53+
transition: background-color 0.2s ease;
54+
border-radius: var(--pico-border-radius);
55+
56+
&::before {
57+
content: "";
58+
position: absolute;
59+
z-index: -1;
60+
top: 0;
61+
left: 0;
62+
right: 0;
63+
bottom: 0;
64+
border-radius: var(--pico-border-radius);
65+
background-color: var(--pico-card-background-color);
66+
opacity: 0;
67+
transform: scale(0.94) scaleX(1.04);
68+
transition: opacity 0.2s ease, transform 0.2s ease;
69+
}
70+
71+
&[data-active="true"] {
72+
&::before {
73+
box-shadow: var(--pico-card-box-shadow);
74+
opacity: 1;
75+
transform: scale(1) scaleX(1);
76+
}
77+
}
78+
79+
&:hover:not([data-active="true"]) {
80+
&::before {
81+
opacity: 0.5;
82+
}
83+
}
84+
}

web/src/components/card.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import styles from "./card.module.css";
2+
import { cls } from "../utils";
3+
4+
export const CardButton = ({
5+
active,
6+
children,
7+
onClick,
8+
className,
9+
type = "button",
10+
disabled,
11+
}: {
12+
children?: React.ReactNode;
13+
active?: boolean;
14+
onClick?: () => void;
15+
className?: string;
16+
type?: "button" | "submit" | "reset";
17+
disabled?: boolean;
18+
}) => {
19+
return (
20+
<button
21+
type={type}
22+
className={cls(className, styles.card)}
23+
onClick={onClick}
24+
disabled={disabled}
25+
data-active={active}
26+
>
27+
{children}
28+
</button>
29+
);
30+
};
31+
32+
export const CardLink = ({
33+
href,
34+
target,
35+
children,
36+
className,
37+
}: {
38+
href: string;
39+
target?: string;
40+
children?: React.ReactNode;
41+
className?: string;
42+
}) => {
43+
return (
44+
<a href={href} target={target} className={cls(className, styles.card)}>
45+
{children}
46+
</a>
47+
);
48+
};

web/src/components/project.module.css

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
justify-content: space-between;
1010
align-items: center;
1111
margin-bottom: 0.2rem;
12-
margin-left: 0.1rem;
1312
flex-wrap: wrap;
1413
gap: 1rem;
1514

@@ -25,7 +24,6 @@
2524
}
2625

2726
.projectStats {
28-
margin: 0 0.4rem;
2927
}
3028

3129
.tables {

web/src/components/project/metric.module.css

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,64 +5,18 @@
55
gap: 0.7rem;
66
margin-bottom: -0.4rem;
77

8-
@media (max-width: 768px) {
8+
@media (max-width: 820px) {
99
flex-wrap: wrap;
1010

1111
button.metric {
12-
width: 50%;
12+
width: calc(50% - 0.4rem);
1313
}
1414
}
1515
}
1616

1717
button.metric {
18-
all: unset;
19-
cursor: pointer;
20-
margin: 0;
21-
font-size: 0.8rem;
2218
min-width: 7rem;
23-
padding: 0.5rem 0.8rem 0.3rem 0.6rem;
24-
margin-left: -0.4rem;
25-
transition: background-color 0.2s ease;
26-
border-radius: var(--pico-border-radius);
27-
user-select: none;
28-
position: relative;
29-
z-index: 0;
30-
box-sizing: border-box;
31-
32-
&::before {
33-
content: "";
34-
position: absolute;
35-
z-index: -1;
36-
top: 0;
37-
left: 0;
38-
right: 0;
39-
bottom: 0;
40-
border-radius: var(--pico-border-radius);
41-
background-color: var(--pico-card-background-color);
42-
opacity: 0;
43-
transform: scale(0.97);
44-
transition: opacity 0.2s ease, transform 0.2s ease;
45-
}
46-
47-
&[data-active="true"] {
48-
&::before {
49-
box-shadow: var(--pico-card-box-shadow);
50-
opacity: 1;
51-
transform: scale(1);
52-
}
53-
54-
h2,
55-
h2,
56-
h3 {
57-
color: var(--pico-h1-color);
58-
}
59-
}
60-
61-
&:hover:not([data-active="true"]) {
62-
&::before {
63-
opacity: 0.5;
64-
}
65-
}
19+
font-size: 0.8rem;
6620

6721
h3 {
6822
margin: 0;
@@ -86,4 +40,12 @@ button.metric {
8640
font-size: 0.8rem;
8741
font-weight: 500;
8842
}
43+
44+
&[data-active="true"] {
45+
h2,
46+
h2,
47+
h3 {
48+
color: var(--pico-h1-color);
49+
}
50+
}
8951
}

web/src/components/project/metric.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { TrendingDownIcon, TrendingUpIcon } from "lucide-react";
33

44
import type { Metric, StatsResponse } from "../../api";
55
import { cls, formatMetricVal, formatPercent } from "../../utils";
6+
import { CardButton } from "../card";
67

78
export const SelectMetrics = ({
89
data,
@@ -75,14 +76,14 @@ export const SelectMetric = ({
7576
const icon = change > 0 ? <TrendingUpIcon size={14} /> : change < 0 ? <TrendingDownIcon size={14} /> : "—";
7677

7778
return (
78-
<button type="button" onClick={onSelect} data-active={selected} className={styles.metric}>
79+
<CardButton onClick={onSelect} active={selected} className={styles.metric}>
7980
<h2>{title}</h2>
8081
<h3>
8182
{formatMetricVal(metric, value)}
8283
<span style={{ color }} className={styles.change}>
8384
{icon} {formatPercent(changePercent)}
8485
</span>
8586
</h3>
86-
</button>
87+
</CardButton>
8788
);
8889
};

web/src/components/project/project.module.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
align-items: center;
55
display: flex;
66

7-
a {
8-
all: unset;
9-
cursor: pointer;
10-
}
11-
127
> span.online {
138
margin-left: 0.2rem;
149
> svg {

web/src/components/project/project.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { CircleIcon, LockIcon } from "lucide-react";
33

44
import { formatMetricVal } from "../../utils";
55
import type { ProjectResponse, StatsResponse } from "../../api";
6+
import { CardLink } from "../card";
67

78
export const ProjectHeader = ({
89
project,
@@ -14,15 +15,10 @@ export const ProjectHeader = ({
1415
return (
1516
<h1 className={styles.statsHeader}>
1617
<span>
17-
<a href={`/p/${project.id}`}>
18-
{project.public ? null : (
19-
<>
20-
<LockIcon size={16} />
21-
&nbsp;
22-
</>
23-
)}
18+
<CardLink href={`/p/${project.id}`}>
2419
{project.displayName}
25-
</a>
20+
{project.public ? null : <LockIcon size={16} />}
21+
</CardLink>
2622
&nbsp;
2723
</span>
2824
{stats && <LiveVisitorCount count={stats.currentVisitors} />}

web/src/components/projects.module.css

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
z-index: 0;
3636
margin-bottom: 0.5rem;
3737

38-
a {
38+
/* a {
3939
padding: 0.5rem 0.6rem 0.3rem 0.6rem;
4040
margin-left: -0.4rem;
4141
margin-top: -0.4rem;
@@ -49,9 +49,9 @@
4949
transform: scale(1);
5050
}
5151
}
52-
}
52+
} */
5353

54-
a::before {
54+
/* a::before {
5555
content: "";
5656
position: absolute;
5757
inset: 0;
@@ -61,7 +61,7 @@
6161
opacity: 0;
6262
transform: scale(0.95);
6363
transition: opacity 0.2s ease, transform 0.2s ease;
64-
}
64+
} */
6565
}
6666
}
6767

@@ -90,7 +90,6 @@
9090
justify-content: space-between;
9191
align-items: center;
9292
margin-bottom: 1rem;
93-
margin-left: 0.1rem;
9493

9594
h1,
9695
details {

web/src/components/projects.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { SelectRange } from "./project/range";
1212
import { SelectMetrics } from "./project/metric";
1313
import { ProjectHeader } from "./project/project";
1414
import * as Accordion from "@radix-ui/react-accordion";
15+
import { CardButton } from "./card";
1516

1617
const signedIn = getUsername();
1718

@@ -112,7 +113,7 @@ const Project = ({
112113
<div className={styles.projectTitle}>
113114
<ProjectHeader project={project} stats={stats.data} />
114115
<Accordion.Trigger className={styles.AccordionTrigger} aria-label="Toggle details">
115-
<ChevronDownIcon size={30} strokeWidth={4} color="var(--pico-h1-color)" />
116+
<ChevronDownIcon size={35} strokeWidth={2} color="var(--pico-h1-color)" />
116117
</Accordion.Trigger>
117118
</div>
118119
<div>

0 commit comments

Comments
 (0)