Skip to content

@nhtio/common-vue

Provides the helper interfaces, types, variables and functions needed to create custom components.

Components

ClassDescription
BaseFieldThe 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

FunctionDescription
useBaseHooksComposable that creates passthrough hooks for all BaseField events. Integrates with component props (onX handlers) and hook arrays (callOnX) to handle events.
useBasePropsComposable that extracts and filters BaseField props into typed computed references. Provides both all defined props and a filtered set with undefined values removed.
useBaseSlotsComposable 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.
useComputedObjectFromPropsCreates a computed object by picking specific props and merging them with overrides. This composable is designed for cases where you need to transform a subset of component props into a specific target type, combining selected reactive prop values with static overrides.
useLocalizedModelValueComposable for managing localized/transformed model values with bidirectional synchronization.
usePassthroughHookBuilds an event invoker that respects component-bound handlers and hook arrays before calling a fallback.
usePropsProxyCreates a computed proxy that unwraps reactive props and merges them with override values. Useful for creating a reactive object that combines component props with custom values, while optionally excluding specific prop keys.

Constants

NameDescription
baseEmitsEmit definitions for the BaseField component. Contains all standard emit validators for field component events.
baseFieldBaseRawEmitsBase 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.
versionThe current version of the package.
iconClosePre-configured close icon using Material Design Icons. Can be used as the clear icon or any other close icon action.

Factories

NameDescription
makeBasePropsFactory function that creates props for the BaseField component. Returns a function that accepts optional defaults and returns fully typed prop definitions.
emitsFactoryCreates emit functions from emit validators. Simply type-casts validators to emit functions; the actual validation happens elsewhere.
propsAndEmitsFactoryFactory that combines props and emits definitions into a unified system. Automatically adds handler props (onX) for each emit, supporting both camelCase and kebab-case.

Types

