InputRating
Gebruik
Gebruik de v-model-richtlijn om de beoordelingswaarde van de InputRating-component te regelen.
<script setup lang="ts">
const value = ref(3)
</script>
<template>
<UInputRating v-model="value" />
</template><script setup lang="ts">
import { ref } from 'vue'
const value = ref(3)
</script>
<template>
<UInputRating v-model="value" />
</template>Gebruik de default-value prop om de beginwaarde in te stellen wanneer u de status niet hoeft te regelen.
<template>
<UInputRating :default-value="3" />
</template>Stap
Gebruik de step-prop om de granulariteit van elke ster te regelen. Stel deze in op 0.5 om beoordelingen van halve sterren toe te staan.
<template>
<UInputRating :step="0.5" :default-value="3.5" />
</template>Lengte
Gebruik de length prop om het aantal sterren in te stellen. Standaard ingesteld op 5.
<template>
<UInputRating :length="10" :step="0.5" :default-value="7.5" />
</template>Opruimbaar
Gebruik de clearable prop om gebruikers in staat te stellen de beoordeling te wissen door op de momenteel geselecteerde waarde te klikken. Standaard is false.
<template>
<UInputRating clearable :default-value="3" />
</template>Hoverbaar
Gebruik de hoverable-prop om te bepalen of de classificatie een voorbeeld is van de waarde wanneer u over de sterren zweeft. Standaard is false.
<template>
<UInputRating hoverable :default-value="3" />
</template>Icoon
Gebruik de icon-prop om het pictogram voor sterren aan te passen. Standaard i-lucide-star.
<template>
<UInputRating icon="i-lucide-heart" :default-value="4" />
</template>app.config.ts onder ui.icons.star-sleutel.vite.config.ts onder ui.icons.star-sleutel.Leeg pictogram
Gebruik de empty-icon prop om het pictogram aan te passen dat wordt gebruikt voor lege sterren. Indien niet voorzien, gebruikt hetzelfde pictogram als icon.
<template>
<UInputRating empty-icon="i-lucide-circle" icon="i-lucide-circle-check" :default-value="3" />
</template>Kleur
Gebruik de color prop om de kleur van de gevulde sterren te veranderen.
<template>
<UInputRating color="neutral" :default-value="4" />
</template>Grootte
Gebruik de size prop om de grootte van de sterren te veranderen.
<template>
<UInputRating size="xl" :default-value="4" />
</template>Oriëntatie
Gebruik de orientation prop om de oriëntatie van de classificatie te wijzigen. Standaard is horizontal.
<template>
<UInputRating orientation="vertical" :default-value="4" />
</template>Uitgeschakeld
Gebruik de disabled-prop om de InputRating-component uit te schakelen. Indien uitgeschakeld, heeft de component een verminderde dekking (75%) en toont een not-allowed-cursor om aan te geven dat deze niet interactief is.
<template>
<UInputRating disabled :default-value="3" />
</template>Alleen-lezen
Gebruik de readonly-prop om een beoordeling weer te geven zonder gebruikersinteractie toe te staan. In tegenstelling tot disabled behoudt het een normaal uiterlijk (volledige dekking, standaardcursor).
Gebruik wanneer u een beoordeling wilt weergeven die niet kan worden gewijzigd, maar er normaal uit moet zien.
<template>
<UInputRating readonly :default-value="4.5" />
</template>API
Props
| Prop | Default | Type |
|---|---|---|
as | 'div' | anyThe element or component this component should render as. |
id | stringThe id of the rating. | |
readonly | false | boolean Make the rating readonly (non-interactive). |
icon | appConfig.ui.icons.star | anyThe icon displayed for each rating value. |
emptyIcon | anyThe icon displayed for empty rating values. Defaults to | |
color | 'primary' | "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" |
size | 'md' | "xs" | "sm" | "md" | "lg" | "xl" |
orientation | 'horizontal' | "horizontal" | "vertical"The orientation of the rating. |
step | 1 | 1 | 0.5 | 0.25 | 0.1The granularity each rating item is divided into. |
disabled | boolean When | |
required | boolean When | |
name | stringThe name of the field. Submitted with its owning form as part of a name/value pair. | |
defaultValue | 0 | numberThe rating value when initially rendered. Use when you do not need to control the state of the rating. |
modelValue | numberThe controlled rating value. Can be bound with | |
length | 5 | numberThe number of rating items to render. |
clearable | false | boolean When |
hoverable | false | boolean When |
ui | { root?: SlotClass; item?: SlotClass; indicator?: SlotClass; icon?: SlotClass; emptyIcon?: SlotClass; } |
Slots
| Slot | Type |
|---|---|
item | { index: number; filled: boolean; }Rendered for each item. |
Uitzendt
| Event | Type |
|---|---|
update:modelValue | [payload: number] |
change | [event: Event] |
Thema
export default defineAppConfig({
ui: {
inputRating: {
slots: {
root: '',
item: [
'relative inline-block cursor-pointer select-none rounded-sm has-focus-visible:outline-3',
'transition'
],
indicator: 'absolute inset-0 overflow-hidden outline-none text-transparent w-(--reka-rating-item-step-width) opacity-(--reka-rating-item-step-opacity) z-(--reka-rating-item-step-z-index)',
icon: 'block',
emptyIcon: 'block w-full h-full text-muted pointer-events-none'
},
variants: {
orientation: {
horizontal: {
root: 'inline-flex items-center gap-0.5'
},
vertical: {
root: 'inline-flex flex-col items-center gap-0.5'
}
},
size: {
xs: {
item: 'size-3',
icon: 'size-3'
},
sm: {
item: 'size-4',
icon: 'size-4'
},
md: {
item: 'size-5',
icon: 'size-5'
},
lg: {
item: 'size-6',
icon: 'size-6'
},
xl: {
item: 'size-7',
icon: 'size-7'
}
},
color: {
primary: {
indicator: 'data-[state=active]:text-primary',
item: 'outline-primary/25'
},
secondary: {
indicator: 'data-[state=active]:text-secondary',
item: 'outline-secondary/25'
},
success: {
indicator: 'data-[state=active]:text-success',
item: 'outline-success/25'
},
info: {
indicator: 'data-[state=active]:text-info',
item: 'outline-info/25'
},
warning: {
indicator: 'data-[state=active]:text-warning',
item: 'outline-warning/25'
},
error: {
indicator: 'data-[state=active]:text-error',
item: 'outline-error/25'
},
neutral: {
indicator: 'data-[state=active]:text-highlighted',
item: 'outline-inverted/25'
}
},
readonly: {
true: {
root: 'cursor-default',
item: 'cursor-default'
},
false: {}
},
disabled: {
true: {
root: 'opacity-75 cursor-not-allowed',
item: 'cursor-not-allowed pointer-events-none'
},
false: {}
}
},
compoundVariants: [
{
readonly: false,
disabled: false,
class: {
item: 'hover:scale-110'
}
}
],
defaultVariants: {
color: 'primary',
size: 'md'
}
}
}
})import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
inputRating: {
slots: {
root: '',
item: [
'relative inline-block cursor-pointer select-none rounded-sm has-focus-visible:outline-3',
'transition'
],
indicator: 'absolute inset-0 overflow-hidden outline-none text-transparent w-(--reka-rating-item-step-width) opacity-(--reka-rating-item-step-opacity) z-(--reka-rating-item-step-z-index)',
icon: 'block',
emptyIcon: 'block w-full h-full text-muted pointer-events-none'
},
variants: {
orientation: {
horizontal: {
root: 'inline-flex items-center gap-0.5'
},
vertical: {
root: 'inline-flex flex-col items-center gap-0.5'
}
},
size: {
xs: {
item: 'size-3',
icon: 'size-3'
},
sm: {
item: 'size-4',
icon: 'size-4'
},
md: {
item: 'size-5',
icon: 'size-5'
},
lg: {
item: 'size-6',
icon: 'size-6'
},
xl: {
item: 'size-7',
icon: 'size-7'
}
},
color: {
primary: {
indicator: 'data-[state=active]:text-primary',
item: 'outline-primary/25'
},
secondary: {
indicator: 'data-[state=active]:text-secondary',
item: 'outline-secondary/25'
},
success: {
indicator: 'data-[state=active]:text-success',
item: 'outline-success/25'
},
info: {
indicator: 'data-[state=active]:text-info',
item: 'outline-info/25'
},
warning: {
indicator: 'data-[state=active]:text-warning',
item: 'outline-warning/25'
},
error: {
indicator: 'data-[state=active]:text-error',
item: 'outline-error/25'
},
neutral: {
indicator: 'data-[state=active]:text-highlighted',
item: 'outline-inverted/25'
}
},
readonly: {
true: {
root: 'cursor-default',
item: 'cursor-default'
},
false: {}
},
disabled: {
true: {
root: 'opacity-75 cursor-not-allowed',
item: 'cursor-not-allowed pointer-events-none'
},
false: {}
}
},
compoundVariants: [
{
readonly: false,
disabled: false,
class: {
item: 'hover:scale-110'
}
}
],
defaultVariants: {
color: 'primary',
size: 'md'
}
}
}
})
]
})