useControls
useControls() returns the set of controls that JSON-described forms and table cell editors pick a control from by name, for example text or date. The ready-made set of Numior UI controls is kitControls from @numior/kit/controls.
Build your own set with defineControls. The entry text: control(NuiInput, isString) means: the name text renders NuiInput, and its value is a string. Pass the set to createNuiConfig({ controls }) or to provideControls.
- Text
- Number
- Switch
The control returned "".
Signature
useControls: () => NuiControlRegistry | nullprovideControls: (registry: NuiControlRegistry) => voiddefineControls: <R extends NuiControlRegistry>(registry: R) => Rcontrol: <C extends Component, V extends ControlValue<C, M>, M extends string = "modelValue">(component: C & EmitsInto<C, V, M>, accepts: Guard<V>, options?: ControlOptions<M>) => NuiControlEntry<C, V, M | "modelValue">controlProps: <S extends Shape>(shape: S) => Guard<ShapeOf<S>>interface NuiControlEntry<C extends Component = Component, V = unknown, M extends string = string> { readonly component: C; readonly model: M; readonly accepts: Guard<V>; readonly props: Guard<Readonly<Record<string, unknown>>>;}type NuiControlRegistry = Readonly<Record<string, NuiControlEntry>>;type ControlProps<C, M extends string = 'modelValue'> = Omit<ComponentProps<C>, ControlKeys | ModelKeys<M>> & Omit<InputHTMLAttributes, ControlKeys | ModelKeys<M> | 'value'>;type ControlValue<C, M extends string = 'modelValue'> = ComponentProps<C> extends { readonly [K in M]: infer V;} ? V : ComponentProps<C> extends { readonly [K in M]?: infer V;} ? V | undefined : unknown;Behaviour
control(component, accepts, { model, props }) checks at the type level that the component value fits the accepts check. model is the name of the component model, modelValue by default.
props checks the props that a form or table passes to the control. controlProps(shape) builds a strict check: a prop with an unknown name or a value of the wrong type fails. Without props the control accepts any props.
When no set is passed in the settings or through provideControls, useControls() returns null.