NameDescription
EmitValidatorsInterface for emit event validators. Each validator is a function that takes event arguments and returns a boolean indicating validity.
AppendDefaultApplies default values to component prop definitions. For each prop, if a default is provided, it updates the prop's default and type accordingly.
BaseClickAppendInnerHookHandlerHook handler type for the 'click:appendInner' event
BaseClickClearHookHandlerHook handler type for the 'click:clear' event
BaseClickControlHookHandlerHook handler type for the 'click:control' event
BaseClickPrependInnerHookHandlerHook handler type for the 'click:prependInner' event
BaseHookableEventsType for the hookable events of BaseField
BaseHookableRawEventsType for the raw emit validators of BaseField
BaseHookHandlersGeneric hook handler type for BaseField events. Creates a typed hook handler for a specific event from the BaseField's hookable events. Can be either a direct handler function or a provider that returns a handler.
BaseHooksType for the hooks system for BaseField
BaseMousedownControlHookHandlerHook handler type for the 'mousedown:control' event
BasePropsThe public prop types of the BaseField component
BaseSetupPropsThe complete prop types (including setup) of the BaseField component
BaseSlotsThe slot types of the BaseField component, combining VInput and VField slots
BaseUpdateFocusedHookHandlerHook handler type for the 'update:focused' event
BaseUpdateModelValueHookHandlerHook handler type for the 'update:modelValue' event
CastToEmitValidatorsConverts emit functions back into emit validators. Maps emit functions (args => void) to validator signatures (args => boolean).
ComponentPublicInstanceTypeUtility 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.).
EmitFunctionsConverts emit validators into emit functions. Maps validator signatures (args => boolean) to emit functions (args => void).
EmitHandlerPropsType helper that generates emit handler prop types from emit validators. Creates both camelCase and kebab-case variants for each emit.
ExtractEmitsFromArrayExtracts emit validators from array format emits definition.
ExtractEmitsFromObjectExtracts emit validators from object format emits definition.
ExtractEmitsFromPropsExtracts emit validators from a component's props (event handlers). Maps event handler props like 'onUpdate:modelValue' to validator format.
ExtractEmitValidatorsFromComponentExtracts emit validators from a Vue component definition. This type utility examines both: 1. The component's .emits property (array or object format) 2. The component's prop types for event handlers (onEventName props)
ExtractEventArgsFromPropHelper to extract event arguments from emit handler prop type.
ExtractEventNamesFromPropsHelper to extract event names from emit handler props (onEventName format). Converts prop names like 'onUpdate:modelValue' or 'onUpdateModelValue' to event names. Filters out Vue internal events (vnode*, $*).
ExtractPrivatePropTypesFromFactoryExtracts the complete (including private) prop types from a prop factory function.
ExtractPublicPropTypesFromFactoryExtracts the public prop types from a prop factory function. Useful for obtaining the public prop interface from a factory that returns prop definitions.
ExtractSlotDefinitionsExtracts the slot definitions from a component with a slots property. Works with both components that have a slots property and direct SlotsType definitions.
FieldHookHandlerHandler type for field hooks that can be either a direct handler or a provider.
GetComponentInstanceHelper to get component instance type from constructor or component definition.
GetComponentPropsHelper to get component props from instance.
HookableEventsConverts emit validators/functions into hookable events with cleanup support. Each event gets a tuple of [callbackArgs, cleanupCallbackArgs] to support hook lifecycle.
IconValueType representing an icon value that can be used in Vuetify components. Can be a string (icon name), component, or function that returns a component.
IconValueType representing an icon value that can be used in Vuetify components. Can be a string (icon name), component, or function that returns a component.
IfAnyConditional type that returns Y if T is any, otherwise returns N.
InferPropTypeInfers the actual prop type from a Vue prop definition. Handles string/number/boolean constructors, prop objects with type, defaults, and more.
MergeDefaultMerges a prop type with a default value, making the prop type non-nullable.
MergeTypeDefaultMerges a prop type with a default value type. If no default is provided, returns just the prop type; otherwise returns the union.
NamedSlotParametersExtracts the parameter types from a named slot by name.
ObjectStrippedOfUndefinedValuesType utility that removes all keys with undefined values from an object type.
PartialKeysCreates a type where all keys are optional and values are unknown. Useful for partial key matching in conditional types.
PropFactoryA factory function type that creates prop definitions with optional defaults. Returns a function that takes optional defaults and returns props with those defaults applied.
RemoveIndexSignatureHelper to remove index signatures from a type, keeping only explicit keys.
ResolvedBasePropsResolved prop types with proper type inference from the BaseField props factory
SlotParametersExtracts the parameter types from a slot function.
UsePassthroughHookOptionsOptions for usePassthroughHook that control when and how a fallback is executed and how the produced handler is scheduled.
VFieldDefaultSlotPropsThe 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.
VFieldSlotsSlot definitions for Vuetify's VField component. Includes slots for field elements like prepend-inner, append-inner, clear, label, and loader.
VInputSlotsSlot definitions for Vuetify's VInput component. Includes slots for input wrapper elements like prepend, append, details, and message.

Utilities

FunctionDescription
extractEmitsFromComponentCtorExtracts emit validators from a Vue component's emits definition. Supports both array format (event names only) and object format (with validators).
getCamelAndMaybeKebabPropKeysForConverts an event name to both camelCase and kebab-case handler prop names. Handles events with colons by treating the first part specially (prepending 'on').
isHTMLElementType guard that checks if a value is an HTMLElement. Safe to use in SSR environments.
isObjectType guard that checks if a value is a plain object (not null, not an array).
omitUtility function that creates a new object with specified keys removed. Useful for filtering out unwanted properties from an object.
pickUtility function that creates a new object with only specified keys included. Useful for extracting a subset of properties from an object.
stripUndefinedValuesFromObjectRemoves 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.
svgPathToIconValueConverts an SVG path string to an IconValue that can be used in Vuetify components.
useSlotRetrieves a slot from the slots object with proper typing.
useSlotRendererCreates a slot renderer function that safely invokes a slot with proper typing. Returns a function that will render the slot if provided, or return undefined if not.