refactor: tidy injections of dropdown

pull/736/head
三咲智子 2023-01-03 19:58:08 +08:00
rodzic 4a3cef9a01
commit ef417f3ccf
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 69992F2250DFD93E
5 zmienionych plików z 14 dodań i 12 usunięć

Wyświetl plik

@ -1,5 +1,6 @@
<script setup lang="ts">
import { dropdownContextKey } from './ctx'
import { InjectionKeyDropdownContext } from '~/constants/symbols'
defineProps<{
placement?: string
}>()
@ -8,7 +9,7 @@ const dropdown = $ref<any>()
const colorMode = useColorMode()
const hide = () => dropdown.hide()
provide(dropdownContextKey, {
provide(InjectionKeyDropdownContext, {
hide,
})

Wyświetl plik

@ -1,6 +1,4 @@
<script setup lang="ts">
import { dropdownContextKey } from './ctx'
const props = defineProps<{
text?: string
description?: string
@ -10,7 +8,7 @@ const props = defineProps<{
}>()
const emit = defineEmits(['click'])
const { hide } = inject(dropdownContextKey, undefined) || {}
const { hide } = useDropdownContext() || {}
const el = ref<HTMLDivElement>()

Wyświetl plik

@ -1,5 +0,0 @@
import type { InjectionKey } from 'vue'
export const dropdownContextKey: InjectionKey<{
hide: () => void
}> = Symbol('dropdownContextKey')

Wyświetl plik

@ -1,5 +1,9 @@
import { InjectionKeyFontSize } from '~/constants/symbols'
import { InjectionKeyDropdownContext, InjectionKeyFontSize } from '~/constants/symbols'
export function useFontSizeRef() {
return inject(InjectionKeyFontSize)!
}
export function useDropdownContext() {
return inject(InjectionKeyDropdownContext, undefined)
}

Wyświetl plik

@ -1,4 +1,8 @@
import type { InjectionKey, Ref } from 'vue'
import type { FontSize } from '~/types'
export const InjectionKeyFontSize = Symbol('font-size') as InjectionKey<Ref<FontSize>>
export const InjectionKeyFontSize: InjectionKey<Ref<FontSize>> = Symbol('font-size')
export const InjectionKeyDropdownContext: InjectionKey<{
hide: () => void
}> = Symbol('dropdown-context')