Skip to content

Commit b6b9e98

Browse files
committed
refactor: use native CSS selectors for dark theme of input borders
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent a2aeca4 commit b6b9e98

File tree

4 files changed

+23
-31
lines changed

4 files changed

+23
-31
lines changed

src/assets/input-border.scss

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,35 @@
22
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
5-
6-
@mixin boxShadow($borderColor) {
7-
box-shadow: 0 -1px $borderColor,
8-
0 0 0 1px color-mix(in srgb, $borderColor, 65% transparent);
9-
}
10-
11-
@mixin boxShadowDark($borderColor) {
12-
box-shadow: 0 1px $borderColor,
13-
0 0 0 1px color-mix(in srgb, $borderColor, 65% transparent);
14-
}
155

166
/**
177
* Similar as inputBorder but without active styles.
188
*/
19-
@mixin inputLikeBorder($darkThemeSelector, $legacySelector, $borderColor: var(--color-border-maxcontrast)) {
9+
@mixin inputLikeBorder($legacySelector, $borderColor: var(--color-border-maxcontrast)) {
10+
--input-border-box-shadow-light: 0 -1px #{$borderColor},
11+
0 0 0 1px color-mix(in srgb, #{$borderColor}, 65% transparent);
12+
--input-border-box-shadow-dark: 0 1px #{$borderColor},
13+
0 0 0 1px color-mix(in srgb, #{$borderColor}, 65% transparent);
14+
--input-border-box-shadow: var(--input-border-box-shadow-light);
2015
border: none;
2116
border-radius: var(--border-radius-element);
22-
@include boxShadow($borderColor);
17+
box-shadow: var(--input-border-box-shadow);
2318

2419
&:hover:not([disabled]) {
2520
box-shadow: 0 0 0 1px $borderColor;
2621
}
2722

28-
@at-root #{$darkThemeSelector} #{&} {
29-
@include boxShadowDark($borderColor);
23+
// override with system theme
24+
@media (prefers-color-scheme: dark) {
25+
--input-border-box-shadow: var(--input-border-box-shadow-dark);
26+
}
27+
28+
// override with nextcloud theme
29+
@at-root [data-theme-dark] #{&} {
30+
--input-border-box-shadow: var(--input-border-box-shadow-dark);
31+
}
32+
@at-root [data-theme-light] #{&} {
33+
--input-border-box-shadow: var(--input-border-box-shadow-light);
3034
}
3135

3236
@at-root #{$legacySelector} #{&} {
@@ -42,8 +46,8 @@
4246
* Create a consistent border for an input element.
4347
* With Nextcloud 32+ there is no real border anymore but we use a box-shadow.
4448
*/
45-
@mixin inputBorder($darkThemeSelector, $legacySelector, $borderColor: var(--color-border-maxcontrast)) {
46-
@include inputLikeBorder($darkThemeSelector, $legacySelector, $borderColor);
49+
@mixin inputBorder($legacySelector, $borderColor: var(--color-border-maxcontrast)) {
50+
@include inputLikeBorder($legacySelector, $borderColor);
4751

4852
&:focus-within:not([disabled]),
4953
&:active:not([disabled]) {

src/components/NcInputField/NcInputField.vue

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ For a list of all available props and attributes, please check the [HTMLInputEle
2020
<div
2121
class="input-field"
2222
:class="{
23-
'input-field--dark': isDarkTheme,
2423
'input-field--disabled': disabled,
2524
'input-field--error': error,
2625
'input-field--label-outside': labelOutside || !isValidLabel,
@@ -108,7 +107,6 @@ For a list of all available props and attributes, please check the [HTMLInputEle
108107
import AlertCircle from 'vue-material-design-icons/AlertCircleOutline.vue'
109108
import Check from 'vue-material-design-icons/Check.vue'
110109
import NcButton from '../NcButton/NcButton.vue'
111-
import { useIsDarkTheme } from '../../composables/useIsDarkTheme/index.ts'
112110
import { useModelMigration } from '../../composables/useModelMigration.ts'
113111
import GenRandomId from '../../utils/GenRandomId.js'
114112
import { isLegacy32 } from '../../utils/legacy.ts'
@@ -288,12 +286,10 @@ export default {
288286
289287
setup() {
290288
const model = useModelMigration('value', 'update:value', true)
291-
const isDarkTheme = useIsDarkTheme()
292289
293290
return {
294291
isLegacy32,
295292
model,
296-
isDarkTheme,
297293
}
298294
},
299295
@@ -417,7 +413,7 @@ export default {
417413
}
418414
419415
&__input {
420-
@include border.inputBorder('.input-field--dark', '.input-field--legacy', var(--input-border-color));
416+
@include border.inputBorder('.input-field--legacy', var(--input-border-color));
421417
background-color: var(--color-main-background);
422418
color: var(--color-main-text);
423419
border-radius: var(--input-border-radius);

src/components/NcSelect/NcSelect.vue

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ export default {
325325
<VueSelect
326326
class="select"
327327
:class="{
328-
'select--dark': isDark,
329328
'select--legacy': isLegacy,
330329
'select--no-wrap': noWrap,
331330
'user-select': userSelect,
@@ -419,7 +418,6 @@ import Close from 'vue-material-design-icons/Close.vue'
419418
import NcEllipsisedOption from '../NcEllipsisedOption/NcEllipsisedOption.vue'
420419
import NcListItemIcon from '../NcListItemIcon/NcListItemIcon.vue'
421420
import NcLoadingIcon from '../NcLoadingIcon/NcLoadingIcon.vue'
422-
import { useIsDarkTheme } from '../../composables/index.ts'
423421
import { useModelMigration } from '../../composables/useModelMigration.ts'
424422
import { t } from '../../l10n.js'
425423
import GenRandomId from '../../utils/GenRandomId.js'
@@ -860,12 +858,10 @@ export default {
860858
const avatarSize = clickableArea - 2 * gridBaseLine
861859
862860
const model = useModelMigration('value', 'input')
863-
const isDark = useIsDarkTheme()
864861
865862
return {
866863
avatarSize,
867864
model,
868-
isDark,
869865
isLegacy,
870866
}
871867
},
@@ -1233,7 +1229,7 @@ body {
12331229
}
12341230
12351231
.vs__dropdown-toggle {
1236-
@include border.inputLikeBorder('.select--dark', '.select--legacy', var(--vs-border-color));
1232+
@include border.inputLikeBorder('.select--legacy', var(--vs-border-color));
12371233
}
12381234
12391235
.vs__dropdown-menu {

src/components/NcTextArea/NcTextArea.vue

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ It extends and styles an HTMLTextAreaElement.
9191
<div
9292
class="textarea"
9393
:class="{
94-
'textarea--dark': isDarkTheme,
9594
'textarea--disabled': disabled,
9695
'textarea--legacy': isLegacy32,
9796
}">
@@ -142,7 +141,6 @@ It extends and styles an HTMLTextAreaElement.
142141
<script>
143142
import AlertCircle from 'vue-material-design-icons/AlertCircleOutline.vue'
144143
import Check from 'vue-material-design-icons/Check.vue'
145-
import { useIsDarkTheme } from '../../composables/useIsDarkTheme/index.ts'
146144
import { useModelMigration } from '../../composables/useModelMigration.ts'
147145
import GenRandomId from '../../utils/GenRandomId.js'
148146
import { isLegacy32 } from '../../utils/legacy.ts'
@@ -283,12 +281,10 @@ export default {
283281
284282
setup() {
285283
const model = useModelMigration('value', 'update:value', true)
286-
const isDarkTheme = useIsDarkTheme()
287284
288285
return {
289286
isLegacy32,
290287
model,
291-
isDarkTheme,
292288
}
293289
},
294290
@@ -395,7 +391,7 @@ export default {
395391
396392
background-color: var(--color-main-background);
397393
color: var(--color-main-text);
398-
@include border.inputBorder('.textarea--dark', '.textarea--legacy', var(--input-border-color));
394+
@include border.inputBorder('.textarea--legacy', var(--input-border-color));
399395
400396
&:active:not([disabled]),
401397
&:focus:not([disabled]) {

0 commit comments

Comments
 (0)