VfIcon
Basic
VfIcon renders a single icon element. It is used when overriding the iconBefore or iconAfter slot of an element to provide a custom icon. It receives an icon prop with the icon class string.
vue
<VfText name="search" label="Search" icon-before="search">
<template #icon-before>
<VfIcon icon="search" />
</template>
</VfText>vue
<template>
<VfText name="search" label="Search" icon-before="search">
<template #icon-before>
<VfIcon icon="search" />
</template>
</VfText>
</template>vue
<script setup lang="ts">
import { defineSchema, defineSlot, useForm } from '@vueform/ui'
import { h, resolveComponent } from 'vue'
const schema = defineSchema({
search: {
type: 'text',
label: 'Search',
iconBefore: 'search',
slots: {
'icon-before': defineSlot('VfText.icon-before', {
setup: () => () => {
const VfIcon = resolveComponent('VfIcon')
return h(VfIcon, { icon: 'search' })
},
}),
},
},
})
const [Form] = useForm({ schema })
</script>
<template>
<Form />
</template>Props
Configure the component's behavior and appearance with these props.
Component
| Prop | Default | Description |
|---|---|---|
icon | — | The icon class string to render. |
Customization
| Prop | Default | Description |
|---|---|---|
parts | — | Custom DOM attribute overrides for the component's structural parts. |
class | — | CSS classes to apply to the component's root element. |
classes | — | Custom CSS class overrides for the component's structural parts. |
reclass | — | CSS class overrides that replace (rather than merge with) default classes. |
slots | — | Custom Vue components to use for named slots. Every component resolves it through the standard outlets pipeline (see useOutlets). |
presets | — | Named configuration presets to apply to the component. |
template | — | A custom Vue component to use as the template instead of the default. |
component | — | A custom Vue component to render in the component's default slot. |
Context
Reactive properties and methods accessible on the component's Context object.
General
| Name | Description |
|---|---|
props | The resolved component props with defaults applied. |
Layout
| Name | Description |
|---|---|
classes | The resolved CSS class map for the component. |
parts | The resolved DOM attribute overrides for internal elements. |
Events
| Name | Description |
|---|---|
fire() | Fires an event synchronously, invoking before, main, and after listeners in order. |
fireAsync() | Fires an event asynchronously, awaiting each callback and short-circuiting when any returns false. |
on() | Subscribes a callback to a specific event. |
off() | Removes a previously registered event callback. |
onBefore() | Registers a callback that runs before the main event listeners. |
onAfter() | Registers a callback that runs after the main event listeners. |
Events
Events emitted by the component. See Events for details.
| Name | Params | Description |
|---|---|---|
beforeMount | context$ | Emitted before the component is mounted. |
mounted | context$ | Emitted after the component is mounted. |
beforeUnmount | context$ | Emitted before the component is unmounted. |
unmounted | context$ | Emitted after the component is unmounted. |
updated | context$ | Emitted after the component is updated. |
Slots
Named Slots for replacing parts of the component's rendering.
| Name | Scope | Description |
|---|---|---|
template | context | Slot that replaces the entire component rendering. Receives the full component context as a single context prop. |
Parts
DOM attribute overrides targeting internal elements. See Parts for details.
Example
root
The root icon element.
| Element | <i> |
| Classes | .vf-icon |
Tokens
All the CSS variables that control this component's appearance with default values in the default theme. See Themes & Tokens for details.
css
:root {
/**
* Component tokens
* -------------------------------------------------------------------------- */
--vf-input-border-width-l: var(--vf-border-width-l);
--vf-icon-font-size: 0.875rem;
--vf-icon-group-color: inherit;
--vf-icon-group-color-danger: var(--vf-color-danger);
--vf-icon-group-width: 2.5rem;
}ts
{
/**
* Component tokens
* -------------------------------------------------------------------------- */
inputBorderWidthL: '$borderWidthL',
iconFontSize: '0.875rem',
iconGroupColor: 'inherit',
iconGroupColorDanger: '$colorDanger',
iconGroupWidth: '2.5rem',
}