@nhtio/common-vue
Provides the helper interfaces, types, variables and functions needed to create custom components.
Components
| Class | Description |
|---|---|
| BaseField | The BaseField component provides a base input field with support for Vue Composition API hooks, custom event handlers, and both VInput and VField functionality from Vuetify. Features include focus management, model value binding, and flexible slot support. |
Composables
| Function | Description |
|---|---|
| useBaseHooks | Composable that creates passthrough hooks for all BaseField events. Integrates with component props (onX handlers) and hook arrays (callOnX) to handle events. |
| useBaseProps | Composable that extracts and filters BaseField props into typed computed references. Provides both all defined props and a filtered set with undefined values removed. |
| useBaseSlots | Composable that extracts and provides typed slot renderer functions for all BaseField slots. Returns an object with individual slot renderer functions that safely invoke slots with proper typing. Each renderer function accepts slot parameters and returns the slot's render result or undefined. |
| useLocalizedModelValue | Composable for managing localized/transformed model values with bidirectional synchronization. |
| usePassthroughHook | Builds an event invoker that respects component-bound handlers and hook arrays before calling a fallback. |
Constants
| Name | Description |
|---|---|
| baseEmits | Emit definitions for the BaseField component. Contains all standard emit validators for field component events. |
| baseFieldBaseRawEmits | Base emit validators for the BaseField component. Defines all standard emit events that can be emitted by field components, including clicks, focus updates, and model value changes. |
| version | The current version of the package. |
| iconClose | Pre-configured close icon using Material Design Icons. Can be used as the clear icon or any other close icon action. |
Factories
| Name | Description |
|---|---|
| makeBaseProps | Factory function that creates props for the BaseField component. Returns a function that accepts optional defaults and returns fully typed prop definitions. |
| emitsFactory | Creates emit functions from emit validators. Simply type-casts validators to emit functions; the actual validation happens elsewhere. |
| propsAndEmitsFactory | Factory that combines props and emits definitions into a unified system. Automatically adds handler props (onX) for each emit, supporting both camelCase and kebab-case. |
Other
| Name | Description |
|---|---|
| BaseHookHandlers | - |
| IconValue | - |
| IconValue | - |
| VFieldSlots | - |
| VInputSlots | - |
| omit | - |
| pick | - |
Types
| Name | Description |
|---|---|
| EmitValidators | Interface for emit event validators. Each validator is a function that takes event arguments and returns a boolean indicating validity. |
| AppendDefault | Applies default values to component prop definitions. For each prop, if a default is provided, it updates the prop's default and type accordingly. |
| BaseClickAppendInnerHookHandler | Hook handler type for the 'click:appendInner' event |
| BaseClickClearHookHandler | Hook handler type for the 'click:clear' event |
| BaseClickControlHookHandler | Hook handler type for the 'click:control' event |
| BaseClickPrependInnerHookHandler | Hook handler type for the 'click:prependInner' event |
| BaseHookableEvents | Type for the hookable events of BaseField |
| BaseHookableRawEvents | Type for the raw emit validators of BaseField |
| BaseHooks | Type for the hooks system for BaseField |
| BaseMousedownControlHookHandler | Hook handler type for the 'mousedown:control' event |
| BaseProps | The public prop types of the BaseField component |
| BaseSetupProps | The complete prop types (including setup) of the BaseField component |
| BaseSlots | The slot types of the BaseField component, combining VInput and VField slots |
| BaseUpdateFocusedHookHandler | Hook handler type for the 'update:focused' event |
| BaseUpdateModelValueHookHandler | Hook handler type for the 'update:modelValue' event |
| CastToEmitValidators | Converts emit functions back into emit validators. Maps emit functions (args => void) to validator signatures (args => boolean). |
| ComponentPublicInstanceType | Utility type that merges a component constructor's instance type with Vue's ComponentPublicInstance. Provides proper typing for component instances that includes both the component's own properties/methods and Vue's public instance API (e.g., $el, $emit, $props, etc.). |
| EmitFunctions | Converts emit validators into emit functions. Maps validator signatures (args => boolean) to emit functions (args => void). |
| EmitHandlerProps | Type helper that generates emit handler prop types from emit validators. Creates both camelCase and kebab-case variants for each emit. |
| ExtractPrivatePropTypesFromFactory | Extracts the complete (including private) prop types from a prop factory function. |
| ExtractPublicPropTypesFromFactory | Extracts the public prop types from a prop factory function. Useful for obtaining the public prop interface from a factory that returns prop definitions. |
| ExtractSlotDefinitions | Extracts the slot definitions from a component with a slots property. Works with both components that have a slots property and direct SlotsType definitions. |
| FieldHookHandler | Handler type for field hooks that can be either a direct handler or a provider. |
| HookableEvents | Converts emit validators/functions into hookable events with cleanup support. Each event gets a tuple of [callbackArgs, cleanupCallbackArgs] to support hook lifecycle. |
| IfAny | Conditional type that returns Y if T is any, otherwise returns N. |
| InferPropType | Infers the actual prop type from a Vue prop definition. Handles string/number/boolean constructors, prop objects with type, defaults, and more. |
| MergeDefault | Merges a prop type with a default value, making the prop type non-nullable. |
| MergeTypeDefault | Merges a prop type with a default value type. If no default is provided, returns just the prop type; otherwise returns the union. |
| NamedSlotParameters | Extracts the parameter types from a named slot by name. |
| ObjectStrippedOfUndefinedValues | Type utility that removes all keys with undefined values from an object type. |
| PartialKeys | Creates a type where all keys are optional and values are unknown. Useful for partial key matching in conditional types. |
| PropFactory | A factory function type that creates prop definitions with optional defaults. Returns a function that takes optional defaults and returns props with those defaults applied. |
| ResolvedBaseProps | Resolved prop types with proper type inference from the BaseField props factory |
| SlotParameters | Extracts the parameter types from a slot function. |
| UsePassthroughHookOptions | Options for usePassthroughHook that control when and how a fallback is executed and how the produced handler is scheduled. |
| VFieldDefaultSlotProps | The prop types for the default slot of Vuetify's VField component. Provides typed access to the props passed to VField's default slot, including field state, focus handlers, and validation status. |
Utilities
| Function | Description |
|---|---|
| isHTMLElement | Type guard that checks if a value is an HTMLElement. Safe to use in SSR environments. |
| isObject | Type guard that checks if a value is a plain object (not null, not an array). |
| stripUndefinedValuesFromObject | Removes all properties with undefined values from an object. This is useful for cleaning up objects before passing them to APIs or components that should not receive undefined values. |
| svgPathToIconValue | Converts an SVG path string to an IconValue that can be used in Vuetify components. |
| useSlot | Retrieves a slot from the slots object with proper typing. |