mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-21 07:21:46 +01:00
feat(ButtonGroup): new component (#88)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
21
src/runtime/composables/useButtonGroup.ts
Normal file
21
src/runtime/composables/useButtonGroup.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { type InjectionKey, type ComputedRef } from 'vue'
|
||||
import { inject, computed } from 'vue'
|
||||
import type { GetObjectField } from '#ui/types/utils'
|
||||
import type { ButtonGroupProps } from '../components/ButtonGroup.vue'
|
||||
|
||||
export const buttonGroupInjectionKey: InjectionKey<ComputedRef<{
|
||||
size: ButtonGroupProps ['size']
|
||||
orientation: ButtonGroupProps['orientation']
|
||||
}>> = Symbol('nuxt-ui.button-group')
|
||||
|
||||
type Props<T> = {
|
||||
size?: GetObjectField<T, 'size'>
|
||||
}
|
||||
|
||||
export function useButtonGroup<T>(props: Props<T>) {
|
||||
const buttonGroup = inject(buttonGroupInjectionKey, undefined)
|
||||
return {
|
||||
orientation: computed(() => buttonGroup?.value.orientation),
|
||||
size: computed(() => props?.size ?? buttonGroup?.value.size)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user