Skip to content

Commit 6ac8a78

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

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
@@ -24,7 +24,6 @@ import { mdiAlertCircleOutline, mdiCheck } from '@mdi/js'
2424
import { computed, useAttrs, useTemplateRef, warn } from 'vue'
2525
import NcButton from '../NcButton/NcButton.vue'
2626
import NcIconSvgWrapper from '../NcIconSvgWrapper/NcIconSvgWrapper.vue'
27-
import { useIsDarkTheme } from '../../composables/useIsDarkTheme/index.ts'
2827
import { createElementId } from '../../utils/createElementId.ts'
2928
import { isLegacy } from '../../utils/legacy.ts'
3029
@@ -162,8 +161,6 @@ const attrs = useAttrs()
162161
163162
const inputElement = useTemplateRef('input')
164163
165-
const isDarkTheme = useIsDarkTheme()
166-
167164
const hasTrailingIcon = computed(() => props.showTrailingButton || props.success)
168165
169166
const internalPlaceholder = computed(() => {
@@ -234,7 +231,6 @@ function handleInput(event: Event) {
234231
<div
235232
class="input-field"
236233
:class="[{
237-
'input-field--dark': isDarkTheme,
238234
'input-field--disabled': disabled,
239235
'input-field--error': error,
240236
'input-field--label-outside': labelOutside || !isValidLabel,
@@ -355,7 +351,7 @@ function handleInput(event: Event) {
355351
}
356352
357353
&__input {
358-
@include border.inputBorder('.input-field--dark', '.input-field--legacy', var(--input-border-color));
354+
@include border.inputBorder('.input-field--legacy', var(--input-border-color));
359355
background-color: var(--color-main-background);
360356
color: var(--color-main-text);
361357
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
}"
@@ -402,7 +401,6 @@ import ChevronDown from 'vue-material-design-icons/ChevronDown.vue'
402401
import Close from 'vue-material-design-icons/Close.vue'
403402
import NcEllipsisedOption from '../NcEllipsisedOption/NcEllipsisedOption.vue'
404403
import NcLoadingIcon from '../NcLoadingIcon/NcLoadingIcon.vue'
405-
import { useIsDarkTheme } from '../../composables/index.ts'
406404
import { t } from '../../l10n.ts'
407405
import { createElementId } from '../../utils/createElementId.ts'
408406
import { isLegacy } from '../../utils/legacy.ts'
@@ -781,8 +779,6 @@ export default {
781779
const gridBaseLine = Number.parseInt(window.getComputedStyle(document.body).getPropertyValue('--default-grid-baseline'))
782780
const avatarSize = clickableArea - 2 * gridBaseLine
783781
784-
const isDark = useIsDarkTheme()
785-
786782
return {
787783
avatarSize,
788784
isLegacy,
@@ -1122,7 +1118,7 @@ body {
11221118
}
11231119
11241120
.vs__dropdown-toggle {
1125-
@include border.inputLikeBorder('.select--dark', '.select--legacy', var(--vs-border-color));
1121+
@include border.inputLikeBorder('.select--legacy', var(--vs-border-color));
11261122
}
11271123
11281124
.vs__dropdown-menu {

src/components/NcTextArea/NcTextArea.vue

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ import type { VueClassType } from '../../utils/VueTypes.ts'
7777
import { mdiAlertCircleOutline, mdiCheck } from '@mdi/js'
7878
import { computed, useAttrs, useTemplateRef, watch } from 'vue'
7979
import NcIconSvgWrapper from '../NcIconSvgWrapper/NcIconSvgWrapper.vue'
80-
import { useIsDarkTheme } from '../../composables/useIsDarkTheme/index.ts'
8180
import { createElementId } from '../../utils/createElementId.ts'
8281
import { isLegacy } from '../../utils/legacy.ts'
8382
import { logger } from '../../utils/logger.ts'
@@ -171,8 +170,6 @@ const attrs = useAttrs()
171170
*/
172171
const textAreaElement = useTemplateRef('input')
173172
174-
const isDarkTheme = useIsDarkTheme()
175-
176173
const internalPlaceholder = computed(() => props.placeholder || (isLegacy ? props.label : undefined))
177174
178175
// warn about invalid labels (missing label and no label outside)
@@ -229,7 +226,6 @@ function select() {
229226
:class="[
230227
$attrs.class,
231228
{
232-
'textarea--dark': isDarkTheme,
233229
'textarea--disabled': disabled,
234230
'textarea--legacy': isLegacy,
235231
},
@@ -321,7 +317,7 @@ function select() {
321317
322318
background-color: var(--color-main-background);
323319
color: var(--color-main-text);
324-
@include border.inputBorder('.textarea--dark', '.textarea--legacy', var(--input-border-color));
320+
@include border.inputBorder('.textarea--legacy', var(--input-border-color));
325321
326322
&:active:not([disabled]),
327323
&:focus:not([disabled]) {

0 commit comments

Comments
 (0)