mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-15 04:29:37 +01:00
54 lines
1.4 KiB
Vue
54 lines
1.4 KiB
Vue
<script lang="ts">
|
|
import { tv, type VariantProps } from 'tailwind-variants'
|
|
import type { AppConfig } from '@nuxt/schema'
|
|
import _appConfig from '#build/app.config'
|
|
import theme from '#build/ui/button-group'
|
|
|
|
const appConfig = _appConfig as AppConfig & { ui: { buttonGroup: Partial<typeof theme> } }
|
|
|
|
const buttonGroup = tv({ extend: tv(theme), ...(appConfig.ui?.buttonGroup) })
|
|
|
|
type ButtonGroupVariants = VariantProps<typeof buttonGroup>
|
|
|
|
export interface ButtonGroupProps {
|
|
/**
|
|
* The element or component this component should render as.
|
|
* @defaultValue 'div'
|
|
*/
|
|
as?: any
|
|
size?: ButtonGroupVariants['size']
|
|
/**
|
|
* The orientation the buttons are laid out.
|
|
* @defaultValue 'horizontal'
|
|
*/
|
|
orientation?: ButtonGroupVariants['orientation']
|
|
class?: any
|
|
}
|
|
|
|
export interface ButtonGroupSlots {
|
|
default(props?: {}): any
|
|
}
|
|
</script>
|
|
|
|
<script setup lang="ts">
|
|
import { provide, computed } from 'vue'
|
|
import { Primitive } from 'radix-vue'
|
|
import { buttonGroupInjectionKey } from '../composables/useButtonGroup'
|
|
|
|
const props = withDefaults(defineProps<ButtonGroupProps>(), {
|
|
orientation: 'horizontal'
|
|
})
|
|
defineSlots<ButtonGroupSlots>()
|
|
|
|
provide(buttonGroupInjectionKey, computed(() => ({
|
|
orientation: props.orientation,
|
|
size: props.size
|
|
})))
|
|
</script>
|
|
|
|
<template>
|
|
<Primitive :as="as" :class="buttonGroup({ orientation })">
|
|
<slot />
|
|
</Primitive>
|
|
</template>
|