Skip to content

Commit 3fb2c80

Browse files
susnuxShGKme
andcommitted
refactor(NcThemeProvider): adjust code style
Co-authored-by: Grigorii K. Shartsev <me@shgk.me> Co-authored-by: Ferdinand Thiessen <opensource@fthiessen.de> Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 8795c5e commit 3fb2c80

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

src/components/NcThemeProvider/NcThemeProvider.vue

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,12 @@ legend {
112112
min-height: 2lh;
113113
}
114114
</style>
115+
```
115116
</docs>
116117

117118
<script setup lang="ts">
118119
import { computed, provide } from 'vue'
119-
import { KEY_ENFORCE_THEME } from '../../composables/useIsDarkTheme/index.ts'
120+
import { INJECTION_KEY_THEME } from '../../composables/useIsDarkTheme/index.ts'
120121
121122
const props = defineProps<{
122123
/**
@@ -138,18 +139,11 @@ const theme = computed(() => {
138139
}
139140
return ''
140141
})
141-
provide(KEY_ENFORCE_THEME, theme)
142-
143-
const dataTheme = computed(() => {
144-
if (theme.value) {
145-
return { [`data-theme-${theme.value}`]: true }
146-
}
147-
return {}
148-
})
142+
provide(INJECTION_KEY_THEME, theme)
149143
</script>
150144

151145
<template>
152-
<div v-bind="dataTheme">
146+
<div :[`data-theme-${theme}`]="theme">
153147
<slot />
154148
</div>
155149
</template>

src/composables/useIsDarkTheme/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import type { ComputedRef, DeepReadonly, Ref } from 'vue'
6+
import type { ComputedRef, DeepReadonly, InjectionKey, Ref } from 'vue'
77

88
import { createSharedComposable, usePreferredDark, useMutationObserver } from '@vueuse/core'
99
import { ref, readonly, watch, inject, computed } from 'vue'
1010
import { checkIfDarkTheme } from '../../functions/isDarkTheme/index.ts'
1111

1212
/**
13-
* Symbol used to provide the enforced dark / light theme state.
14-
* Injected by `NcThemeProvider`.
13+
* Enforced dark / light theme state
1514
*/
16-
export const KEY_ENFORCE_THEME = Symbol('enforce-theme')
15+
export const INJECTION_KEY_THEME: InjectionKey<ComputedRef<'light' | 'dark' | ''>> = Symbol.for('nc:theme:enforced')
1716

1817
/**
1918
* Check whether the dark theme is enabled on a specific element.
@@ -55,7 +54,7 @@ const useInternalIsDarkTheme = createSharedComposable(() => useIsDarkThemeElemen
5554
*/
5655
export function useIsDarkTheme(): DeepReadonly<Ref<boolean>> {
5756
const isDarkTheme = useInternalIsDarkTheme()
58-
const enforcedTheme = inject<ComputedRef<string>>(KEY_ENFORCE_THEME)
57+
const enforcedTheme = inject(INJECTION_KEY_THEME)
5958

6059
return computed(() => {
6160
if (enforcedTheme?.value) {

0 commit comments

Comments
 (0)