mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-29 03:10:42 +01:00
chore(components): use Primitive where possible
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { tv, type VariantProps } from 'tailwind-variants'
|
import { tv, type VariantProps } from 'tailwind-variants'
|
||||||
|
import type { PrimitiveProps } from 'radix-vue'
|
||||||
import type { AppConfig } from '@nuxt/schema'
|
import type { AppConfig } from '@nuxt/schema'
|
||||||
import _appConfig from '#build/app.config'
|
import _appConfig from '#build/app.config'
|
||||||
import theme from '#build/ui/badge'
|
import theme from '#build/ui/badge'
|
||||||
@@ -10,8 +11,7 @@ const badge = tv({ extend: tv(theme), ...(appConfig.ui?.badge || {}) })
|
|||||||
|
|
||||||
type BadgeVariants = VariantProps<typeof badge>
|
type BadgeVariants = VariantProps<typeof badge>
|
||||||
|
|
||||||
export interface BadgeProps {
|
export interface BadgeProps extends Omit<PrimitiveProps, 'asChild'> {
|
||||||
as?: string
|
|
||||||
label?: string
|
label?: string
|
||||||
color?: BadgeVariants['color']
|
color?: BadgeVariants['color']
|
||||||
variant?: BadgeVariants['variant']
|
variant?: BadgeVariants['variant']
|
||||||
@@ -25,14 +25,16 @@ export interface BadgeSlots {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { Primitive } from 'radix-vue'
|
||||||
|
|
||||||
const props = withDefaults(defineProps<BadgeProps>(), { as: 'span' })
|
const props = withDefaults(defineProps<BadgeProps>(), { as: 'span' })
|
||||||
defineSlots<BadgeSlots>()
|
defineSlots<BadgeSlots>()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<component :is="as" :class="badge({ color, variant, size, class: props.class })">
|
<Primitive :as="as" :class="badge({ color, variant, size, class: props.class })">
|
||||||
<slot>
|
<slot>
|
||||||
{{ label }}
|
{{ label }}
|
||||||
</slot>
|
</slot>
|
||||||
</component>
|
</Primitive>
|
||||||
</template>
|
</template>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { tv } from 'tailwind-variants'
|
import { tv } from 'tailwind-variants'
|
||||||
|
import type { PrimitiveProps } from 'radix-vue'
|
||||||
import type { AppConfig } from '@nuxt/schema'
|
import type { AppConfig } from '@nuxt/schema'
|
||||||
import _appConfig from '#build/app.config'
|
import _appConfig from '#build/app.config'
|
||||||
import theme from '#build/ui/card'
|
import theme from '#build/ui/card'
|
||||||
@@ -8,8 +9,7 @@ const appConfig = _appConfig as AppConfig & { ui: { card: Partial<typeof theme>
|
|||||||
|
|
||||||
const card = tv({ extend: tv(theme), ...(appConfig.ui?.card || {}) })
|
const card = tv({ extend: tv(theme), ...(appConfig.ui?.card || {}) })
|
||||||
|
|
||||||
export interface CardProps {
|
export interface CardProps extends Omit<PrimitiveProps, 'asChild'> {
|
||||||
as?: string
|
|
||||||
class?: any
|
class?: any
|
||||||
ui?: Partial<typeof card.slots>
|
ui?: Partial<typeof card.slots>
|
||||||
}
|
}
|
||||||
@@ -17,6 +17,7 @@ export interface CardProps {
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
|
import { Primitive } from 'radix-vue'
|
||||||
|
|
||||||
const props = withDefaults(defineProps<CardProps>(), { as: 'div' })
|
const props = withDefaults(defineProps<CardProps>(), { as: 'div' })
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ const ui = computed(() => tv({ extend: card, slots: props.ui })())
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<component :is="as" :class="ui.root({ class: props.class })">
|
<Primitive :as="as" :class="ui.root({ class: props.class })">
|
||||||
<div v-if="$slots.header" :class="ui.header()">
|
<div v-if="$slots.header" :class="ui.header()">
|
||||||
<slot name="header" />
|
<slot name="header" />
|
||||||
</div>
|
</div>
|
||||||
@@ -36,5 +37,5 @@ const ui = computed(() => tv({ extend: card, slots: props.ui })())
|
|||||||
<div v-if="$slots.footer" :class="ui.footer()">
|
<div v-if="$slots.footer" :class="ui.footer()">
|
||||||
<slot name="footer" />
|
<slot name="footer" />
|
||||||
</div>
|
</div>
|
||||||
</component>
|
</Primitive>
|
||||||
</template>
|
</template>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { tv } from 'tailwind-variants'
|
import { tv } from 'tailwind-variants'
|
||||||
|
import type { PrimitiveProps } from 'radix-vue'
|
||||||
import type { AppConfig } from '@nuxt/schema'
|
import type { AppConfig } from '@nuxt/schema'
|
||||||
import _appConfig from '#build/app.config'
|
import _appConfig from '#build/app.config'
|
||||||
import theme from '#build/ui/container'
|
import theme from '#build/ui/container'
|
||||||
@@ -8,18 +9,19 @@ const appConfig = _appConfig as AppConfig & { ui: { container: Partial<typeof th
|
|||||||
|
|
||||||
const container = tv({ extend: tv(theme), ...(appConfig.ui?.container || {}) })
|
const container = tv({ extend: tv(theme), ...(appConfig.ui?.container || {}) })
|
||||||
|
|
||||||
export interface ContainerProps {
|
export interface ContainerProps extends Omit<PrimitiveProps, 'asChild'> {
|
||||||
as?: string
|
|
||||||
class?: any
|
class?: any
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { Primitive } from 'radix-vue'
|
||||||
|
|
||||||
const props = withDefaults(defineProps<ContainerProps>(), { as: 'div' })
|
const props = withDefaults(defineProps<ContainerProps>(), { as: 'div' })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<component :is="as" :class="container({ class: props.class })">
|
<Primitive :as="as" :class="container({ class: props.class })">
|
||||||
<slot />
|
<slot />
|
||||||
</component>
|
</Primitive>
|
||||||
</template>
|
</template>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { tv, type VariantProps } from 'tailwind-variants'
|
import { tv, type VariantProps } from 'tailwind-variants'
|
||||||
|
import type { PrimitiveProps } from 'radix-vue'
|
||||||
import type { AppConfig } from '@nuxt/schema'
|
import type { AppConfig } from '@nuxt/schema'
|
||||||
import _appConfig from '#build/app.config'
|
import _appConfig from '#build/app.config'
|
||||||
import theme from '#build/ui/kbd'
|
import theme from '#build/ui/kbd'
|
||||||
@@ -10,8 +11,7 @@ const kbd = tv({ extend: tv(theme), ...(appConfig.ui?.kbd || {}) })
|
|||||||
|
|
||||||
type KbdVariants = VariantProps<typeof kbd>
|
type KbdVariants = VariantProps<typeof kbd>
|
||||||
|
|
||||||
export interface KbdProps {
|
export interface KbdProps extends Omit<PrimitiveProps, 'asChild'> {
|
||||||
as?: string
|
|
||||||
value?: string
|
value?: string
|
||||||
size?: KbdVariants['size']
|
size?: KbdVariants['size']
|
||||||
class?: any
|
class?: any
|
||||||
@@ -23,14 +23,16 @@ export interface KbdSlots {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { Primitive } from 'radix-vue'
|
||||||
|
|
||||||
const props = withDefaults(defineProps<KbdProps>(), { as: 'kbd' })
|
const props = withDefaults(defineProps<KbdProps>(), { as: 'kbd' })
|
||||||
defineSlots<KbdSlots>()
|
defineSlots<KbdSlots>()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<component :is="as" :class="kbd({ size, class: props.class })">
|
<Primitive :as="as" :class="kbd({ size, class: props.class })">
|
||||||
<slot>
|
<slot>
|
||||||
{{ value }}
|
{{ value }}
|
||||||
</slot>
|
</slot>
|
||||||
</component>
|
</Primitive>
|
||||||
</template>
|
</template>
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import type { PrimitiveProps } from 'radix-vue'
|
||||||
import type { NuxtLinkProps } from '#app'
|
import type { NuxtLinkProps } from '#app'
|
||||||
|
|
||||||
export interface LinkProps extends NuxtLinkProps {
|
export interface LinkProps extends NuxtLinkProps, Omit<PrimitiveProps, 'asChild'> {
|
||||||
as?: string
|
|
||||||
type?: string
|
type?: string
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
active?: boolean
|
active?: boolean
|
||||||
@@ -15,7 +15,7 @@ export interface LinkProps extends NuxtLinkProps {
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { isEqual } from 'ohash'
|
import { isEqual } from 'ohash'
|
||||||
import { useForwardProps } from 'radix-vue'
|
import { Primitive, useForwardProps } from 'radix-vue'
|
||||||
import { reactiveOmit } from '@vueuse/core'
|
import { reactiveOmit } from '@vueuse/core'
|
||||||
import type { RouteLocation } from '#vue-router'
|
import type { RouteLocation } from '#vue-router'
|
||||||
|
|
||||||
@@ -45,18 +45,17 @@ function resolveLinkClass (route: RouteLocation, currentRoute: RouteLocation, {
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- eslint-disable vue/no-template-shadow -->
|
|
||||||
<template>
|
<template>
|
||||||
<component
|
<Primitive
|
||||||
:is="as"
|
|
||||||
v-if="!to"
|
v-if="!to"
|
||||||
|
:as="as"
|
||||||
:type="type"
|
:type="type"
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
:class="active ? activeClass : inactiveClass"
|
:class="active ? activeClass : inactiveClass"
|
||||||
>
|
>
|
||||||
<slot v-bind="{ isActive: active }" />
|
<slot v-bind="{ isActive: active }" />
|
||||||
</component>
|
</Primitive>
|
||||||
<NuxtLink v-else v-slot="{ route, href, target, rel, navigate, isActive, isExactActive, isExternal }" v-bind="forward" custom>
|
<NuxtLink v-else v-slot="{ route, href, target, rel, navigate, isActive, isExactActive, isExternal }" v-bind="forward" custom>
|
||||||
<a
|
<a
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { tv } from 'tailwind-variants'
|
import { tv } from 'tailwind-variants'
|
||||||
|
import type { PrimitiveProps } from 'radix-vue'
|
||||||
import type { AppConfig } from '@nuxt/schema'
|
import type { AppConfig } from '@nuxt/schema'
|
||||||
import _appConfig from '#build/app.config'
|
import _appConfig from '#build/app.config'
|
||||||
import theme from '#build/ui/skeleton'
|
import theme from '#build/ui/skeleton'
|
||||||
@@ -8,18 +9,19 @@ const appConfig = _appConfig as AppConfig & { ui: { skeleton: Partial<typeof the
|
|||||||
|
|
||||||
const skeleton = tv({ extend: tv(theme), ...(appConfig.ui?.skeleton || {}) })
|
const skeleton = tv({ extend: tv(theme), ...(appConfig.ui?.skeleton || {}) })
|
||||||
|
|
||||||
export interface SkeletonProps {
|
export interface SkeletonProps extends Omit<PrimitiveProps, 'asChild'> {
|
||||||
as?: string
|
|
||||||
class?: any
|
class?: any
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { Primitive } from 'radix-vue'
|
||||||
|
|
||||||
const props = withDefaults(defineProps<SkeletonProps>(), { as: 'div' })
|
const props = withDefaults(defineProps<SkeletonProps>(), { as: 'div' })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<component :is="as" :class="skeleton({ class: props.class })">
|
<Primitive :as="as" :class="skeleton({ class: props.class })">
|
||||||
<slot />
|
<slot />
|
||||||
</component>
|
</Primitive>
|
||||||
</template>
|
</template>
|
||||||
Reference in New Issue
Block a user