Skip to content

Commit 837bc10

Browse files
committed
fix: forced contrast mode styling, server style tag
1 parent ab07136 commit 837bc10

File tree

2 files changed

+148
-2
lines changed

2 files changed

+148
-2
lines changed

app/components/Settings/Toggle.client.vue

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import TooltipApp from '~/components/Tooltip/App.vue'
33
44
const props = withDefaults(
55
defineProps<{
6-
label?: string
6+
label: string
77
description?: string
88
justify?: 'between' | 'start'
99
tooltip?: string
@@ -139,4 +139,55 @@ const id = useId()
139139
transition: none;
140140
}
141141
}
142+
143+
/* Support forced colors */
144+
@media (forced-colors: active) {
145+
label > span {
146+
background: Canvas;
147+
color: var(--bg);
148+
forced-color-adjust: none;
149+
}
150+
151+
label:has(.toggle:checked) > span {
152+
background: Highlight;
153+
color: var(--fg);
154+
}
155+
156+
.toggle::before {
157+
forced-color-adjust: none;
158+
}
159+
160+
@media (prefers-color-scheme: dark) {
161+
.toggle::before {
162+
background-color: Highlight;
163+
}
164+
165+
label > span {
166+
background: Canvas;
167+
color: var(--fg);
168+
forced-color-adjust: none;
169+
}
170+
171+
label:has(.toggle:checked) > span {
172+
background: Highlight;
173+
color: var(--bg);
174+
}
175+
}
176+
177+
.toggle,
178+
.toggle:hover {
179+
background: Canvas;
180+
border-color: CanvasText;
181+
}
182+
183+
.toggle:checked,
184+
.toggle:checked:hover {
185+
background: Highlight;
186+
border-color: HighlightText;
187+
}
188+
189+
.toggle:checked::before {
190+
background: Canvas;
191+
}
192+
}
142193
</style>

app/components/Settings/Toggle.server.vue

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
const props = withDefaults(
33
defineProps<{
4-
label?: string
4+
label: string
55
description?: string
66
justify?: 'between' | 'start'
77
reverseOrder?: boolean
@@ -51,3 +51,98 @@ const props = withDefaults(
5151
{{ description }}
5252
</p>
5353
</template>
54+
55+
<style scoped>
56+
/* Thumb position: logical property for RTL support */
57+
.toggle::before {
58+
inset-inline-start: 1px;
59+
}
60+
61+
/* Track transition */
62+
.toggle {
63+
transition:
64+
background-color 100ms ease-in,
65+
border-color 100ms ease-in;
66+
}
67+
68+
.toggle::before {
69+
transition: translate 200ms ease-in-out;
70+
}
71+
72+
/* Hover states */
73+
.toggle:hover:not(:checked) {
74+
background: var(--fg-muted);
75+
}
76+
77+
.toggle:checked:hover {
78+
background: var(--fg-muted);
79+
border-color: var(--fg-muted);
80+
}
81+
82+
/* RTL-aware checked thumb position */
83+
:dir(ltr) .toggle:checked::before {
84+
translate: 20px;
85+
}
86+
87+
:dir(rtl) .toggle:checked::before {
88+
translate: -20px;
89+
}
90+
91+
@media (prefers-reduced-motion: reduce) {
92+
.toggle,
93+
.toggle::before {
94+
transition: none;
95+
}
96+
}
97+
98+
/* Support forced colors */
99+
@media (forced-colors: active) {
100+
label > span {
101+
background: Canvas;
102+
color: var(--bg);
103+
forced-color-adjust: none;
104+
}
105+
106+
label:has(.toggle:checked) > span {
107+
background: Highlight;
108+
color: var(--fg);
109+
}
110+
111+
.toggle::before {
112+
forced-color-adjust: none;
113+
}
114+
115+
@media (prefers-color-scheme: dark) {
116+
.toggle::before {
117+
background-color: Highlight;
118+
}
119+
120+
label > span {
121+
background: Canvas;
122+
color: var(--fg);
123+
forced-color-adjust: none;
124+
}
125+
126+
label:has(.toggle:checked) > span {
127+
background: Highlight;
128+
color: var(--bg);
129+
}
130+
}
131+
132+
.toggle,
133+
.toggle:hover {
134+
background: Canvas;
135+
border-color: CanvasText;
136+
}
137+
138+
.toggle:checked,
139+
.toggle:checked:hover {
140+
background: Highlight;
141+
border-color: HighlightText;
142+
}
143+
144+
.toggle:checked::before {
145+
background: Canvas;
146+
}
147+
}
148+
</style>

0 commit comments

Comments
 (0)