Repository URL to install this package:
|
Version:
3.7.1 ▾
|
/**
* @todo @name InputPluginsContext
*/
import { createContext } from 'react'
import { ComponentClass } from 'react'
import {
Value,
AnyObj,
SerializerFunction,
ValidatorFunction,
} from '../typings'
export interface InputPluginIsSatisfiedByArg {
[key: string]: any
type: string
}
export interface DefaultStateReturn<Props = AnyObj> {
serializer?: SerializerFunction
validator?: ValidatorFunction
type?: string
attributes?: Props
formState?: any
propertyName?: string
label?: string
value?: Value
identifier?: string
isActive?: boolean
isSelected?: boolean
// anything else would end up in .attributes
[key: string]: any
}
// @todo type...
export type DefaultStateFunction = <InputState = any>(
inputState: InputState
) => DefaultStateReturn
export interface InputPluginStaticTypes {
// or defaultState keyof InputState
defaultState?: DefaultStateReturn | DefaultStateFunction
isSatisfiedByProps: (props: InputPluginIsSatisfiedByArg) => boolean
}
export type InputPluginType<Type = any> = ComponentClass<Type> &
InputPluginStaticTypes
// @todo InputPlugin[]
export type PluginsContextValue = InputPluginType[]
export const PluginsContext = createContext<PluginsContextValue>(
undefined as any
)
export const { Provider, Consumer } = PluginsContext