Skip to content

Commit 848af4d

Browse files
committed
Refactor checkbox/radio selection SVGs to use background masks to work in darkmode. Closes #15.
1 parent 24aada3 commit 848af4d

1 file changed

Lines changed: 26 additions & 11 deletions

File tree

src/css/form.css

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,22 @@
7474
&:checked {
7575
background-color: var(--primary);
7676
border-color: var(--primary);
77-
background-position: center;
78-
background-repeat: no-repeat;
7977
}
8078
}
8179

8280
input[type=checkbox] {
8381
border-radius: var(--radius-small);
84-
85-
&:checked {
86-
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
87-
background-size: 0.75rem;
82+
position: relative;
83+
84+
&:checked::after {
85+
content: "";
86+
position: absolute;
87+
inset: 0;
88+
background-color: var(--primary-foreground);
89+
mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='4'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
90+
mask-size: 90%;
91+
mask-position: center;
92+
mask-repeat: no-repeat;
8893
}
8994

9095
&[role=switch] {
@@ -114,7 +119,10 @@
114119

115120
&:checked {
116121
background-color: var(--primary);
117-
background-image: none;
122+
123+
&::after {
124+
content: none;
125+
}
118126

119127
&::before {
120128
transform: translateY(-50%) translateX(var(--switch-height));
@@ -125,10 +133,17 @@
125133

126134
input[type=radio] {
127135
border-radius: var(--radius-full);
128-
129-
&:checked {
130-
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='4' fill='white'/%3E%3C/svg%3E");
131-
background-size: 100%;
136+
position: relative;
137+
138+
&:checked::after {
139+
content: "";
140+
position: absolute;
141+
inset: 0;
142+
background-color: var(--primary-foreground);
143+
mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Ccircle cx='8' cy='8' r='4' fill='currentColor'/%3E%3C/svg%3E");
144+
mask-size: 100%;
145+
mask-position: center;
146+
mask-repeat: no-repeat;
132147
}
133148
}
134149

0 commit comments

Comments
 (0)